[英]TypeError: 'int' object is not iterable when using model.fit()
I tried to fit my model, but encountered 'type error'.我试图安装我的 model,但遇到“类型错误”。 This code was written almost the same as described in a kaggle source code example for CNN.
这段代码的编写与 CNN 的 kaggle 源代码示例中描述的几乎相同。
https://www.kaggle.com/kanncaa1/convolutional-neural-network-cnn-tutorial/notebook https://www.kaggle.com/kanncaa1/convolutional-neural-network-cnn-tutorial/notebook
However, continuously the type error occurs.但是,不断出现类型错误。 I changed
model.fit_generator
to model. fit
我将
model.fit_generator
更改为model. fit
model. fit
because the function is updated from the new version of tensorflow. model. fit
,因为 function 是从新版本的 tensorflow 更新而来的。 I guessed shape[0]
could make this int-relevant issue.我猜
shape[0]
可能会导致这个与 int 相关的问题。 Could anyone help to point out the wrong type in the code below?谁能帮忙指出下面代码中的错误类型?
# model fitting
# from tensorflow 2.1.0
history = model.fit(datagen.flow(train_x, train_y, batch_size = batch_size),
epochs = epochs,
validation_data = (valid_x, valid_y),
steps_per_epoch = train_x.shape[0] // batch_size)
Possible Solutions:可能的解决方案:
run print(x_train.shape)
, and make sure all the values except the first dimension match the input_shape
that you specified during the model definition.运行
print(x_train.shape)
,并确保除第一个维度之外的所有值都与您在 model 定义期间指定的input_shape
匹配。 If you ported the code from the kaggle kernel then I assume your model was defined as:如果您从 kaggle kernel 移植代码,那么我假设您的 model 定义为:
model.add(Conv2D(filters = 8, kernel_size = (5,5),padding = 'Same',
activation ='relu', input_shape = (28,28,1)))
Make Sure that x_train.shape
is in accordance with the specified input_shape
.确保
x_train.shape
符合指定的input_shape
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.