本文介绍了ValueError:tensorflow中以10为底的int()的无效文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在tensorflow中使用图像,并且我正在尝试运行此代码,但它给出了这个错误:

i am trying to play with image in tensorflow and i am trying to run this code but its giving this error :

/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替换为float:

if i am trying to replace int with float :

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

然后我收到此错误:

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

我的第二个问题是此行中的3是什么

my second question is what is 3 in this line

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

如果我正确学习,则None,None = row,

if i learned correctly then None , None = row , col

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

我了解其尺寸不受限制的矩阵

i understand its a Matrix of unconstrained size

但是这里的3是什么?

推荐答案

您的place_holder1是一个张量,其大小为None,None,3,并键入float(tf.placeholder("float32",[None,None,3])).取而代之的是传递一个字符串,该字符串是文件的名称.读取该文件并将其转换为张量.

Your place_holder1 is a tensor of size None, None, 3 and type float (tf.placeholder("float32",[None,None,3])). Instead of it you pass a string which is a name of the file. Read this file and convert it to a tensor.

您的3是通道(颜色)的数量.对于RGB图像,该值为3.

Your 3 is the number of channels (colors). For RGB images it is 3.

这篇关于ValueError:tensorflow中以10为底的int()的无效文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 11:15