现在,我能够在图像数据上训练和测试神经网络。我希望能够从DirectoryIterator train_generator中提取图像数据和相应的标签,以便也许可以改组此数据并执行交叉验证。有没有一种方法可以提取(如果需要的话可以格式化)这些数据?
from keras.preprocessing.image import ImageDataGenerator
img_width, img_height = 150, 150
train_data_dir = '/train'
datagen = ImageDataGenerator(rescale=1./255) #rescales [0,1]
train_generator = datagen.flow_from_directory(train_data_dir, target_size=(img_width, img_height), shuffle=True, batch_size=32, class_mode='binary')
#I want to do something like (X, Y) = train_generator.getData()
答案 0 :(得分:-1)
train_generator = datagen.flow_from_directory(
train_data_dir,
target_size=(img_width, img_height),
shuffle=True,
batch_size=SIZE_OF_DATASET, ## change to size of entire dataset
class_mode='binary')
for X, Y in train_generator:
break