1 回答

TA贡献1777条经验 获得超3个赞
是的,图像仍会匹配相应的标签,因此您可以安全地设置shuffle为True。在引擎盖下,其工作方式如下。调用.flow()的ImageDataGenerator将返回一个NumpyArrayIterator对象,它实现了洗牌的指标以下逻辑:
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
自己检查源代码,它可能比您想象的要容易理解。
改组验证数据应该没什么大不了的。改组的主要目的是在训练过程中引入一些额外的随机性。
添加回答
举报