Fetch argument 1 has invalid type <type ‘int‘>, must be a string or Tensor.
记录一个报错, 等有用到的时候可以回查
TypeError:
Fetch argument 1 has invalid type <type ‘int’>, must be a string or Tensor. Can not convert a int into a Tensor or Operation.
这个报错出在这么一行代码上:
sess.run(ret,feed_dict={test_in_tensor: [miaomiao]})
出现这种问题一般有两种可能:
原因1:
例如
loss = sess.run(loss, feed_dict = {image: image0})
里面的loss其实是一个 tensorflow 的operation, 返回的是run后loss operation 运行后的结果, 这个结果是个具体的数字(或者矩阵什么的),就不再是operation了, 而这个loss在下次运行的时候是不能被sess.run()接受的, 于是报错.
报错的特点基本也是运行了一次对了, 后面就错了
原因2:
例如:
a = tf.variable(2, 'w')
b = tf.variable(3, 'b')
loss = {'a' : a, 'b' : b }
sess.run(loss, feed_dict = {image: image0})
这里sess.run只接受tensor 或者 operation 或者 这两者的列表 例如 [a, b], 而loss是个字典, 于是还是报错,因为它自己是不会去找里面的东西的.
我自己在报错的时候找了好久,卡在了这么个小玩意儿上, 很恶心. 以此为鉴, 愿武运昌隆!