• 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,有很多也不太了解,)

  • 相关阅读:
    frog-jump
    nth-digit
    binary-watch
    elimination-game
    evaluate-division
    random-pick-index
    integer-replacement
    rotate-function
    longest-substring-with-at-least-k-repeating-characters
    decode-string
  • 原文地址:https://www.cnblogs.com/1394htw/p/5357976.html
Copyright © 2020-2023  润新知