如何为一个输出输入多个图像并拟合 ImageDataGenerator 数据 Tensorflow

How to input Multiple Image for one output and fit ImageDataGenerator data Tensorflow

提问人:Mert Erişen 提问时间:11/18/2023 最后编辑:Christoph RackwitzMert Erişen 更新时间:11/19/2023 访问量:36

问:

我正在使用 ImageDataGenerator 加载数据。我的代码如下,当我尝试适合时,我收到错误此错误:

ValueError:找不到可以处理输入的数据适配器:(<class 'list'> 包含 {“<class 'keras.src.preprocessing.image.DirectoryIterator'>”})、<class 'NoneType' 类型的值>

from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.layers import Input, Conv2D, MaxPooling2D, Flatten, Dense

# Loading Data
train_a = ImageDataGenerator(rescale=1/255)
train_a_gen = train_a.flow_from_directory(path+'/a/', target_size=(500, 500), batch_size=32, class_mode='binary')

train_b = ImageDataGenerator(rescale=1/255)
train_b_gen = train_b.flow_from_directory(path+'/b/', target_size=(500, 500), batch_size=32, class_mode='binary')

# Layers
conv1 = Conv2D(32, (3, 3), activation='relu')
pool1 = MaxPool2D(pool_size=(2, 2))
conv2 = Conv2D(64, (3, 3), activation='relu')
pool2 = MaxPool2D(pool_size=(2, 2))
flatten = Flatten()

input_a = Input(shape=(500, 500, 3))
input_b = Input(shape=(500, 500, 3))

x1 = flatten(pool2(conv2(pool1(conv1(x1)))))
x2 = flatten(pool2(conv2(pool1(conv1(x2)))))

merged = tf.keras.layers.Concatenate()([x1, x2])

dense1 = tf.keras.layers.Dense(64, activation='relu')(merged)
output = tf.keras.layers.Dense(1, activation='softmax')(dense1)

model = Model(inputs=[input_a, input_b], outputs=output)
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

history = model.fit(
    [train_a_gen, train_b_gen],
    epochs=10,
    batch_size=32,
)

我无法弄清楚如何修复我的代码以及如何拟合模型。这种方法正确吗?

python tensorflow keras 深度学习 值错误

答: 暂无答案