第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

從圖像本地目錄創(chuàng)建 tensorflow 數(shù)據(jù)集

從圖像本地目錄創(chuàng)建 tensorflow 數(shù)據(jù)集

蕪湖不蕪 2021-11-02 16:50:16
我在本地有一個(gè)非常龐大的圖像數(shù)據(jù)庫(kù),數(shù)據(jù)分布就像每個(gè)文件夾都包含一個(gè)類的圖像。我想使用 tensorflow 數(shù)據(jù)集 API 來(lái)批量獲取數(shù)據(jù),而無(wú)需將所有圖像加載到內(nèi)存中。我試過(guò)這樣的事情:def _parse_function(filename, label):    image_string = tf.read_file(filename, "file_reader")    image_decoded = tf.image.decode_jpeg(image_string, channels=3)    image = tf.cast(image_decoded, tf.float32)    return image, labelimage_list, label_list, label_map_dict = read_data()dataset = tf.data.Dataset.from_tensor_slices((tf.constant(image_list), tf.constant(label_list)))dataset = dataset.shuffle(len(image_list))dataset = dataset.repeat(epochs).batch(batch_size)dataset = dataset.map(_parse_function)iterator = dataset.make_one_shot_iterator()image_list 是一個(gè)列表,其中附加了圖像的路徑(和名稱),label_list 是一個(gè)列表,其中每個(gè)圖像的類都以相同的順序附加。但是 _parse_function 不起作用,我的錯(cuò)誤是:ValueError: Shape must be rank 0 but is rank 1 for 'file_reader' (op: 'ReadFile') with input shape: [?]。我用谷歌搜索了錯(cuò)誤,但對(duì)我沒(méi)有任何作用。如果我不使用 map 函數(shù),我只是記錄圖像的路徑(它們存儲(chǔ)在 image_list 中),所以我認(rèn)為我需要 map 函數(shù)來(lái)讀取圖像,但我無(wú)法使其工作。先感謝您。編輯:    def read_data():        image_list = []        label_list = []        label_map_dict = {}        count_label = 0        for class_name in os.listdir(base_path):            class_path = os.path.join(base_path, class_name)            label_map_dict[class_name]=count_label            for image_name in os.listdir(class_path):                image_path = os.path.join(class_path, image_name)                label_list.append(count_label)                image_list.append(image_path)            count_label += 1
查看完整描述

1 回答

?
泛舟湖上清波郎朗

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超3個(gè)贊

錯(cuò)誤在這一行dataset = dataset.repeat(epochs).batch(batch_size)您的管道將批量大小添加為輸入的維度。


您需要像這樣在 map 函數(shù)之后批處理您的數(shù)據(jù)集


    dataset = tf.data.Dataset.from_tensor_slices((tf.constant(image_list), tf.constant(label_list)))

    dataset = dataset.shuffle(len(image_list))

    dataset = dataset.repeat(epochs)

    dataset = dataset.map(_parse_function).batch(batch_size)


查看完整回答
反對(duì) 回復(fù) 2021-11-02
  • 1 回答
  • 0 關(guān)注
  • 235 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)