how to import segmentation-models with tensorflow keras? getting ModuleNotFoundError: No module named 'keras.legacy'
how to import segmentation-models with tensorflow keras? getting ModuleNotFoundError: No module named 'keras.legacy'
我尝试使用安装分段模型。
!pip install -U segmentation-models==0.2.1
import tensorflow as tf
import tensorflow.keras as keras
print(tf.__version__)
print(keras.__version__)
Output:
2.4.1
2.4.0
# Tried for import
import segmentation_models as sm
导致错误:ModuleNotFoundError:没有名为 'keras.legacy'
的模块
以下是堆栈跟踪
stack Trace:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-16-7b5049dd4be0> in <module>()
----> 1 import segmentation_models as sm
6 frames
/usr/local/lib/python3.7/dist-packages/segmentation_models/__init__.py in <module>()
4
5 from .unet import Unet
----> 6 from .fpn import FPN
7 from .linknet import Linknet
8 from .pspnet import PSPNet
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/__init__.py in <module>()
----> 1 from .model import FPN
2
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/model.py in <module>()
----> 1 from .builder import build_fpn
2 from ..backbones import get_backbone, get_feature_layers
3 from ..utils import freeze_model
4 from ..utils import legacy_support
5
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/builder.py in <module>()
6 from keras.models import Model
7
----> 8 from .blocks import pyramid_block
9 from ..common import ResizeImage
10 from ..common import Conv2DBlock
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/blocks.py in <module>()
1 from keras.layers import Add
2
----> 3 from ..common import Conv2DBlock
4 from ..common import ResizeImage
5 from ..utils import to_tuple
/usr/local/lib/python3.7/dist-packages/segmentation_models/common/__init__.py in <module>()
1 from .blocks import Conv2DBlock
----> 2 from .layers import ResizeImage
/usr/local/lib/python3.7/dist-packages/segmentation_models/common/layers.py in <module>()
2 from keras.engine import InputSpec
3 from keras.utils import conv_utils
----> 4 from keras.legacy import interfaces
5 from keras.utils.generic_utils import get_custom_objects
6
ModuleNotFoundError: No module named 'keras.legacy'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
尝试的解决方案:
将 tensorflow 和 keras 降级到
!pip install tensorflow==2.2.0
!pip install keras==2.3.1
但它在 tensorflow.keras 和 keras 之间造成了冲突。
有什么方法可以使用 tensorflow.keras?
截至目前,以下方法正在发挥作用。
不要尝试使用特定版本的 segmentation_models 模块。
#install this way
!pip3 install tensorflow==2.2
!pip3 install keras==2.3.1
!pip3 install -U segmentation-models
import tensorflow as tf
import tensorflow.keras as keras
import segmentation_models as sm
现在segmentation_models导入成功。
我尝试使用安装分段模型。
!pip install -U segmentation-models==0.2.1
import tensorflow as tf
import tensorflow.keras as keras
print(tf.__version__)
print(keras.__version__)
Output:
2.4.1
2.4.0
# Tried for import
import segmentation_models as sm
导致错误:ModuleNotFoundError:没有名为 'keras.legacy'
的模块以下是堆栈跟踪
stack Trace:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-16-7b5049dd4be0> in <module>()
----> 1 import segmentation_models as sm
6 frames
/usr/local/lib/python3.7/dist-packages/segmentation_models/__init__.py in <module>()
4
5 from .unet import Unet
----> 6 from .fpn import FPN
7 from .linknet import Linknet
8 from .pspnet import PSPNet
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/__init__.py in <module>()
----> 1 from .model import FPN
2
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/model.py in <module>()
----> 1 from .builder import build_fpn
2 from ..backbones import get_backbone, get_feature_layers
3 from ..utils import freeze_model
4 from ..utils import legacy_support
5
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/builder.py in <module>()
6 from keras.models import Model
7
----> 8 from .blocks import pyramid_block
9 from ..common import ResizeImage
10 from ..common import Conv2DBlock
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/blocks.py in <module>()
1 from keras.layers import Add
2
----> 3 from ..common import Conv2DBlock
4 from ..common import ResizeImage
5 from ..utils import to_tuple
/usr/local/lib/python3.7/dist-packages/segmentation_models/common/__init__.py in <module>()
1 from .blocks import Conv2DBlock
----> 2 from .layers import ResizeImage
/usr/local/lib/python3.7/dist-packages/segmentation_models/common/layers.py in <module>()
2 from keras.engine import InputSpec
3 from keras.utils import conv_utils
----> 4 from keras.legacy import interfaces
5 from keras.utils.generic_utils import get_custom_objects
6
ModuleNotFoundError: No module named 'keras.legacy'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
尝试的解决方案: 将 tensorflow 和 keras 降级到
!pip install tensorflow==2.2.0
!pip install keras==2.3.1
但它在 tensorflow.keras 和 keras 之间造成了冲突。 有什么方法可以使用 tensorflow.keras?
截至目前,以下方法正在发挥作用。 不要尝试使用特定版本的 segmentation_models 模块。
#install this way
!pip3 install tensorflow==2.2
!pip3 install keras==2.3.1
!pip3 install -U segmentation-models
import tensorflow as tf
import tensorflow.keras as keras
import segmentation_models as sm
现在segmentation_models导入成功。