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

OmG*_*OmG 7 python python-3.x tensorflow

我已经考虑过这两篇文章(这个这个),但它们不是我的问题和解决方案。我有以下代码在 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)
Run Code Online (Sandbox Code Playgroud)

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

类型错误:用于 attr 'T' 的数据类型 float32 不在允许值列表中:int32、int64

显然一切正常,但问题是这个错误是什么以及它来自哪里?

OmG*_*OmG 4

我已经找到问题了。问题来自numOfState. 我发现它的类型是float32. 因此,通过将此变量转换为 int 来解决问题:

#numOfState = (toState - fromState) / step 
# change to
numOfState = int((toState - fromState) / step)
Run Code Online (Sandbox Code Playgroud)