当前位置:网站首页>【Tensorflow】AttributeError: module ‘keras.backend‘ has no attribute ‘tf‘
【Tensorflow】AttributeError: module ‘keras.backend‘ has no attribute ‘tf‘
2022-08-02 13:51:00 【there2belief】
问题:
以下伪代码在keras 2.2.4使用正常,但在keras2.3.1时出现错误:
AttributeError: module 'keras.backend' has no attribute 'tf'
代码:
import tensorflow as tf
import keras
tf_backend = keras.backend.tf
model = keras.models.model_from_json(json_str, custom_objects={'swish':swish, 'backend':keras.backend, 'tf':tf_backend})
解决:
出错的原因是在keras 2.3.1中已经没有 keras.backend.tf方法了,此时可以直接使用tf代替keras.backend.tf,以上代码可以更新为:
import tensorflow as tf
import keras
if keras.__version__ == "2.2.4":
tf_backend = keras.backend.tf
else:
tf_backend = tf
model = keras.models.model_from_json(json_str, custom_objects={'swish':swish, 'backend':keras.backend, 'tf':tf_backend})
边栏推荐
猜你喜欢
Diodes and their applications
Differences and concepts between software testing and hardware testing
86.(cesium之家)cesium叠加面接收阴影效果(gltf模型)
智能指针-使用、避坑和实现
攻防世界----unfinish
【C语言】明解数组(1)
百日刷题计划 ———— DAY1
巴比特 | 元宇宙每日必读:蒂芙尼宣布推出限量版 CryptoPunk 定制吊坠
高效代码静态测试工具Klocwork 2022.2——Portal全新升级、支持RLM
Singleton pattern of seven kinds of writing, you know?
随机推荐
保姆级教程:写出自己的移动应用和小程序(篇三)
SQL函数 UCASE
SQL函数 UPPER
二进制中1的个数
WPF效果第一百九十三篇之登录实现
Based on the flask mall administrator functions
rust使用mysql插入数据
苹果,与Web3 “八字不合”
Embedded system driver primary [2] - based on character device driver _ basic framework
Win11怎么修改关机界面颜色?Win11修改关机界面颜色的方法
requestparam注解接的收的是什么格式(玄机赋注解)
OpenMMLab简介
网络安全第一次作业
How to improve the originality of self-media creation and create popular works?
Large and comprehensive pom file example
永远退出机器学习界!
Why does a four-byte float represent a wider range than an eight-byte long
供应磷脂-聚乙二醇-羧基,DSPE-PEG-COOH,DSPE-PEG-Acid,MW:5000
Fabric.js 动态设置字号大小
【ONE·Data || 排序入门】