Giter VIP home page Giter VIP logo

vehicle-counting's Introduction

🏍️ 🚙 Vehicle Tracking using YOLOv5 + DeepSORT 🚌

Dev logs [19/12/2021] Update to new YOLOv5 version 6. Can load checkpoints from original repo now 🤞
[16/07/2021] BIG REFACTOR Code is cleaned and working fine now, promise 🤞
[27/09/2021] All trained checkpoints on AIC-HCMC-2020 have been lost. Now use pretrained models on COCO for inference.

Method

  • Use YOLOv5 for vehicle detection task, only considers objects in Region of Interest (ROI)
  • Use DeepSORT for car tracking, not need to retrain this model, only inference
  • Use Cosine Similarity to assign object's tracks to most similar directions.
  • Count each type of vehicle on each direction.

📔 Notebook

  • For inference, use this notebook Notebook
  • To retrain detection model, follow instructions from original Yolov5

Dataset

  • AIC-HCMC-2020: link
  • Direction and ROI annotation format:
cam_01.json # match video name
{
    "shapes": [
        {
            "label": "zone",
            "points": [[x1,y1], [x2,y2], [x3,y3], [x4,y4], ... ] #Points of a polygon
        },
        {
            "label": "direction01",
            "points": [[x1,y1], [x2,y2]] #Points of vector
        },
        {
            "label": "direction{id}",
            "points": [[x1,y1], [x2,y2]]
        },...
    ],
}
screen

🥇 Pretrained weights

  • Download finetuned models from on AIC-HCMC-2020 dataset:
Model Image Size Weights Precision Recall [email protected] [email protected]
YOLOv5s 640x640 link 0.87203 0.87356 0.91797 0.60795
YOLOv5m 1024x1024 link 0.89626 0.91098 0.94711 0.66816

🌟 Inference

  • File structure
this repo
│   detect.py
└───configs
│      configs.yaml           # Contains model's configurations
│      cam_configs.yaml       # Contains DEEPSORT's configuration for each video
  • Install dependencies by pip install -r requirements.txt
  • To run full pipeline:
python run.py --input_path=<input video or dir> --output_path=<output dir> --weight=<trained weight>
  • Extra Parameters:
    • --min_conf: minimum confident for detection
    • --min_iou: minimum iou for detection

Results

  • After running, a .csv file contains results has following example format:
track_id frame_id box color label direction fpoint lpoint fframe lframe
2 3 [607, 487, 664, 582] (144, 238, 144) 0 1 (635.5, 534.5) (977.0, 281.5) 3 109
2 4 [625, 475, 681, 566] (144, 238, 144) 0 1 (635.5, 534.5) (977.0, 281.5) 3 109
2 5 [631, 471, 686, 561] (144, 238, 144) 0 1 (635.5, 534.5) (977.0, 281.5) 3 109
  • With:
    • track_id: the id of the object
    • frame_id: the current frame
    • box: the box wraps around the object in the corresponding frame
    • color: the color which is used to visualize the object
    • direction: the direction of the object
    • fpoint, lpoint: first/last coordinate where the object appears
    • fframe, lframe: first/last frame where the object appears
Visualization result
screen
screen

References

vehicle-counting's People

Contributors

kaylode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vehicle-counting's Issues

Slow to detect on windows 10?

Hi,

I'm not getting the best performance I was expecting. I am running on windows with an i7 4790k and GTX970 and its not utilizing my cpu or gpu when running the detect.py with -c=2 and batch size of 8. I am running it on a long video but I want to know am I missing something regarding performance or is this just the way it is? It's running incredibly slow with 7s/it.

A problem has occurred. Why is this?

I did everything in order, but I got an error.
Do you know what the problem is?

(py38) C:\coding\DeepSORT_YOLOv5_Pytorch-master>python main.py --cam 0 --display
Namespace(agnostic_nms=False, augment=False, cam=0, classes=[0], conf_thres=0.5, config_deepsort='./configs/deep_sort.yaml', device='', display=True, display_height=600, display_width=800, fourcc='mp4v', frame_interval=2, img_size=640, input_path='input_480.mp4', iou_thres=0.5, save_path='output/', save_txt='output/predict/', weights='yolov5/weights/yolov5s.pt')
Initialize DeepSORT & YOLO-V5
Using CPU

Using webcam 0
Traceback (most recent call last):
File "main.py", line 259, in
with VideoTracker(args) as vdo_trk:
File "main.py", line 53, in init
cfg.merge_from_file(args.config_deepsort)
File "C:\coding\DeepSORT_YOLOv5_Pytorch-master\utils_ds\parser.py", line 23, in merge_from_file
self.update(yaml.load(fo.read()))
TypeError: load() missing 1 required positional argument: 'Loader'
[ WARN:0] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (438) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

