Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/RizwanMunawar/yolov7-segmentation
YOLOv7 Instance Segmentation using OpenCV and PyTorch
https://github.com/RizwanMunawar/yolov7-segmentation
imagesegmentation medium-article opencv-python yolov5 yolov7-mask
Last synced: 3 months ago
JSON representation
YOLOv7 Instance Segmentation using OpenCV and PyTorch
- Host: GitHub
- URL: https://github.com/RizwanMunawar/yolov7-segmentation
- Owner: RizwanMunawar
- License: gpl-3.0
- Created: 2022-08-19T13:23:09.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-27T15:46:33.000Z (4 months ago)
- Last Synced: 2024-11-07T03:03:13.518Z (4 months ago)
- Topics: imagesegmentation, medium-article, opencv-python, yolov5, yolov7-mask
- Language: Python
- Homepage:
- Size: 4.87 MB
- Stars: 314
- Watchers: 3
- Forks: 77
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-yolo-object-detection - RizwanMunawar/yolov7-segmentation - segmentation?style=social"/> : YOLOv7 Instance Segmentation using OpenCV and PyTorch. (Applications)
- awesome-yolo-object-detection - RizwanMunawar/yolov7-segmentation - segmentation?style=social"/> : YOLOv7 Instance Segmentation using OpenCV and PyTorch. (Applications)
README
# yolov7-instance-segmentation
## Coming Soon
- Development of streamlit dashboard for Instance-Segmentation with Object Tracking## Code Medium Blog
- https://chr043416.medium.com/train-yolov7-segmentation-on-custom-data-b91237bd2a29## 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](https://github.com/RizwanMunawar/yolov7-segmentation/releases/download/yolov7-segmentation/yolov7-seg.pt) 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](https://roboflow.com/) 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](https://app.roboflow.com/my-personal-workspace/createSample) and create a new workspace. Make sure to login with roboflow account.

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

- 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.
-You can upload your dataset now.

- 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.

- Click on any Image in Unannotated tab, and then you can start labelling.
- Note: Press p and then draw polygon points for segmentation

- 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.

- 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
- https://github.com/WongKinYiu/yolov7/tree/u7/seg
- https://github.com/ultralytics/yolov5## My Medium Articles
- https://medium.com/augmented-startups/yolov7-training-on-custom-data-b86d23e6623
- https://medium.com/augmented-startups/roadmap-for-computer-vision-engineer-45167b94518c
- https://medium.com/augmented-startups/how-can-computer-vision-products-help-in-warehouses-aa1dd95ec79c
- https://medium.com/augmented-startups/problems-in-the-development-of-computer-vision-products-eb081ec7aa2e
- https://medium.com/augmented-startups/yolor-or-yolov5-which-one-is-better-2f844d35e1a1
- https://medium.com/augmented-startups/train-yolor-on-custom-data-f129391bd3d6
- https://chr043416.medium.com/train-yolov7-segmentation-on-custom-data-b91237bd2a29
- https://medium.com/augmented-startups/develop-an-analytics-dashboard-using-streamlit-e6282fa5e0f
- https://muhammadrizwanmunawarvisionai.blogspot.com/2023/04/maskrcnn-vs-yolov7-a-comparison-of-object-segmentation-algorithms.html