Giter Club home page Giter Club logo

yolov8_segmentation_deepsort_object_tracking's Introduction

YOLOv8 Segmentation with DeepSORT Object Tracking(ID + Trails)

Google Colab File Link (A Single Click Solution)

The google colab file link for yolov8 segmentation and tracking is provided below, you can check the implementation in Google Colab, and its a single click implementation ,you just need to select the Run Time as GPU, and click on Run All.

Google Colab File

YouTube Video Tutorial Link

YouTube Link

YOLOv8 with DeepSORT Object Tracking

Github Repo Link

Object Segmentation and Tracking (ID + Trails) using YOLOv8 on Custom Data

Google Colab File Link (A Single Click Solution)

Google Colab File

YouTube Video Tutorial Link

YouTube Link

Steps to run Code

  • Clone the repository
git clone https://github.com/MuhammadMoinFaisal/YOLOv8_Segmentation_DeepSORT_Object_Tracking.git
  • Goto the cloned folder.
cd YOLOv8_Segmentation_DeepSORT_Object_Tracking
  • Install the Dependencies
pip install -e '.[dev]'

  • Setting the Directory.
cd ultralytics/yolo/v8/segment

  • Downloading the DeepSORT Files From The Google Drive

https://drive.google.com/drive/folders/1kna8eWGrSfzaR6DtNJ8_GchGgPMv3VC8?usp=sharing
  • After downloading the DeepSORT Zip file from the drive, unzip it go into the subfolders and place the deep_sort_pytorch folder into the ultralytics/yolo/v8/segment folder

  • Downloading a Sample Videos from the Google Drive

  • Demo Video 1

gdown "https://drive.google.com/uc?id=19P9Cf9UiJ9gU9KHnAfud6hrFOgobETTX"
  • Demo Video 2
gdown "https://drive.google.com/uc?id=1rjBn8Fl1E_9d0EMVtL24S9aNQOJAveR5&confirm=t"
  • Demo Video 3
gdown "https://drive.google.com/uc?id=1aL0XIoOQlHf9FBvUx3FMfmPbmRu0-rF-&confirm=t"
  • Run the code with mentioned command below.

  • For yolov8 segmentation + Tracking

python predict.py model=yolov8x-seg.pt source="test1.mp4"

RESULTS

Object Segmentation and DeepSORT Tracking (ID + Trails) and Vehicles Counting

Object Segmentation and DeepSORT Tracking (ID + Trails)

Watch the Complete Step by Step Explanation

Watch the Complete Tutorial for the Step by Step Explanation

References

yolov8_segmentation_deepsort_object_tracking's People

Contributors

muhammadmoinfaisal 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

yolov8_segmentation_deepsort_object_tracking's Issues

Masks tracking

this repositoriy only tracks boxes and cls,doesn't track masks....

Traffic Counting using YOLOv8 and DeepSORT Object Tracking -- cannot import name 'DEFAULT_CONFIG' from 'ultralytics.utils'

python predict.py model=yolov8l.pt source="test3.mp4"

ERROR:

/Users/ankushsingal/miniconda3/envs/book_env/lib/python3.8/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: dlopen(/Users/ankushsingal/miniconda3/envs/book_env/lib/python3.8/site-packages/torchvision/image.so, 0x0006): Symbol not found: __ZN2at4_ops19empty_memory_format4callEN3c108ArrayRefIxEENS2_8optionalINS2_10ScalarTypeEEENS5_INS2_6LayoutEEENS5_INS2_6DeviceEEENS5_IbEENS5_INS2_12MemoryFormatEEE
  Referenced from: <320D718F-E2FD-3687-B2F0-E83CF97743B1> /Users/ankushsingal/miniconda3/envs/book_env/lib/python3.8/site-packages/torchvision/image.so
  Expected in:     <33B9BCB1-C3B0-309D-8DFD-07CBC1A23530> /Users/ankushsingal/miniconda3/envs/book_env/lib/python3.8/site-packages/torch/lib/libtorch_cpu.dylib
  warn(f"Failed to load image Python extension: {e}")
