Skip to content

yangyin2016/yolov7-instance-segmentation

 
 

Repository files navigation

yolov7-instance-segmentation

Features

  • How to run Code on Windows
  • How to run Code on Linux
  • How to train on Custom Data

Coming Soon

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

Requirements

  • GPU (Needed for installation of detectron2)
  • Git for Windows Download Link
  • Git on Linux (Install git on linux by using command in terminal. sudo apt-get install git)

Steps to run Code

Linux Users

  • Open the terminal and run mentioned command below to download & install anaconda for linux operating system
wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh
bash Anaconda3-2022.05-Linux-x86_64.sh #(you will need to accept license terms from terminal, then you installation will continue)
  • Once Anaconda Installed, restart your machine.

  • Open the terminal in home folder, and run the mentioned command below.

cd ~
sudo chmod 777 .conda
  • Clone the repository.
git clone https://github.com/RizwanMunawar/yolov7-instance-segmentation
  • Goto the cloned folder.
cd yolov7-instance-segmentation
  • Create envirnoment
conda env create -f envirnoment.yml
  • Activate the envirnoment
conda activate detectron2
  • Install extra modules
pip install -r requirements.txt
  • Download weights
wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-mask.pt
  • Run Code with mentioned command.
#Basic Usage
python instance-segmentation.py

#For LiveStream (Ip Stream URL Format i.e "rtsp://username:pass@ipaddress:portno/video/video.amp")
python instance-segmentation.py --source "your IP Camera Stream URL"

#For WebCam
python instance-segmentation.py --source 0

#For External Camera
python instance-segmentation.py --source 1
  • Output file will be created in the working directory with name ("your-file-name-without-extension"+"_segmentation.mp4")

Window Users

  • Download the 64-Bit or 32-Bit Anaconda (Based on your system specifications).
  • Install the executable
  • Goto Start Menu and search for "Anaconda Prompt". Double Click to Open it.
  • Change the path of anaconda prompt with mentioned command below.
cd "C:\Users\"yourusername"\Desktop
  • Clone the repository.
git clone https://github.com/RizwanMunawar/yolov7-instance-segmentation
  • Goto the cloned folder.
cd yolov7-instance-segmentation
  • Create envirnoment
conda env create -f environment.yml
  • Activate the envirnoment
conda activate detectron2
  • Install extra modules
pip install -r requirements.txt
  • Download weights from link and move them to the cloned folder.
  • Run Code with mentioned command.
#Basic Usage
python instance-segmentation.py

#For LiveStream (Ip Stream URL Format i.e "rtsp://username:pass@ipaddress:portno/video/video.amp")
python instance-segmentation.py --source "your IP Camera Stream URL"

#For WebCam
python instance-segmentation.py --source 0

#For External Camera
python instance-segmentation.py --source 1
  • Output file will be created in the working directory with name ("your-file-name-without-extension"+"_segmentation.mp4")

RESULTS

Football Match Image Segmentation Cricket Match Image Segmentation FPS and Time Comparision Graph

Training

  • Make sure to follow above mentioned steps before you will start training on custom dataset.
  • Make a folder name inside yolov7-instance-segmentation with name dataset.
  • Move your (segmentation custom labelled data) inside that folder with mentioned structure.

└── dataset

└── train

    └── images (folder including all training images)

    └── labels (folder including all training labels)

└── test

    └── images (folder including all testing images)

    └── labels (folder including all testing labels)
  • Go to the data folder and 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: 2

# class names
names: [ 'person','Bike']
  • Go to the terminal, and run mentioned command below. (Make sure to activate first conda envirnoment "detectron2")
python train.py --weights yolov7-mask.pt --cfg cfg/yolov7-mask.yaml --batch-size 4 --img 256 --hyp data/hyp.scratch.mask.yaml --data data/custom.yaml 

Testing

python test.py --data data/custom.yaml --img 256 --conf 0.25 --iou 0.65 --weights yolov7-mask.pt

References

My Medium Articles

About

YOLOv7 Instance Segmentation using OpenCV, PyTorch and Detectron2

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.8%
  • Shell 0.2%