Skip to content

YOLOv7 Instance Segmentation using OpenCV and PyTorch

License

RizwanMunawar/yolov7-segmentation

Repository files navigation

YOLOv7 Instance Segmentation

YOLOv7-object-tracking DeepWiki

Steps to run Code

  • Clone the repository
git clone https://github.com/RizwanMunawar/yolov7-segmentation.git
  • Go to the cloned folder.
cd yolov7-segmentation
  • Create a virtual environment (Recommended, if you don't want to disturb Python packages)
### For Linux Users
python3 -m venv yolov7seg
source yolov7seg/bin/activate

### For Windows Users
python3 -m venv yolov7seg
cd yolov7seg
cd Scripts
activate
cd ..
cd ..
  • Upgrade pip with the mentioned command below.
pip install --upgrade pip
  • Install requirements with the mentioned command below.
pip install -r requirements.txt
  • Download weights from link and store in "yolov7-segmentation" directory.

  • Run the code with the mentioned command below.

#for segmentation with detection
python3 segment/predict.py --weights yolov7-seg.pt --source "videopath.mp4"

#for segmentation with detection + Tracking
python3 segment/predict.py --weights yolov7-seg.pt --source "videopath.mp4" --trk

#save the labels files of segmentation
python3 segment/predict.py --weights yolov7-seg.pt --source "videopath.mp4" --save-txt
  • Output file will be created in the working directory with name runs/predict-seg/exp/original-video-name.mp4

RESULTS

Car Semantic Segmentation Car Semantic Segmentation Person Segmentation + Tracking

Custom Data Labelling

  • I have used roboflow for data labelling. The data labelling for Segmentation will be a Polygon box, while data labelling for object detection will be a bounding box

  • Go to the link and create a new workspace. Make sure to log in with your Roboflow account.

1

  • Once you click on create workspace, you will see the pop-up as shown below to upload the dataset.

2

  • Click on upload dataset, and Roboflow will ask for the workspace name as shown below. Fill that form and then click on Create Private Project
  • Note: Make sure to select Instance Segmentation Option in below image. dataset

-You can upload your dataset now.

Screenshot 2022-09-17 155330

  • Once the files are uploaded, you can click on Finish Uploading.

  • Roboflow will ask you to assign Images to someone, click on Assign Images.

  • After that, you will see the tab shown below.

6

  • Click on any Image in Unannotated tab, and then you can start labelling.

  • Note: Press p and then draw polygon points for segmentation

10

  • Once you have completed labelling, you can then export the data and follow the steps mentioned below to start training.

Custom Training

  • Move your (segmentation custom labelled data) inside the yolov7-segmentation/data folder by following the mentioned structure.

ss

  • Go to the data folder, create a file with name custom.yaml and paste the mentioned code below inside that.
train: "path to train folder"
val: "path to validation folder"
# number of classes
nc: 1
# class names
names: [ 'car']
  • Download weights from the link and move to yolov7-segmentation folder.
  • Go to the terminal, and run the mentioned command below to start training.
python3 segment/train.py --data data/custom.yaml \
                          --batch 4 \
                          --weights "yolov7-seg.pt"
                          --cfg yolov7-seg.yaml \
                          --epochs 10 \
                          --name yolov7-seg \
                          --img 640 \
                          --hyp hyp.scratch-high.yaml

Custom Model Detection Command

python3 segment/predict.py --weights "runs/yolov7-seg/exp/weights/best.pt" --source "videopath.mp4"

RESULTS

Car Semantic Segmentation Car Semantic Segmentation Person Segmentation + Tracking

References

Some of my articles/research papers | computer vision awesome resources for learning | How do I appear to the world? 🚀

Ultralytics YOLO11: Object Detection and Instance Segmentation🤯 Published Date

Parking Management using Ultralytics YOLO11 Published Date

My 🖐️Computer Vision Hobby Projects that Yielded Earnings Published Date

Best Resources to Learn Computer Vision Published Date

Roadmap for Computer Vision Engineer Published Date

How did I spend 2022 in the Computer Vision Field Published Date

Domain Feature Mapping with YOLOv7 for Automated Edge-Based Pallet Racking Inspections Published Date

Exudate Regeneration for Automated Exudate Detection in Retinal Fundus Images Published Date

Feature Mapping for Rice Leaf Defect Detection Based on a Custom Convolutional Architecture Published Date

Yolov5, Yolo-x, Yolo-r, Yolov7 Performance Comparison: A Survey Published Date

Explainable AI in Drug Sensitivity Prediction on Cancer Cell Lines Published Date

Train YOLOv8 on Custom Data Published Date

More Information

For more details, you can reach out to me on Medium or can connect with me on LinkedIn

About

YOLOv7 Instance Segmentation using OpenCV and PyTorch

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •