'ImportError: cannot import name 'get_source_inputs' from 'keras.engine' (/usr/local/lib/python3.7/dist-packages/keras/engine/__init__.py)

Here when i import the library i found this type of error, i tried everythings but i can not slove the problem

import segmentation_models as sm
from segmentation_models import Unet
# sm.set_framework('tf.keras')
tf.keras.backend.set_image_data_format('channels_last')

while importing the library I got this type of errors

ImportError                               Traceback (most recent call last)
<ipython-input-98-9567886360a6> in <module>()
      2 # we are importing the pretrained unet from the segmentation models
      3 # https://github.com/qubvel/segmentation_models
----> 4 import segmentation_models as sm
      5 from segmentation_models import Unet
      6 # sm.set_framework('tf.keras')

7 frames
/usr/local/lib/python3.7/dist-packages/classification_models/resnet/builder.py in <module>()
      9 from keras.layers import Dense
     10 from keras.models import Model
---> 11 from keras.engine import get_source_inputs
     12 
     13 from .params import get_conv_params

ImportError: cannot import name 'get_source_inputs' from 'keras.engine' (/usr/local/lib/python3.7/dist-packages/keras/engine/__init__.py)


Solution 1:[1]

import tensorflow at the top and change

from keras.engine import get_source_inputs

to

from tensorflow.keras.utils import get_source_inputs

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Benjamin Breton