GeekAlexis / FastMOT

High-performance multiple object tracking based on YOLO, Deep SORT, and KLT 🚀
MIT License
1.14k stars 254 forks source link

How can I detect a picture? #68

Closed Russell565 closed 3 years ago

Russell565 commented 3 years ago

I want to detect only one picture and return the coordinates of the detection frame. How can I achieve it?

GeekAlexis commented 3 years ago

You can use the detector API from FastMOT to do so. https://github.com/GeekAlexis/FastMOT/blob/c1cd264d94e19a69d70716122b40be383871026c/fastmot/detector.py#L22-L42

A simple example:

import fastmot

config = {
  "model": "YOLOv4",
  "class_ids": [1],
  "conf_thresh": 0.25,
  "max_area": 800000,
  "nms_thresh": 0.5
}
detector = fastmot.detector.YOLODetector((1280, 720), config)

img = cv2.imread(...)
detections = detector(img)
Russell565 commented 3 years ago

@GeekAlexis thank you for your help! I also want to know about std_factor_accstd_offset_accmax_age and iou_thresh in multi_tracker of mot.json.Please help me to explain these args.

Russell565 commented 3 years ago

Recently, I have two problems

  1. Sometimes, the same person has two detection boxes. The original detection frame appears at the position of the previous frame, and the new detection frame appears at the present position

  2. Sometimes there's a "blink" in the picture, and then the detectionbox and Reid were changed

It bothers me. Do you have any idea?

GeekAlexis commented 3 years ago
  1. You mean there are two track boxes associated with one person (duplicate tracks)?
  2. Not sure what you mean by a blink. Can you elaborate?
Russell565 commented 3 years ago

You can see these mp4. https://drive.google.com/drive/folders/1dlFEnnNVgQ5MQ3VVb3U5_rxW30_pZfgY?usp=sharing

1、In the begining, the track id of box is 1. Sometime, when the person walking, the box stop at the previous position.But the person has moved to next position. And it will creat a new box on the person, and then these boxes will disappear 2、I think,the blink is because the light changes.But when it happened,i lost the track id .Maybe i should increase the max_age?

GeekAlexis commented 3 years ago
  1. It looks like either association failed or optical flow failed and locked onto the building in the background. Try increasing the following parameters for fast moving objects:

https://github.com/GeekAlexis/FastMOT/blob/2851316a2d8c87923bd9a2e58c55e24676558288/cfg/mot.json#L52-L53

You may also want to lower iou_thresh such that the next detection can be associated with the track more easily: https://github.com/GeekAlexis/FastMOT/blob/2851316a2d8c87923bd9a2e58c55e24676558288/cfg/mot.json#L46

  1. The lighting change probably causes camera motion estimation to fail. By default, all tracks will be cleared in that case. Try lowering inlier_thresh so motion estimation is less likely to fail: https://github.com/GeekAlexis/FastMOT/blob/faf36a8e51d36ebee9817ed1006c3f6881bcbde6/cfg/mot.json#L72 If it doesn't work, you can delete the following lines: https://github.com/GeekAlexis/FastMOT/blob/faf36a8e51d36ebee9817ed1006c3f6881bcbde6/fastmot/tracker.py#L102-L104

Hope it helps.

Russell565 commented 3 years ago

I try to increase the std_factor_accand std_offset_acc , now i got two questions:

  1. How much should i increase? Is there any standard?
  2. I changed iou_thresh to 0.1 、std_factor_acc to 184.25 and std_offset_acc to 208.5. It helps a lot. But this is easy to happen when people move sideways (in my scene people are turning). Is this the problem with YOLO? Or should I keep to increase?

And i also changed the inlier_thresh, but the "blink" is not appear for now.

GeekAlexis commented 3 years ago

Keep in mind that the Kaman filter acceleration std (uncertainty) is determined by the following: https://github.com/GeekAlexis/FastMOT/blob/faf36a8e51d36ebee9817ed1006c3f6881bcbde6/fastmot/kalman_filter.py#L250-L251 There is no limit but generally, I probably won't increase the slope std_factor_acc to 200. Maybe 10x more is enough. The offset can be arbitrary. All units are in pixels.

To help me better understand the issue, can you turn on verbose drawing -v option when running app.py and show me the results again? This will show optical flow matches.

Russell565 commented 3 years ago

https://drive.google.com/drive/folders/1Lgmq_VTdk4GyqVXbLPfJR8TB6r-x7_uc?usp=sharing

In the indoor environment, I simulated the situation by jumping 、moving and turning. You can view it frame by frame through VLC. The red boxes is created by yolo, i change the color. I will learn about the Kaman filter and keep on change parameters.

GeekAlexis commented 3 years ago

How did you set detector_frame_skip? YOLO seems to detect at every frame. Can you briefly tell me what other changes you made.

If you are tracking objects really up close, you definitely need to change std_factor_acc and std_offset_acc to large values. The default config is not designed for that. Also make sure you set camera frame rate correctly in the config. You can lower these parameters a bit too: https://github.com/GeekAlexis/FastMOT/blob/faf36a8e51d36ebee9817ed1006c3f6881bcbde6/cfg/mot.json#L54-L55

Russell565 commented 3 years ago

https://drive.google.com/drive/folders/1Lgmq_VTdk4GyqVXbLPfJR8TB6r-x7_uc?usp=sharing This URL contains my latest mot.json.

The overall process of code has not changed, but it only changes some other things, such as the content displayed in the screen. detector_frame_skip is 5; In yolo, conf_thresh is 0.12 and nms_thresh is 0.44; In multi_tracker, max_age is 9 and iou_thresh is 0.1; The distance between the camera and the person is about 1-3 meters. In kalman_filter, std_factor_acc is 105.25 and std_offset_acc is 208.5. is it enough?; In flow, inlier_thresh is 3.

GeekAlexis commented 3 years ago

If detector_frame_skip is 5, why does the red bounding box appear at every frame and it's not associated to any track?

Russell565 commented 3 years ago

Oh! My fault, forgot to delete my test code. I will delete it and try again

Russell565 commented 3 years ago

It seems better now. Today is raining, i will find another day to do more test in outdoor enviroment, and i will tell you the result.

Thanks for your help

Russell565 commented 3 years ago

I think i can close this issue now. Thanks a lot !