Code Monkey home page Code Monkey logo

tensorflow-advanced-segmentation-models's Introduction

TensorFlow Advanced Segmentation Models

A Python Library for High-Level Semantic Segmentation Models.

Preface

Since the breakthrough of Deep Learning and Computer Vision was always one of the core problems that researcher all over the world have worked on, to create better models every day. One Computer Vision area that got huge attention in the last couple of years is Semantic Segmentation. The task to segment every pixel on a given image led to the invention of many great models starting with the classical U-Net up to now more and more complex neural network structures. But even though many new algorithms were developed, the distribution of easy to use open source libraries which contain High-Level APIs that make the technology accessible for everyone is still far behind the huge amount of research that is published continuously.

Inspired by qubvel's segmentation_models this repository builds upon his work and extends it by a variety of recently developed models which achieved great results on the Cityscapes, PASCAL VOC 2012, PASCAL Context, ADE20K dataset and many more.

The library contains to date 14 different Semantic Segmentation Model Architecters for multi-class semantic segmentation as well as many on imagenet pretrained backbones. An important new feature is the upgrade to Tensorflow 2.x including the use of the advanced model subclassing feauture to build customized segmentation models. Further are now all system platforms compatible with the library this means that tasm can run on Windows, Linux and MacOS as well.

Main Library Features

  • High Level API
  • 14 Segmentation Model Architectures for multi-class semantic segmentation
    • New: HRNet + OCR Model
  • Many already pretrained backbones for each architecture
  • Many useful segmentation losses (Dice, Focal, Tversky, Jaccard and many more combinations of them)
  • New: Models can be used as Subclassed or Functional Model
  • New: TASM works now on all platforms, i.e. Windows, Linux, MacOS with Intel or Apple Silicon Chips

Table of Contents

Installation and Setup

To get the repository running just check the following requirements.

Requirements Windows or Linus

  1. Python 3.6 or higher
  2. tensorflow >= 2.3.0 (>= 2.0.0 is sufficient if no efficientnet backbone is used)
  3. numpy
  4. matplotlib

MacOS

  1. Python 3.9 or higher
  2. tensorflow-macos >= 2.5.0
  3. numpy >= 1.21.0
  4. matplotlib

Furthermore just execute the following command to download and install the git repository.

Clone Repository

$ git clone https://github.com/JanMarcelKezmann/TensorFlow-Advanced-Segmentation-Models.git

or directly install it:
Pip Install Repository

$ pip install git+https://github.com/JanMarcelKezmann/TensorFlow-Advanced-Segmentation-Models.git

Training Pipeline

Please check that Tensorflow is installed on your computer.

To import the library just use the standard python import statement:

import tensorflow_advanced_segmentation_models as tasm

Then pick any model backbone from the list below and define weights, height and width:

BACKBONE_NAME = "efficientnetb3"
WEIGHTS = "imagenet"
HEIGHT = 320
WIDTH = 320

Load the data

TrainingGenerator, ValidationGenerator = get_data(...)

Create the base model that works as backbone for the segmentation model:

base_model, layers, layer_names = tasm.create_base_model(name=BACKBONE_NAME, weights=WEIGHTS, height=HEIGHT, width=WIDTH)

Define a Model and compile it with an appropriate loss:

model = tasm.DANet(n_classes=3, base_model=base_model, output_layers=layers, backbone_trainable=False)
model.compile(tf.keras.optimizers.Adam(0.0001), loss=tasm.losses.CategoricalFocalLoss, tasm.metrics.IOUScore(threshold=0.5))

If you want to use the Functional Model class define instead:

model = tasm.DANet(n_classes=3, base_model=base_model, output_layers=layers, backbone_trainable=False).model()
model.compile(tf.keras.optimizers.Adam(0.0001), loss=tasm.losses.CategoricalFocalLoss, tasm.metrics.IOUScore(threshold=0.5))

Now finally train the model:

history = model.fit(
    TrainingGenerator
    batch_size=8,
    epochs=50,
    validation_data=ValidationGenerator
)

You can use the fit_generator method too, e.g. if you want to apply augmentations to the data. For complete training pipelines, go to the Examples folder

Examples

  • [Jupyter Notebook] Multi-class (3 classes) segmentation (sky, building, background) on CamVid dataset here
  • [Jupyter Notebook] Multi-class (11 classes) segmentation on CamVid dataset here
  • [Jupyter Notebook] Multi-class (11 classes) segmentation on CamVid dataset with a custom training loophere
  • [Jupyter Notebook] Two-class (2 classes) segmentation on Caltech-Birds-2010 dataset here