WARNING ⚠️ 'ultralytics.yolo.v8' is deprecated since '8.0.136' and will be removed in '8.1.0'. Please use 'ultralytics.models.yolo' instead.
WARNING ⚠️ 'ultralytics.yolo.engine' is deprecated since '8.0.136' and will be removed in '8.1.0'. Please use 'ultralytics.engine' instead.
WARNING ⚠️ 'ultralytics.yolo.utils' is deprecated since '8.0.136' and will be removed in '8.1.0'. Please use 'ultralytics.utils' instead.
Note this warning may be related to loading older models. You can update your model to current structure with:
    import torch
    ckpt = torch.load("model.pt")  # applies to both official and custom models
    torch.save(ckpt, "updated-model.pt")

Traceback (most recent call last):
  File "predict.py", line 15, in <module>
    from ultralytics.yolo.utils import DEFAULT_CONFIG, ROOT, ops
ImportError: cannot import name 'DEFAULT_CONFIG' from 'ultralytics.utils' (/Users/ankushsingal/miniconda3/envs/book_env/lib/python3.8/site-packages/ultralytics/utils/__init__.py)

How to use GPU instead of CPU

I have follow along your Yolov8 deepsort object tracking. It work very well, the problem now is how I can use the GPU instead of CPU for tracking? What should I set? I'm not using googlw Colab, I'm using my own computer with GPU

ModuleNotFoundError: No module named 'ultralytics.yolo'

python predict.py model=yolov8x-seg.pt source="test3.mp4"
Traceback (most recent call last):
  File "/Users/ankushsingal/Desktop/yolov8/ObjectTrackingsYOLOv8/YOLOv8-DeepSORT-Object-Tracking/ultralytics/yolo/v8/detect/predict.py", line 13, in <module>
    from ultralytics.yolo.engine.predictor import BasePredictor
ModuleNotFoundError: No module named 'ultralytics.yolo'

RuntimeError: unexpected EOF, expected 120303 more bytes. The file might be corrupted.

I have followed all the steps of installation and when I am running this

