Detectron2: How to write the resulting detections to a text file?

Created on 13 Feb 2020  路  4Comments  路  Source: facebookresearch/detectron2

Hi, I know the following command produces an output video file with the detections.
python demo/demo.py --config-file configs/COCO-Detection/faster_rcnn_X_101_32x8d_FPN_3x.yaml --video-input new5.mp4 --output outputs/outvideo.avi --opts MODEL.WEIGHTS detectron2://COCO-Detection/faster_rcnn_X_101_32x8d_FPN_3x/139173657/model_final_68b088.pkl

I'd like to know how to write the detections to an output text file in the MOT format like this:
1,-1,126.682,445.587,489.079,205.913,0.996153,-1,-1,-1

I tried the following command to write the detections to an output text file:
python demo/demo.py --config-file configs/COCO-Detection/faster_rcnn_X_101_32x8d_FPN_3x.yaml --video-input new5.mp4 --output outputs/output_detections.txt --opts MODEL.WEIGHTS detectron2://COCO-Detection/faster_rcnn_X_101_32x8d_FPN_3x/139173657/model_final_68b088.pkl

But it just creates an empty text file.

Can anyone provide me suggestions as to how to write the detection(bounding box) information to a text file?

All 4 comments

Files under demo/ are examples that users are expected to be able to understand. The outputs are named predictions in demo/predictor.py, which is a dict whose type and format is documented in https://detectron2.readthedocs.io/tutorials/models.html#model-output-format. These information should be enough for a user to write code to produce output in any format.

@anzy0621 Regarding the numbers:
1,-1,126.682,445.587,489.079,205.913,0.996153,-1,-1,-1
-I think the first number represents the frame number and the instance detected in that frame, so when it's repeated it means the number of instances detected in that frame
-The second number i think is a non existent class (let's say human) also i think every -1 represents a non existent class
-The next 4 numbers represent x1, y1 ,w, h the bounding box of the detected object, so you can get the width and height from x2-x1 and y2-y1 which you can get from the bounding box info from let's say:
outputs["instances"].pred_boxes
that will give you the tensor and you can get the values from:
outputs["instances"].pred_boxes[i].tensor[0, 0].data.cpu().numpy() (tensor[0, 0] for x1)
-The last number (0.996153) i think represents the accuracy that it's the said class (let's say car)
-The rest of the -1s represent non existent classes in the frame
You can basically write the numbers in that format in a text file and give the detections and the input video to the deepsort tracker and it should work fine. :)

Thank you I appreciate it!

Hi @ppwwyyxx thanks for this project but i wonder how can i export the output which is according to MODEL.ROI_HEADS.SCORE_THRESH_TEST and ROI_HEADS.NMS_THRESH_TEST, since i using this to export all output to css but it returns many cases which i believed it doesnt do the nms and conf_thres there.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GiovanniPasq picture GiovanniPasq  路  3Comments

aminekechaou picture aminekechaou  路  3Comments

choasup picture choasup  路  3Comments

LotharTUM picture LotharTUM  路  3Comments

jinfagang picture jinfagang  路  3Comments