Keras(tensorflow后端)获取" TypeError:不可用类型:' Dimension'"

时间:2018-01-24 06:18:26

标签: python tensorflow neural-network keras conv-neural-network

嗨我在安装此模型时出现尺寸错误,有人知道为什么吗?

multiCapabilities: [
{
  browserName: 'firefox',
  firefoxOptions: {
    args: ['--headless']
  },
  'moz:firefoxOptions': {
    args: [ '--headless' ]
  }
}
]

每个变量的维度为

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

1 个答案:

答案 0 :(得分:3)

这是因为您正在使用tf.reshape,它会返回Tensor,而Keras模型的fit方法不适用于张量。

请考虑使用np.reshape,这将完全相同。