theano报一种float类型错误的处理办法

  我实际用的环境是Keras,查错误时查到是Theano的配置问题,所以在标题里就写成Theano的问题了,

  是这样的,从Github上下载的别人的代码,准备复现别人的实验,结果在机器上部署好环境之后跑代码时报错为:

  TypeError: ('An update must have the same type as the original shared variable (shared_var=weight_1,
shared_var.type=TensorType(float32, matrix), update_val=Elemwise{sub,no_inplace}.0,
update_val.type=TensorType(float64, matrix)).', 'If the difference is related to the broadcast pattern, you
can call the tensor.unbroadcast(var, axis_to_unbroadcast[, ...]) function to remove broadcastable
dimensions.')

  意思就是代码里float的位数不对,以前的Keras版本都是float32的,现在的新版Keras默认是float64的,具体两者有什么区别还不太清楚,但是表现在执行的时候就是报上面的错,之后程序停止,

  解决方案:在代码中,import语句的下面添加下面一行代码,

   theano.config.floatX= 'float32'

  之后运行就行了,此时就是显式设置相关编译信息,

 

  (初来乍到,有错误之处还望指正,其实个人刚开始使用Keras和Theano,有很多也不太了解,)

转载于:https://www.cnblogs.com/1394htw/p/5357976.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值