qubvel / segmentation_models

Segmentation models with pretrained backbones. Keras and TensorFlow Keras.
MIT License
4.73k stars 1.03k forks source link

Keras layers to Tensorflow keras layers - help! #524

Open sachinkmohan opened 2 years ago

sachinkmohan commented 2 years ago

Wonderful repository! Thanks!

Using -> TF 1.15

I wanted to optimize this repository using the tensorflow model optimization techniques but I am having a challenge.

After creating the model as below

# define network parameters
n_classes = 1 if len(CLASSES) == 1 else (len(CLASSES) + 1)  # case for binary and multiclass segmentation
activation = 'sigmoid' if n_classes == 1 else 'softmax'

#create model
model = sm.Unet(BACKBONE, classes=n_classes, activation=activation)

I checked the type of the model type(model) -> keras.engine.training.Model

But I need the model type to be -> tensorflow.python.keras.engine.training.Model

Does someone have an idea how to convert into tensorflow.python.keras.engine.training.Model ?

kitbransby commented 2 years ago

Have you tried : import segmentation_models as sm sm.set_framework('tf.keras') ?