From 17a4b8153c352fdb0087cd2eab29cd64cf257d9f Mon Sep 17 00:00:00 2001 From: Feng Ni Date: Wed, 30 Mar 2022 18:13:51 +0800 Subject: [PATCH] [MOT] remove cython box and fix doc (#5525) * rename lite model tar name; test=document_fix * Update Readme_cn and Add Readme_en on 2.4 (#5500) * Update README_cn.md * Update Readme * Update README_cn.md * Update README_cn.md * Update docs for PP-YOLOE (#5494) (#5495) * [cherry-pick] fix test arch (#5504) * [cherry-pick] update pphuman en doc, test=document_fix (#5507) * update pphuman en doc, test=document_fix * update doc * add warnings and TestDataset dataset_dir * remove cython_box and fix doc * fix conflict, test=document_fix Co-authored-by: zhiboniu Co-authored-by: YixinKristy <48054808+YixinKristy@users.noreply.github.com> Co-authored-by: qingqing01 Co-authored-by: wangguanzhong --- configs/mot/README.md | 3 +- configs/mot/README_en.md | 3 +- configs/mot/fairmot/README.md | 2 +- configs/mot/fairmot/README_cn.md | 2 +- ...fairmot_dla34_30e_1088x608_bytetracker.yml | 10 +++++ configs/mot/pedestrian/README_cn.md | 6 +-- .../python/mot/matching/jde_matching.py | 40 +++++++++++-------- ppdet/metrics/mcmot_metrics.py | 7 ++-- ppdet/metrics/mot_metrics.py | 11 +++-- ppdet/modeling/mot/matching/jde_matching.py | 40 +++++++++++-------- requirements.txt | 1 - 11 files changed, 75 insertions(+), 50 deletions(-) diff --git a/configs/mot/README.md b/configs/mot/README.md index 18284eb34..f14975f9a 100644 --- a/configs/mot/README.md +++ b/configs/mot/README.md @@ -47,12 +47,11 @@ PP-Tracking 提供了简洁的GUI可视化界面,教程请参考[PP-Tracking ## 安装依赖 一键安装MOT相关的依赖: ``` -pip install lap sklearn motmetrics openpyxl cython_bbox +pip install lap sklearn motmetrics openpyxl 或者 pip install -r requirements.txt ``` **注意:** -- `cython_bbox`在windows上安装:`pip install -e git+https://github.com/samson-wang/cython_bbox.git#egg=cython-bbox`。可参考这个[教程](https://stackoverflow.com/questions/60349980/is-there-a-way-to-install-cython-bbox-for-windows)。 - 预测需确保已安装[ffmpeg](https://ffmpeg.org/ffmpeg.html), Linux(Ubuntu)平台可以直接用以下命令安装:`apt-get update && apt-get install -y ffmpeg`。 diff --git a/configs/mot/README_en.md b/configs/mot/README_en.md index e23bc451b..6cbdf3d66 100644 --- a/configs/mot/README_en.md +++ b/configs/mot/README_en.md @@ -49,12 +49,11 @@ PP-Tracking supports GUI predict and deployment. Please refer to this [doc](http ## Installation Install all the related dependencies for MOT: ``` -pip install lap sklearn motmetrics openpyxl cython_bbox +pip install lap sklearn motmetrics openpyxl or pip install -r requirements.txt ``` **Notes:** -- Install `cython_bbox` for Windows: `pip install -e git+https://github.com/samson-wang/cython_bbox.git#egg=cython-bbox`. You can refer to this [tutorial](https://stackoverflow.com/questions/60349980/is-there-a-way-to-install-cython-bbox-for-windows). - 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`. diff --git a/configs/mot/fairmot/README.md b/configs/mot/fairmot/README.md index 25441f21c..fbb9daa04 100644 --- a/configs/mot/fairmot/README.md +++ b/configs/mot/fairmot/README.md @@ -86,7 +86,7 @@ PP-tracking provides an AI studio public project tutorial. Please refer to this ### Results on MOT-17 Half Set | backbone | input shape | MOTA | IDF1 | IDS | FP | FN | FPS | download | config | | :--------------| :------- | :----: | :----: | :----: | :----: | :----: | :------: | :----: |:-----: | -| DLA-34 | 1088x608 | 69.1 | 72.8 | 299 | 1957 | 14412 | - |[model](https://paddledet.bj.bcebos.com/models/mot/fairmot_dla34_30e_1088x608_bytetracker.pdparams) | [config](./fairmot_dla34_30e_1088x608.yml) | +| DLA-34 | 1088x608 | 69.1 | 72.8 | 299 | 1957 | 14412 | - |[model](https://paddledet.bj.bcebos.com/models/mot/fairmot_dla34_30e_1088x608.pdparams) | [config](./fairmot_dla34_30e_1088x608.yml) | | DLA-34 + BYTETracker| 1088x608 | 70.3 | 73.2 | 234 | 2176 | 13598 | - |[model](https://paddledet.bj.bcebos.com/models/mot/fairmot_dla34_30e_1088x608_bytetracker.pdparams) | [config](./fairmot_dla34_30e_1088x608_bytetracker.yml) | **Notes:** diff --git a/configs/mot/fairmot/README_cn.md b/configs/mot/fairmot/README_cn.md index bb22459e8..dd5a27874 100644 --- a/configs/mot/fairmot/README_cn.md +++ b/configs/mot/fairmot/README_cn.md @@ -82,7 +82,7 @@ PP-Tracking 提供了AI Studio公开项目案例,教程请参考[PP-Tracking ### 在MOT-17 Half上结果 | 骨干网络 | 输入尺寸 | MOTA | IDF1 | IDS | FP | FN | FPS | 下载链接 | 配置文件 | | :--------------| :------- | :----: | :----: | :----: | :----: | :----: | :------: | :----: |:-----: | -| DLA-34 | 1088x608 | 69.1 | 72.8 | 299 | 1957 | 14412 | - |[下载链接](https://paddledet.bj.bcebos.com/models/mot/fairmot_dla34_30e_1088x608_bytetracker.pdparams) | [配置文件](./fairmot_dla34_30e_1088x608.yml) | +| DLA-34 | 1088x608 | 69.1 | 72.8 | 299 | 1957 | 14412 | - |[下载链接](https://paddledet.bj.bcebos.com/models/mot/fairmot_dla34_30e_1088x608.pdparams) | [配置文件](./fairmot_dla34_30e_1088x608.yml) | | DLA-34 + BYTETracker| 1088x608 | 70.3 | 73.2 | 234 | 2176 | 13598 | - |[下载链接](https://paddledet.bj.bcebos.com/models/mot/fairmot_dla34_30e_1088x608_bytetracker.pdparams) | [配置文件](./fairmot_dla34_30e_1088x608_bytetracker.yml) | diff --git a/configs/mot/fairmot/fairmot_dla34_30e_1088x608_bytetracker.yml b/configs/mot/fairmot/fairmot_dla34_30e_1088x608_bytetracker.yml index 7b668c568..a0ad44a0f 100644 --- a/configs/mot/fairmot/fairmot_dla34_30e_1088x608_bytetracker.yml +++ b/configs/mot/fairmot/fairmot_dla34_30e_1088x608_bytetracker.yml @@ -14,8 +14,18 @@ TrainDataset: image_lists: ['mot17.half', 'caltech.all', 'cuhksysu.train', 'prw.train', 'citypersons.train', 'eth.train'] data_fields: ['image', 'gt_bbox', 'gt_class', 'gt_ide'] +# for MOT evaluation +# If you want to change the MOT evaluation dataset, please modify 'data_root' +EvalMOTDataset: + !MOTImageFolder + dataset_dir: dataset/mot + data_root: MOT17/images/half + keep_ori_im: False # set True if save visualization images or video, or used in DeepSORT + JDETracker: use_byte: True match_thres: 0.8 conf_thres: 0.4 low_conf_thres: 0.2 + min_box_area: 200 + vertical_ratio: 1.6 # for pedestrian diff --git a/configs/mot/pedestrian/README_cn.md b/configs/mot/pedestrian/README_cn.md index eca2963c5..768733db5 100644 --- a/configs/mot/pedestrian/README_cn.md +++ b/configs/mot/pedestrian/README_cn.md @@ -18,7 +18,7 @@ | :-------------| :-------- | :------- | :----: | :----: | :----: | :-----: |:------: | | PathTrack | DLA-34 | 1088x608 | 44.9 | 59.3 | - |[下载链接](https://paddledet.bj.bcebos.com/models/mot/fairmot_dla34_30e_1088x608_pathtrack.pdparams) | [配置文件](./fairmot_dla34_30e_1088x608_pathtrack.yml) | | VisDrone | DLA-34 | 1088x608 | 49.2 | 63.1 | - | [下载链接](https://paddledet.bj.bcebos.com/models/mot/fairmot_dla34_30e_1088x608_visdrone_pedestrian.pdparams) | [配置文件](./fairmot_dla34_30e_1088x608_visdrone_pedestrian.yml) | -| VisDrone | HRNetv2-W18| 1088x608 | 40.5 | 54.7 | - | [下载链接](https://paddledet.bj.bcebos.com/models/mot/fairmot_hrnetv2_w18_dlafpn_30e_864x480_visdrone_pedestrian.pdparams) | [配置文件](./fairmot_hrnetv2_w18_dlafpn_30e_864x480_visdrone_pedestrian.yml) | +| VisDrone | HRNetv2-W18| 1088x608 | 40.5 | 54.7 | - | [下载链接](https://paddledet.bj.bcebos.com/models/mot/fairmot_hrnetv2_w18_dlafpn_30e_1088x608_visdrone_pedestrian.pdparams) | [配置文件](./fairmot_hrnetv2_w18_dlafpn_30e_1088x608_visdrone_pedestrian.yml) | | VisDrone | HRNetv2-W18| 864x480 | 38.6 | 50.9 | - | [下载链接](https://paddledet.bj.bcebos.com/models/mot/fairmot_hrnetv2_w18_dlafpn_30e_864x480_visdrone_pedestrian.pdparams) | [配置文件](./fairmot_hrnetv2_w18_dlafpn_30e_864x480_visdrone_pedestrian.yml) | | VisDrone | HRNetv2-W18| 576x320 | 30.6 | 47.2 | - | [下载链接](https://paddledet.bj.bcebos.com/models/mot/fairmot_hrnetv2_w18_dlafpn_30e_576x320_visdrone_pedestrian.pdparams) | [配置文件](./fairmot_hrnetv2_w18_dlafpn_30e_576x320_visdrone_pedestrian.yml) | @@ -124,8 +124,8 @@ month={Oct},} @ARTICLE{9573394, author={Zhu, Pengfei and Wen, Longyin and Du, Dawei and Bian, Xiao and Fan, Heng and Hu, Qinghua and Ling, Haibin}, - journal={IEEE Transactions on Pattern Analysis and Machine Intelligence}, - title={Detection and Tracking Meet Drones Challenge}, + journal={IEEE Transactions on Pattern Analysis and Machine Intelligence}, + title={Detection and Tracking Meet Drones Challenge}, year={2021}, volume={}, number={}, diff --git a/deploy/pptracking/python/mot/matching/jde_matching.py b/deploy/pptracking/python/mot/matching/jde_matching.py index eb3749885..308b78c64 100644 --- a/deploy/pptracking/python/mot/matching/jde_matching.py +++ b/deploy/pptracking/python/mot/matching/jde_matching.py @@ -26,7 +26,7 @@ warnings.filterwarnings("ignore") __all__ = [ 'merge_matches', 'linear_assignment', - 'cython_bbox_ious', + 'bbox_ious', 'iou_distance', 'embedding_distance', 'fuse_motion', @@ -68,22 +68,28 @@ def linear_assignment(cost_matrix, thresh): return matches, unmatched_a, unmatched_b -def cython_bbox_ious(atlbrs, btlbrs): - ious = np.zeros((len(atlbrs), len(btlbrs)), dtype=np.float) - if ious.size == 0: +def bbox_ious(atlbrs, btlbrs): + boxes = np.ascontiguousarray(atlbrs, dtype=np.float) + query_boxes = np.ascontiguousarray(btlbrs, dtype=np.float) + N = boxes.shape[0] + K = query_boxes.shape[0] + ious = np.zeros((N, K), dtype=boxes.dtype) + if N * K == 0: return ious - try: - import cython_bbox - except Exception as e: - print('cython_bbox not found, please install cython_bbox.' - 'for example: `pip install cython_bbox`.') - exit() - - ious = cython_bbox.bbox_overlaps( - np.ascontiguousarray( - atlbrs, dtype=np.float), - np.ascontiguousarray( - btlbrs, dtype=np.float)) + + for k in range(K): + box_area = ((query_boxes[k, 2] - query_boxes[k, 0] + 1) * + (query_boxes[k, 3] - query_boxes[k, 1] + 1)) + for n in range(N): + iw = (min(boxes[n, 2], query_boxes[k, 2]) - max( + boxes[n, 0], query_boxes[k, 0]) + 1) + if iw > 0: + ih = (min(boxes[n, 3], query_boxes[k, 3]) - max( + boxes[n, 1], query_boxes[k, 1]) + 1) + if ih > 0: + ua = float((boxes[n, 2] - boxes[n, 0] + 1) * (boxes[ + n, 3] - boxes[n, 1] + 1) + box_area - iw * ih) + ious[n, k] = iw * ih / ua return ious @@ -98,7 +104,7 @@ def iou_distance(atracks, btracks): else: atlbrs = [track.tlbr for track in atracks] btlbrs = [track.tlbr for track in btracks] - _ious = cython_bbox_ious(atlbrs, btlbrs) + _ious = bbox_ious(atlbrs, btlbrs) cost_matrix = 1 - _ious return cost_matrix diff --git a/ppdet/metrics/mcmot_metrics.py b/ppdet/metrics/mcmot_metrics.py index 48d15c90e..c38cbda0e 100644 --- a/ppdet/metrics/mcmot_metrics.py +++ b/ppdet/metrics/mcmot_metrics.py @@ -306,11 +306,12 @@ class MCMOTEvaluator(object): def load_annotations(self): assert self.data_type == 'mcmot' - self.gt_filename = os.path.join(self.data_root, '../', - 'sequences', + self.gt_filename = os.path.join(self.data_root, '../', 'sequences', '{}.txt'.format(self.seq_name)) if not os.path.exists(self.gt_filename): - logger.warning("gt_filename '{}' of MCMOTEvaluator is not exist, so the MOTA will be -inf.") + logger.warning( + "gt_filename '{}' of MCMOTEvaluator is not exist, so the MOTA will be -INF." + ) def reset_accumulator(self): import motmetrics as mm diff --git a/ppdet/metrics/mot_metrics.py b/ppdet/metrics/mot_metrics.py index af2f7dd19..117525df2 100644 --- a/ppdet/metrics/mot_metrics.py +++ b/ppdet/metrics/mot_metrics.py @@ -37,8 +37,11 @@ __all__ = ['MOTEvaluator', 'MOTMetric', 'JDEDetMetric', 'KITTIMOTMetric'] def read_mot_results(filename, is_gt=False, is_ignore=False): valid_label = [1] ignore_labels = [2, 7, 8, 12] # only in motchallenge datasets like 'MOT16' - logger.info("In MOT16/17 dataset the valid_label of ground truth is '{}', " - "in other dataset it should be '0' for single classs MOT.".format(valid_label[0])) + if is_gt: + logger.info( + "In MOT16/17 dataset the valid_label of ground truth is '{}', " + "in other dataset it should be '0' for single classs MOT.".format( + valid_label[0])) results_dict = dict() if os.path.isfile(filename): with open(filename, 'r') as f: @@ -118,7 +121,9 @@ class MOTEvaluator(object): gt_filename = os.path.join(self.data_root, self.seq_name, 'gt', 'gt.txt') if not os.path.exists(gt_filename): - logger.warning("gt_filename '{}' of MOTEvaluator is not exist, so the MOTA will be -inf.") + logger.warning( + "gt_filename '{}' of MOTEvaluator is not exist, so the MOTA will be -INF." + ) self.gt_frame_dict = read_mot_results(gt_filename, is_gt=True) self.gt_ignore_frame_dict = read_mot_results( gt_filename, is_ignore=True) diff --git a/ppdet/modeling/mot/matching/jde_matching.py b/ppdet/modeling/mot/matching/jde_matching.py index e9c40dba4..308b78c64 100644 --- a/ppdet/modeling/mot/matching/jde_matching.py +++ b/ppdet/modeling/mot/matching/jde_matching.py @@ -26,7 +26,7 @@ warnings.filterwarnings("ignore") __all__ = [ 'merge_matches', 'linear_assignment', - 'cython_bbox_ious', + 'bbox_ious', 'iou_distance', 'embedding_distance', 'fuse_motion', @@ -68,22 +68,28 @@ def linear_assignment(cost_matrix, thresh): return matches, unmatched_a, unmatched_b -def cython_bbox_ious(atlbrs, btlbrs): - ious = np.zeros((len(atlbrs), len(btlbrs)), dtype=np.float) - if ious.size == 0: +def bbox_ious(atlbrs, btlbrs): + boxes = np.ascontiguousarray(atlbrs, dtype=np.float) + query_boxes = np.ascontiguousarray(btlbrs, dtype=np.float) + N = boxes.shape[0] + K = query_boxes.shape[0] + ious = np.zeros((N, K), dtype=boxes.dtype) + if N * K == 0: return ious - try: - import cython_bbox - except Exception as e: - print('cython_bbox not found, please install cython_bbox.' - 'for example: `pip install cython_bbox`.') - raise e - - ious = cython_bbox.bbox_overlaps( - np.ascontiguousarray( - atlbrs, dtype=np.float), - np.ascontiguousarray( - btlbrs, dtype=np.float)) + + for k in range(K): + box_area = ((query_boxes[k, 2] - query_boxes[k, 0] + 1) * + (query_boxes[k, 3] - query_boxes[k, 1] + 1)) + for n in range(N): + iw = (min(boxes[n, 2], query_boxes[k, 2]) - max( + boxes[n, 0], query_boxes[k, 0]) + 1) + if iw > 0: + ih = (min(boxes[n, 3], query_boxes[k, 3]) - max( + boxes[n, 1], query_boxes[k, 1]) + 1) + if ih > 0: + ua = float((boxes[n, 2] - boxes[n, 0] + 1) * (boxes[ + n, 3] - boxes[n, 1] + 1) + box_area - iw * ih) + ious[n, k] = iw * ih / ua return ious @@ -98,7 +104,7 @@ def iou_distance(atracks, btracks): else: atlbrs = [track.tlbr for track in atracks] btlbrs = [track.tlbr for track in btracks] - _ious = cython_bbox_ious(atlbrs, btlbrs) + _ious = bbox_ious(atlbrs, btlbrs) cost_matrix = 1 - _ious return cost_matrix diff --git a/requirements.txt b/requirements.txt index 91c79fc0f..e4009c30f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,4 +14,3 @@ lap sklearn motmetrics openpyxl -cython_bbox -- GitLab