本文介绍了如何在多个输入中使用 fit_generator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以有两个 fit_generator 吗?
Is it possible to have two fit_generator?
我正在创建一个具有两个输入的模型,模型配置如下所示.
I'm creating a model with two inputs,The model configuration is shown below.
标签 Y 对 X1 和 X2 数据使用相同的标签.
Label Y uses the same labeling for X1 and X2 data.
以下错误将继续发生.
检查模型输入时出错:您传递给模型的 Numpy 数组列表不是模型预期的大小.预期的查看 2 个数组,但得到了以下 1 个数组的列表:[数组([[[[0.75686276, 0.75686276, 0.75686276],[0.75686276, 0.75686276, 0.75686276],[0.75686276, 0.75686276, 0.75686276],...,[0.65882355, 0.65882355, 0.65882355...
我的代码如下:
def generator_two_img(X1, X2, Y,batch_size):
generator = ImageDataGenerator(rotation_range=15,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest')
genX1 = generator.flow(X1, Y, batch_size=batch_size)
genX2 = generator.flow(X2, Y, batch_size=batch_size)
while True:
X1 = genX1.__next__()
X2 = genX2.__next__()
yield [X1, X2], Y
"""
.................................
"""
hist = model.fit_generator(generator_two_img(x_train, x_train_landmark,
y_train, batch_size),
steps_per_epoch=len(x_train) // batch_size, epochs=nb_epoch,
callbacks = callbacks,
validation_data=(x_validation, y_validation),
validation_steps=x_validation.shape[0] // batch_size,
`enter code here`verbose=1)
推荐答案
试试这个生成器:
def generator_two_img(X1, X2, y, batch_size):
genX1 = gen.flow(X1, y, batch_size=batch_size, seed=1)
genX2 = gen.flow(X2, y, batch_size=batch_size, seed=1)
while True:
X1i = genX1.next()
X2i = genX2.next()
yield [X1i[0], X2i[0]], X1i[1]
3 个输入的生成器:
def generator_three_img(X1, X2, X3, y, batch_size):
genX1 = gen.flow(X1, y, batch_size=batch_size, seed=1)
genX2 = gen.flow(X2, y, batch_size=batch_size, seed=1)
genX3 = gen.flow(X3, y, batch_size=batch_size, seed=1)
while True:
X1i = genX1.next()
X2i = genX2.next()
X3i = genX3.next()
yield [X1i[0], X2i[0], X3i[0]], X1i[1]
这篇关于如何在多个输入中使用 fit_generator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!