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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在機器學習中混洗如何與 ImageDataGenerator 一起工作?

在機器學習中混洗如何與 ImageDataGenerator 一起工作?

三國紛爭 2021-05-30 16:09:48
我正在使用Inception V3創(chuàng)建圖像分類模型,并且有兩個類。我將數(shù)據(jù)集和標簽分為兩個numpy數(shù)組,數(shù)據(jù)分別以trainX和testY作為圖像,trainY和testY作為對應的標簽。data = np.array(data, dtype="float")/255.0labels = np.array(labels,dtype ="uint8")(trainX, testX, trainY, testY) = train_test_split(                                data,labels,                                 test_size=0.2,                                 random_state=42) train_datagen = keras.preprocessing.image.ImageDataGenerator(          zoom_range = 0.1,          width_shift_range = 0.2,           height_shift_range = 0.2,          horizontal_flip = True,          fill_mode ='nearest') val_datagen = keras.preprocessing.image.ImageDataGenerator()train_generator = train_datagen.flow(        trainX,         trainY,        batch_size=batch_size,        shuffle=True)validation_generator = val_datagen.flow(                testX,                testY,                batch_size=batch_size) 當我使用 ImageDataGenerator shuffle train_generator 時,圖像是否仍然匹配相應的標簽?驗證數(shù)據(jù)集也應該改組嗎?
查看完整描述

1 回答

?
慕森王

TA貢獻1777條經(jīng)驗 獲得超3個贊

是的,圖像仍會匹配相應的標簽,因此您可以安全地設置shuffle為True。在引擎蓋下,其工作方式如下。調(diào)用.flow()的ImageDataGenerator將返回一個NumpyArrayIterator對象,它實現(xiàn)了洗牌的指標以下邏輯:


def _set_index_array(self):

    self.index_array = np.arange(self.n)

    if self.shuffle: # if shuffle==True, shuffle the indices

        self.index_array = np.random.permutation(self.n) 

self.index_array然后用于生成圖像(x)和標簽(y)(為了可讀性而截斷了代碼):


def _get_batches_of_transformed_samples(self, index_array):

    batch_x = np.zeros(tuple([len(index_array)] + list(self.x.shape)[1:]),

                       dtype=self.dtype)

    # use index_array to get the x's

    for i, j in enumerate(index_array):

        x = self.x[j]

        ... # data augmentation is done here

        batch_x[i] = x

     ...

     # use the same index_array to fetch the labels

     output += (self.y[index_array],)


    return output

自己檢查源代碼,它可能比您想象的要容易理解。


改組驗證數(shù)據(jù)應該沒什么大不了的。改組的主要目的是在訓練過程中引入一些額外的隨機性。


查看完整回答
反對 回復 2021-06-01
  • 1 回答
  • 0 關注
  • 187 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號