title: how to import segmentation-models with tensorflow keras? getting ModuleNotFoundError: No module named 'keras.legacy'
body: <p>I tried to install segmentation-models using.</p>
  <pre><code>!pip install -U segmentation-models==0.2.1  
  </code></pre>
  <pre><code>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
  </code></pre>
  <p>Resulted in error: ModuleNotFoundError: No module named 'keras.legacy'</p>
  <p>Following is the stack trace</p>
  <pre><code>
  stack Trace:
  ---------------------------------------------------------------------------
  
  ModuleNotFoundError                       Traceback (most recent call last)
  
  &lt;ipython-input-16-7b5049dd4be0&gt; in &lt;module&gt;()
  ----&gt; 1 import segmentation_models as sm
  
  6 frames
  
  /usr/local/lib/python3.7/dist-packages/segmentation_models/__init__.py in &lt;module&gt;()
        4 
        5 from .unet import Unet
  ----&gt; 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 &lt;module&gt;()
  ----&gt; 1 from .model import FPN
        2 
  
  /usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/model.py in &lt;module&gt;()
  ----&gt; 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 &lt;module&gt;()
        6 from keras.models import Model
        7 
  ----&gt; 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 &lt;module&gt;()
        1 from keras.layers import Add
        2 
  ----&gt; 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 &lt;module&gt;()
        1 from .blocks import Conv2DBlock
  ----&gt; 2 from .layers import ResizeImage
  
  /usr/local/lib/python3.7/dist-packages/segmentation_models/common/layers.py in &lt;module&gt;()
        2 from keras.engine import InputSpec
        3 from keras.utils import conv_utils
  ----&gt; 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
  &quot;Open Examples&quot; button below.
  ---------------------------------------------------------------------------
  </code></pre>
  <p>Solution Tried:
  To downgrade both tensorflow and keras to</p>
  <pre><code>!pip install tensorflow==2.2.0
  !pip install keras==2.3.1
  </code></pre>
  <p>But it is creating conflict between the tensorflow.keras and keras.
  Is there any way to work this using tensorflow.keras?</p>