2017-04-22 262 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

相關問題