From 2e61ae9626af1b2cdfe498efff337d65b727aaae Mon Sep 17 00:00:00 2001 From: George Ni Date: Thu, 20 May 2021 10:27:34 +0800 Subject: [PATCH] [MOT] fix video infer (#3078) * fix ffmpeg video infer, fix doc, test=document_fix * fix ffmpeg installl, test=document_fix --- configs/mot/README.md | 14 +++++++++++++- configs/mot/README_cn.md | 14 +++++++++++++- configs/mot/deepsort/README.md | 2 +- configs/mot/deepsort/README_cn.md | 2 +- configs/mot/fairmot/README.md | 3 +-- configs/mot/fairmot/README_cn.md | 2 +- .../mot/fairmot/_base_/fairmot_reader_1088x608.yml | 11 +++++++++++ configs/mot/jde/README.md | 13 +------------ configs/mot/jde/README_cn.md | 13 +------------ ppdet/engine/tracker.py | 10 ++++++---- 10 files changed, 49 insertions(+), 35 deletions(-) diff --git a/configs/mot/README.md b/configs/mot/README.md index b6f761592..549719564 100644 --- a/configs/mot/README.md +++ b/configs/mot/README.md @@ -186,9 +186,21 @@ Evaluating the track performance of FairMOT on val dataset in single GPU with fo CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml -o weights=https://paddledet.bj.bcebos.com/models/mot/fairmot_dla34_30e_1088x608.pdparams # use saved checkpoint in training -CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml -o weights=output/fairmot_dla34_30e_1088x608/model_final +CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml -o weights=output/fairmot_dla34_30e_1088x608/model_final.pdparams ``` +### 3. Inference + +Inference a vidoe on single GPU with following command: + +```bash +# inference on video and save a video +CUDA_VISIBLE_DEVICES=0 python tools/infer_mot.py -c configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml -o weights=https://paddledet.bj.bcebos.com/models/mot/fairmot_dla34_30e_1088x608.pdparams --video_file={your video name}.mp4 --save_videos +``` +**Notes:** + Please make sure that [ffmpeg](https://ffmpeg.org/ffmpeg.html) is installed first, on Linux(Ubuntu) platform you can directly install it by the following command:`apt-get update && apt-get install -y ffmpeg`. + + ## Citations ``` @article{wang2019towards, diff --git a/configs/mot/README_cn.md b/configs/mot/README_cn.md index 15fac03a2..53f8e4db4 100644 --- a/configs/mot/README_cn.md +++ b/configs/mot/README_cn.md @@ -184,9 +184,21 @@ FairMOT使用单张GPU通过如下命令一键式启动评估 CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml -o weights=https://paddledet.bj.bcebos.com/models/mot/fairmot_dla34_30e_1088x608.pdparams # 使用训练保存的checkpoint -CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml -o weights=output/fairmot_dla34_30e_1088x608/model_final +CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml -o weights=output/fairmot_dla34_30e_1088x608/model_final.pdparams ``` +### 3. 预测 + +使用单个GPU通过如下命令预测一个视频,并保存为视频 + +```bash +# 预测一个视频 +CUDA_VISIBLE_DEVICES=0 python tools/infer_mot.py -c configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml -o weights=https://paddledet.bj.bcebos.com/models/mot/fairmot_dla34_30e_1088x608.pdparams --video_file={your video name}.mp4 --save_videos +``` + +**注意:** + 请先确保已经安装了[ffmpeg](https://ffmpeg.org/ffmpeg.html), Linux(Ubuntu)平台可以直接用以下命令安装:`apt-get update && apt-get install -y ffmpeg`。 + ## 引用 ``` @article{wang2019towards, diff --git a/configs/mot/deepsort/README.md b/configs/mot/deepsort/README.md index 4847be341..237d3bd70 100644 --- a/configs/mot/deepsort/README.md +++ b/configs/mot/deepsort/README.md @@ -53,7 +53,7 @@ Each txt is the detection result of all the pictures extracted from each video, CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/jde/jde_darknet53_30e_1088x608_track.yml -o weights=https://paddledet.bj.bcebos.com/models/mot/jde_darknet53_30e_1088x608.pdparams # use saved checkpoint after training -CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/jde/jde_darknet53_30e_1088x608_track.yml -o weights=output/jde_darknet53_30e_1088x608/model_final +CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/jde/jde_darknet53_30e_1088x608_track.yml -o weights=output/jde_darknet53_30e_1088x608/model_final.pdparams ``` ### 2. Tracking diff --git a/configs/mot/deepsort/README_cn.md b/configs/mot/deepsort/README_cn.md index 81af5f6c1..203df6a81 100644 --- a/configs/mot/deepsort/README_cn.md +++ b/configs/mot/deepsort/README_cn.md @@ -53,7 +53,7 @@ det_results_dir CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/jde/jde_darknet53_30e_1088x608_track.yml -o weights=https://paddledet.bj.bcebos.com/models/mot/jde_darknet53_30e_1088x608.pdparams # 使用训练保存的checkpoint -CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/jde/jde_darknet53_30e_1088x608_track.yml -o weights=output/jde_darknet53_30e_1088x608/model_final +CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/jde/jde_darknet53_30e_1088x608_track.yml -o weights=output/jde_darknet53_30e_1088x608/model_final.pdparams ``` ### 2. 跟踪预测 diff --git a/configs/mot/fairmot/README.md b/configs/mot/fairmot/README.md index 0254ef340..e6b7d7491 100644 --- a/configs/mot/fairmot/README.md +++ b/configs/mot/fairmot/README.md @@ -53,8 +53,7 @@ Evaluating the track performance of FairMOT on val dataset in single GPU with fo CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml -o weights=https://paddledet.bj.bcebos.com/models/mot/fairmot_dla34_30e_1088x608.pdparams # use saved checkpoint in training -CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml -o weights=output/fairmot_dla34_30e_1088x608/model_final -``` +CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml -o weights=output/fairmot_dla34_30e_1088x608/model_final.pdparams ## Citations ``` diff --git a/configs/mot/fairmot/README_cn.md b/configs/mot/fairmot/README_cn.md index 8bab81c78..f6b4fac48 100644 --- a/configs/mot/fairmot/README_cn.md +++ b/configs/mot/fairmot/README_cn.md @@ -50,7 +50,7 @@ python -m paddle.distributed.launch --log_dir=./fairmot_dla34_30e_1088x608/ --gp CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml -o weights=https://paddledet.bj.bcebos.com/models/mot/fairmot_dla34_30e_1088x608.pdparams # 使用训练保存的checkpoint -CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml -o weights=output/fairmot_dla34_30e_1088x608/model_final +CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml -o weights=output/fairmot_dla34_30e_1088x608/model_final.pdparams ``` ## 引用 diff --git a/configs/mot/fairmot/_base_/fairmot_reader_1088x608.yml b/configs/mot/fairmot/_base_/fairmot_reader_1088x608.yml index 6dadac3a3..5c0d4824a 100644 --- a/configs/mot/fairmot/_base_/fairmot_reader_1088x608.yml +++ b/configs/mot/fairmot/_base_/fairmot_reader_1088x608.yml @@ -28,3 +28,14 @@ EvalMOTReader: - NormalizeImage: {mean: [0, 0, 0], std: [1, 1, 1]} - Permute: {to_rgb: True} batch_size: 1 + + +TestMOTReader: + inputs_def: + image_shape: [3, 608, 1088] + sample_transforms: + - Decode: {to_rgb: False} + - LetterBoxResize: {target_size: [608, 1088]} + - NormalizeImage: {mean: [0, 0, 0], std: [1, 1, 1]} + - Permute: {to_rgb: True} + batch_size: 1 diff --git a/configs/mot/jde/README.md b/configs/mot/jde/README.md index d8ace647b..4e3893d1c 100644 --- a/configs/mot/jde/README.md +++ b/configs/mot/jde/README.md @@ -48,20 +48,9 @@ Evaluating the track performance of JDE on val dataset in single GPU with follow CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/jde/jde_darknet53_30e_1088x608.yml -o weights=https://paddledet.bj.bcebos.com/models/mot/jde_darknet53_30e_1088x608.pdparams # use saved checkpoint in training -CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/jde/jde_darknet53_30e_1088x608.yml -o weights=output/jde_darknet53_30e_1088x608/model_final +CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/jde/jde_darknet53_30e_1088x608.yml -o weights=output/jde_darknet53_30e_1088x608/model_final.pdparams ``` -### 3. Inference - -Inference a vidoe in single GPU with following commands. - -```bash -# inference on video and save a video -CUDA_VISIBLE_DEVICES=0 python tools/infer_mot.py -c configs/mot/jde/jde_darknet53_30e_1088x608.yml -o weights=https://paddledet.bj.bcebos.com/models/mot/jde_darknet53_30e_1088x608.pdparams --video_file={your video name}.mp4 --save_videos -``` -**Notes:** - Please make sure that [ffmpeg](https://www.ffmpeg.org) is installed first. - ## Citations ``` @article{wang2019towards, diff --git a/configs/mot/jde/README_cn.md b/configs/mot/jde/README_cn.md index 50672cf4e..f25772682 100644 --- a/configs/mot/jde/README_cn.md +++ b/configs/mot/jde/README_cn.md @@ -47,20 +47,9 @@ python -m paddle.distributed.launch --log_dir=./jde_darknet53_30e_1088x608/ --gp CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/jde/jde_darknet53_30e_1088x608.yml -o weights=https://paddledet.bj.bcebos.com/models/mot/jde_darknet53_30e_1088x608.pdparams # 使用训练保存的checkpoint -CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/jde/jde_darknet53_30e_1088x608.yml -o weights=output/jde_darknet53_30e_1088x608/model_final +CUDA_VISIBLE_DEVICES=0 python tools/eval_mot.py -c configs/mot/jde/jde_darknet53_30e_1088x608.yml -o weights=output/jde_darknet53_30e_1088x608/model_final.pdparams ``` -### 3. 预测 - -使用单个GPU通过如下命令预测一个视频,并保存为视频 - -```bash -# 预测一个视频 -CUDA_VISIBLE_DEVICES=0 python tools/infer_mot.py -c configs/mot/jde/jde_darknet53_30e_1088x608.yml -o weights=https://paddledet.bj.bcebos.com/models/mot/jde_darknet53_30e_1088x608.pdparams --video_file={your video name}.mp4 --save_videos -``` -**注意:** - 请先确保已经安装了[ffmpeg](https://www.ffmpeg.org)。 - ## 引用 ``` @article{wang2019towards, diff --git a/ppdet/engine/tracker.py b/ppdet/engine/tracker.py index 153db303b..4040d9200 100644 --- a/ppdet/engine/tracker.py +++ b/ppdet/engine/tracker.py @@ -280,8 +280,9 @@ class Tracker(object): timer_calls.append(tc) if save_videos: - output_video_path = os.path.join(save_dir, '{}.mp4'.format(seq)) - cmd_str = 'ffmpeg -f image2 -i {}/%05d.jpg -c:v copy {}'.format( + output_video_path = os.path.join(save_dir, '..', + '{}_vis.mp4'.format(seq)) + cmd_str = 'ffmpeg -f image2 -i {}/%05d.jpg {}'.format( save_dir, output_video_path) os.system(cmd_str) logger.info('Save video in {}.'.format(output_video_path)) @@ -367,8 +368,9 @@ class Tracker(object): raise ValueError(model_type) if save_videos: - output_video_path = os.path.join(save_dir, '{}.mp4'.format(seq)) - cmd_str = 'ffmpeg -f image2 -i {}/%05d.jpg -c:v copy {}'.format( + output_video_path = os.path.join(save_dir, '..', + '{}_vis.mp4'.format(seq)) + cmd_str = 'ffmpeg -f image2 -i {}/%05d.jpg {}'.format( save_dir, output_video_path) os.system(cmd_str) logger.info('Save video in {}'.format(output_video_path)) -- GitLab