Example of Mask2Former Image Segmentation Based on EasyCV
Introduction: EasyCV is an all in one visual algorithm modeling tool based on Python, with self-monitoring learning and Transformer technology as the core, and contains SOTA algorithms for image classification, measurement learning, target detection, pose recognition and other visual tasks. This paper will introduce the training and prediction of image segmentation models using EasyCV.
EasyCV Image Segmentation - Mask2Fformer
Mask2Former is a unified Transformer based image segmentation architecture, which can achieve semantic segmentation, instance segmentation and panoramic segmentation tasks under the same model structure.
This paper will introduce how to use EasyCV to train image segmentation models based on Mask2Fformer, and how to use the trained models to predict image segmentation
Operating environment requirements
PAI Python image or native Python 1.8++environment GPU machine with more than 32G memory
Install dependent packages
Note: There is no need to install dependencies in PAI-DSW docker. You can skip this part and execute it in the local notebook environment
1. First, install pytorch and the corresponding version of torchvision, and support Python version 1.8 or above
# install pytorch and torch vision
! conda install --yes pytorch==1.10.0 torchvision==0.11.0 -c pytorch
2. Get the torch and cuda versions, and install the corresponding versions of mmcv and nvidia dali
import torch
import os
os. environ['CUDA']='cu' + torch.version.cuda.replace('.', '')
os.environ['Torch']='torch'+torch.version.__ version__. replace('+PAI', '')
! echo "cuda version: $CUDA"
! echo "pytorch version: $Torch"
# install some python deps
! pip install mmdet
! pip install mmcv-full==1.4.4 -f https://download.openmmlab.com/mmcv/dist/ ${CUDA}/${Torch}/index.html
! pip install http://pai-vision-data-hz.oss-cn-zhangjiakou.aliyuncs.com/third_party/nvidia_dali_cuda100-0.25.0-1535750-py3-none-manylinux2014_x86_64.whl
3. Install EasyCV algorithm package
pip install pai-easycv
4. Simple verification
from easycv. apis import *
5. Install deformable_ attention
import easycv
print(easycv.__file__)
#Enter the easycv installation directory to compile deformable_ attention
! cd /home/pai/lib/python3.6/site-packages/easycv/thirdparty/deformable_ attention && python setup. py build install
model training
In this Demo, we use the Mask2Former image segmentation algorithm to train the ResNet50 backbone network and download the sample configuration file
To adapt to small data, we set the configuration file mask2Former_ r50_ 8xb2_ e50_ The following fields of instance.py are modified to reduce the number of training epochs and increase the frequency of printing logs.
Note: If COCO complete data training is used, it is recommended to use a single 8-card for training to ensure the effect;
To ensure the model effect, we finetune the pre training model and execute the following command to start the training.
EasyCV Image Segmentation - Mask2Fformer
Mask2Former is a unified Transformer based image segmentation architecture, which can achieve semantic segmentation, instance segmentation and panoramic segmentation tasks under the same model structure.
This paper will introduce how to use EasyCV to train image segmentation models based on Mask2Fformer, and how to use the trained models to predict image segmentation
Operating environment requirements
PAI Python image or native Python 1.8++environment GPU machine with more than 32G memory
Install dependent packages
Note: There is no need to install dependencies in PAI-DSW docker. You can skip this part and execute it in the local notebook environment
1. First, install pytorch and the corresponding version of torchvision, and support Python version 1.8 or above
# install pytorch and torch vision
! conda install --yes pytorch==1.10.0 torchvision==0.11.0 -c pytorch
2. Get the torch and cuda versions, and install the corresponding versions of mmcv and nvidia dali
import torch
import os
os. environ['CUDA']='cu' + torch.version.cuda.replace('.', '')
os.environ['Torch']='torch'+torch.version.__ version__. replace('+PAI', '')
! echo "cuda version: $CUDA"
! echo "pytorch version: $Torch"
# install some python deps
! pip install mmdet
! pip install mmcv-full==1.4.4 -f https://download.openmmlab.com/mmcv/dist/ ${CUDA}/${Torch}/index.html
! pip install http://pai-vision-data-hz.oss-cn-zhangjiakou.aliyuncs.com/third_party/nvidia_dali_cuda100-0.25.0-1535750-py3-none-manylinux2014_x86_64.whl
3. Install EasyCV algorithm package
pip install pai-easycv
4. Simple verification
from easycv. apis import *
5. Install deformable_ attention
import easycv
print(easycv.__file__)
#Enter the easycv installation directory to compile deformable_ attention
! cd /home/pai/lib/python3.6/site-packages/easycv/thirdparty/deformable_ attention && python setup. py build install
model training
In this Demo, we use the Mask2Former image segmentation algorithm to train the ResNet50 backbone network and download the sample configuration file
To adapt to small data, we set the configuration file mask2Former_ r50_ 8xb2_ e50_ The following fields of instance.py are modified to reduce the number of training epochs and increase the frequency of printing logs.
Note: If COCO complete data training is used, it is recommended to use a single 8-card for training to ensure the effect;
To ensure the model effect, we finetune the pre training model and execute the following command to start the training.
Related Articles
-
A detailed explanation of Hadoop core architecture HDFS
Knowledge Base Team
-
What Does IOT Mean
Knowledge Base Team
-
6 Optional Technologies for Data Storage
Knowledge Base Team
-
What Is Blockchain Technology
Knowledge Base Team
Explore More Special Offers
-
Short Message Service(SMS) & Mail Service
50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00