简体   繁体   English

模块 'tensorflow._api.v1.compat.v2' 没有属性 '__internal__' google colab 错误

[英]module 'tensorflow._api.v1.compat.v2' has no attribute '__internal__' google colab error

I am running a tensorflow model on google colab.我在 google colab 上运行 tensorflow model。 Today, I got this error:今天,我收到了这个错误:

 Using TensorFlow backend.
    Traceback (most recent call last):
      File "train.py", line 6, in <module>
        from yolo import create_yolov3_model, dummy_loss
      File "/content/drive/MyDrive/yolo/yolo_plz_work/yolo.py", line 1, in <module>
        from keras.layers import Conv2D, Input, BatchNormalization, LeakyReLU, ZeroPadding2D, UpSampling2D, Lambda
      File "/usr/local/lib/python3.7/dist-packages/keras/__init__.py", line 3, in <module>
        from . import utils
      File "/usr/local/lib/python3.7/dist-packages/keras/utils/__init__.py", line 26, in <module>
        from .vis_utils import model_to_dot
      File "/usr/local/lib/python3.7/dist-packages/keras/utils/vis_utils.py", line 7, in <module>
        from ..models import Model
      File "/usr/local/lib/python3.7/dist-packages/keras/models.py", line 10, in <module>
        from .engine.input_layer import Input
      File "/usr/local/lib/python3.7/dist-packages/keras/engine/__init__.py", line 3, in <module>
        from .input_layer import Input
      File "/usr/local/lib/python3.7/dist-packages/keras/engine/input_layer.py", line 7, in <module>
        from .base_layer import Layer
      File "/usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py", line 12, in <module>
        from .. import initializers
      File "/usr/local/lib/python3.7/dist-packages/keras/initializers/__init__.py", line 124, in <module>
        populate_deserializable_objects()
      File "/usr/local/lib/python3.7/dist-packages/keras/initializers/__init__.py", line 49, in populate_deserializable_objects
        LOCAL.GENERATED_WITH_V2 = tf.__internal__.tf2.enabled()
      File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/util/module_wrapper.py", line 193, in __getattr__
        attr = getattr(self._tfmw_wrapped_module, name)
    AttributeError: module 'tensorflow._api.v1.compat.v2' has no attribute '__internal__'

Previously, things had been running smoothly, so I'm not sure why this happened.以前,事情一直很顺利,所以我不确定为什么会这样。 I am using Python 3.7.10, and these are the packages I am supposed to use:我正在使用 Python 3.7.10,这些是我应该使用的包:

absl-py==0.9.0
astor==0.8.1
gast==0.2.2
google-pasta==0.1.8
grpcio==1.26.0
h5py==2.10.0
Keras==2.3.1
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.0
Markdown==3.1.1
numpy==1.18.1
opencv-contrib-python==4.1.2.30
opt-einsum==3.1.0
protobuf==3.11.2
PyYAML==5.3
scipy==1.4.1
six==1.14.0
tensorboard==1.15.0
tensorflow==1.15.0
tensorflow-estimator==1.15.1
termcolor==1.1.0
tqdm==4.41.1
Werkzeug==0.16.0
wrapt==1.11.2

Perhaps colab recently upgraded some libraries?也许 colab 最近升级了一些库? I am sure that I followed the same installation steps as I usually do.我确定我遵循了与往常相同的安装步骤。

EDIT: I think there may be an issue in the keras version.编辑:我认为 keras 版本可能存在问题。 Here are the first few lines of the file I am running:这是我正在运行的文件的前几行:

from keras.layers import Conv2D, Input, BatchNormalization, LeakyReLU, ZeroPadding2D, UpSampling2D, Lambda
from keras.layers.merge import add, concatenate
from keras.models import Model
from keras.engine.topology import Layer
import tensorflow as tf

If I remove all of the lines starting with "from keras", I don't get the error.如果我删除所有以“from keras”开头的行,我不会收到错误。 However, I never touched these lines before, so I don't know why they would suddenly cause an error now.但是,我以前从未接触过这些行,所以我不知道为什么它们现在会突然出错。 Also, it is not the python version causing this error, because colab changed it to 3.7.10 in April and I had no problem.另外,不是python版本导致的这个错误,因为4月份colab改成了3.7.10,我没有问题。

Try these parameters, it works with me试试这些参数,它适用于我

!pip3 uninstall keras-nightly
!pip3 uninstall -y tensorflow
!pip3 install keras==2.1.6
!pip3 install tensorflow==1.15.0
!pip3 install h5py==2.10.0

One morning I woke up and my code was giving the exact same error (in google colab).一天早上我醒来,我的代码给出了完全相同的错误(在 google colab 中)。

I was running this code to downgrade my tensorflow我正在运行此代码来降级我的 tensorflow

!pip install tensorflow==1.13.0

I replaced it with:我将其替换为:

%tensorflow_version 1.x

Everything else remains the same.其他一切都保持不变。 It worked!有效!

Try downgrading Python to 3.6 using this link.尝试使用链接将 Python 降级到 3.6。 You need to re-install the packages you previously used.您需要重新安装以前使用的软件包。

try this one:试试这个:

!pip uninstall keras-nightly !pip 卸载 keras-nightly

.pip install h5py==2.10.0 .pip 安装 h5py==2.10.0

I had the same problem but using python 3.7 together with我有同样的问题但是使用 python 3.7 和

tensorflow==1.15.0
keras==2.1.6

Worked for me.为我工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tensorflow 问题 google colab; tensorflow._api.v1.compat.v2' 没有属性 '__internal__ - Tensorflow issue google colab ; tensorflow._api.v1.compat.v2' has no attribute '__internal__ AttributeError:模块'tensorflow_core.compat.v2'没有属性'__internal__'(一周前工作?) - AttributeError: module 'tensorflow_core.compat.v2' has no attribute '__internal__' (Worked a week ago?) AttributeError: 模块 'tensorflow.compat.v2.__internal__' 没有属性 'dispatch' - AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'dispatch' 模块“tensorflow.compat.v2.__internal__”没有属性“tf2” - module 'tensorflow.compat.v2.__internal__' has no attribute 'tf2' Tensorflow.compat.v2.__internal__.tracking' has no attribute 'TrackableSaver' 错误 - Tensorflow.compat.v2.__internal__.tracking' has no attribute 'TrackableSaver' Error AttributeError: 模块“tensorflow._api.v1.compat”没有用于 Tensorflow 对象检测 API 的属性“v2” - AttributeError: module 'tensorflow._api.v1.compat' has no attribute 'v2' For Tensorflow Object Detection API Tensorflow 对象检测 AttributeError:模块“tensorflow._api.v1.compat”没有属性“v2” - Tensorflow Object Detection AttributeError: module 'tensorflow._api.v1.compat' has no attribute 'v2' AttributeError:模块“ tensorflow._api.v1.compat.v1”没有属性“ pywrap_tensorflow” - AttributeError: module 'tensorflow._api.v1.compat.v1' has no attribute 'pywrap_tensorflow' 属性 AttributeError:模块“tensorflow.compat.v2”没有属性“_internal_” - Attribute AttributeError: module 'tensorflow.compat.v2' has no attribute '_internal_' 导入时出错 keras: AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'register_clear_session_function' - Error while import keras: AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'register_clear_session_function'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM