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ù)應該沒什么大不了的。改組的主要目的是在訓練過程中引入一些額外的隨機性。
添加回答
舉報