菜尼奥排错之keras ‘tensorflow.compat.v2.

菜尼奥排错之keras ‘tensorflow.compat.v2.,第1张

菜尼奥排错之keras ‘tensorflow.compat.v2. 环境版本:

        Ubuntu 16.04.2 LTS

        Nvidia GeForce RTX 3080*2  CUDA Version 11.2

        tensorflow 2.5.0

        keras 2.7.0

报错信息:

训练时报错如下:

AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'register_clear_session_function'
解决方法:

之前python脚本头:

from keras.models import Model
from keras.layers import Input, Conv2D, GlobalAveragePooling2D, Dropout
from keras.layers import Activation, BatchNormalization, Add, Reshape, DepthwiseConv2D
from keras.utils.vis_utils import plot_model
from keras.optimizers import Adam
from keras.preprocessing.image import ImageDataGenerator
from keras.callbacks import EarlyStopping
from keras import backend as K

修改为如下即可:

from tensorflow.python.keras.models import Model
from tensorflow.python.keras.layers import Input, Conv2D, GlobalAveragePooling2D, Dropout
from tensorflow.python.keras.layers import Activation, BatchNormalization, Add, Reshape, DepthwiseConv2D
from tensorflow.python.keras.utils.vis_utils import plot_model
from tensorflow.keras.optimizers import Adam
from tensorflow.python.keras.preprocessing.image import ImageDataGenerator
from tensorflow.python.keras.callbacks import EarlyStopping
from tensorflow.python.keras import backend as K
根本原因:

        tensorflow-gpu 1.12(tf一代keras)的代码在tensorflow2.x(tf2二代keras)使用时,keras模块调用路径变更了而已。诸如此类问题还有一大推。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5652191.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存