Giter VIP home page Giter VIP logo

pytorch_objectdetecttrack's Introduction

PyTorch Object Detection and Tracking

Object detection in images, and tracking across video frames

Full story at: https://towardsdatascience.com/object-detection-and-tracking-in-pytorch-b3cf1a696a98

References:

  1. YOLOv3: https://pjreddie.com/darknet/yolo/
  2. Erik Lindernoren's YOLO implementation: https://github.com/eriklindernoren/PyTorch-YOLOv3
  3. YOLO paper: https://pjreddie.com/media/files/papers/YOLOv3.pdf
  4. SORT paper: https://arxiv.org/pdf/1602.00763.pdf
  5. Alex Bewley's SORT implementation: https://github.com/abewley/sort
  6. Installing Python 3.6 and Torch 1.0: https://medium.com/@chrisfotache/getting-started-with-fastai-v1-the-easy-way-using-python-3-6-apt-and-pip-772386952d03

pytorch_objectdetecttrack's People

Contributors

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

pytorch_objectdetecttrack's Issues

requirements.txt

Just wondering if you can upload the requirements.txt too, will make the installation and work easier.

RuntimeError: Expected object of type torch.FloatTensor but found type torch.DoubleTensor for argument #3 'other'

Error3

#changes in code :

Load model and weights

model = Darknet(config_path, img_size=img_size)
model.load_weights(weights_path)
#model.cuda()
device = torch.device("Cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
model.eval()
classes = utils.load_classes(class_path)
Tensor = torch.FloatTensor

Code runs and provide output also for seconds but after that its shows above error , Please help me ?

Runtimeerror

whenever I am trying object detection.py I am getting this error-
Traceback (most recent call last):
File "object_tracker.py", line 87, in
tracked_objects = mot_tracker.update(detections.cpu())
File "Z:\DEEP_Learning\original files\Yolo based model\using GPU\pytorch_objectdetecttrack\sort.py", line 208, in update
matched, unmatched_dets, unmatched_trks = associate_detections_to_trackers(dets,trks)
File "Z:\DEEP_Learning\original files\Yolo based model\using GPU\pytorch_objectdetecttrack\sort.py", line 147, in associate_detections_to_trackers
iou_matrix[d,t] = iou(det,trk)
RuntimeError: Expected object of type torch.FloatTensor but found type torch.DoubleTensor for argument #3 'other'

Modifications for running yolov3-tiny

What kind of modifications are required in the code to run "tiny yolov3" for object detection, apart from using different config file and weights ?

I'am getting the following error

File "/pytorch_objectdetecttrack/models.py", line 129, in forward
prediction = x.view(nB, nA, self.bbox_attrs, nG, nG).permute(0, 1, 3, 4, 2).contiguous()

RuntimeError: shape '[1, 3, 85, 12, 12]' is invalid for input of size 39780

Thanks

PIL error

Hello, I got this error, when I tried to run the program with the custom datasets, anybody know how to resolve it?
('Video size', 640, 480)

(Stream:14631): GStreamer-CRITICAL **: 09:39:54.096: gst_element_make_from_uri: assertion 'gst_uri_is_valid (uri)' failed
OpenCV Error: Unsupported format or combination of formats (Gstreamer Opencv backend does not support this file type.) in CvVideoWriter_GStreamer::open, file /home/nvidia/build_opencv/opencv/modules/videoio/src/cap_gstreamer.cpp, line 1534
VIDEOIO(cvCreateVideoWriter_GStreamer (filename, fourcc, fps, frameSize, is_color)): raised OpenCV exception:

/home/nvidia/build_opencv/opencv/modules/videoio/src/cap_gstreamer.cpp:1534: error: (-210) Gstreamer Opencv backend does not support this file type. in function CvVideoWriter_GStreamer::open

Traceback (most recent call last):
File "own_object_detection.py", line 276, in
detections = detect_image(pilimg)
File "own_object_detection.py", line 242, in detect_image
image_tensor = img_transforms(img).float()
File "build/bdist.linux-aarch64/egg/torchvision/transforms/transforms.py", line 61, in call
File "build/bdist.linux-aarch64/egg/torchvision/transforms/transforms.py", line 196, in call
File "build/bdist.linux-aarch64/egg/torchvision/transforms/functional.py", line 246, in resize
File "build/bdist.linux-aarch64/egg/PIL/Image.py", line 1892, in resize
TypeError: integer argument expected, got float

Invalid Syntax

Traceback (most recent call last):
File "object_tracker.py", line 1, in
from models import *
File "/home/krsbi/TA-Bill/pytorch_objectdetecttrack/models.py", line 259
x, *losses = module[0](x, targets)
^
SyntaxError: invalid syntax

Can someone help me?

torch.FloatTensor but found type torch.DoubleTensor

Hi Chris,

You have done a great job.

But While executing the object_tracker.py, I am getting the following error:

RuntimeError: Expected object of type torch.FloatTensor but found type torch.DoubleTensor for argument #3 'other'

error

Where am I going wrong ?

Thanks :)

