AttributeError: module ‘tensorflow.compat.v2‘ has no attribute ‘__internal__‘

尝试了很多方式,都不行,今天总结一下。
—————————————————
在用tensorflow的时候出现以下问题:
在这里插入图片描述
这是tensorflow和keras版本不对应问题。
解决办法
一种可能的版本:tensorflow 2.3.0,keras 2.3.1。
安装之前把其他版本全部卸载。
安装:

pip install tensorflow==2.3.0
pip install keras==2.3.1

该问题解决。
————————————————
然后出现以下问题:
在这里插入图片描述
解决办法
找到该目录的tensorflow_backend.py文件:
在这里插入图片描述
找到is_tensor函数,把原来函数里的那句话注释掉,改成上面那句话:
在这里插入图片描述
该问题解决。
————————————————
之后又出现以下问题:
在这里插入图片描述
这是因为文件里将keras和tf.keras进行了混用,导致不兼容。将tf.keras全部换成keras;或者把所有keras换成tf.keras。
例如:

from tensorflow.keras.optimizers import Adam
from keras.utils import multi_gpu_model

换成

from tensorflow.keras.optimizers import Adam
from tensorflow.keras.utils import multi_gpu_model

该问题解决。

  • 7
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
要解决AttributeError: module 'tensorflow.compat.v2' has no attribute 'contrib'的问题,你可以尝试以下两种方法。 方法一: 1. 首先,卸载所有的kerastensorflow包。你可以使用以下命令: ``` !pip uninstall keras -y !pip uninstall keras-nightly -y !pip uninstall keras-Preprocessing -y !pip uninstall keras-vis -y !pip uninstall tensorflow -y ``` 2. 接下来,安装Retinanet支持的版本的tensorflowkeras。你可以使用以下命令: ``` !pip install tensorflow==2.3.0 !pip install keras==2.4 ``` 3. 在你的Colab笔记本的顶部添加这段代码,并重启运行时。 ``` import tensorflow.compat.v1 as tf tf.disable_v2_behavior() ``` 方法二: 1. 首先,卸载所有的kerastensorflow包。你可以使用以下命令: ``` !pip uninstall keras -y !pip uninstall keras-nightly -y !pip uninstall keras-Preprocessing -y !pip uninstall keras-vis -y !pip uninstall tensorflow -y ``` 2. 接下来,安装tensorflow 2.3.0和keras 2.3.1版本。你可以使用以下命令: ``` !pip install tensorflow==2.3.0 !pip install keras==2.3.1 ``` 这些方法中的任何一种都应该能够解决AttributeError: module 'tensorflow.compat.v2' has no attribute 'contrib'的问题。希望对你有所帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [AttributeError: module 'tensorflow.compat.v1' has no attribute '](https://download.csdn.net/download/qq_38766019/86272235)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [moduletensorflow.compat.v2‘ has no attribute ‘__internal__](https://blog.csdn.net/cherr_bomb/article/details/129035304)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [AttributeError: moduletensorflow.compat.v2‘ has no attribute ‘__internal__](https://blog.csdn.net/hhhhhh5863/article/details/122622488)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值