I tried to fit my model, but encountered 'type error'. This code was written almost the same as described in a kaggle source code example for CNN.
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
because the function is updated from the new version of tensorflow. I guessed shape[0]
could make this int-relevant issue. 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. If you ported the code from the kaggle kernel then I assume your model was defined as:
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.