tensorflow TypeError: run() got multiple values for argument 'feed_dict'

tensorflow在session调用run()时,报上述错误。

import tensorflow as tf
sess = tf.InteractiveSession()

import numpy as np


a = np.array([[1.0,2.0,3.0,4.0],[5.0,6.0,7.0,8.0],[9.0,10.0,11.0,12.0],[1.0,1.0,1.0,1.0]])
w = np.ones([3.0,3.0,1.0,1.0])

W_conv1 = tf.Variable(w)

def conv2d(x, W):
  return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')


x = tf.placeholder(tf.float64, shape=[4,4])

x_image = tf.reshape(x,[1,4,4,1])

h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1))

sess.run(tf.initialize_all_variables())

i,h1 = sess.run(x_image,h_conv1, feed_dict={x:a})

解决办法:

i,h1 = sess.run([x_image, h_conv1], feed_dict={x:a})

原因:
session.run()的参数如下:

run(
    fetches,
    feed_dict=None,
    options=None,
    run_metadata=None
)

各个参数的含义:
Args:
fetches: A single graph element, a list of graph elements, or a dictionary whose values are graph elements or lists of graph elements (described above).
feed_dict: A dictionary that maps graph elements to values (described above).
options: A [RunOptions] protocol buffer
run_metadata: A [RunMetadata] protocol buffer

x_image,h_conv1应该是fetches参数,要以list给出,不然会解析为两个参数。

参考:https://www.tensorflow.org/api_docs/python/tf/Session

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值