您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

ValueError:参数必须是密集张量–Python和TensorFlow

5b51 2022/1/14 8:23:32 python 字数 3013 阅读 580 来源 www.jb51.cc/python

我正在提取可能与我遇到的问题相关的代码的一些部分: from PIL import Image import tensorflow as tf data = Image.open('1-enhanced.png') ... ... raw_data = data raw_img = raw_data 我收到以下长消息,我不确定如何分析(你对这里发生了什么有任何想法): Traceback (mo

概述

from PIL import Image
import tensorflow as tf

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

我收到以下长消息,我不确定如何分析(你对这里发生了什么有任何想法):

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,name=name)
  File "C:\python35\lib\site-packages\tensorflow\python\framework\constant_op.py",line 165,in constant
    tensor_util.make_tensor_proto(value,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,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",but wanted [].

谢谢.

尝试将其转换为numpy数组:

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

总结

以上是编程之家为你收集整理的ValueError:参数必须是密集张量–Python和TensorFlow全部内容,希望文章能够帮你解决ValueError:参数必须是密集张量–Python和TensorFlow所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