Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tensorflow:切片输入图像和灰度_Python_Image_Numpy_Matrix_Tensorflow - Fatal编程技术网

Python Tensorflow:切片输入图像和灰度

Python Tensorflow:切片输入图像和灰度,python,image,numpy,matrix,tensorflow,Python,Image,Numpy,Matrix,Tensorflow,我是Tensorflow的新手,正在尝试对图像进行切片,然后将其灰度化。到目前为止,我的代码是这样的。我首先获取输入,然后将图像数据提取到张量中,然后对图像的中间部分进行切片。在这一步中可以忽略权重等,只是想给读者提供上下文: ############################## # NETWORK IMPLEMENTATION # ############################## tf.reset_default_graph() ######## #Forward

我是Tensorflow的新手,正在尝试对图像进行切片,然后将其灰度化。到目前为止,我的代码是这样的。我首先获取输入,然后将图像数据提取到张量中,然后对图像的中间部分进行切片。在这一步中可以忽略权重等,只是想给读者提供上下文:

##############################
#   NETWORK IMPLEMENTATION   #
##############################
tf.reset_default_graph()

########
#Forward

##Inputs
input = tf.placeholder(shape=[210, 160, 3], dtype=tf.float32)
print(input.get_shape())
#inputs = tf.reshape(input, [1, 210, 160, 3])
#print(inputs.get_shape())

##Grayscale
#inputs = tf.image.rgb_to_grayscale(input, name=None)
#print(inputs.get_shape())

#Slicing
inputs = tf.slice(input, [25, 0, 0], [160, 160, 3])
print(inputs.get_shape())

#Downsample to new dimensions
#inputs = tf.image.decode_jpeg(inputs)
inputs = tf.image.resize_images(inputs, [84, 84]) 
print(inputs.get_shape())
inputs = tf.reshape(inputs, [1, -1])
print(inputs.get_shape())

W = tf.Variable(tf.random_uniform([84*84, 6], 0.00, 0.01))
Qout = tf.matmul(inputs, W)
predict = tf.argmax(Qout, 1) #why exactly this operation?
但是,每当我运行此操作时,都会出现一个错误,说明:

Traceback (most recent call last):
  File "main.py", line 43, in <module>
    inputs = tf.image.resize_images(inputs, [84, 84])
TypeError: resize_images() takes at least 3 arguments (2 given)
回溯(最近一次呼叫最后一次):
文件“main.py”,第43行,在
输入=tf.image.resize_图像(输入[84,84])
TypeError:resize_images()至少接受3个参数(给定2个)
我已经阅读了关于切片和调整大小的文档,但是我仍然感到困惑。如前所述,我是tensorflow的新手,非常感谢您的帮助:)

我试着对调试进行注释,但我甚至不确定这是否导致了问题。我总是收到上述错误。

更新:

看起来您使用的是旧版本的tensorflow,但没有说明。要纠正错误,请将其更改为这样

    inputs = tf.image.resize_images(inputs, 84, 84)
在这种情况下,第一个84是新高度,第二个是宽度

旧答案适用于tensorflow 1.0: 我想你的问题是

inputs = tf.image.resize_images(inputs, [84, 84, 3])
应该是

inputs = tf.image.resize_images(inputs, [84, 84])

因为大小应该只描述高度和宽度,而不应该包括频道的数量。

输入
占位符
,所以您不能有第二个
输入=…
,只需更改variance@xxi你到底是什么意思?(无法识别任何带有“input=…”的第二行)对不起,我误读了您所有的差异是
输入
,没有注意到
输入
。我刚刚运行了你的代码,它运行得很好,唯一的问题是
W
的大小,我认为它是
[84*84*3,6]
。也许你的例子丢失了什么?@xxi-hmm很有趣,那么也许我的tensorflow版本有问题,非常感谢你的努力!!:)非常感谢您的更正,但不幸的是,更改此选项没有帮助…您用新错误更新了问题?另外,您使用的是tensorflow的哪个版本?你可以看到打印(tf.\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu