JanMarcelKezmann / TensorFlow-Advanced-Segmentation-Models

A Python Library for High-Level Semantic Segmentation Models based on TensorFlow and Keras with pretrained backbones.
Other
151 stars 46 forks source link

backbones and models #3

Closed minouei-kl closed 3 years ago

minouei-kl commented 3 years ago

Hi, Congratulations on your work. this project is great! I have a question: Are all the models and backbones compatible with one another or every model should be trained with a specific backbone?

JanMarcelKezmann commented 3 years ago

Hi minoeui-kl,

thank you. The project was designed in a way that allows in easy integration of any backbone into any of the given models. So to answer your question, yes all the backbones are compatible with all the models. (If not please tell me and I will fix it) Next to that, you could also design your own backbone and give it to the model if you choose the "layers" & "layer_names" properly.

minouei-kl commented 3 years ago

Hi, I have been doing some testing. I followed the examples and trained the DANet and saved a checkpoint and loaded it again everything works fine but encounter a problem with DeepLabV3plus when trying to load a checkpoint and doing predict. I'm getting this error:

    /usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/training.py:1462 predict_function  *
        return step_function(self, iterator)
    /home/minouei/Documents/models/report/tf/TensorFlow-Advanced-Segmentation-Models/tensorflow_advanced_segmentation_models/models/DeepLabV3plus.py:66 call  *
        encoder = self.atrous_sepconv_bn_relu_1(x, training)
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/base_layer.py:982 __call__  **
        self._maybe_build(inputs)
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/base_layer.py:2643 _maybe_build
        self.build(input_shapes)  # pylint:disable=not-callable
    /home/minouei/Documents/models/report/tf/TensorFlow-Advanced-Segmentation-Models/tensorflow_advanced_segmentation_models/models/_custom_layers_and_blocks.py:128 build
        self.dw_filter = self.add_weight(
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/base_layer.py:597 add_weight
        variable = self._add_variable_with_custom_getter(
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/training/tracking/base.py:730 _add_variable_with_custom_getter
        checkpoint_initializer = self._preload_simple_restoration(
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/training/tracking/base.py:797 _preload_simple_restoration
        return CheckpointInitialValue(
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/training/tracking/base.py:75 __init__
        self.wrapped_value.set_shape(shape)
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/ops.py:1207 set_shape
        raise ValueError(

    ValueError: Tensor's shape (1, 1, 288, 256) is not compatible with supplied shape [3, 3, 288, 1]

seems to be related to _custom_layers_and_blocks.py but I couldn't debug it. have you any hint regarding this?

JanMarcelKezmann commented 3 years ago

Hi, I could not replicate the error. Can you maybe show me the code parts, where you defined the model initially as well as the parts where you load the weights including the code where you run the prediction? Do you checked if the initialization of the model is for the training and restoring part the same?

JanMarcelKezmann commented 3 years ago

So I have double checked it and I assume that you have used the subclassed model and not the functional one to define the DeepLabV3plus model, with that I received the same error message as you.

The problem lies in the definition of the AtrousSeparableConvBnReLU layer in _custom_layers_and_blocks.py, where I have defined the _dwfilter and _pwfilter for the separable convolution. The problem was that I do not set the parameter trainable=True, which caused the error message.

I have fixed this now and already updated the repository and in my case the training as well as the prediction ran perfectly. I hope it works in your case too.

minouei-kl commented 3 years ago

Hi, it's great! thank you for your response. would you explain how I can define the model in functional mode instead of the subclassed mode?

JanMarcelKezmann commented 3 years ago

Hi, your welcome. In the Readme at the end of the Models and Backbones section I already mentioned it:

"Further Model Information

A new feature makes it possible to define the model as a Subclassed Model or as a Functional Model instead. To define the model as a Subclassed Model just write: tasm.UNet to define the UNet or replace it with any other model. If you want to define the Functional Model instead just append .model(), i.e. tasm.UNet.model(). This provides further TensorFlow features like saving the model in the "tf" format."

I hope that answers your question.

minouei-kl commented 3 years ago

Hi, I have another question. There is a function in the examples called data_get_preprocessing that accept a preprocessing_fn but there is no example of a preprocessing_fn. would you illustrate this more? or an example of a preprocessing function?

JanMarcelKezmann commented 3 years ago

I had taken that idea for the preprocessing_fn() from another github repository but later discarded it, since I found it unnecessary to implement it properly in my repository. Therefore this is more or less outdated and just code for testing purposes I forgot to delete. I will take it out, thank you.