2017-04-22 124 views
2

我试图在tensorflow与图像玩,我试图运行此代码,但它给这个错误:ValueError异常:无效的文字在tensorflow INT()基数为10

/anaconda/bin/python "/Users/tony/Downloads/Tensorflow learning/9th pro.py" 
/anaconda/lib/python3.5/site-packages/matplotlib/tight_layout.py:222: UserWarning: tight_layout : falling back to Agg renderer 
    warnings.warn("tight_layout : falling back to Agg renderer") 
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. 
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. 
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. 
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. 
Traceback (most recent call last): 
    File "/Users/tony/Downloads/Tensorflow learning/9th pro.py", line 11, in <module> 
    sess_1=sess.run(slice_thing,feed_dict={place_holder1:image_a}) 
    File "/anaconda/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 767, in run 
    run_metadata_ptr) 
    File "/anaconda/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 938, in _run 
    np_val = np.asarray(subfeed_val, dtype=subfeed_dtype) 
    File "/anaconda/lib/python3.5/site-packages/numpy/core/numeric.py", line 531, in asarray 
    return array(a, dtype, copy=False, order=order) 
ValueError: invalid literal for int() with base 10: 'dd.jpg' 

我的代码是:

import skimage.io as i 
import matplotlib.pyplot as plt 
import tensorflow as tf 

image_a="dd.jpg" 
read_image=i.imread(image_a) 
show_image=i.imshow(image_a) 
place_holder1=tf.placeholder("uint8",[None,None,3]) 
slice_thing=tf.slice(place_holder1,[1,1,0],[1,1,0]) 
with tf.Session() as sess: 
    sess_1=sess.run(slice_thing,feed_dict={place_holder1:image_a}) 
    print(sess_1.shape) 
print(i.imshow(sess_1)) 
plt.show() 

如果我试图用浮动更换INT:

place_holder1=tf.placeholder("float32",[None,None,3]) 

然后我收到此错误:

ValueError: could not convert string to float: 'dd.jpg' 

我的第二个问题是什么是3在这一行

place_holder1=tf.placeholder("unit8",[None,None,3]) 

如果我没有学到那么无,无=行,列

placeholder("unit8",[row,col,3] 

我了解它的约束矩阵大小

但这里3是什么?

回答

0

place_holder1是大小无,无,3和浮点型(tf.placeholder("float32",[None,None,3]))的张量。而不是传递一个字符串,它是文件的名称。阅读这个文件并将其转换为张量。

你3是通道(颜色)的数目。对于RGB图像是3

+0

你能解释一下多一点我的意思是[无,无,3意味着它的3×3的矩阵?因为一个球场是None,第二个是None,那么第三个会是3? – stephen

+0

@stephen没有,没有,3'不是一个矩阵,这是一个等级3的张量。你可以把它想象成3个大小为'none,none'的矩阵。 “无”意味着任何维度,因此它可以是“5,7,3”或“1,4,3”。我建议你阅读介绍性教程,因为这些是基本的定义,没有这些基本的定义就不可能在TF中做任何事情 –

+0

你说过:“你可以把它想象成3个大小都不是的矩阵,但是如果我写[None,None,3 ],则第一个无是张量的深度,第2个无是该张量中的矩阵行,第3个是这些矩阵的列。所以它将是“无约束矩阵深度无约束的行,每个矩阵只有3列”。 ? – stephen

相关问题