qubvel / segmentation_models

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

Can I use my own custom feature extraction model to export to the backbone? #586

Open emrullahpolat opened 4 months ago

emrullahpolat commented 4 months ago

Hello, I want to use the UNet of Segmentation Model, I tried VGG and effnetB3 to add backbone. I wonder if I can add my own Keras feature extraction model. For example ;

`feature_extract_model = tf.keras.models.Sequential([

tf.keras.layers.Conv2D(128, (5, 5), strides=(4, 4), activation='relu', input_shape=(image_width, image_height, 3)),
tf.keras.layers.BatchNormalization(),
tf.keras.layers.MaxPooling2D(3, strides=(2, 2)),

tf.keras.layers.Conv2D(256, (3, 3), strides=(1, 1), activation='relu', padding='same'),
tf.keras.layers.BatchNormalization(),

tf.keras.layers.Conv2D(128, (5, 5), strides=(1, 1), activation='relu', padding='same'),
tf.keras.layers.BatchNormalization(),
tf.keras.layers.MaxPooling2D(3, strides=(2, 2))
])

model = sm.Linknet(BACKBONE=feature_extract_model , classes=n_classes, activation=activation, encoder_weights=None, encoder_freeze=True)

Do you think It is true?

qubvel commented 4 months ago

Hi @emrullahpolat, unfortunately, it is not that trivial, but you can do it. Here is an example https://segmentation-models-pytorch.readthedocs.io/en/latest/insights.html#creating-your-own-encoder

emrullahpolat commented 4 months ago

Thanks @qubvel, Can I use the these codes Keras backend? It seems as Pytorch.

qubvel commented 4 months ago

Not sure if you can, I don't have experience with Keras+(Pytorch backend). Let me know if you will be able to use it :)