DataType float32 for attr 'T' not in list of allowed values: int32, int64

孤街浪徒 提交于 2021-01-27 14:30:21

问题


I have considered these two posts(this and this), but they are not my problem and solution. I have the following code to create a feed forward network in 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)

However, I've got the following error in this line Qout = tf.matmul(inputs1,W):

TypeError: DataType float32 for attr 'T' not in list of allowed values: int32, int64

Apparently everything is ok, but the question is what is this error and where does it come from?


回答1:


I have found the problem. The problem comes from numOfState. As I have found its type is float32. Hence, the problem is solved by casting this variable to int:

#numOfState = (toState - fromState) / step 
# change to
numOfState = int((toState - fromState) / step)


来源:https://stackoverflow.com/questions/47004522/datatype-float32-for-attr-t-not-in-list-of-allowed-values-int32-int64

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!