简体   繁体   English

Keras(tensorflow后端)得到“TypeError:unhashable type:'Dimension'”

[英]Keras (tensorflow backend) getting “TypeError: unhashable type: 'Dimension'”

Hi I get a dimension error when fitting this model, would anyone know why? 嗨我在拟合这个模型时遇到尺寸误差,有人知道为什么吗?

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))

The dimension of each variable is 每个变量的维度是

X_train = (27367, 64, 64, 1)
X_test = (4553, 64, 64, 1)
y_train = (164202, 11)
y_test = (27318, 11)

This is because you are using tf.reshape , which returns a Tensor, and the fit method of Keras models don't work well with tensors. 这是因为你使用的是返回Tensor的tf.reshape ,并且tf.reshape模型的fit方法不适用于张量。

Consider using np.reshape instead, which will do the exact same thing. 请考虑使用np.reshape ,它将执行完全相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Keras InceptionV3 类型错误:不可哈希类型:'维度' - Keras InceptionV3 TypeError: unhashable type: 'Dimension' 不可用类型:Keras LSTM中的“Dimension” - unhashable type: 'Dimension' in Keras LSTM 获取TypeError:无法散列的类型:'list' - GETTING A TypeError: unhashable type: 'list' TypeError: unhashable type: 'numpy.ndarray' Python3.9 图像分类使用 tensorflow 和 keras - TypeError: unhashable type: 'numpy.ndarray' Python3.9 image classification using tensorflow and keras tensorflow TypeError:无法散列的类型:'numpy.ndarray' - tensorflow TypeError: unhashable type: 'numpy.ndarray' TypeError:不可用类型:'numpy.ndarray'Tensorflow - TypeError: unhashable type: 'numpy.ndarray' Tensorflow Tensorflow 抛出“TypeError: unhashable type: 'list'”错误 - Tensorflow throws "TypeError: unhashable type: 'list'" error “TypeError: unhashable type: 'Dimension'” with BatchNormalization(axis=CHANNEL_AXIS)(input) - “TypeError: unhashable type: 'Dimension'” with BatchNormalization(axis=CHANNEL_AXIS)(input) Keras拟合模型:TypeError:不可用类型:'numpy.ndarray' - Keras fit model: TypeError: unhashable type: 'numpy.ndarray' TensorFlow和单词嵌入-TypeError:不可哈希类型:'numpy.ndarray' - TensorFlow and word embeddings - TypeError: unhashable type: 'numpy.ndarray'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM