Image segmentation with Python Pixellib

mylogo

Deep learning libs to process images and videos and execute tasks like segmentation, classification and etc… Pixelib now is using tensorflow and pytorch as a core so let’s do some tests using the pytorch version.

1 – Installing the libs

pip3 install torch==1.8.2+cu102 torchvision==0.9.2+cu102 torchaudio==0.8.2 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.htmlpip3 install pycocotoolspip3 install pixellib

2 – Importing the libs and downloading an image as example:

import numpy as npimport cv2from google.colab.patches import cv2_imshow!wget https://github.com/ayoolaolafenwa/PixelLib/blob/master/Images/github.jpg?raw=true -q -O input.jpg!wget https://github.com/ayoolaolafenwa/PixelLib/releases/download/0.2.0/pointrend_resnet50.pkl -q -O pointrend_resnet50.pklim = cv2.imread("./input.jpg")cv2_imshow(im)

3 – Creating a segmentation using the pre-trained model pointrend_resnet50.pkl:

import pixellibfrom pixellib.torchbackend.instance import instanceSegmentationins = instanceSegmentation()ins.load_model("pointrend_resnet50.pkl")ins.segmentImage("./input.jpg", show_bboxes=True, output_image_name="./output_image.jpg")  im = cv2.imread("./output_image.jpg")cv2_imshow(im)

4 – Let’s check the results:

Original image
The image classified

5 – Conclusion

Pixelib showed great results make segmentations! Let’s try to do some custom models next time!

Reference: https://github.com/ayoolaolafenwa/PixelLib

Post a Comment

Previous Post Next Post