深度学习如何获得免费GPU(3)——Google Colab实践——Kearas后端选择:Theano backend 和 Tensorflow backend?

问题由来:
加载模型出错
在这里插入图片描述
解决一:Keras的后端没选对
解决二:模型参数不匹配
解决三:Kearas版本匹配
(以下方法不行)
1.
os.environ[‘KERAS_BACKEND’]=‘theano’
os.environ[‘KERAS_BACKEND’]
2.
I solved the issue by compelling congruency between the versions of Keras installed on my different machines.

It makes sense to think working with the same model across different versions of the library could engender hiccups due to discrepancies in convention employed in said versions.

First I looked up what versions were installed on my different machines (Guide here: https://stackoverflow.com/a/10215100/2661720),

and for the machine on which I was loading the model, I overwrote the existing Keras version with that installed on the model’s parent machine (Guide here: https://stackoverflow.com/a/33812968/2661720).

This was the thought process that sublimated the problem for me.

到底有何区别?
如何切换?(特别是在colab)
本地:https://www.jianshu.com/p/dd1af9c07b81
云端:https://stackoverflow.com/questions/40310035/how-to-change-keras-backend-wheres-the-json-file

折腾了一天多,试过很多方法,最终成功实现,由默认的tensorflow切换到theano:
主要参考:https://stackoverflow.com/questions/42177658/how-to-switch-backend-with-keras-from-tensorflow-to-theano?rq=1
在这里插入图片描述
附代码:
import importlib

from keras import backend as K
from os import environ

#user defined function to change keras backend
def set_keras_backend(backend):
if K.backend() != backend:
environ[‘KERAS_BACKEND’] = backend
importlib.reload(K)
assert K.backend() == backend

#call the function with “theano”
set_keras_backend(“theano”)

检验:
keras.backend.backend() # 显示正在使用的Kerasbacked

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值