DataType float32 for attr' T'不在允许值列表中:int32,int64

时间:2017-10-29 19:47:00

标签: python python-3.x tensorflow

我已经考虑了这两个帖子(thisthis),但它们不是我的问题和解决方案。我有以下代码在tf:

中创建前馈网络
step = 500
fromState = 0
toState = 5000000
numOfState = (toState - fromState) / step
numOfAction = 11

tf.reset_default_graph()
inputs1 = tf.placeholder(shape=[1,numOfState], dtype = tf.float32)
W = tf.Variable(tf.random_uniform([numOfState,4],0,0.01),)
Qout = tf.matmul(inputs1,W)
predict = tf.argmax(Qout,1)

但是,我在此行Qout = tf.matmul(inputs1,W)中遇到以下错误:

  

TypeError:attr的数据类型float32' T'不在允许值列表中:int32,int64

显然一切都还可以,但问题是这个错误是什么?它来自哪里?

1 个答案:

答案 0 :(得分:0)

我发现了这个问题。问题来自numOfState。我发现它的类型是float32。因此,通过将此变量强制转换为int:

来解决问题
#numOfState = (toState - fromState) / step 
# change to
numOfState = int((toState - fromState) / step)