2017-03-16 14 views
4

私が問題に関連するかもしれない私のコードのいくつかの部分を抽出してる私がいる:とValueError:引数が密テンソルでなければなりません - PythonとTensorFlow

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, 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 []. 

感謝。

+2

ただの推測:numpyの配列に変換: 'numpy.asarray (Image.open( '1-enhanced.png')。convert( 'L')) '。その後、それを試してみる? – Dair

+0

ありがとうございます。はい、私はエラーを削除したと思います。私は別のエラーが発生していますが、これには関係していないようです。 – Simplicity

答えて

3

問題を解決しているように見えるので、単にコメントを投稿:

numpyの配列に変換してみてください。

numpy.asarray(Image.open('1-enhanced.png').convert('L')) 
関連する問題