Indexes out of range

Hello, would someone kindly help me with this error

DeprecationWarning: The linear_assignment_ module is deprecated in 0.21 and will be removed from 0.23. Use scipy.optimize.linear_sum_assignment instead.
DeprecationWarning)
Video size 1280 720
2
Traceback (most recent call last):
File "object_tracker.py", line 105, in
cls = classes[int(cls_pred)]
IndexError: list index out of range

Bounding boxes are not in correct locations

Thank you for the notebook and the blog!!
When i try to run the notebook attached for detection and tracking the bounding box dimensions seem to be correct, but their locations are not on the objects. Please let me know what modification need s to be made in the notebook
grafik

kindly help me fix this problem

tracked_objects = mot_tracker.update(detections.cpu())

this above line i am facing this below error

TypeError: tuple indices must be integers or slices, not tuple

IndexError: too many indices for tensor of dimension 2

Hye, what a great project! I tried to run the code however I am using a vgg16 model. I can't run the code since it said the dimension has too many indices on line 136 in utils file. May I know the dimension representing what? And do you have any suggestions or references to give?

Tracking ID changes between frames even when objects remain the same

I have noticed that when tracking people, if one person walks in front of another there are a couple of frames where the person behind is not detected, and then detected again when the person in front has moved away. However, when this happens the ID of the person has changed. Is there any way to resolve this issue? I suppose not in this instance as there would be no reliable way to tell if this is a new person or not.

I have also noticed it occur on consecutive frames on the same person where one frame has not made a correct detection. In this case would it just be best to lower the detection threshold?

Thanks in advance

Can't find filterby folder

from filterpy.kalman import KalmanFilter
ModuleNotFoundError: No module named 'filterpy'
Help me, please

Compilation is failing Back

Hi! I am trying to use your code for object detection and tracking using Ubuntu 20.04. Detection on image works fine but when attempting on videos and trying to track, I get following warnings and errors:

/home/anam/anaconda3/envs/yolov3/lib/python3.6/site-packages/torch/nn/_reduction.py:44: UserWarning: size_average and reduce args will be deprecated, please use reduction='mean' instead.
warnings.warn(warning.format(ret))
/home/anam/Codes/YOLOv4/Yolov3/pytorch_objectdetecttrack/sort.py:33: NumbaWarning:
Compilation is falling back to object mode WITH looplifting enabled because Function "iou" failed type inference due to: non-precise type pyobject
During: typing of argument at /home/anam/Codes/YOLOv4/Yolov3/pytorch_objectdetecttrack/sort.py (38)

File "sort.py", line 38:
def iou(bb_test,bb_gt):