Models and Backbones

Models

Backbones (For Details see here.)

Type Names
VGG 'vgg16' 'vgg19'
ResNet 'resnet50' 'resnet50v2' 'resnet101' 'resnet101v2' 'resnet152' 'resnet152v2'
Xception 'xception'
MobileNet 'mobilenet' 'mobilenetv2' 'mobilenetv3small'
NASNet 'nasnetlarge' 'nasnetmobile'
DenseNet 'densenet121' 'densenet169' 'densenet201'
EfficientNet 'efficientnetb0' 'efficientnetb1' 'efficientnetb2' 'efficientnetb3' 'efficientnetb4' 'efficientnetb5' 'efficientnetb6' efficientnetb7'
All backbones have weights trained on 2012 ILSVRC ImageNet dataset.

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.

Citing

@misc{Kezmann:2020,
  Author = {Jan-Marcel Kezmann},
  Title = {Tensorflow Advanced Segmentation Models},
  Year = {2020},
  Publisher = {GitHub},
  Journal = {GitHub repository},
  Howpublished = {\url{https://github.com/JanMarcelKezmann/TensorFlow-Advanced-Segmentation-Models}}
}

License

Project is distributed under MIT License.

References

Thank you for all the papers that made this repository possible and especially thank you Pavel Yakubovskiy's initial segmentation models repository.

tensorflow-advanced-segmentation-models's People

Contributors

janmarcelkezmann avatar nackjaylor avatar shub-kris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

tensorflow-advanced-segmentation-models's Issues

HRNetOCR error

Hi

it seems tasm.HRNetOCR give error with any backbone.

TypeError Traceback (most recent call last)
in ()
2
3 BACKBONE_TRAINABLE = False
----> 4 model = tasm.HRNetOCR(n_classes=N_CLASSES, base_model=base_model, output_layers=layers, backbone_trainable=BACKBONE_TRAINABLE)

3 frames
/usr/local/lib/python3.7/dist-packages/keras/utils/generic_utils.py in validate_kwargs(kwargs, allowed_kwargs, error_message)
1168 for kwarg in kwargs:
1169 if kwarg not in allowed_kwargs:
-> 1170 raise TypeError(error_message, kwarg)
1171
1172

TypeError: ('Keyword argument not understood:', 'base_model')

keypoint detection

hello author,

can the hrnet model be used to detect keypoints by heatmap regression?

Change Logo

logo

I was reading the README and noticed that there is a spelling error in the project logo, where instead of segmentation it says "segmeNAtion". I believe that to improve the presentation of the repository, the ideal would be to update the logo with the commented change.

Trainable Parameters

Hi there!

I have been using your repository quite extensively and I must say, I really like it so far! So thank you very much!

I do have one question though: I am training a Deeplabv3+ model with ResNet-50 as backbone.

image

As you can see, it says that the network has rougly 3.5M trainable parameters. But doesn't ResNet-50 have more than 23M trainable parameters? Or am I missing something?

Thanks in advance!
Hball99

error: OpenCV(4.5.5) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

I am currently running the jupyter notebook from the examples folder. The first one.

scores = model.evaluate(TestSet, steps=101)

print("Loss: {:.5}".format(scores[0]))
for metric, value in zip(metrics, scores[1:]):
    if metric != "accuracy":
        metric = metric.__name__
    print("mean {}: {:.5}".format(metric, value))

When I try to run the above block, I am getting the below error

error                                     Traceback (most recent call last)
<ipython-input-16-50d655bc0639> in <module>
----> 1 scores = model.evaluate(TestSet, steps=101)
      2 
      3 print("Loss: {:.5}".format(scores[0]))
      4 for metric, value in zip(metrics, scores[1:]):
      5     if metric != "accuracy":

~/.local/lib/python3.7/site-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
     65     except Exception as e:  # pylint: disable=broad-except
     66       filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67       raise e.with_traceback(filtered_tb) from None
     68     finally:
     69       del filtered_tb

<ipython-input-7-23e4dfb47eb3> in DataGenerator(train_dir, label_dir, batch_size, height, width, classes, augmentation, wwo_aug, shuffle, seed)
     80             for i in range(batch_size):
     81                 image_path, label_path = next(image_label_path_generator)
---> 82                 image, label = process_image_label(image_path, label_path, classes=classes, augmentation=augmentation)
     83                 images[i], labels[i] = image, label
     84 

<ipython-input-7-23e4dfb47eb3> in process_image_label(images_paths, masks_paths, classes, augmentation, preprocessing)
     30     # read data
     31     image = cv2.imread(images_paths)
---> 32     image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
     33     mask = cv2.imread(masks_paths, 0)
     34 

error: OpenCV(4.5.5) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

Somehow the images are not getting generated I guess. Can you please help.

P.S - I replaced TestSet with ValidationSet and it works.

error in tf_backbones.py

Hi. I was running TASM_Example_2.ipynb and got this error. There is still error when I change the backbone name.

NameError Traceback (most recent call last)
in ()
----> 1 base_model, layers, layer_names = tasm.create_base_model(name=BACKBONE_NAME, weights=WEIGHTS, height=HEIGHT, width=WIDTH, include_top=False, pooling=None)
2
3 BACKBONE_TRAINABLE = False
4 model = tasm.DANet(n_classes=N_CLASSES, base_model=base_model, output_layers=layers, backbone_trainable=BACKBONE_TRAINABLE)

/content/drive/My Drive/cityscape/TensorFlow-Advanced-Segmentation-Models/tensorflow_advanced_segmentation_models/backbones/tf_backbones.py in create_base_model(name, weights, height, width, channels, include_top, pooling, alpha, depth_multiplier, dropout)
91 if height <= 31 or width <= 31:
92 raise ValueError("Parameters 'height' and 'width' should not be smaller than 32.")
---> 93 base_model = tf.keras.applications.ResNet50(include_top=include_top, weights=weights, input_shape=input_shape, pooling=pooling)
94 layer_names = ["conv1_relu", "conv2_block3_out", "conv3_block4_out", "conv4_block6_out", "conv5_block3_out"]
95 elif name.lower() == "resnet50v2":

NameError: name 'tf' is not defined

score is misspelled in two function

score is misspelled in these two function as sccore than results in an error:

def precision(y_true, y_pred, class_weights=1., smooth=1e-5, threshold=None):
y_true, y_pred = gather_channels(y_true, y_pred)
y_pred = round_if_needed(y_pred, threshold)
axes = [1, 2] if K.image_data_format() == "channels_last" else [2, 3]
tp = K.sum(y_true * y_pred, axis=axes)
fp = K.sum(y_pred, axis=axes) - tp
score = (tp + smooth) / (tp + fp + smooth)
score = average(sccore, class_weights)
return score

def recall(y_true, y_pred, class_weights=1., smooth=1e-5, threshold=None):
y_true, y_pred = gather_channels(y_true, y_pred)
y_pred = round_if_needed(y_pred, threshold)
axes = [1, 2] if K.image_data_format() == "channels_last" else [2, 3]
tp = K.sum(y_true * y_pred, axis=axes)
fn = K.sum(y_true, axis=axes) - tp
score = (tp + smooth) / (tp + fn + smooth)
score = average(sccore, class_weights)
return score

UNet Model has too many non-trainable variables

I was testing the UNet model along with a mobilenetv2 and saw that there are a lot non-trainable params, which I could not explain. I quick lookup in the model revealed that besides the non-trainable BN params, there are also normal kernels that are marked as non-trainable. I guess this behavior is not desired.

Correct me if I am wrong, but I guess the default trainable parameter should be set to true ?

class Upsample_x2_Block(tf.keras.layers.Layer):
"""
"""
def __init__(self, filters, trainable=None):
super(Upsample_x2_Block, self).__init__()
self.trainable = trainable

Model: "UNet_mobilenetv2_1.00_None"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input (InputLayer)           [(None, None, None, 3)]   0         
_________________________________________________________________
u_net (UNet)                 (None, None, None, 30)    15387454  
=================================================================
Total params: 15,387,454
Trainable params: 2,384,222
Non-trainable params: 13,003,232
for variable in model.non_trainable_variables:
    print(variable.name)
u_net/convolution_bn_activation/batch_normalization/moving_mean:0
u_net/convolution_bn_activation/batch_normalization/moving_variance:0
u_net/convolution_bn_activation_1/batch_normalization_1/moving_mean:0
u_net/convolution_bn_activation_1/batch_normalization_1/moving_variance:0
u_net/upsample_x2__block/conv2d/kernel:0
u_net/upsample_x2__block/conv2d/bias:0
u_net/upsample_x2__block/convolution_bn_activation_2/conv2d_2/kernel:0
u_net/upsample_x2__block/convolution_bn_activation_2/conv2d_2/bias:0
u_net/upsample_x2__block/convolution_bn_activation_2/batch_normalization_2/gamma:0
u_net/upsample_x2__block/convolution_bn_activation_2/batch_normalization_2/beta:0
u_net/upsample_x2__block/convolution_bn_activation_2/batch_normalization_2/moving_mean:0
u_net/upsample_x2__block/convolution_bn_activation_2/batch_normalization_2/moving_variance:0
u_net/upsample_x2__block/convolution_bn_activation_3/conv2d_3/kernel:0
u_net/upsample_x2__block/convolution_bn_activation_3/conv2d_3/bias:0
u_net/upsample_x2__block/convolution_bn_activation_3/batch_normalization_3/gamma:0
u_net/upsample_x2__block/convolution_bn_activation_3/batch_normalization_3/beta:0
u_net/upsample_x2__block/convolution_bn_activation_3/batch_normalization_3/moving_mean:0
u_net/upsample_x2__block/convolution_bn_activation_3/batch_normalization_3/moving_variance:0
u_net/upsample_x2__block_1/conv2d_1/kernel:0
u_net/upsample_x2__block_1/conv2d_1/bias:0
u_net/upsample_x2__block_1/convolution_bn_activation_4/conv2d_4/kernel:0
u_net/upsample_x2__block_1/convolution_bn_activation_4/conv2d_4/bias:0
u_net/upsample_x2__block_1/convolution_bn_activation_4/batch_normalization_4/gamma:0
u_net/upsample_x2__block_1/convolution_bn_activation_4/batch_normalization_4/beta:0
u_net/upsample_x2__block_1/convolution_bn_activation_4/batch_normalization_4/moving_mean:0
u_net/upsample_x2__block_1/convolution_bn_activation_4/batch_normalization_4/moving_variance:0
u_net/upsample_x2__block_1/convolution_bn_activation_5/conv2d_5/kernel:0
u_net/upsample_x2__block_1/convolution_bn_activation_5/conv2d_5/bias:0
u_net/upsample_x2__block_1/convolution_bn_activation_5/batch_normalization_5/gamma:0
u_net/upsample_x2__block_1/convolution_bn_activation_5/batch_normalization_5/beta:0
u_net/upsample_x2__block_1/convolution_bn_activation_5/batch_normalization_5/moving_mean:0
u_net/upsample_x2__block_1/convolution_bn_activation_5/batch_normalization_5/moving_variance:0
u_net/upsample_x2__block_2/conv2d_2/kernel:0
u_net/upsample_x2__block_2/conv2d_2/bias:0
u_net/upsample_x2__block_2/convolution_bn_activation_6/conv2d_6/kernel:0
u_net/upsample_x2__block_2/convolution_bn_activation_6/conv2d_6/bias:0
u_net/upsample_x2__block_2/convolution_bn_activation_6/batch_normalization_6/gamma:0
u_net/upsample_x2__block_2/convolution_bn_activation_6/batch_normalization_6/beta:0
u_net/upsample_x2__block_2/convolution_bn_activation_6/batch_normalization_6/moving_mean:0
u_net/upsample_x2__block_2/convolution_bn_activation_6/batch_normalization_6/moving_variance:0
u_net/upsample_x2__block_2/convolution_bn_activation_7/conv2d_7/kernel:0
u_net/upsample_x2__block_2/convolution_bn_activation_7/conv2d_7/bias:0
u_net/upsample_x2__block_2/convolution_bn_activation_7/batch_normalization_7/gamma:0
u_net/upsample_x2__block_2/convolution_bn_activation_7/batch_normalization_7/beta:0
u_net/upsample_x2__block_2/convolution_bn_activation_7/batch_normalization_7/moving_mean:0
u_net/upsample_x2__block_2/convolution_bn_activation_7/batch_normalization_7/moving_variance:0
u_net/upsample_x2__block_3/conv2d_3/kernel:0
u_net/upsample_x2__block_3/conv2d_3/bias:0
u_net/upsample_x2__block_3/convolution_bn_activation_8/conv2d_8/kernel:0
u_net/upsample_x2__block_3/convolution_bn_activation_8/conv2d_8/bias:0
u_net/upsample_x2__block_3/convolution_bn_activation_8/batch_normalization_8/gamma:0
u_net/upsample_x2__block_3/convolution_bn_activation_8/batch_normalization_8/beta:0
u_net/upsample_x2__block_3/convolution_bn_activation_8/batch_normalization_8/moving_mean:0
u_net/upsample_x2__block_3/convolution_bn_activation_8/batch_normalization_8/moving_variance:0
u_net/upsample_x2__block_3/convolution_bn_activation_9/conv2d_9/kernel:0
u_net/upsample_x2__block_3/convolution_bn_activation_9/conv2d_9/bias:0
u_net/upsample_x2__block_3/convolution_bn_activation_9/batch_normalization_9/gamma:0
u_net/upsample_x2__block_3/convolution_bn_activation_9/batch_normalization_9/beta:0
u_net/upsample_x2__block_3/convolution_bn_activation_9/batch_normalization_9/moving_mean:0
u_net/upsample_x2__block_3/convolution_bn_activation_9/batch_normalization_9/moving_variance:0
u_net/upsample_x2__block_4/conv2d_4/kernel:0
u_net/upsample_x2__block_4/conv2d_4/bias:0
u_net/upsample_x2__block_4/convolution_bn_activation_10/conv2d_10/kernel:0
u_net/upsample_x2__block_4/convolution_bn_activation_10/conv2d_10/bias:0
u_net/upsample_x2__block_4/convolution_bn_activation_10/batch_normalization_10/gamma:0
u_net/upsample_x2__block_4/convolution_bn_activation_10/batch_normalization_10/beta:0
u_net/upsample_x2__block_4/convolution_bn_activation_10/batch_normalization_10/moving_mean:0
u_net/upsample_x2__block_4/convolution_bn_activation_10/batch_normalization_10/moving_variance:0
u_net/upsample_x2__block_4/convolution_bn_activation_11/conv2d_11/kernel:0
u_net/upsample_x2__block_4/convolution_bn_activation_11/conv2d_11/bias:0
u_net/upsample_x2__block_4/convolution_bn_activation_11/batch_normalization_11/gamma:0
u_net/upsample_x2__block_4/convolution_bn_activation_11/batch_normalization_11/beta:0
u_net/upsample_x2__block_4/convolution_bn_activation_11/batch_normalization_11/moving_mean:0
u_net/upsample_x2__block_4/convolution_bn_activation_11/batch_normalization_11/moving_variance:0

Support for 'mixed_float16'

Saw your article in Medium, from October 7, and wanted to try it out on my 3090. (Training in 143.27s and Inference in 196.57s, for the Semantic Segmentation). Then I wanted to test with 16-bit floats, by adding:

from tensorflow.keras import mixed_precision
mixed_precision.set_global_policy('mixed_float16')

However, the code crashes in model.fit due to lack of float16 support in your custom_layers_and_blocks:

File ~/anaconda3/lib/python3.9/site-packages/tensorflow_advanced_segmentation_models/models/_custom_layers_and_blocks.py:252, in AtrousSpatialPyramidPoolingV3.call(self, input_tensor, training)
    249 z = self.atrous_sepconv_bn_relu_3(input_tensor, training=training)
    251 # concatenation
--> 252 net = tf.concat([glob_avg_pool, w, x, y, z], axis=-1)
    253 net = self.conv_reduction_1(net, training=training)
    255 return net

InvalidArgumentError: Exception encountered when calling layer 'atrous_spatial_pyramid_pooling_v3_4' (type AtrousSpatialPyramidPoolingV3).

cannot compute ConcatV2 as input #1(zero-based) was expected to be a float tensor but is a half tensor [Op:ConcatV2] name: concat

Call arguments received by layer 'atrous_spatial_pyramid_pooling_v3_4' (type AtrousSpatialPyramidPoolingV3):
  • input_tensor=tf.Tensor(shape=(16, 40, 40, 288), dtype=float16)
  • training=True

Any chance of an update to support float16?

bug in unet.py?

there should be something wrong with unet.py ?{ValueError: The channel dimension of the inputs should be defined. Found None.}

imports in hcr

Hi,
I think that there are missing lines (imports) in the beguining of the new HRNetOCR model:

import tensorflow as tf
import tensorflow.keras.backend as K

from ._custom_layers_and_blocks import ...............
from ..backbones.tf_backbones import create_base_model

Errow while save and load the model

I had uncommented the checkpoint and tried to save the model. It generated saved_model.pb file. Below are the warning messages when the model was saved.

callbacks = [
              tf.keras.callbacks.ModelCheckpoint("DeepLabV3plus1.ckpt", verbose=1, save_weights_only=False, save_best_only=False),
             tf.keras.callbacks.ReduceLROnPlateau(monitor="iou_score", factor=0.2, patience=6, verbose=1, mode="max"),
             tf.keras.callbacks.EarlyStopping(monitor="iou_score", patience=16, mode="max", verbose=1, restore_best_weights=True)
]
366/366 [==============================] - ETA: 0s - loss: 0.3064 - iou_score: 0.6460
Epoch 00001: saving model to DeepLabV3plus1.ckpt
WARNING:tensorflow:Skipping full serialization of Keras layer <keras.layers.merge.Concatenate object at 0x7fe5cc066350>, because it is not built.
WARNING:absl:Found untraced functions such as activation_layer_call_fn, activation_layer_call_and_return_conditional_losses, conv2d_layer_call_fn, conv2d_layer_call_and_return_conditional_losses, activation_1_layer_call_fn while saving (showing 5 of 135). These functions will not be directly callable after loading.
INFO:tensorflow:Assets written to: DeepLabV3plus1.ckpt/assets
INFO:tensorflow:Assets written to: DeepLabV3plus1.ckpt/assets
/home/mohan/.local/lib/python3.7/site-packages/keras/engine/functional.py:1410: CustomMaskWarning: Custom mask layers require a config and must override get_config. When loading, the custom mask layer must be passed to the custom_objects argument.
  layer_config = serialize_layer_fn(layer)
/home/mohan/.local/lib/python3.7/site-packages/keras/saving/saved_model/layer_serialization.py:112: CustomMaskWarning: Custom mask layers require a config and must override get_config. When loading, the custom mask layer must be passed to the custom_objects argument.
  return generic_utils.serialize_keras_object(obj)
366/366 [==============================] - 96s 258ms/step - loss: 0.3064 - iou_score: 0.6460 - lr: 0.2000

Now when loading the model, I am getting the following error.

model = tf.keras.models.load_model('/home/mohan/git/TensorFlow-Advanced-Segmentation-Models/examples/DeepLabV3plus1.ckpt/')

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-ae5de3c338c0> in <module>
----> 1 model = tf.keras.models.load_model('/home/mohan/git/TensorFlow-Advanced-Segmentation-Models/examples/DeepLabV3plus1.ckpt/')

~/.local/lib/python3.7/site-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
     65     except Exception as e:  # pylint: disable=broad-except
     66       filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67       raise e.with_traceback(filtered_tb) from None
     68     finally:
     69       del filtered_tb

~/.local/lib/python3.7/site-packages/keras/saving/saved_model/load.py in revive_custom_object(identifier, metadata)
   1007   else:
   1008     raise ValueError(
-> 1009         f'Unable to restore custom object of type {identifier}. '
   1010         f'Please make sure that any custom layers are included in the '
   1011         f'`custom_objects` arg when calling `load_model()` and make sure that '

ValueError: Unable to restore custom object of type _tf_keras_metric. Please make sure that any custom layers are included in the `custom_objects` arg when calling `load_model()` and make sure that all layers implement `get_config` and `from_config`.

I am not sure how to load the custom objects though. Please help.

Is there exist performance issue when training or forward model pass to models like UNet,DeepLabV3plus,FCN,FPNet...

Is there exist performance issue when training or forward model pass?
take UNet for example,
···
def call(self, inputs, training=None, mask=None):
···
企业微信截图_16566568825370

when training or prediction, self.backbone(inputs) is calculated for 5 times, but the input and backbone not changed,so can this
code can be changed to
x0, x1, x2, x3, x4 = self.backbone(inputs, training=training)
self.upsample2d_x2_block function can use x0, x1, x2, x3, x4 , in this way, the backbone will calculate only 1 time.

thank U.

Information about input

Can you provide information on how xtrain, y_train should be. There shapes/dimensions etc. It would be better if you added any end to end trainable example using any publicly available dataset. tensorflow_datasets has many such datasets which you can use easily.

Thank you in advance

backbones and models

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?

quvbel's backbones

Hi, what is the reason behind commenting out quvbel's backbones? Are they completely not compitable with TASM models or they need refactoring first? For example I used MobileNetV2 for better inference time but I see that this backbone is not in avaliable list and the source file comment it out.

HRnet as backbone

Hi! Would you consider adding HRNet trained on imagenet dataset to your backbone networks? I am really looking forward to that

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.