tryolabs / norfair

Lightweight Python library for adding real-time multi-object tracking to any detector.
https://tryolabs.github.io/norfair/
BSD 3-Clause "New" or "Revised" License
2.41k stars 245 forks source link

Question about skip_period #301

Closed utility-aagrawal closed 8 months ago

utility-aagrawal commented 8 months ago

Hi,

I have been processing all the frames from my videos so far (skip_period =1) but now I am at a point where I want to process less frames to make the process faster. I just ran one test with skip_period = 15 and tracking results don't look as good. My understanding is that there are other parameters such as initialization_delay, hit_counter_max etc. that I probably need to also adjust for a better performance. Do you know which all parameters I need to change if I change skip_period? Also, is there a rule of thumb like if I change skip_period to 10x, I should change these other parameters to ?x to match the performance. Let me know if my question is not clear to you and I can add more details. Thanks a lot!!

aguscas commented 8 months ago

One thing you would have to increase is your distance_threshold, since the TrackedObject instances will be further from the associated Detection, because the TrackedObject assumed constant velocity to estimate where the object was between those 15 frames and compared that estimation with your detections.

Another thing to consider is that you shouldn't be skipping an amount of frames greater than the hit_counter, since norfair always decreases by one the hit_counter even for the frames you are skipping (here in the tracker_step method), and then when you finally use the detector and not skip that frame norfair compensates by adding 2*skip_period to the hit counter if it matched a detection (here in the hit method). One of those added skip_period is to compensate all the times the hit_counter was decreased by one in the skipped frames, and the other added skip_period is to increase the hit_counter by that amount (so is like the tracked object actually matched with detections in all those skipped frames). As a result of all that, if the TrackedObject didn't match in that unkskipped frame, the hit_counter decreased by skip_period (with respect to the value it had the last time you didn't skip a frame), and if it matches then the hit_counter is increased by skip_period.

One way of thinking about that period variable, is that it represents by how much is the hit_counter increased or decreased between frames that are not skipped. It is done this way so that when you skip more frames, you require less consecutive matches to initialize an object (otherwise you would have to wait too many seconds for an object to get initialized), and also you require less consecutive frames without matching to destroy them (otherwise you would have objects that have actually disappeared many seconds ago).

To sum up everything I said, these are the things you should be aware when playing with the period:

Last comment / personal opinion: I don't know the FPS of your footage and how erratically do the objects move in your videos, but assuming is 30FPS, having a period of 15 means that you only use the detector twice a second. I would try to use the detector at least 10 times a second (that would be an skip_period of 3 in the 30 fps example) if it is possible. The more times you use it, the less uncertainty in the tracking. You need to find a good balance between tracking quality and your processing speed.

utility-aagrawal commented 8 months ago

Thanks a lot @aguscas ! That's a lot of information to digest :) It'll take me a little bit but I'll get back to you shortly in case I have any questions.