attr 'T' 的数据类型 float32 不在允许值列表中:int32、int64 [英] DataType float32 for attr 'T' not in list of allowed values: int32, int64

查看:34
本文介绍了attr 'T' 的数据类型 float32 不在允许值列表中:int32、int64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经考虑过这两篇文章(thisthis),但它们不是我的问题和解决方案.我有以下代码在 tf 中创建前馈网络:

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)

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

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

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

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?

推荐答案

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

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)

这篇关于attr 'T' 的数据类型 float32 不在允许值列表中:int32、int64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