ValueError:参数必须是密集张量 - Python 和 TensorFlow [英] ValueError: Argument must be a dense tensor - Python and TensorFlow

查看:25
本文介绍了ValueError:参数必须是密集张量 - Python 和 TensorFlow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在提取可能与我遇到的问题相关的部分代码:

I'm extracting some portions of my code that might be relevant to the issue I'm having:

from PIL import Image
import tensorflow as tf

data = Image.open('1-enhanced.png')
...
...
raw_data = data
raw_img = raw_data

我收到了以下很长的消息,我不知道如何分析(你知道这里发生了什么吗):

I'm getting the following long message which I'm not sure how to analyze (do you have any idea on what's going on here):

Traceback (most recent call last):
  File "C:\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 490, in apply_op
    preferred_dtype=default_dtype)
  File "C:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 669, in convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "C:\Python35\lib\site-packages\tensorflow\python\framework\constant_op.py", line 176, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "C:\Python35\lib\site-packages\tensorflow\python\framework\constant_op.py", line 165, in constant
    tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 376, in make_tensor_proto
    _GetDenseDimensions(values)))
ValueError: Argument must be a dense tensor: <PIL.PngImagePlugin.PngImageFile image mode=L size=150x150 at 0x1E07D3C0AC8> - got shape [150, 150], but wanted [].

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "conv_visuals.py", line 54, in <module>
    x = tf.reshape(raw_data, shape=[-1,150,150,1])
  File "C:\Python35\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 2448, in reshape
    name=name)
  File "C:\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 503, in apply_op
    as_ref=input_arg.is_ref).dtype.name
  File "C:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 669, in convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "C:\Python35\lib\site-packages\tensorflow\python\framework\constant_op.py", line 176, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "C:\Python35\lib\site-packages\tensorflow\python\framework\constant_op.py", line 165, in constant
    tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 376, in make_tensor_proto
    _GetDenseDimensions(values)))
ValueError: Argument must be a dense tensor: <PIL.PngImagePlugin.PngImageFile image mode=L size=150x150 at 0x1E07D3C0AC8> - got shape [150, 150], but wanted [].

谢谢.

推荐答案

刚刚发表评论,因为它似乎已经解决了问题:

Just posting the comment since it seems to have resolved the issue:

尝试将其转换为 numpy 数组:

Try converting it to a numpy array:

numpy.asarray(Image.open('1-enhanced.png').convert('L'))

这篇关于ValueError:参数必须是密集张量 - Python 和 TensorFlow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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