层“模型”的输入0与层不兼容:预期形状=(无, 250, 3),在经过训练的变压器模型中发现形状=(无, 3)
我有一个用tensorflow 2.7.0
和 python 3.7
训练的 keras transformer
模型,输入形状:(None, 250, 3)
和形状为:(250, 3)
(不是图像)的二维数组输入
使用以下方式进行预测时:
prediction = model.predict(state)
我得到 ValueError: Layer "model" 的输入 0 与该层不兼容:预期 shape=(None, 250, 3),找到 shape=(None, 3)
项目代码: https://github.com/MikeSifanele/TT
这是 state
的样子:
<代码>状态= np.array([[-0.07714844,-0.06640625,-0.140625],[-0.140625,-0.1650391,-0.22 65625]...[0.6376953,0.6005859,0.6083984],[0.7714844,0.7441406,0.7578125]], np.float32)
I have a keras transformer
model trained with tensorflow 2.7.0
and python 3.7
with input shape: (None, 250, 3)
and a 2D array input with shape: (250, 3)
(not an image)
When making a prediction with:
prediction = model.predict(state)
I get ValueError: Input 0 of layer "model" is incompatible with the layer: expected shape=(None, 250, 3), found shape=(None, 3)
project code: https://github.com/MikeSifanele/TT
This is how state
looks like:
state = np.array([[-0.07714844,-0.06640625,-0.140625],[-0.140625,-0.1650391,-0.2265625]...[0.6376953,0.6005859,0.6083984],[0.7714844,0.7441406,0.7578125]], np.float32)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些解释:
对于模型的输入形状,即
(None, 250, 3)
,第一个轴(由None
表示)是“样本”轴,而其余轴即250,3
表示输入维度。因此,当输入形状为(250, 3)
时,它假定第一个轴为“样本”轴,其余轴为输入维度,即3
。因此,为了使其一致,我们需要在开头添加一个维度,如下所示:state
的形状则变为(1, 250, 3)
~(无,250,3)
。Some explanation:
For input shape to the model i.e.
(None, 250, 3)
, the first axis (represented byNone
) is the "sample" axis, while the rest i.e.250,3
denotes the input dimension. Thus, when the input shape is(250, 3)
it assumes the first axis as the "sample" axis and the rest as the input dimension i.e. just3
. So, to make it consistent we need to add a dimension at the beginning described in the following:The shape of
state
then becomes(1, 250, 3)
~(None, 250, 3)
.