【发布时间】:2021-11-24 23:19:08
【问题描述】:
我正在尝试制作读取图像的机器学习模型。但在第一个 epoch 结束时出现错误。
tensorflow.python.framework.errors_impl.InvalidArgumentError:reshape 的输入是一个具有 147456 个值的张量,但请求的形状需要 12544 的倍数 有什么想法吗?
validation_generator = ImageDataGenerator(rescale=1./255)
train_data_gen = train_generator.flow_from_dataframe(
dataframe=df,
#directory="CatDog",
x_col="images",
y_col="label",
class_mode="binary",
batch_size=64,
target_size=(128,128))
validation_data_gen = validation_generator.flow_from_dataframe(
dataframe=df,
#directory='',
x_col="images",
y_col="label",
class_mode="binary",
batch_size=64,
target_size=(64,64))
from keras.models import Sequential
from keras.layers import Dense, Conv2D, MaxPooling2D, Dropout, Flatten
model = Sequential([
Conv2D(16, (3,3), activation='relu', input_shape=(128,128,3)),
MaxPool2D((2,2)),
Conv2D(32, (3,3), activation='relu'),
MaxPool2D((2,2)),
Conv2D(64, (3,3), activation='relu'),
MaxPool2D((2,2)),
Flatten(),
Dense(512, activation='relu'),
Dense(1, activation='sigmoid')
])
model.compile(optimizer='adam',
loss='binary_crossentropy',
metrics=['accuracy'])
model.summary()
history = model.fit(train_data_gen, epochs=2, validation_data=validation_data_gen)
【问题讨论】:
-
欢迎来到Stack Overflow.!如果不查看产生问题的数据和您编写的代码,就很难回答您的问题。请阅读如何提出一个好问题并尝试发布Minimal Reproducible Example,以便我们更好地帮助您。
标签: python tensorflow machine-learning keras