Python Keras(tensorflow后端)获得;类型错误:不可损坏的类型:';尺寸'&引用;
嗨,我在安装这个模型时出现尺寸错误,有人知道原因吗Python Keras(tensorflow后端)获得;类型错误:不可损坏的类型:';尺寸'&引用;,python,tensorflow,neural-network,keras,conv-neural-network,Python,Tensorflow,Neural Network,Keras,Conv Neural Network,嗨,我在安装这个模型时出现尺寸错误,有人知道原因吗 num_classes = 11 input_shape = (64,64,1) batch_size = 128 epochs = 12 X_train = tf.reshape(X_train, [-1, 64, 64, 1]) X_test = tf.reshape(X_test, [-1, 64, 64, 1]) model = Sequential() model.add(Conv2D(32, kernel_size=(3,3),
num_classes = 11
input_shape = (64,64,1)
batch_size = 128
epochs = 12
X_train = tf.reshape(X_train, [-1, 64, 64, 1])
X_test = tf.reshape(X_test, [-1, 64, 64, 1])
model = Sequential()
model.add(Conv2D(32, kernel_size=(3,3), strides=1, activation='relu', input_shape=input_shape))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dense(num_classes, activation='softmax'))
model.compile(loss=keras.losses.categorical_crossentropy,
optimizer=keras.optimizers.Adadelta(),
metrics=['accuracy'])
model.fit(X_train, y_train,
batch_size=batch_size,
epochs=epochs,
verbose=1,
validation_data=(X_test, y_test))
每个变量的维度是
X_train = (27367, 64, 64, 1)
X_test = (4553, 64, 64, 1)
y_train = (164202, 11)
y_test = (27318, 11)
这是因为您使用的是
tf.reformate
,它返回一个张量,而Keras模型的fit
方法不能很好地处理张量
考虑使用
np。改为重塑,这将做完全相同的事情。你能发布完整的堆栈跟踪吗?是的,它现在可以工作了。谢谢。基本上,我需要重塑,然后添加通道。i、 e.X_train=X_train.reforme(X_train.shape[0],img_行,img_列,1)我该怎么做?