Semantic Segmentation ===================== Semantic segmentation is a computer vision task in which an algorithm assigns a label or class to each pixel in an image. For example, semantic segmentation can be used to identify the boundaries of different objects in an image, such as cars, buildings, and trees. The output of semantic segmentation is typically an image where each pixel is colored with a different color or label depending on its class. .. _semantic_segmentation_image_example: .. image:: ../../../../../utils/images/semantic_seg_example.png :width: 600 :alt: image uploaded from this `source `_ | We solve this task by utilizing segmentation decoder heads on the multi-level image features obtained by the feature extractor backbone. For the supervised training we use the following algorithms components: .. _semantic_segmentation_supervised_pipeline: - ``Augmentations``: Besides basic augmentations like random flip, random rotate and random crop, we use mixing images technique with different `photometric distortions `_. - ``Optimizer``: We use `Adam `_ and `AdamW ` optimizers. - ``Learning rate schedule``: For scheduling training process we use **ReduceLROnPlateau** with linear learning rate warmup for 100 iterations for `Lite-HRNet `_ family. This method monitors a target metric (in our case we use metric on the validation set) and if no improvement is seen for a ``patience`` number of epochs, the learning rate is reduced. For `SegNext `_ and `DinoV2 `_ models we use `PolynomialLR `_ scheduler. - ``Loss function``: We use standard `Cross Entropy Loss `_ to train a model. - ``Additional training techniques`` - ``Early stopping``: To add adaptability to the training pipeline and prevent overfitting. ************** Dataset Format ************** For the dataset handling inside OpenVINO™ Training Extensions, we use `Dataset Management Framework (Datumaro) `_. At this end we support `Common Semantic Segmentation `_ data format. If you organized supported dataset format, starting training will be very simple. We just need to pass a path to the root folder and desired model recipe to start training: ****** Models ****** .. _semantic_segmentation_models: We support the following ready-to-use model recipes: +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+-----------------+-----------------+-----------------+ | Recipe Path | Complexity (GFLOPs) | Model size (M) | FPS (GPU) | iter time (sec) | +======================================================================================================================================================================================+=====================+=================+=================+=================+ | `Lite-HRNet-s-mod2 `_ | 1.44 | 0.82 | 37.68 | 0.151 | +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+-----------------+-----------------+-----------------+ | `Lite-HRNet-18-mod2 `_ | 2.63 | 1.10 | 31.17 | 0.176 | +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+-----------------+-----------------+-----------------+ | `Lite-HRNet-x-mod3 `_ | 9.20 | 1.50 | 15.07 | 0.347 | +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+-----------------+-----------------+-----------------+ | `SegNext_T `_ | 12.44 | 4.23 | 104.90 | 0.126 | +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+-----------------+-----------------+-----------------+ | `SegNext_S `_ | 30.93 | 13.90 | 85.67 | 0.134 | +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+-----------------+-----------------+-----------------+ | `SegNext_B `_ | 64.65 | 27.56 | 61.91 | 0.215 | +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+-----------------+-----------------+-----------------+ | `DinoV2 `_ | 124.01 | 24.40 | 3.52 | 0.116 | +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+-----------------+-----------------+-----------------+ All of these models differ in the trade-off between accuracy and inference/training speed. For example, ``SegNext_B`` is the recipe with heavy-size architecture for more accurate predictions, but it requires longer training. Whereas the ``Lite-HRNet-s-mod2`` is the lightweight architecture for fast inference and training. It is the best choice for the scenario of a limited amount of data. The ``Lite-HRNet-18-mod2`` and ``SegNext_S`` models are the middle-sized architectures for the balance between fast inference and training time. ``DinoV2`` is the state-of-the-art model producing universal features suitable for all image-level and pixel-level visual tasks. This model doesn't require fine-tuning of the whole backbone, but only segmentation decode head. Because of that, it provides faster training preserving high accuracy. In the table below the `Dice score `_ on some academic datasets using our :ref:`supervised pipeline ` is presented. We use 512x512 (560x560 fot DinoV2) image crop resolution, for other hyperparameters, please, refer to the related recipe. We trained each model with single Nvidia GeForce RTX3090. +-----------------------+--------------------------------------------------------------+-----------------------------------------------------+----------------------------------------------------------------------+-----------------------------------------------------------------+--------+ | Model name | `DIS5K `_ | `Cityscapes `_ | `Pascal-VOC 2012 `_ | `KITTI `_ | Mean | +=======================+==============================================================+=====================================================+======================================================================+=================================================================+========+ | Lite-HRNet-s-mod2 | 78.73 | 69.25 | 63.26 | 41.73 | 63.24 | +-----------------------+--------------------------------------------------------------+-----------------------------------------------------+----------------------------------------------------------------------+-----------------------------------------------------------------+--------+ | Lite-HRNet-18-mod2 | 81.43 | 72.66 | 62.10 | 46.73 | 65.73 | +-----------------------+--------------------------------------------------------------+-----------------------------------------------------+----------------------------------------------------------------------+-----------------------------------------------------------------+--------+ | Lite-HRNet-x-mod3 | 82.36 | 74.57 | 59.55 | 49.97 | 66.61 | +-----------------------+--------------------------------------------------------------+-----------------------------------------------------+----------------------------------------------------------------------+-----------------------------------------------------------------+--------+ | SegNext-t | 83.99 | 77.09 | 84.05 | 48.99 | 73.53 | +-----------------------+--------------------------------------------------------------+-----------------------------------------------------+----------------------------------------------------------------------+-----------------------------------------------------------------+--------+ | SegNext-s | 85.54 | 79.45 | 86.00 | 52.19 | 75.80 | +-----------------------+--------------------------------------------------------------+-----------------------------------------------------+----------------------------------------------------------------------+-----------------------------------------------------------------+--------+ | SegNext-b | 86.76 | 76.14 | 87.92 | 57.73 | 77.14 | +-----------------------+--------------------------------------------------------------+-----------------------------------------------------+----------------------------------------------------------------------+-----------------------------------------------------------------+--------+ | DinoV2 | 84.87 | 73.58 | 88.15 | 65.91 | 78.13 | +-----------------------+--------------------------------------------------------------+-----------------------------------------------------+----------------------------------------------------------------------+-----------------------------------------------------------------+--------+ .. note:: Please, refer to our :doc:`dedicated tutorial <../../../tutorials/base/how_to_train/semantic_segmentation>` for more information on how to train, validate and optimize the semantic segmentation model.