InvalidArgumentError: Incompatible shapes: [6,2,3] vs. [6,1] what does
this means.
不兼容的形状意味着什么
InvalidArgumentErrorTraceback(最近一次通话最近)
()中的
4 frames
/usr/local/lib/python2.7/dist-
packages/tensorflow/python/framework/errors_impl.pyc in __exit__(self,
type_arg, value_arg, traceback_arg)
526 None, None,
527 compat.as_text(c_api.TF_Message(self.status.status)),
--> 528 c_api.TF_GetCode(self.status.status))
529 # Delete the underlying status object from memory otherwise it
stays alive
530 # as there is a reference to status from this from the traceback
due to
InvalidArgumentError: Incompatible shapes: [6,2,3] vs. [6,1]
[ ]
> Blockquote
import tensorflow as tf
import numpy as np
from tensorflow import keras
odel = tf.keras.Sequential([keras.layers.Dense(units=3)])
odel.compile(optimizer='sgd', loss='mean_squared_error')
x = np.array([[[1,2],[6,3]],[[3,4],[6,3]],[[4,5],[6,6]],[[5,6],[6,6]],
[[6,7],[6,4]],[[7,8],[6,2]]], dtype=float)
y = np.array([6, 10, 15, 17, 17,17], dtype=float)
odel.fit(x, y, epochs=500)
a=np.array([[2,3]])`enter code here`
print(odel.predict(a))
答案 0 :(得分:0)
代码中有很多事情需要解决
1- InputShape
tf.Sequential的第一层应具有InputShape。它是要素之一的形状
2-标签
标签至少具有二维尺寸(特征也是如此)。 y的形状为[6]
,而其形状应为[b, 3]
,其中3是最后一层的单位值,b是批数。看特征,b是6