模块'tensorflow.compat.v2 .__ internal__'没有属性'tf2' [英] module 'tensorflow.compat.v2.__internal__' has no attribute 'tf2'
问题描述
昨天我尝试使用TensorFlow作为后端,但今天,当我尝试导入Keras时,使用它显示一些错误消息,所以这是我的代码:
I'm trying to use TensorFlow as backend yesterday I can use it, but today when I use it to show some error message when I'm trying to import Keras, so here's my code:
# Install required libs
# NOTE: Run this one code, then restart this runtime and run again for next all... (PENTING!!!)
### please update Albumentations to version>=0.3.0 for `Lambda` transform support
!pip install -U segmentation-models
!pip install q tensorflow==2.1
!pip install q keras==2.3.1
!pip install tensorflow-estimator==2.1.
## Imports libs
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
import cv2
import Keras
import NumPy as np
import matplotlib.pyplot as plt
它显示此错误:
AttributeError Traceback (most recent call last)
<ipython-input-3-9c78a7be919d> in <module>()
5
6 import cv2
----> 7 import keras
8 import numpy as np
9 import matplotlib.pyplot as plt
8 frames
/usr/local/lib/python3.7/dist-packages/keras/initializers/__init__.py in populate_deserializable_objects()
47
48 LOCAL.ALL_OBJECTS = {}
---> 49 LOCAL.GENERATED_WITH_V2 = tf.__internal__.tf2.enabled()
50
51 # Compatibility aliases (need to exist in both V1 and V2).
AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'tf2'
因此,当我使用TensorFlow 2.2版和Keras 2.3.1版时,昨天我可以运行,但今天似乎无法运行.对于今天的Keras和TensorFlow,我导入的版本是否错误?
while therefore I was using TensorFlow version 2.2 and Keras version 2.3.1, yesterday I can run, but today it seems can't. did I was the wrong version import for my Keras and TensorFlow for today?
当我从tensorFlow import keras使用时,我想要的
使用tensorflow后端
的输出未显示,然后当我将 import segmentation_models加载为sm
当我像上面一样使用 import Keras
时,它会显示相同的错误.
when I use from tensorFlow import keras
the output I want using tensorflow backend
doesn't show up, And then when I load import segmentation_models as sm
it shows the same error when I use import Keras
like on above.
推荐答案
这是您的问题的解决方案,我已经在colab上对其进行了测试.
Here is the solution to your problem, I've tested it on colab.
!pip install -U -q segmentation-models
!pip install -q tensorflow==2.1
!pip install -q keras==2.3.1
!pip install -q tensorflow-estimator==2.1.
## Imports libs
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
os.environ["SM_FRAMEWORK"] = "tf.keras"
from tensorflow import keras
import segmentation_models as sm
|████████████████████████████████| 51kB 3.3MB/s
|████████████████████████████████| 421.8MB 42kB/s
|████████████████████████████████| 450kB 35.7MB/s
|████████████████████████████████| 3.9MB 33.6MB/s
Building wheel for gast (setup.py) ... done
ERROR: tensorflow-probability 0.12.1 has requirement gast>=0.3.2,
but you'll have gast 0.2.2 which is incompatible.
|████████████████████████████████| 378kB 2.1MB/s
Segmentation Models: using `tf.keras` framework.
这篇关于模块'tensorflow.compat.v2 .__ internal__'没有属性'tf2'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!