t7 to pb

Hi,
would you advise how to convert t7 to pb?

how to put custom weight?

Hello kaylode!
First, Thank you for sharing your project :) It is a really helpful idea for me!

I customized labels and could get customized yolo v5 weights files(best.pt).
I have tried your code using my custom weights and video but it was failde :(

When I run code without weight value. It works (but it is not result what i expected )
like this (python run.py --input_path="./cam_04.mp4" --output_path="~" )

When I run code with weight value, It shows error :(
(python run.py --input_path="./cam_04.mp4" --output_path="~" --weight="./best.pt")

image

you mentioned 3 things in "Start inference: Define these things before run"

  • path to street annotation files in configs.cam_configs.yaml
  • path to video file
  • model's checkpoint

as I undertood,

  • path to street annotation files in configs/cam_configs.yaml
    --> i can resize street size(zone) by modifying cam_configs.yaml
  • path to video file
    --> check my video file path
  • model's checkpoint
  • -> replace "vehicle-counting/models/deepsort/deep/checkpoint/ckpt.t7"
    with "customized deepsort model result(checkpint/ckpt.t7)"

Am I right?

I'll wait for your reply. Again Thanks for the good research.

Request file camera config

Hello,

I see that in your folder ./vehicle-counting/configs/cam_configs.yaml. There is a file naming 'aic-hcmc2020/zones/zones_movement_paths/cam_01.json'. But in your link of dataset there is not, just images and annotation. Could you please provide the file json with the zone movement ?

Best regard

i have an issue

Can't get attribute 'Model' on <module 'models.yolo' from 'E:\Python\vehicle-counting-master\vehicle-counting-master\models\yolo\init.py'>

i run

python run.py --input_path='moos.mp4' --output_path="results" --weight="best.pt"

IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

why this error happened ?
it happened in some videos. not all videos .

Fusing layers... Model Summary: 308 layers, 21065925 parameters, 0 gradients Adding AutoShape... 76% 219/288 [00:08<00:02, 25.41it/s] Traceback (most recent call last): File "run.py", line 48, in <module> main(args, config) File "run.py", line 30, in main pipeline.run() File "/content/main/modules/__init__.py", line 67, in run track_result = self.tracker.run(ori_img, boxes, labels, scores) File "/content/main/modules/track.py", line 40, in run bbox_xyxy[:, 2] += bbox_xyxy[:, 0] IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

a quick question about download process yolov5 master.zip file to root

i really love your repo here, it such a great project. i have a quick question for you. before inference process, there's a process to download file like this.
Downloading: "https://github.com/ultralytics/yolov5/archive/master.zip" to /root/.cache/torch/hub/master.zip
is it really mandatory to download the file ? or you can put the file locally ? thank you.

pth files

Hi,

I would like to run your program. However, I m unable to download the pre-trained pth files for testing.
Do you still keep the model files? Possible to share the link to download?

Thanks.

(ptrorch) PS C:\Users\Administrator\Downloads\Compressed\vehicle-counting-1-master> python detect.py --video_path input.mp4 Traceback (most recent call last): File "detect.py", line 123, in <module> config = Config(os.path.join('configs',args.config)) File "D:\ProgramData\Anaconda3\envs\ptrorch\lib\ntpath.py", line 117, in join genericpath._check_arg_types('join', path, *paths) File "D:\ProgramData\Anac

(ptrorch) PS C:\Users\Administrator\Downloads\Compressed\vehicle-counting-1-master> python detect.py --video_path input.mp4
Traceback (most recent call last):
File "detect.py", line 123, in
config = Config(os.path.join('configs',args.config))
File "D:\ProgramData\Anaconda3\envs\ptrorch\lib\ntpath.py", line 117, in join
genericpath._check_arg_types('join', path, *paths)
File "D:\ProgramData\Anaconda3\envs\ptrorch\lib\genericpath.py", line 152, in _check_arg_types
raise TypeError(f'{funcname}() argument must be str, bytes, or '
TypeError: join() argument must be str, bytes, or os.PathLike object, not 'NoneType'
(ptrorch) PS C:\Users\Administrator\Downloads\Compressed\vehicle-counting-1-master>

colab error

`content/main
Traceback (most recent call last):
File "run.py", line 1, in
from utilities.getter import *
File "/content/main/utilities/init.py", line 1, in
from .getter import *
File "/content/main/utilities/getter.py", line 1, in
from networks import *
File "/content/main/networks/init.py", line 1, in
from .yolo import get_model
File "/content/main/networks/yolo.py", line 6, in
from augmentations import MEAN, STD
File "/content/main/augmentations/init.py", line 1, in
from .transforms import *
File "/content/main/augmentations/transforms.py", line 1, in
import cv2
File "/usr/local/lib/python3.7/dist-packages/cv2/init.py", line 9, in
from .cv2 import _registerMatType
ImportError: cannot import name '_registerMatType' from 'cv2.cv2' (/usr/local/lib/python3.7/dist-packages/cv2/cv2.cpython-37m-x86_64-linux-gnu.so)

`

i got this error when running your colab , and also it didnot work in my pc

Pass video without the json file

@kaylode thanks for great work !
How to run the code with new video that don't have the json file that include annotations as in demo folder, I have multiple videos and I want to use the pretrained model on them

!python run.py --input_path='/content/main/demo/sample/cam_04.mp4' \
              --output_path="/content/results" \
              --weight="/content/gdrive/MyDrive/best.pt"

as we can see we should have a json file in the same folder (demo/sample) with the video and it must have the same name, what if we want to pass a new video that don't have a json of annotations ?

Question: Where to find the list of vehicle types?

Thanks for a really fun project to play with. I tried to find the description of the vehicle/object type detected (e.g. motorcycle, car, bus, etc.). I noticed that one of your gifs shows those, but I couldn't find the list not get a similar result. I did look quickly at the original training data, but at least at first glance couldn't find it in there either.

Could you point me in the right direction?

(oops was logged in with the wrong account, oh well)

Suggest to loosen the dependency on albumentations

Hi, your project vehicle-counting(commit id: 5007a54) requires "albumentations==0.5.2" in its dependency. After analyzing the source code, we found that the following versions of albumentations can also be suitable, i.e., albumentations 0.5.0, 0.5.1, since all functions that you directly (6 APIs: albumentations.augmentations.transforms.Resize.init, albumentations.core.composition.Compose.init, albumentations.augmentations.transforms.PadIfNeeded.init, albumentations.core.composition.BboxParams.init, albumentations.augmentations.transforms.Normalize.init, albumentations.augmentations.transforms.LongestMaxSize.init) or indirectly (propagate to 10 albumentations's internal APIs and 0 outsider APIs) used from the package have not been changed in these versions, thus not affecting your usage.

Therefore, we believe that it is quite safe to loose your dependency on albumentations from "albumentations==0.5.2" to "albumentations>=0.5.0,<=0.5.2". This will improve the applicability of vehicle-counting and reduce the possibility of any further dependency conflict with other projects.

May I pull a request to further loosen the dependency on albumentations?

By the way, could you please tell us whether such an automatic tool for dependency analysis may be potentially helpful for maintaining dependencies easier during your development?

error in useing different video name

when i use your video demo , it works well
but if i use different video name ,(i also remember to change the .josn file name) , it gives me this error.
(car_video is the video name).
if i rename my video to cam_04 it works .

Fusing layers... Model Summary: 213 layers, 7020913 parameters, 0 gradients Adding AutoShape... Traceback (most recent call last): File "run.py", line 48, in <module> main(args, config) File "run.py", line 30, in main pipeline.run() File "/content/main/modules/__init__.py", line 34, in run self.cam_config.cam[cam_name], KeyError: 'car_video'

all things is done, but can't read any sample video ?!

Traceback (most recent call last):
File "C:\AhmedHefnawy\buy\altr\vehicle-counting-master\vehicle-counting-master\run.py", line 48, in
main(args, config)
File "C:\AhmedHefnawy\buy\altr\vehicle-counting-master\vehicle-counting-master\run.py", line 30, in main
pipeline.run()
File "C:\AhmedHefnawy\buy\altr\vehicle-counting-master\vehicle-counting-master\modules_init_.py", line 31, in run
videoloader = VideoLoader(self.config, video_path)
File "C:\AhmedHefnawy\buy\altr\vehicle-counting-master\vehicle-counting-master\modules\datasets.py", line 88, in init
dataset = VideoSet(config, video_path)
File "C:\AhmedHefnawy\buy\altr\vehicle-counting-master\vehicle-counting-master\modules\datasets.py", line 24, in init
self.initialize_stream()
File "C:\AhmedHefnawy\buy\altr\vehicle-counting-master\vehicle-counting-master\modules\datasets.py", line 45, in initialize_stream
assert 0, f"Cannot read video {os.path.basename(self.input_path)}"
AssertionError: Cannot read video cam_04.mp4'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.