Vehicle tracking/re-identification is one of the major deep learning problems that is amply popular in surveillance applications.
In this repository, we'll train a vehicle tracking model using
Based on the instructions provided by
deep-person-reid in their blog, 3 subset of data should be generated:
pip install requirements.txt
Download the dataset from the following google-drive link and put it in
veri directory. Then, unzip it.
# Download cd veri gdown --id 1wLmUWY5clm88Jcmu1e5ITMYNCht_mnds # Unzip unzip VeRi_ReID_Simulation.zip
Note: I don't remember where did I get the link to this dataset. Although this is a simulation dataset, if it's private and should not be published publicly open an issue or email me I remove it immediately!
Each dataset sample should have 3 identifiers in its name:
As explained in the dataset instructions which is provided in the following quote, image_id should be the main key for generating
class NewDataset(ImageDataset): dataset_dir = 'new_dataset'
def __init__(self, root='', **kwargs): self.root = osp.abspath(osp.expanduser(root)) self.dataset_dir = osp.join(self.root, self.dataset_dir) # All you need to do here is to generate three lists, # which are train, query and gallery. # Each list contains tuples of (img_path, pid, camid), # where # - img_path (str): absolute path to an image. # - pid (int): person ID, e.g. 0, 1. # - camid (int): camera ID, e.g. 0, 1. # Note that # - pid and camid should be 0-based. # - query and gallery should share the same pid scope (e.g. # pid=0 in query refers to the same person as pid=0 in gallery). # - train, query and gallery share the same camid scope (e.g. # camid=0 in train refers to the same camera as camid=0 # in query/gallery). train = ... query = ... gallery = ... super(NewDataset, self).__init__(train, query, gallery, **kwargs)
Using the following code generate 3 aforementioned subsets:
cd veri python generate_subsets.py
deep-person-reid repo and install the requirements:
git clone https://github.com/KaiyangZhou/deep-person-reid.git cd deep-person-reid pip install -r requirements.txt # install torch and torchvision (select the proper cuda version to suit your machine) conda install pytorch torchvision cudatoolkit=9.0 -c pytorch python setup.py develop
For training run the
# cd to project root python train.py --source veri --model_type osnet_x0_25
The output should be like the following:
** Results ** mAP: 84.9% CMC curve Rank-1 : 97.7% Rank-5 : 99.6% Rank-10 : 99.8% Rank-20 : 99.9% Checkpoint saved to "log/osnet_x0_25/model/model.pth.tar-20" Elapsed 0:25:59
Inference can be applied on any video. To make it easier, there is sample that can be downloaded with the following command:
gdown --id 1JVnzhFcUmZxMAxMazJ__AbkRksoBSag0
deep_sort is used which is taken from
Yolov5_DeepSort_Pytorch GitHub repository and wrapped by
deep_utils. In addition to a
re-identification model, an object detection model is required which in this case
deep_utils wrapper is used!
vehicle-reid models using the following commands:
gdown --id 1JVnzhFcUmZxMAxMazJ__AbkRksoBSag0 gdown --id 1vyFhX18vcDb5BQIGa2jGXnQJ9Bi2tU25
For inference run the following command:
# pretrained python inference.py --video_path test_traffic.mp4 --model_path model.pth.tar-20 # trained by you python inference.py --video_path test_traffic.mp4 --model_path log/osnet_x0_25/model/model.pth.tar-20
The result should be like the following gif:
SQLAlchemy Admin for Starlette/FastAPI
work with Tehran stock exchange data in Python
In this repository, I include all my notes and whatever I learn, so that everyone can benefit from them
Python Engineer Roadmap
SelfUp is a free and open source project to helps us become the better version of ourselves.
A simple Aparat Video Downloader Script
Coefficient of Variation (CV) and Coefficient of Quartile Variation (CQV) with Confidence Intervals (CI). Python port of https://github.com/MaaniBeigy/cvcqv)
Computer vision and Deep learning