ValueError:输入0与图层不兼容:预期形状=(无,48,187,621,64),找到形状=(48,187,621,64) [英] ValueError: Input 0 is incompatible with layer: expected shape=(None, 48, 187, 621, 64), found shape=(48, 187, 621, 64)

查看:57
本文介绍了ValueError:输入0与图层不兼容:预期形状=(无,48,187,621,64),找到形状=(48,187,621,64)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Tensorflow训练模型,其中输入不是批处理的,而是形状的单个输入:

I'm training a model in tensorflow, where the input isn't batched but is a single input of shape:

(48,187,621,64)

(48, 187, 621, 64)

当我在模型l_regularization内部传递此输入时,如下所示:

When I pass this input inside the model l_regularization, like so:

make_regularization(l_cost_volume)

我得到了错误:

Traceback (most recent call last):
  File "train.py", line 300, in <module>
    train(ds, epochs)
  File "train.py", line 278, in train
    x_train_right, y_train_right_noc)
  File "train.py", line 242, in train_step
    l_regularization = make_regularization(l_cost_volume)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 977, in __call__
    input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/engine/input_spec.py", line 274, in assert_input_compatibility
    ', found shape=' + display_shape(x.shape))
ValueError: Input 0 is incompatible with layer gc-net-part1: expected shape=(None, 48, 187, 621, 64), found shape=(48, 187, 621, 64)

如何解决此问题?有没有一种方法可以将单个图像的尺寸扩展为无",或者可以让模型接受已找到的形状"?尺寸?顺便说一下,可以扩展已找到形状"的尺寸.也不起作用.它给出了:

How to fix this? Is there a way to extend the dimension of the single image by None or alternatively have the model accept the "found shape" dimension? By the way, extending the dimension of the "found shape" doesn't work either. It gives:

ValueError: Input 0 is incompatible with layer gc-net-part1: expected shape=(None, 48, 187, 621, 64), found shape=(1, 48, 187, 621, 64)

推荐答案

要添加批处理维度,您可以轻松使用 tf.expand_dims()或使用 None进行特殊索引.第一种方法是

To add a batch dimension, you can easily make use of tf.expand_dims() or by special indexing using None. The first method is

l_cost_volume = tf.expand_dims(l_cost_volume)

另一个是

l_cost_volume = l_cost_volume[None]

两者的输出形状均为(1、48、187、621、64)

这篇关于ValueError:输入0与图层不兼容:预期形状=(无,48,187,621,64),找到形状=(48,187,621,64)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