MMSegmentation (MMSeg) has emerged as a top-tier toolkit in the realm of semantic segmentation, gaining notable popularity in the Python community. Its comprehensive documentation and setup process, while thorough, can initially seem overwhelming for those new to the platform.
This guide aims to simplify your introduction to MMSegmentation/MMSeg, highlighting essential steps and addressing typical challenges encountered while employing the MMSegmentation/MMSeg API.
We'll also introduce an efficient method to leverage MMSegmentation's capabilities via the Ikomia API, enhancing your overall experience in semantic segmentation.
Prepare to elevate your semantic segmentation projects!
Semantic segmentation is a vital and constantly advancing area in the field of computer vision.
Among the most prominent and cutting-edge tools in this domain is MMSegmentation (MMseg), a comprehensive open-source toolbox for semantic segmentation, developed on the PyTorch platform.
MMSegmentation is part of the OpenMMLab project and is developed by the Multimedia Laboratory at the Chinese University of Hong Kong. It specializes in semantic segmentation, a vital component in the field of computer vision. It offers an extensive collection of segmentation models and algorithms, making it a go-to choice for both researchers and practitioners in the field.
MMSegmentation isn’t just a theoretical tool; it has practical implications in various sectors:
For this section, we will navigate through the MMSegmentation documentation for semantic segmentation.[1]It's advisable to review the entire setup process beforehand, as we've identified certain steps that might be tricky or simply not working.
OpenMMLab suggests specific Python and PyTorch versions for optimal results.
For this demonstration, we used a Windows setup with CUDA 11.8 installed.
The first step in preparing your environment involves creating a Python virtual environment [2] and installing the necessary Torch dependencies.
We followed the recommendation by using Python 3.8:
Once you activate the 'openmmlab' virtual environment, the next step is to install the required PyTorch dependencies.
Then we install the following dependencies:
Subsequently, we installed 'mmsegmentation' as a dependency:
To obtain the necessary checkpoint file (.pth) and configuration file (.py) for MMSegmentation/MMSeg, use the following command:
Executing this command will download both the checkpoint and the configuration file directly into your current working directory.
For testing our setup, we conducted an inference test using a sample image with the PSPNetmodel. This step is crucial to verify the effectiveness of the installation and setup.
We ran into the following problem: "no module name 'ftfy'"
Installation of the ftfy module:
Following the execution of the inference code snippet, we successfully achieved image segmentation:
The installation process was completed without any significant issues. During the testing phase of the inference code snippet, we encountered a minor hiccup with the missing 'ftfy' dependency, but this was quickly resolved.
In the upcoming section, we'll explore how to use MMSegmentation/MMSeg through the Ikomia API. This approach bypasses the complexity of installing various dependencies and simplifies the process into just 2 straightforward steps.
With the Ikomia team, we've been working on a prototyping tool to avoid and speed up tedious installation and testing phases.
We wrapped it in an open source Python API. Now we're going to explain how to use it to detect objects with MMSegmentation in less than 10 minutes.
As before, you need to install the API in a virtual environment. [2]
Then the only thing you need is to install ikomia:
You can also charge directly the open-source notebook we have prepared.
List of parameters:
- model_name (str, default="maskformer"): model name.
- model_config (str, default="maskformer_r50-d32_8xb2-160k_ade20k-512x512"): name of the model configuration file.
- config_file (str, default=""): path to model config file (only if use_custom_model=True). The file is generated at the end of a custom training. Use algorithm train_mmlab_detection from Ikomia HUB to train custom model.
- model_weight_file (str, default=""): path to model weights file (.pt) (only if use_custom_model=True). The file is generated at the end of a custom training.
- cuda (bool, default=True): CUDA acceleration if True, run on CPU otherwise.
MMLab framework for semantic segmentation offers a large range of models. To ease the choice of couple (model_name/model_config), you can call the function get_model_zoo() to get a list of possible values.
To carry out semantic segmentation, we simply installed Ikomia and ran the workflow code snippets. All dependencies were seamlessly handled in the background.
This guide has delved into the nuances of developing a semantic segmentation workflow using MMSegmentation (MMseg).
Customizing your model to meet specific needs and harmonizing it with other state-of-the-art models is a vital skill in the field of Computer Vision.
Keen on elevating your proficiency in semantic segmentation?
Discover how to fine-tune your semantic segmentation model →