Python Keras使用datagenerator';直接从文件夹合并层加载输入;来自目录方法的流。
是否有一种方法可以使用datagenerator和flow_from_directory将数据从目录加载到带有2个输入张量的合并层Python Keras使用datagenerator';直接从文件夹合并层加载输入;来自目录方法的流。,python,numpy,keras,Python,Numpy,Keras,是否有一种方法可以使用datagenerator和flow_from_directory将数据从目录加载到带有2个输入张量的合并层 x = merge([base_x, base_y], mode='concat', concat_axis=1) x = Dense(256, activation='relu', name="fc-1")(x) x = Dropout(0.5)(x) predictions = Dense(2, activation='softmax
x = merge([base_x, base_y], mode='concat', concat_axis=1)
x = Dense(256, activation='relu', name="fc-1")(x)
x = Dropout(0.5)(x)
predictions = Dense(2, activation='softmax', name='predictions')(x)
model = Model(input=[base_x.input, base_y.input], output=predictions)
# note that it is necessary to start with a fully-trained
# classifier, including the top classifier,
# in order to successfully do fine-tuning
# add the model on top of the convolutional base
print('Model loaded.')
# compile the model with a SGD/momentum optimizer
# and a very slow learning rate.
model.compile(loss="categorical_crossentropy",
optimizer=optimizers.SGD(lr=1e-4, momentum=0.9),
metrics=['accuracy'])
model.summary()
# prepare data augmentation configuration
train_datagen = ImageDataGenerator(
rescale=1. / 255,
)
test_datagen = ImageDataGenerator(rescale=1. / 255)
train_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size=(img_height, img_width),
batch_size=32,
class_mode='categorical')
validation_generator = test_datagen.flow_from_directory(
validation_data_dir,
target_size=(img_height, img_width),
batch_size=32,
class_mode='categorical')
model.fit_generator(
train_generator,
samples_per_epoch=train_generator.nb_sample,
nb_epoch=150,
validation_data=validation_generator,
nb_val_samples=3000)
文件夹的结构如下所示
train_dir --
--> category 1
--> category 2
Test_dir --
--> category 1
--> category 2
我想运行这个模型,直接从目录中读取数据。但我得到的例外是
ValueError: The model expects 2 input arrays, but only received one array. Found: array with shape (32, 224, 224, 3
如何直接从目录添加2个输入数组。不希望将输入转换为Numpy数组。I输入应该从目录本身读取。是否有方法执行此操作