为什么我收到此错误“图层“dense_30”的输入 0 与图层不兼容:预期 min_ndim=2,发现 ndim=1。收到完整形状:(无,)”
tensorflow 339
原文标题 :why I’m getting this error “Input 0 of layer “dense_30″ is incompatible with the layer:expected min_ndim=2,found ndim=1. Full shape received: (None,)”
设置随机种子
print(np.__version__) tf.random.set_seed(42)
- 使用 Sequential Api model = tf.keras.Sequential([tf.keras.layers.Dense(1)]) 创建模型
- 编译模型 model.compile(loss=tf.keras.losses.mae,# mae 是 mean absolute error optimizer = tf.keras.optimizers.SGD(), # sgd 是 stochastic gradient descent metrics=[“mae 的缩写”]
- 拟合模型 model.fit(X, y, epochs=5) // 这里是错误