!python tracking_vehicle_counting.py model=yolov8l.pt source="test.mp4" show=True
Error:
Error executing job with overrides: ['model=yolov8l.pt', 'source=/content/YOLOv8-Object-Detection-with-DeepSORT-Tracking/output_video.mp4', 'show=True']
Traceback (most recent call last):
File "/content/YOLOv8-Object-Detection-with-DeepSORT-Tracking/yolo/v8/detect/tracking_vehicle_counting.py", line 310, in predict
init_tracker()
File "/content/YOLOv8-Object-Detection-with-DeepSORT-Tracking/yolo/v8/detect/tracking_vehicle_counting.py", line 38, in init_tracker
deepsort= DeepSort(cfg_deep.DEEPSORT.REID_CKPT,
File "/content/YOLOv8-Object-Detection-with-DeepSORT-Tracking/yolo/v8/detect/deep_sort_pytorch/deep_sort/deep_sort.py", line 18, in init
self.extractor = Extractor(model_path, use_cuda=use_cuda)
File "/content/YOLOv8-Object-Detection-with-DeepSORT-Tracking/yolo/v8/detect/deep_sort_pytorch/deep_sort/deep/feature_extractor.py", line 14, in init
state_dict = torch.load(model_path, map_location=torch.device(self.device))[
File "/usr/local/lib/python3.10/dist-packages/torch/serialization.py", line 815, in load
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File "/usr/local/lib/python3.10/dist-packages/torch/serialization.py", line 1051, in _legacy_load
typed_storage._untyped_storage._set_from_file(
RuntimeError: unexpected EOF, expected 120303 more bytes. The file might be corrupted.

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.

Facing issue while training the model

%cd {HOME}
!python train.py model=yolov8l-seg.pt task=segment data={dataset.location}/data.yaml epochs=100 imgsz=640 v5loader=true

the above command I tried to run in the Google collab based on your video. However, then, I am facing this issue.

Error executing job with overrides: ['model=yolov8l-seg.pt', 'task=segment', 'data=/content/YOLOv8_Segmentation_DeepSORT_Object_Tracking/ultralytics/yolo/v8/segment/Pothole-Detection-Project-2/data.yaml', 'epochs=100', 'imgsz=640', 'v5loader=true']
Traceback (most recent call last):
  File "train.py", line 150, in train
    model.train(**cfg)
  File "/content/YOLOv8_Segmentation_DeepSORT_Object_Tracking/ultralytics/yolo/engine/model.py", line 193, in train
    self.trainer.train()
  File "/content/YOLOv8_Segmentation_DeepSORT_Object_Tracking/ultralytics/yolo/engine/trainer.py", line 177, in train
    self._do_train(int(os.getenv("RANK", -1)), world_size)
  File "/content/YOLOv8_Segmentation_DeepSORT_Object_Tracking/ultralytics/yolo/engine/trainer.py", line 293, in _do_train
    self.loss, self.loss_items = self.criterion(preds, batch)
  File "/content/YOLOv8_Segmentation_DeepSORT_Object_Tracking/ultralytics/yolo/v8/segment/train.py", line 44, in criterion
    return self.compute_loss(preds, batch)
  File "/content/YOLOv8_Segmentation_DeepSORT_Object_Tracking/ultralytics/yolo/v8/segment/train.py", line 89, in __call__
    masks = batch["masks"].to(self.device).float()
KeyError: 'masks'

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.

Please help.

Module Not Found

from deep_sort_pytorch.utils.parser import get_config ModuleNotFoundError: No module named 'deep_sort_pytorch'

I can not find this package anywhere.....

Issue while training the model

Hi @MuhammadMoinFaisal

Thank you for your response.
Still facing the same issue after removing v5Loader.

Here is the collab link that I am working on: (https://colab.research.google.com/drive/1pj43CxXThyDXjBOn_xZpYslRu38CGlER?usp=sharing)

Error executing job with overrides: ['model=yolov8l-seg.pt', 'task=segment', 'data=/content/YOLOv8_Segmentation_DeepSORT_Object_Tracking/ultralytics/yolo/v8/segment/Pothole-Detection-Project-2/data.yaml', 'epochs=100', 'imgsz=640', 'pretrained=True']
Traceback (most recent call last):
  File "train.py", line 151, in train
    model.train(**cfg)
  File "/content/YOLOv8_Segmentation_DeepSORT_Object_Tracking/ultralytics/yolo/engine/model.py", line 193, in train
    self.trainer.train()
  File "/content/YOLOv8_Segmentation_DeepSORT_Object_Tracking/ultralytics/yolo/engine/trainer.py", line 177, in train
    self._do_train(int(os.getenv("RANK", -1)), world_size)
  File "/content/YOLOv8_Segmentation_DeepSORT_Object_Tracking/ultralytics/yolo/engine/trainer.py", line 275, in _do_train
    for i, batch in pbar:
  File "/usr/local/lib/python3.8/dist-packages/tqdm/std.py", line 1195, in __iter__
    for obj in iterable:
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 628, in __next__
    data = self._next_data()
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 1333, in _next_data
    return self._process_data(data)
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 1359, in _process_data
    data.reraise()
  File "/usr/local/lib/python3.8/dist-packages/torch/_utils.py", line 543, in reraise
    raise exception
ValueError: Caught ValueError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/worker.py", line 302, in _worker_loop
    data = fetcher.fetch(index)
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/fetch.py", line 58, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/fetch.py", line 58, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/content/YOLOv8_Segmentation_DeepSORT_Object_Tracking/ultralytics/yolo/data/base.py", line 179, in __getitem__
    return self.transforms(self.get_label_info(index))
  File "/content/YOLOv8_Segmentation_DeepSORT_Object_Tracking/ultralytics/yolo/data/augment.py", line 48, in __call__
    data = t(data)
  File "/content/YOLOv8_Segmentation_DeepSORT_Object_Tracking/ultralytics/yolo/data/augment.py", line 48, in __call__
    data = t(data)
  File "/content/YOLOv8_Segmentation_DeepSORT_Object_Tracking/ultralytics/yolo/data/augment.py", line 361, in __call__
    i = self.box_candidates(box1=instances.bboxes.T,
  File "/content/YOLOv8_Segmentation_DeepSORT_Object_Tracking/ultralytics/yolo/data/augment.py", line 375, in box_candidates
    return (w2 > wh_thr) & (h2 > wh_thr) & (w2 * h2 / (w1 * h1 + eps) > area_thr) & (ar < ar_thr)  # candidates
ValueError: operands could not be broadcast together with shapes (5,) (6,) 


Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.

Originally posted by @soleyromit in #3 (comment)

txt file with frame information

Hi,

Is there a way to get .txt files from each frame with information about track_id and bounding box location for each object tracked? I am working with custom data.

Thank you.

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.