我正在尝试在 tensorflow 中处理图像,并且我正在尝试运行此代码,但它给出了此错误:
/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()
如果我尝试用 float 替换 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])
如果我学得正确,那么 None , None = row , col
placeholder("unit8",[row,col,3]
我理解它是一个不受大小限制的矩阵
但是这里的3是什么?
最佳答案
您的 place_holder1
是大小为 None、None、3 且类型为 float 的张量 (tf.placeholder("float32",[None,None,3])
) 。相反,您传递一个字符串,它是文件的名称。读取此文件并将其转换为张量。
您的 3 是 channel 数(颜色)。对于 RGB 图像,该值为 3。
关于python - 值错误: invalid literal for int() with base 10 in tensorflow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43557190/