更新时间:2023-12-02 18:45:46
我认为问题是您在Theano排序中设置了输入形状,但在Tensorflow后端和Tensorflow img排序中使用了Keras.另外,y_train数组必须转换为分类标签.
I think that the problem is that you are setting the input shape in Theano ordering but you are using Keras with Tensorflow backend and Tensorflow img ordering. In addition the y_train array has to be converted to categorical labels.
更新的代码:
from keras.utils import np_utils
from keras import backend as K
if K.image_dim_ordering() == 'th':
X_train = X_train.reshape(X_train.shape[0], 1, img_rows, img_cols, img_depth)
input_shape = (1, img_rows, img_cols, img_depth)
else:
X_train = X_train.reshape(X_train.shape[0], img_rows, img_cols, img_depth, 1)
input_shape = (img_rows, img_cols, img_depth, 1)
Y_train = np_utils.to_categorical(Y_train, nb_classes)
添加此行应该可以解决此问题.
Adding this lines should fix it.