MVIG-SJTU / AlphaPose

Real-Time and Accurate Full-Body Multi-Person Pose Estimation&Tracking System
http://mvig.org/research/alphapose.html
Other
7.96k stars 1.97k forks source link

demo_inference.py for video stuck at 99% #946

Open just-barcodes opened 2 years ago

just-barcodes commented 2 years ago

I encountered a bug where demo_inference.py sometimes was stuck for a few videos (usually at 99%).

It looks like this can happen because det_loader.length is not always accurate. It uses int(stream.get(cv2.CAP_PROP_FRAME_COUNT)) but CAP_PROP_FRAME_COUNT might not be accurate. So DetectionLoader can get stuck at det_loader.read() when the underlying queue.Queue is empty.

I think you can "reproduce" this e.g. by setting data_len = det_loader.length + 15 for any video.

For now I fixed this by replacing DetectionLoader with a patched class

class MyDetectionLoader(DetectionLoader):
    def read(self):
        # raises queue.Empty Exception after timeout!
        return self.pose_queue.get(timeout=5)

and catching the possible exception

try:
    (
        inps,
        orig_img,
        im_name,
        boxes,
        scores,
        ids,
        cropped_boxes,
    ) = det_loader.read()
except queue.Empty:
    break

but there is probably a better way to handle this

(I'm also using the `--sp`` flag)

Fang-Haoshu commented 2 years ago

Hi, you are right. Sometimes opencv reads the wrong frame number for some videos. You try-except is a nice solution.