张量流:张量集形状()ValueError:“image”必须完全定义

2024-04-27 04:32:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用tf.image.resize_image_with_crop_or_pad裁剪输入图像的一部分。但是出现了一个错误:ValueError: 'image' must be fully defined。我检查了添加的Why do I get ValueError('\'image\' must be fully defined.') when transforming image in Tensorflow?,但它也不能工作。 我列出我的代码和错误如下:

example = tf.image.decode_png(file_contents, channels=3)
example.set_shape = ([256,256,3])
crop_image = tf.image.resize_image_with_crop_or_pad(example, crop_size, crop_size)

错误:

^{pr2}$

我不知道为什么错误会出现,即使我设置了一定的形状图像。 但是,我测试代码如下:

example = tf.image.decode_png(file_contents, channels=3)
example = tf.reshape(example, [256,256,3])
crop_image = tf.image.resize_image_with_crop_or_pad(example, crop_size, crop_size)

它起作用了。我认为整形到同一个形状不会改变张量值的顺序,对吗?也许这就是解决办法。在


Tags: or图像cropimagesizeexampletf错误
1条回答
网友
1楼 · 发布于 2024-04-27 04:32:40

问题出在线路上

example.set_shape = ([256,256,3])

您将重写方法tf.Tensor.set_shape,并将其设置为一个值。在

set_shape是一个方法,因此必须正确调用它:

^{2}$

在那之后,你的代码就可以工作了。在

I think reshape to the same shape does not change the order of values in Tensor, am I right?

是的,你说得对

相关问题 更多 >