• Stars
    star
    282
  • Rank 146,549 (Top 3 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created about 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

YOLOv7 Instance Segmentation using OpenCV and PyTorch

yolov7-instance-segmentation

Coming Soon

  • Development of streamlit dashboard for Instance-Segmentation with Object Tracking

Code Medium Blog

Steps to run Code

  • Clone the repository
git clone https://github.com/RizwanMunawar/yolov7-segmentation.git
  • Goto the cloned folder.
cd yolov7-segmentation
  • Create a virtual envirnoment (Recommended, If you dont want to disturb python packages)
### For Linux Users
python3 -m venv yolov7seg
source yolov7seg/bin/activate

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

  • Run the code with 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 yolov7-segmentation/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 login with roboflow account.

1

  • Once you will click on create workspace, You will see the popup as shown below to upload the dataset.

2

  • Click on upload dataset and roboflow will ask for 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 files will upload, 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 will complete labelling, you can then export the data and follow mentioned steps below to start training.

Custom Training

  • Move your (segmentation custom labelled data) inside "yolov7-segmentation\data" folder by following 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 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

My Medium Articles

More Repositories

1

yolov7-object-tracking

YOLOv7 Object Tracking Using PyTorch, OpenCV and Sort Tracking
Python
532
star
2

yolov7-pose-estimation

YOLOv7 Pose estimation using OpenCV, PyTorch
Python
323
star
3

yolov8-object-tracking

YOLOv8 Object Tracking Using PyTorch, OpenCV and Ultralytics
Python
245
star
4

yolov5-object-tracking

YOLOv5 Object Tracking + Detection + Object Blurring + Streamlit Dashboard Using OpenCV, PyTorch and Streamlit
Python
86
star
5

yolov7-object-blurring

YOLOv7 Object Blurring Using PyTorch and OpenCV
Python
63
star
6

yolov7-object-cropping

YOLOv7 Object Cropping Using OpenCV
Python
16
star
7

Extraction-of-frames-from-single-video-computer-vision-

Extraction of frames from single video using OpenCV
Jupyter Notebook
14
star
8

YOLO-RX57-FPS-Comparision

FPS Comparision with same specification of YOLOX, YOLOR, YOLOv5 and YOLOv7
Python
13
star
9

Houses-price-prediction-web-app-machine-learning-

Houses price prediction web app
HTML
7
star
10

Face-recognition-using-opencv-computer-vision-

Face detection and recognition using OpenCV.
Python
5
star
11

RizwanMunawar

My Repositories stars, commits, pull requests, Information
4
star
12

Spark-foundation-internship-tasks-computer-vision-

Spark foundation Internship Tasks of domain (Computer Vision & IoT Field).
Jupyter Notebook
3
star
13

Extraction-of-frames-from-multiple-frames-computer-vision-

Frames extraction from multiple videos
Jupyter Notebook
3
star
14

Houses-price-prediction-machine-learning-

Houses Price Prediction using Linear Regression
Jupyter Notebook
3
star
15

skin-cancer-binary-classification-computer-vision-

Skin Cancer binary(Benign vs malignant) Classification using convolutional neural networks
Jupyter Notebook
2
star
16

Cats-vs-dogs-classification-computer-vision-

Cats vs dogs classification using deep learning. Data augmentation and convolutional neural networks.
Jupyter Notebook
1
star
17

Covid-19-chest-x_rays-images-multi-class-classification-computer-vision-

Covid-19 chest x_rays images multi-class classification while classes are (COVID, Pneumonia, normal)
Jupyter Notebook
1
star
18

Data-analysis-on-csv-datasets-machine-learning-

Data Analysis and model building on CSV datasets.
Jupyter Notebook
1
star