"""
xx1 = np.maximum(bb_test[0], bb_gt[0])
^

@jit
/home/anam/anaconda3/envs/yolov3/lib/python3.6/site-packages/numba/core/object_mode_passes.py:178: NumbaWarning: Function "iou" was compiled in object mode without forceobj=True.

File "sort.py", line 34:
@jit
def iou(bb_test,bb_gt):
^

state.func_ir.loc))
/home/anam/anaconda3/envs/yolov3/lib/python3.6/site-packages/numba/core/object_mode_passes.py:188: NumbaDeprecationWarning:
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.

For more information visit https://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit

File "sort.py", line 34:
@jit
def iou(bb_test,bb_gt):
^

state.func_ir.loc))
Traceback (most recent call last):
File "object_detector.py", line 124, in
tracked_objects = mot_tracker.update(detections.cpu())
File "/home/anam/Codes/YOLOv4/Yolov3/pytorch_objectdetecttrack/sort.py", line 209, in update
matched, unmatched_dets, unmatched_trks = associate_detections_to_trackers(dets,trks)
File "/home/anam/Codes/YOLOv4/Yolov3/pytorch_objectdetecttrack/sort.py", line 153, in associate_detections_to_trackers
if(d not in matched_indices[:,0]):
TypeError: tuple indices must be integers or slices, not tuple

Wondering if you can help.

iou_matrix[d,t] = iou(det,trk) with det input not match with sort requirment (a bug?)

Great work, thanks a lot for sharing!

Noticed this thing and seems a bug due to input format:

In original sort, the input format of det is
Computes IOU between two bboxes in the form [x1,y1,x2,y2]

in your code, the det is in format of [x1, y1, x2, y2, object_conf, class_score, class_pred], due to the yolov3 output.

suggested change:
iou_matrix[d,t] = iou(det[:4],trk[:4])

Let me know if it makes sense or not, thanks again!

YOLOV3-Tiny Runtime Error

When running object_tracker.py using yolov3-tiny weights and cfg file, I get the following:

RuntimeError: Given groups=1, weight of size 256 256 3 3, expected input[1, 384, 26, 26] to have 256 channels, but got 384 channels instead

Any help will be greatly appreciated..

cannot connect to X server

When running object_tracker.py, I get the following the error:

/home/ubuntu/.local/lib/python3.6/site-packages/torch/nn/_reduction.py:46: UserWarning: size_average and reduce args will be deprecated, please use reduction='mean' instead.
warnings.warn(warning.format(ret))
: cannot connect to X server

I'd really appreciate if anyone can tell me where is that server or how can I solve this problem?

Sample Labels input needed

https://github.com/cfotache/pytorch_objectdetecttrack/blob/master/utils/datasets.py#L92-L116

It would be helpful to include the label document so I can make sense of the code that goes inside the above area.. Not sure how to return the Labels.. seems I need to return a matrix of all classes? Based on a list of pre-filled classes? I want to train new classes with transfer learning and a dataset of images and bounding boxes..

currently my labels are a single text file for each image.. so I will open it and load the text file

MyExampleClass [859, 36, 2329, 1801]

And I seem to need to return a torch.from_numpy likeso

        if labels is not None:
            filled_labels[range(len(labels))[:self.max_objects]] = labels[:self.max_objects]
        filled_labels = torch.from_numpy(filled_labels)

is the filled_labels an array of [[x1,y1,x2,y2,classification]....] ?

plt.savefig() giving error of too large pixels

While drawing the bounding boxes in the image using plt.savefig(), I am getting the error of
ValueError: Image size of 3396073x2015469 pixels is too large. It must be less than 2^16 in each direction.
Can anyone please tell me how to resolve the issue and save the bounding boxes?

Complete error log:
plt.savefig(img_path.replace(".jpg", "-det.png"), dpi=500, bbox_inches='tight', pad_inches=0.0)
File "/home/sipaul/anaconda3/envs/pytorch/lib/python3.8/site-packages/matplotlib/pyplot.py", line 723, in savefig
res = fig.savefig(*args, **kwargs)
File "/home/sipaul/anaconda3/envs/pytorch/lib/python3.8/site-packages/matplotlib/figure.py", line 2203, in savefig
self.canvas.print_figure(fname, **kwargs)
File "/home/sipaul/anaconda3/envs/pytorch/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 2119, in print_figure
result = print_method(
File "/home/sipaul/anaconda3/envs/pytorch/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py", line 514, in print_png
FigureCanvasAgg.draw(self)
File "/home/sipaul/anaconda3/envs/pytorch/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py", line 388, in draw
self.renderer = self.get_renderer(cleared=True)
File "/home/sipaul/anaconda3/envs/pytorch/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py", line 404, in get_renderer
self.renderer = RendererAgg(w, h, self.figure.dpi)
File "/home/sipaul/anaconda3/envs/pytorch/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py", line 92, in init
self._renderer = _RendererAgg(int(width), int(height), dpi)
ValueError: Image size of 3396073x2015469 pixels is too large. It must be less than 2^16 in each direction

Custom Dataset

This is a very interesting insight on object vision, is there a good tutorial to train a yolo on pytorch from scratch

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.