因安装cuda10.2导致tensorflow1.0级版本(对应cuda10.0)相关代码不兼容的解决方案

解决过程:

提示:这里简述项目相关背景:

keras-yolov3 搭配虚拟环境 Python3.7(tensorflow-gpu)
运行 predict.py,出现错误,提示如下:

  • ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory
    说明cuda与tensorflow版本不兼容,提高tensorflow到2.0以上版本(当时我的版本是keras=2.6.0; tensorflow=2.6.0)

  • 运行后提示,错误如下:

ModuleNotFoundError: No module named
‘keras.layers.advanced_activations’

参考该网友的解决办法:12345
先将 tensorflow 降级为 2.2.0再将 keras 2.9.0 降级到 2.1.0;错误提示如下:

AttributeError: tensorflow no module"get_default_session"

于是修改如下(在yolo.py中):

添加了 import tensorflow as tf # 20230224
后将下边这句改一下(这里没有直接改为import tensorflow.compat.v1 as tf 的原因是有网友说会导致其他错误)
self.sess = tf.compat.v1.keras.backend.get_session() #self.sess = K.get_session()

  • 运行后又提示一处错误(tensorflow_backend.py中):

AttributeError: module ‘tensorflow’ has no attribute ‘get_default_graph’

AttributeError: module ‘tensorflow’ has no attribute ‘placeholder’

在这里就彻底解决了,具体如下:
参考网友:45678

import tensorflow as tf
改为如下两句:
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

提示: 成功运行后Python3.7(tensorflow-gpu)下的相关软件 Keras-2.1.0 python3.7.9 tensorflow-2.2.0没用tensorflow-gpu:


猜你喜欢

转载自blog.csdn.net/weixin_42017945/article/details/129196074
今日推荐