Showing preview only (1,263K chars total). Download the full file or copy to clipboard to get everything.
Repository: xingyizhou/CenterNet
Branch: master
Commit: 4c50fd3a46bd
Files: 156
Total size: 1.2 MB
Directory structure:
gitextract_hokebfv4/
├── .gitignore
├── .travis.yml
├── LICENSE
├── NOTICE
├── README.md
├── data/
│ └── .gitignore
├── exp/
│ └── .gitignore
├── experiments/
│ ├── ctdet_coco_dla_1x.sh
│ ├── ctdet_coco_dla_2x.sh
│ ├── ctdet_coco_hg.sh
│ ├── ctdet_coco_resdcn101.sh
│ ├── ctdet_coco_resdcn18.sh
│ ├── ctdet_pascal_dla_384.sh
│ ├── ctdet_pascal_dla_512.sh
│ ├── ctdet_pascal_resdcn101_384.sh
│ ├── ctdet_pascal_resdcn101_512.sh
│ ├── ctdet_pascal_resdcn18_384.sh
│ ├── ctdet_pascal_resdcn18_512.sh
│ ├── ddd_3dop.sh
│ ├── ddd_sub.sh
│ ├── exdet_coco_dla.sh
│ ├── exdet_coco_hg.sh
│ ├── multi_pose_dla_1x.sh
│ ├── multi_pose_dla_3x.sh
│ ├── multi_pose_hg_1x.sh
│ └── multi_pose_hg_3x.sh
├── images/
│ └── NOTICE
├── models/
│ └── .gitignore
├── readme/
│ ├── DATA.md
│ ├── DEVELOP.md
│ ├── GETTING_STARTED.md
│ ├── INSTALL.md
│ └── MODEL_ZOO.md
├── requirements.txt
└── src/
├── _init_paths.py
├── demo.py
├── lib/
│ ├── datasets/
│ │ ├── dataset/
│ │ │ ├── coco.py
│ │ │ ├── coco_hp.py
│ │ │ ├── kitti.py
│ │ │ └── pascal.py
│ │ ├── dataset_factory.py
│ │ └── sample/
│ │ ├── ctdet.py
│ │ ├── ddd.py
│ │ ├── exdet.py
│ │ └── multi_pose.py
│ ├── detectors/
│ │ ├── base_detector.py
│ │ ├── ctdet.py
│ │ ├── ddd.py
│ │ ├── detector_factory.py
│ │ ├── exdet.py
│ │ └── multi_pose.py
│ ├── external/
│ │ ├── .gitignore
│ │ ├── Makefile
│ │ ├── __init__.py
│ │ ├── nms.pyx
│ │ └── setup.py
│ ├── logger.py
│ ├── models/
│ │ ├── data_parallel.py
│ │ ├── decode.py
│ │ ├── losses.py
│ │ ├── model.py
│ │ ├── networks/
│ │ │ ├── DCNv2/
│ │ │ │ ├── .gitignore
│ │ │ │ ├── LICENSE
│ │ │ │ ├── README.md
│ │ │ │ ├── __init__.py
│ │ │ │ ├── build.py
│ │ │ │ ├── build_double.py
│ │ │ │ ├── dcn_v2.py
│ │ │ │ ├── dcn_v2_func.py
│ │ │ │ ├── make.sh
│ │ │ │ ├── src/
│ │ │ │ │ ├── cuda/
│ │ │ │ │ │ ├── dcn_v2_im2col_cuda.cu
│ │ │ │ │ │ ├── dcn_v2_im2col_cuda.h
│ │ │ │ │ │ ├── dcn_v2_im2col_cuda_double.cu
│ │ │ │ │ │ ├── dcn_v2_im2col_cuda_double.h
│ │ │ │ │ │ ├── dcn_v2_psroi_pooling_cuda.cu
│ │ │ │ │ │ ├── dcn_v2_psroi_pooling_cuda.h
│ │ │ │ │ │ ├── dcn_v2_psroi_pooling_cuda_double.cu
│ │ │ │ │ │ └── dcn_v2_psroi_pooling_cuda_double.h
│ │ │ │ │ ├── dcn_v2.c
│ │ │ │ │ ├── dcn_v2.h
│ │ │ │ │ ├── dcn_v2_cuda.c
│ │ │ │ │ ├── dcn_v2_cuda.h
│ │ │ │ │ ├── dcn_v2_cuda_double.c
│ │ │ │ │ ├── dcn_v2_cuda_double.h
│ │ │ │ │ ├── dcn_v2_double.c
│ │ │ │ │ └── dcn_v2_double.h
│ │ │ │ └── test.py
│ │ │ ├── dlav0.py
│ │ │ ├── large_hourglass.py
│ │ │ ├── msra_resnet.py
│ │ │ ├── pose_dla_dcn.py
│ │ │ └── resnet_dcn.py
│ │ ├── scatter_gather.py
│ │ └── utils.py
│ ├── opts.py
│ ├── trains/
│ │ ├── base_trainer.py
│ │ ├── ctdet.py
│ │ ├── ddd.py
│ │ ├── exdet.py
│ │ ├── multi_pose.py
│ │ └── train_factory.py
│ └── utils/
│ ├── __init__.py
│ ├── ddd_utils.py
│ ├── debugger.py
│ ├── image.py
│ ├── oracle_utils.py
│ ├── post_process.py
│ └── utils.py
├── main.py
├── test.py
└── tools/
├── _init_paths.py
├── calc_coco_overlap.py
├── convert_hourglass_weight.py
├── convert_kitti_to_coco.py
├── eval_coco.py
├── eval_coco_hp.py
├── get_kitti.sh
├── get_pascal_voc.sh
├── kitti_eval/
│ ├── README.md
│ ├── evaluate_object_3d.cpp
│ ├── evaluate_object_3d_offline
│ ├── evaluate_object_3d_offline.cpp
│ └── mail.h
├── merge_pascal_json.py
├── reval.py
├── vis_pred.py
└── voc_eval_lib/
├── LICENSE
├── Makefile
├── __init__.py
├── datasets/
│ ├── __init__.py
│ ├── bbox.pyx
│ ├── ds_utils.py
│ ├── imdb.py
│ ├── pascal_voc.py
│ └── voc_eval.py
├── model/
│ ├── __init__.py
│ ├── bbox_transform.py
│ ├── config.py
│ ├── nms_wrapper.py
│ └── test.py
├── nms/
│ ├── .gitignore
│ ├── __init__.py
│ ├── cpu_nms.c
│ ├── cpu_nms.pyx
│ ├── gpu_nms.cpp
│ ├── gpu_nms.hpp
│ ├── gpu_nms.pyx
│ ├── nms_kernel.cu
│ └── py_cpu_nms.py
├── setup.py
└── utils/
├── .gitignore
├── __init__.py
├── bbox.pyx
├── blob.py
├── timer.py
└── visualization.py
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
legacy/*
.DS_Store
debug/*
*.DS_Store
*.json
*.mat
src/.vscode/*
preds/*
*.h5
*.pth
*.checkpoint
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# dotenv
.env
# virtualenv
.venv
venv/
ENV/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
================================================
FILE: .travis.yml
================================================
group: travis_latest
dist: xenial # ubuntu-16.04
language: python
cache: pip
python:
- 3.6
- 3.7
install:
- pip install flake8
- pip install -r requirements.txt
before_script:
# stop the build if there are Python syntax errors or undefined names
- flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
script:
- true # add other tests here
notifications:
on_success: change
on_failure: change # `always` will be the setting once code changes slow down
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2019 Xingyi Zhou
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: NOTICE
================================================
Portions of this software are derived from tf-faster-rcnn.
==============================================================================
tf-faster-rcnn licence
==============================================================================
MIT License
Copyright (c) 2017 Xinlei Chen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Portions of this software are derived from human-pose-estimation.pytorch.
==============================================================================
human-pose-estimation.pytorch licence
==============================================================================
MIT License
Copyright (c) Microsoft Corporation. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
Portions of this software are derived from CornerNet.
==============================================================================
CornerNet licence
==============================================================================
BSD 3-Clause License
Copyright (c) 2018, University of Michigan
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Portions of this software are derived from DCNv2.
==============================================================================
DCNv2 licence
==============================================================================
BSD 3-Clause License
Copyright (c) 2019, Charles Shang
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
==============================================================================
DLA licence
==============================================================================
BSD 3-Clause License
Copyright (c) 2018, Fisher Yu
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
================================================
FILE: README.md
================================================
# Objects as Points
Object detection, 3D detection, and pose estimation using center point detection:

> [**Objects as Points**](http://arxiv.org/abs/1904.07850),
> Xingyi Zhou, Dequan Wang, Philipp Krähenbühl,
> *arXiv technical report ([arXiv 1904.07850](http://arxiv.org/abs/1904.07850))*
Contact: [zhouxy2017@gmail.com](mailto:zhouxy2017@gmail.com). Any questions or discussions are welcomed!
## Updates
- (June, 2020) We released a state-of-the-art Lidar-based 3D detection and tracking framework [CenterPoint](https://github.com/tianweiy/CenterPoint).
- (April, 2020) We released a state-of-the-art (multi-category-/ pose-/ 3d-) tracking extension [CenterTrack](https://github.com/xingyizhou/CenterTrack).
## Abstract
Detection identifies objects as axis-aligned boxes in an image. Most successful object detectors enumerate a nearly exhaustive list of potential object locations and classify each. This is wasteful, inefficient, and requires additional post-processing. In this paper, we take a different approach. We model an object as a single point -- the center point of its bounding box. Our detector uses keypoint estimation to find center points and regresses to all other object properties, such as size, 3D location, orientation, and even pose. Our center point based approach, CenterNet, is end-to-end differentiable, simpler, faster, and more accurate than corresponding bounding box based detectors. CenterNet achieves the best speed-accuracy trade-off on the MS COCO dataset, with 28.1% AP at 142 FPS, 37.4% AP at 52 FPS, and 45.1% AP with multi-scale testing at 1.4 FPS. We use the same approach to estimate 3D bounding box in the KITTI benchmark and human pose on the COCO keypoint dataset. Our method performs competitively with sophisticated multi-stage methods and runs in real-time.
## Highlights
- **Simple:** One-sentence method summary: use keypoint detection technic to detect the bounding box center point and regress to all other object properties like bounding box size, 3d information, and pose.
- **Versatile:** The same framework works for object detection, 3d bounding box estimation, and multi-person pose estimation with minor modification.
- **Fast:** The whole process in a single network feedforward. No NMS post processing is needed. Our DLA-34 model runs at *52* FPS with *37.4* COCO AP.
- **Strong**: Our best single model achieves *45.1*AP on COCO test-dev.
- **Easy to use:** We provide user friendly testing API and webcam demos.
## Main results
### Object Detection on COCO validation
| Backbone | AP / FPS | Flip AP / FPS| Multi-scale AP / FPS |
|--------------|-----------|--------------|-----------------------|
|Hourglass-104 | 40.3 / 14 | 42.2 / 7.8 | 45.1 / 1.4 |
|DLA-34 | 37.4 / 52 | 39.2 / 28 | 41.7 / 4 |
|ResNet-101 | 34.6 / 45 | 36.2 / 25 | 39.3 / 4 |
|ResNet-18 | 28.1 / 142| 30.0 / 71 | 33.2 / 12 |
### Keypoint detection on COCO validation
| Backbone | AP | FPS |
|--------------|-----------|--------------|
|Hourglass-104 | 64.0 | 6.6 |
|DLA-34 | 58.9 | 23 |
### 3D bounding box detection on KITTI validation
|Backbone|FPS|AP-E|AP-M|AP-H|AOS-E|AOS-M|AOS-H|BEV-E|BEV-M|BEV-H|
|--------|---|----|----|----|-----|-----|-----|-----|-----|-----|
|DLA-34 |32 |96.9|87.8|79.2|93.9 |84.3 |75.7 |34.0 |30.5 |26.8 |
All models and details are available in our [Model zoo](readme/MODEL_ZOO.md).
## Installation
Please refer to [INSTALL.md](readme/INSTALL.md) for installation instructions.
## Use CenterNet
We support demo for image/ image folder, video, and webcam.
First, download the models (By default, [ctdet_coco_dla_2x](https://drive.google.com/file/d/18Q3fzzAsha_3Qid6mn4jcIFPeOGUaj1d) for detection and
[multi_pose_dla_3x](https://drive.google.com/file/d/1mC2PAQT_RuHi_9ZMZgkt4rg7BSY2_Lkd) for human pose estimation)
from the [Model zoo](readme/MODEL_ZOO.md) and put them in `CenterNet_ROOT/models/`.
For object detection on images/ video, run:
~~~
python demo.py ctdet --demo /path/to/image/or/folder/or/video --load_model ../models/ctdet_coco_dla_2x.pth
~~~
We provide example images in `CenterNet_ROOT/images/` (from [Detectron](https://github.com/facebookresearch/Detectron/tree/master/demo)). If set up correctly, the output should look like
<p align="center"> <img src='readme/det1.png' align="center" height="230px"> <img src='readme/det2.png' align="center" height="230px"> </p>
For webcam demo, run
~~~
python demo.py ctdet --demo webcam --load_model ../models/ctdet_coco_dla_2x.pth
~~~
Similarly, for human pose estimation, run:
~~~
python demo.py multi_pose --demo /path/to/image/or/folder/or/video/or/webcam --load_model ../models/multi_pose_dla_3x.pth
~~~
The result for the example images should look like:
<p align="center"> <img src='readme/pose1.png' align="center" height="200px"> <img src='readme/pose2.png' align="center" height="200px"> <img src='readme/pose3.png' align="center" height="200px"> </p>
You can add `--debug 2` to visualize the heatmap outputs.
You can add `--flip_test` for flip test.
To use this CenterNet in your own project, you can
~~~
import sys
CENTERNET_PATH = /path/to/CenterNet/src/lib/
sys.path.insert(0, CENTERNET_PATH)
from detectors.detector_factory import detector_factory
from opts import opts
MODEL_PATH = /path/to/model
TASK = 'ctdet' # or 'multi_pose' for human pose estimation
opt = opts().init('{} --load_model {}'.format(TASK, MODEL_PATH).split(' '))
detector = detector_factory[opt.task](opt)
img = image/or/path/to/your/image/
ret = detector.run(img)['results']
~~~
`ret` will be a python dict: `{category_id : [[x1, y1, x2, y2, score], ...], }`
## Benchmark Evaluation and Training
After [installation](readme/INSTALL.md), follow the instructions in [DATA.md](readme/DATA.md) to setup the datasets. Then check [GETTING_STARTED.md](readme/GETTING_STARTED.md) to reproduce the results in the paper.
We provide scripts for all the experiments in the [experiments](experiments) folder.
## Develop
If you are interested in training CenterNet in a new dataset, use CenterNet in a new task, or use a new network architecture for CenterNet, please refer to [DEVELOP.md](readme/DEVELOP.md). Also feel free to send us emails for discussions or suggestions.
## Third-party resources
- CenterNet + embedding learning based tracking: [FairMOT](https://github.com/ifzhang/FairMOT) from [Yifu Zhang](https://github.com/ifzhang).
- Detectron2 based implementation: [CenterNet-better](https://github.com/FateScript/CenterNet-better) from [Feng Wang](https://github.com/FateScript).
- Keras Implementation: [keras-centernet](https://github.com/see--/keras-centernet) from [see--](https://github.com/see--) and [keras-CenterNet](https://github.com/xuannianz/keras-CenterNet) from [xuannianz](https://github.com/xuannianz).
- MXnet implementation: [mxnet-centernet](https://github.com/Guanghan/mxnet-centernet) from [Guanghan Ning](https://github.com/Guanghan).
- Stronger human open estimation models: [centerpose](https://github.com/tensorboy/centerpose) from [tensorboy](https://github.com/tensorboy).
- TensorRT extension with ONNX models: [TensorRT-CenterNet](https://github.com/CaoWGG/TensorRT-CenterNet) from [Wengang Cao](https://github.com/CaoWGG).
- CenterNet + DeepSORT tracking implementation: [centerNet-deep-sort](https://github.com/kimyoon-young/centerNet-deep-sort) from [kimyoon-young](https://github.com/kimyoon-young).
- Blogs on training CenterNet on custom datasets (in Chinese): [ships](https://blog.csdn.net/weixin_42634342/article/details/97756458) from [Rhett Chen](https://blog.csdn.net/weixin_42634342) and [faces](https://blog.csdn.net/weixin_41765699/article/details/100118353) from [linbior](https://me.csdn.net/weixin_41765699).
## License
CenterNet itself is released under the MIT License (refer to the LICENSE file for details).
Portions of the code are borrowed from [human-pose-estimation.pytorch](https://github.com/Microsoft/human-pose-estimation.pytorch) (image transform, resnet), [CornerNet](https://github.com/princeton-vl/CornerNet) (hourglassnet, loss functions), [dla](https://github.com/ucbdrive/dla) (DLA network), [DCNv2](https://github.com/CharlesShang/DCNv2)(deformable convolutions), [tf-faster-rcnn](https://github.com/endernewton/tf-faster-rcnn)(Pascal VOC evaluation) and [kitti_eval](https://github.com/prclibo/kitti_eval) (KITTI dataset evaluation). Please refer to the original License of these projects (See [NOTICE](NOTICE)).
## Citation
If you find this project useful for your research, please use the following BibTeX entry.
@inproceedings{zhou2019objects,
title={Objects as Points},
author={Zhou, Xingyi and Wang, Dequan and Kr{\"a}henb{\"u}hl, Philipp},
booktitle={arXiv preprint arXiv:1904.07850},
year={2019}
}
================================================
FILE: data/.gitignore
================================================
*
!.gitignore
================================================
FILE: exp/.gitignore
================================================
*
!.gitignore
================================================
FILE: experiments/ctdet_coco_dla_1x.sh
================================================
cd src
# train
python main.py ctdet --exp_id coco_dla_1x --batch_size 128 --master_batch 9 --lr 5e-4 --gpus 0,1,2,3,4,5,6,7 --num_workers 16
# test
python test.py ctdet --exp_id coco_dla_1x --keep_res --resume
# flip test
python test.py ctdet --exp_id coco_dla_1x --keep_res --resume --flip_test
# multi scale test
python test.py ctdet --exp_id coco_dla_1x --keep_res --resume --flip_test --test_scales 0.5,0.75,1,1.25,1.5
cd ..
================================================
FILE: experiments/ctdet_coco_dla_2x.sh
================================================
cd src
# train
python main.py ctdet --exp_id coco_dla_2x --batch_size 128 --master_batch 9 --lr 5e-4 --gpus 0,1,2,3,4,5,6,7 --num_workers 16 --num_epochs 230 lr_step 180,210
# or use the following command if your have coco_s2_dla_1x trained
# python main.py ctdet --exp_id coco_dla_2x --batch_size 128 --master_batch 9 --lr 5e-4 --gpus 0,1,2,3,4,5,6,7 --num_workers 16 --load_model ../exp/ctdet/coco_dla_1x/model_90.pth --resume
# test
python test.py ctdet --exp_id coco_dla_2x --keep_res --resume
# flip test
python test.py ctdet --exp_id coco_dla_2x --keep_res --resume --flip_test
# multi scale test
python test.py ctdet --exp_id coco_dla_2x --keep_res --resume --flip_test --test_scales 0.5,0.75,1,1.25,1.5
cd ..
================================================
FILE: experiments/ctdet_coco_hg.sh
================================================
cd src
# train
python main.py ctdet --exp_id coco_hg --arch hourglass --batch_size 24 --master_batch 4 --lr 2.5e-4 --load_model ../models/ExtremeNet_500000.pth --gpus 0,1,2,3,4
# test
python test.py ctdet --exp_id coco_hg --arch hourglass --keep_res --resume
# flip test
python test.py ctdet --exp_id coco_hg --arch hourglass --keep_res --resume --flip_test
# multi scale test
python test.py ctdet --exp_id coco_hg --arch hourglass --keep_res --resume --flip_test --test_scales 0.5,0.75,1,1.25,1.5
cd ..
================================================
FILE: experiments/ctdet_coco_resdcn101.sh
================================================
cd src
# train
python main.py ctdet --exp_id coco_resdcn101 --arch resdcn_101 --batch_size 96 --master_batch 5 --lr 3.75e-4 --gpus 0,1,2,3,4,5,6,7 --num_workers 16
# test
python test.py ctdet --exp_id coco_resdcn101 --keep_res --resume
# flip test
python test.py ctdet --exp_id coco_resdcn101 --keep_res --resume --flip_test
# multi scale test
python test.py ctdet --exp_id coco_resdcn101 --keep_res --resume --flip_test --test_scales 0.5,0.75,1,1.25,1.5
cd ..
================================================
FILE: experiments/ctdet_coco_resdcn18.sh
================================================
cd src
# train
python main.py ctdet --exp_id coco_resdcn18 --arch resdcn_18 --batch_size 114 --master_batch 18 --lr 5e-4 --gpus 0,1,2,3 --num_workers 16
# test
python test.py ctdet --exp_id coco_resdcn18 --arch resdcn_18 --keep_res --resume
# flip test
python test.py ctdet --exp_id coco_resdcn18 --arch resdcn_18 --keep_res --resume --flip_test
# multi scale test
python test.py ctdet --exp_id coco_resdcn18 --arch resdcn_18 --keep_res --resume --flip_test --test_scales 0.5,0.75,1,1.25,1.5
cd ..
================================================
FILE: experiments/ctdet_pascal_dla_384.sh
================================================
cd src
# train
python main.py ctdet --exp_id pascal_dla_384 --dataset pascal --num_epochs 70 --lr_step 45,60
# test
python test.py ctdet --exp_id pascal_dla_384 --dataset pascal --resume
# flip test
python test.py ctdet --exp_id pascal_dla_384 --dataset pascal --resume --flip_test
cd ..
================================================
FILE: experiments/ctdet_pascal_dla_512.sh
================================================
cd src
# train
python main.py ctdet --exp_id pascal_dla_512 --dataset pascal --input_res 512 --num_epochs 70 --lr_step 45,60 --gpus 0,1
# test
python test.py ctdet --exp_id pascal_dla_512 --dataset pascal --input_res 512 --resume
# flip test
python test.py ctdet --exp_id pascal_dla_512 --dataset pascal --input_res 512 --resume --flip_test
cd ..
================================================
FILE: experiments/ctdet_pascal_resdcn101_384.sh
================================================
cd src
# train
python main.py ctdet --exp_id pascal_resdcn101_384 --arch resdcn_101 --dataset pascal --num_epochs 70 --lr_step 45,60 --gpus 0,1
# test
python test.py ctdet --exp_id pascal_resdcn101_384 --arch resdcn_101 --dataset pascal --resume
# flip test
python test.py ctdet --exp_id pascal_resdcn101_384 --arch resdcn_101 --dataset pascal --resume --flip_test
cd ..
================================================
FILE: experiments/ctdet_pascal_resdcn101_512.sh
================================================
cd src
# train
python main.py ctdet --exp_id pascal_resdcn101_512 --arch resdcn_101 --dataset pascal --input_res 512 --num_epochs 70 --lr_step 45,60 --gpus 0,1,2,3
# test
python test.py ctdet --exp_id pascal_resdcn101_512 --arch resdcn_101 --dataset pascal --input_res 512 --resume
# flip test
python test.py ctdet --exp_id pascal_resdcn101_512 --arch resdcn_101 --dataset pascal --input_res 512 --resume --flip_test
cd ..
================================================
FILE: experiments/ctdet_pascal_resdcn18_384.sh
================================================
cd src
# train
python main.py ctdet --exp_id pascal_resdcn18_384 --arch resdcn_18 --dataset pascal --num_epochs 70 --lr_step 45,60
# test
python test.py ctdet --exp_id pascal_resdcn18_384 --arch resdcn_18 --dataset pascal --resume
# flip test
python test.py ctdet --exp_id pascal_resdcn18_384 --arch resdcn_18 --dataset pascal --resume --flip_test
cd ..
================================================
FILE: experiments/ctdet_pascal_resdcn18_512.sh
================================================
cd src
# train
python main.py ctdet --exp_id pascal_resdcn18_512 --arch resdcn_18 --dataset pascal --input_res 512 --num_epochs 70 --lr_step 45,60
# test
python test.py ctdet --exp_id pascal_resdcn18_512 --arch resdcn_18 --dataset pascal --input_res 512 --resume
# flip test
python test.py ctdet --exp_id pascal_resdcn18_512 --arch resdcn_18 --dataset pascal --input_res 512 --resume --flip_test
cd ..
================================================
FILE: experiments/ddd_3dop.sh
================================================
cd src
# train
python main.py ddd --exp_id 3dop --dataset kitti --kitti_split 3dop --batch_size 16 --master_batch 7 --num_epochs 70 --lr_step 45,60 --gpus 0,1
# test
python test.py ddd --exp_id 3dop --dataset kitti --kitti_split 3dop --resume
cd ..
================================================
FILE: experiments/ddd_sub.sh
================================================
cd src
# train
python main.py ddd --exp_id sub --dataset kitti --kitti_split subcnn --batch_size 16 --master_batch 7 --num_epochs 70 --lr_step 45,60 --gpus 0,1
# test
python test.py ddd --exp_id sub --dataset kitti --kitti_split subcnn --resume
cd ..
================================================
FILE: experiments/exdet_coco_dla.sh
================================================
cd src
# train
python main.py exdet --exp_id coco_dla --batch_size 64 --master_batch 1 --lr 2.5e-4 --gpus 0,1,2,3,4,5,6,7 --num_workers 8
# test
python test.py exdet --exp_id coco_dla --keep_res --resume
# flip test
python test.py exdet --exp_id coco_dla --keep_res --resume --flip_test
# multi scale test
python test.py exdet --exp_id coco_dla --keep_res --resume --flip_test --test_scales 0.5,0.75,1,1.25,1.5
cd ..
================================================
FILE: experiments/exdet_coco_hg.sh
================================================
cd src
# train
python main.py exdet --exp_id coco_hg --arch hourglass --batch_size 24 --master_batch 4 --lr 2.5e-4 --gpus 0,1,2,3,4
# test
python test.py exdet --exp_id coco_hg --arch hourglass --keep_res --resume
# flip test
python test.py exdet --exp_id coco_hg --arch hourglass --keep_res --resume --flip_test
# multi scale test
python test.py exdet --exp_id coco_hg --arch hourglass --keep_res --resume --flip_test --test_scales 0.5,0.75,1,1.25,1.5
cd ..
================================================
FILE: experiments/multi_pose_dla_1x.sh
================================================
cd src
# train
python main.py multi_pose --exp_id dla_1x --dataset coco_hp --batch_size 128 --master_batch 9 --lr 5e-4 --load_model ../models/ctdet_coco_dla_2x.pth --gpus 0,1,2,3,4,5,6,7 --num_workers 16
# test
python test.py multi_pose --exp_id dla_1x --dataset coco_hp --keep_res --resume
# flip test
python test.py multi_pose --exp_id dla_1x --dataset coco_hp --keep_res --resume --flip_test
cd ..
================================================
FILE: experiments/multi_pose_dla_3x.sh
================================================
cd src
# train
python main.py multi_pose --exp_id dla_3x --dataset coco_hp --batch_size 128 --master_batch 9 --lr 5e-4 --load_model ../models/ctdet_coco_dla_2x.pth --gpus 0,1,2,3,4,5,6,7 --num_workers 16 --num_epochs 320 lr_step 270,300
# or use the following command if your have dla_1x trained
# python main.py multi_pose --exp_id dla_3x --dataset coco_hp --batch_size 128 --master_batch 9 --lr 5e-4 --gpus 0,1,2,3,4,5,6,7 --num_workers 16 --load_model ../exp/multi_pose/dla_1x/model_90.pth --resume
# test
python test.py multi_pose --exp_id dla_3x --dataset coco_hp --keep_res --resume
# flip test
python test.py multi_pose --exp_id dla_3x --dataset coco_hp --keep_res --resume --flip_test
cd ..
================================================
FILE: experiments/multi_pose_hg_1x.sh
================================================
cd src
# train
python main.py multi_pose --exp_id hg_1x --dataset coco_hp --arch hourglass --batch_size 24 --master_batch 4 --lr 2.5e-4 --load_model ../models/ctdet_coco_hg.pth --gpus 0,1,2,3,4 --num_epochs 50 --lr_step 40
# test
python test.py multi_pose --exp_id hg_1x --dataset coco_hp --arch hourglass --keep_res --resume
# flip test
python test.py multi_pose --exp_id hg_1x --dataset coco_hp --arch hourglass --keep_res --resume --flip_test
cd ..
================================================
FILE: experiments/multi_pose_hg_3x.sh
================================================
cd src
# train
python main.py multi_pose --exp_id hg_3x --dataset coco_hp --arch hourglass --batch_size 24 --master_batch 4 --lr 2.5e-4 -load_model ../models/ctdet_coco_hg.pth --gpus 0,1,2,3,4 --num_epochs 150 --lr_step 130
# or use the following command if your have dla_1x trained
# python main.py multi_pose --exp_id hg_3x --dataset coco_hp --arch hourglass --batch_size 24 --master_batch 4 --lr 2.5e-4 --gpus 0,1,2,3,4 --num_epochs 150 --lr_step 130 --load_model ../exp/multi_pose/hg_1x/model_40.pth --resume
# test
python test.py multi_pose --exp_id hg_3x --dataset coco_hp --arch hourglass --keep_res --resume
# flip test
python test.py multi_pose --exp_id hg_3x --dataset coco_hp --arch hourglass --keep_res --resume --flip_test
cd ..
================================================
FILE: images/NOTICE
================================================
The demo images are licensed as United States government work:
https://www.usa.gov/government-works
The image files were obtained on Jan 13, 2018 from the following
URLs.
16004479832_a748d55f21_k.jpg
https://www.flickr.com/photos/archivesnews/16004479832
18124840932_e42b3e377c_k.jpg
https://www.flickr.com/photos/usnavy/18124840932
33887522274_eebd074106_k.jpg
https://www.flickr.com/photos/usaid_pakistan/33887522274
15673749081_767a7fa63a_k.jpg
https://www.flickr.com/photos/usnavy/15673749081
34501842524_3c858b3080_k.jpg
https://www.flickr.com/photos/departmentofenergy/34501842524
24274813513_0cfd2ce6d0_k.jpg
https://www.flickr.com/photos/dhsgov/24274813513
19064748793_bb942deea1_k.jpg
https://www.flickr.com/photos/statephotos/19064748793
33823288584_1d21cf0a26_k.jpg
https://www.flickr.com/photos/cbpphotos/33823288584
17790319373_bd19b24cfc_k.jpg
https://www.flickr.com/photos/secdef/17790319373
================================================
FILE: models/.gitignore
================================================
*
!.gitignore
================================================
FILE: readme/DATA.md
================================================
# Dataset preparation
If you want to reproduce the results in the paper for benchmark evaluation and training, you will need to setup dataset.
### COCO
- Download the images (2017 Train, 2017 Val, 2017 Test) from [coco website](http://cocodataset.org/#download).
- Download annotation files (2017 train/val and test image info) from [coco website](http://cocodataset.org/#download).
- Place the data (or create symlinks) to make the data folder like:
~~~
${CenterNet_ROOT}
|-- data
`-- |-- coco
`-- |-- annotations
| |-- instances_train2017.json
| |-- instances_val2017.json
| |-- person_keypoints_train2017.json
| |-- person_keypoints_val2017.json
| |-- image_info_test-dev2017.json
|---|-- train2017
|---|-- val2017
`---|-- test2017
~~~
- [Optional] If you want to train ExtremeNet, generate extreme point annotation from segmentation:
~~~
cd $CenterNet_ROOT/tools/
python gen_coco_extreme_points.py
~~~
It generates `instances_extreme_train2017.json` and `instances_extreme_val2017.json` in `data/coco/annotations/`.
### Pascal VOC
- Run
~~~
cd $CenterNet_ROOT/tools/
bash get_pascal_voc.sh
~~~
- The above script includes:
- Download, unzip, and move Pascal VOC images from the [VOC website](http://host.robots.ox.ac.uk/pascal/VOC/).
- [Download](https://storage.googleapis.com/coco-dataset/external/PASCAL_VOC.zip) Pascal VOC annotation in COCO format (from [Detectron](https://github.com/facebookresearch/Detectron/tree/master/detectron/datasets/data)).
- Combine train/val 2007/2012 annotation files into a single json.
- Move the created `voc` folder to `data` (or create symlinks) to make the data folder like:
~~~
${CenterNet_ROOT}
|-- data
`-- |-- voc
`-- |-- annotations
| |-- pascal_trainval0712.json
| |-- pascal_test2017.json
|-- images
| |-- 000001.jpg
| ......
`-- VOCdevkit
~~~
The `VOCdevkit` folder is needed to run the evaluation script from [faster rcnn](https://github.com/rbgirshick/py-faster-rcnn/blob/master/tools/reval.py).
### KITTI
- Download [images](http://www.cvlibs.net/download.php?file=data_object_image_2.zip), [annotations](http://www.cvlibs.net/download.php?file=data_object_label_2.zip), and [calibrations](http://www.cvlibs.net/download.php?file=data_object_calib.zip) from [KITTI website](http://www.cvlibs.net/datasets/kitti/eval_object.php?obj_benchmark=3d) and unzip.
- Download the train-val split of [3DOP](https://xiaozhichen.github.io/files/mv3d/imagesets.tar.gz) and [SubCNN](https://github.com/tanshen/SubCNN/tree/master/fast-rcnn/data/KITTI) and place the data as below
~~~
${CenterNet_ROOT}
|-- data
`-- |-- kitti
`-- |-- training
| |-- image_2
| |-- label_2
| |-- calib
|-- ImageSets_3dop
| |-- test.txt
| |-- train.txt
| |-- val.txt
| |-- trainval.txt
`-- ImageSets_subcnn
|-- test.txt
|-- train.txt
|-- val.txt
|-- trainval.txt
~~~
- Run `python convert_kitti_to_coco.py` in `tools` to convert the annotation into COCO format. You can set `DEBUG=True` in `line 5` to visualize the annotation.
- Link image folder
~~~
cd ${CenterNet_ROOT}/data/kitti/
mkdir images
ln -s training/image_2 images/trainval
~~~
- The data structure should look like:
~~~
${CenterNet_ROOT}
|-- data
`-- |-- kitti
`-- |-- annotations
| |-- kitti_3dop_train.json
| |-- kitti_3dop_val.json
| |-- kitti_subcnn_train.json
| |-- kitti_subcnn_val.json
`-- images
|-- trainval
|-- test
~~~
================================================
FILE: readme/DEVELOP.md
================================================
# Develop
This document provides tutorials to develop CenterNet. `lib/src/opts` lists a few more options that the current version supports.
## New dataset
Basically there are three steps:
- Convert the dataset annotation to [COCO format](http://cocodataset.org/#format-data). Please refer to [src/tools/convert_kitti_to_coco.py](../src/tools/convert_kitti_to_coco.py) for an example to convert kitti format to coco format.
- Create a dataset intilization file in `src/lib/datasets/dataset`. In most cases you can just copy `src/lib/datasets/dataset/coco.py` to your dataset name and change the category information, and annotation path.
- Import your dataset at `src/lib/datasets/dataset_factory`.
## New task
You will need to add files to `src/lib/datasets/sample/`, `src/lib/datasets/trains/`, and `src/lib/datasets/detectors/`, which specify the data generation during training, the training targets, and the testing, respectively.
## New architecture
- Add your model file to `src/lib/models/networks/`. The model should accept a dict `heads` of `{name: channels}`, which specify the name of each network output and its number of channels. Make sure your model returns a list (for multiple stages. Single stage model should return a list containing a single element.). The element of the list is a dict contraining the same keys with `heads`.
- Add your model in `model_factory` of `src/lib/models/model.py`.
================================================
FILE: readme/GETTING_STARTED.md
================================================
# Getting Started
This document provides tutorials to train and evaluate CenterNet. Before getting started, make sure you have finished [installation](INSTALL.md) and [dataset setup](DATA.md).
## Benchmark evaluation
First, download the models you want to evaluate from our [model zoo](MODEL_ZOO.md) and put them in `CenterNet_ROOT/models/`.
### COCO
To evaluate COCO object detection with DLA
run
~~~
python test.py ctdet --exp_id coco_dla --keep_res --load_model ../models/ctdet_coco_dla_2x.pth
~~~
This will give an AP of `37.4` if setup correctly. `--keep_res` is for keep the original image resolution. Without `--keep_res` it will resize the images to `512 x 512`. You can add `--flip_test` and `--flip_test --test_scales 0.5,0.75,1,1.25,1.5` to the above commend, for flip test and multi_scale test, respectively. The expected APs are `39.2` and `41.7`, respectively.
To test with hourglass net, run
~~~
python test.py ctdet --exp_id coco_hg --arch hourglass --fix_res --load_model ../models/ctdet_coco_hg.pth
~~~
Similarly, to evaluate human pose estimation, run the following command for dla
~~~
python test.py multi_pose --exp_id dla --keep_res --load_model ../models/multi_pose_dla_3x.pth --flip_test
~~~
and the following for hourglass
~~~
python test.py multi_pose --exp_id hg --arch hourglass --keep_res --load_model ../models/multi_pose_dla_3x.pth --flip_test
~~~
The expected results can be found in the model zoo.
### Pascal
To evaluate object detection on Pascal VOC (test2007), run
~~~
python test.py ctdet --exp_id dla --dataset pascal --load_model ../models/ctdet_pascal_dla.pth --flip_test
~~~
Note that we fix the resolution during testing.
And you can change to other network architectures and resolutions by specifying `--arch` and `--input_res 512`.
### KITTI
To evaluate the kitti dataset, first compile the evaluation tool (from [here](https://github.com/prclibo/kitti_eval)):
~~~
cd CenterNet_ROOT/src/tools/kitti_eval
g++ -o evaluate_object_3d_offline evaluate_object_3d_offline.cpp -O3
~~~
Then run the evaluation with pretrained model:
~~~
python test.py ddd --exp_id 3dop --dataset kitti --kitti_split 3dop --load_model ../models/ddd_3dop.pth
~~~
to evaluate the 3DOP split. For the subcnn split, change `--kitti_split` to `subcnn` and load the corresponding models.
Note that test time augmentation is not trivially applicable for 3D orientation.
## Training
We have packed all the training scripts in the [experiments](../experiments) folder.
The experiment names are correspond to the model name in the [model zoo](MODEL_ZOO.md).
The number of GPUs for each experiments can be found in the scripts and the model zoo.
In the case that you don't have 8 GPUs, you can follow the [linear learning rate rule](https://arxiv.org/abs/1706.02677) to scale the learning rate as batch size.
For example, to train COCO object detection with dla on 2 GPUs, run
~~~
python main.py ctdet --exp_id coco_dla --batch_size 32 --master_batch 15 --lr 1.25e-4 --gpus 0,1
~~~
The default learning rate is `1.25e-4` for batch size `32` (on 2 GPUs).
By default, pytorch evenly splits the total batch size to each GPUs.
`--master_batch` allows using different batchsize for the master GPU, which usually costs more memory than other GPUs.
If it encounters GPU memory out, using slightly less batch size (e.g., `112` of `128`) with the same learning is fine.
If the training is terminated before finishing, you can use the same commond with `--resume` to resume training. It will found the lastest model with the same `exp_id`.
Our HourglassNet model is finetuned from the pretrained [ExtremeNet model](https://drive.google.com/file/d/1JMbHgN4uLkP9MAyJU5EeHrgxwe101hwO) (from the [ExtremeNet repo](https://github.com/xingyizhou/ExtremeNet)).
You will need to download the model, run `python convert_hourglass_weight.py` to convert the model format, and load the model for training (see the [script](../experiments/ctdet_coco_hg.sh)).
================================================
FILE: readme/INSTALL.md
================================================
# Installation
The code was tested on Ubuntu 16.04, with [Anaconda](https://www.anaconda.com/download) Python 3.6 and [PyTorch]((http://pytorch.org/)) v0.4.1. NVIDIA GPUs are needed for both training and testing.
After install Anaconda:
0. [Optional but recommended] create a new conda environment.
~~~
conda create --name CenterNet python=3.6
~~~
And activate the environment.
~~~
conda activate CenterNet
~~~
1. Install pytorch0.4.1:
~~~
conda install pytorch=0.4.1 torchvision -c pytorch
~~~
And disable cudnn batch normalization(Due to [this issue](https://github.com/xingyizhou/pytorch-pose-hg-3d/issues/16)).
~~~
# PYTORCH=/path/to/pytorch # usually ~/anaconda3/envs/CenterNet/lib/python3.6/site-packages/
# for pytorch v0.4.0
sed -i "1194s/torch\.backends\.cudnn\.enabled/False/g" ${PYTORCH}/torch/nn/functional.py
# for pytorch v0.4.1
sed -i "1254s/torch\.backends\.cudnn\.enabled/False/g" ${PYTORCH}/torch/nn/functional.py
~~~
For other pytorch version, you can manually open `torch/nn/functional.py` and find the line with `torch.batch_norm` and replace the `torch.backends.cudnn.enabled` with `False`. We observed slight worse training results without doing so.
2. Install [COCOAPI](https://github.com/cocodataset/cocoapi):
~~~
# COCOAPI=/path/to/clone/cocoapi
git clone https://github.com/cocodataset/cocoapi.git $COCOAPI
cd $COCOAPI/PythonAPI
make
python setup.py install --user
~~~
3. Clone this repo:
~~~
CenterNet_ROOT=/path/to/clone/CenterNet
git clone https://github.com/xingyizhou/CenterNet $CenterNet_ROOT
~~~
4. Install the requirements
~~~
pip install -r requirements.txt
~~~
5. Compile deformable convolutional (from [DCNv2](https://github.com/CharlesShang/DCNv2/tree/pytorch_0.4)).
~~~
cd $CenterNet_ROOT/src/lib/models/networks/DCNv2
./make.sh
~~~
6. [Optional, only required if you are using extremenet or multi-scale testing] Compile NMS if your want to use multi-scale testing or test ExtremeNet.
~~~
cd $CenterNet_ROOT/src/lib/external
make
~~~
7. Download pertained models for [detection]() or [pose estimation]() and move them to `$CenterNet_ROOT/models/`. More models can be found in [Model zoo](MODEL_ZOO.md).
================================================
FILE: readme/MODEL_ZOO.md
================================================
# MODEL ZOO
### Common settings and notes
- The experiments are run with pytorch 0.4.1, CUDA 9.0, and CUDNN 7.1.
- Training times are measured on our servers with 8 TITAN V GPUs (12 GB Memeory).
- Testing times are measured on our local machine with TITAN Xp GPU.
- The models can be downloaded directly from [Google drive](https://drive.google.com/drive/folders/1S3NnppRgXea_IG4WeyquJcnOB3I6G-LX).
## Object Detection
### COCO
| Model | GPUs |Train time(h)| Test time (ms) | AP | Download |
|--------------------------|------|-------------|----------------|--------------------|-----------|
|[ctdet\_coco\_hg](../experiments/ctdet_coco_hg.sh) | 5 |109 | 71 / 129 / 674 | 40.3 / 42.2 / 45.1 | [model](https://drive.google.com/file/d/13F904yXltGIqa_K3g3-FLleaNX0n7c9O) |
|[ctdet\_coco\_dla\_1x](../experiments/ctdet_coco_dla_1x.sh) | 8 | 57 | 19 / 36 / 248 | 36.3 / 38.2 / 40.7 | [model](https://drive.google.com/file/d/1xqFsdA3DANMq1MfnXG8n7nQPe4AfXTHv) |
|[ctdet\_coco\_dla\_2x](../experiments/ctdet_coco_dla_2x.sh) | 8 | 92 | 19 / 36 / 248 | 37.4 / 39.2 / 41.7 | [model](https://drive.google.com/file/d/18Q3fzzAsha_3Qid6mn4jcIFPeOGUaj1d) |
|[ctdet\_coco\_resdcn101](../experiments/ctdet_coco_resdcn101.sh)| 8 | 65 | 22 / 40 / 259 | 34.6 / 36.2 / 39.3 | [model](https://drive.google.com/file/d/1tKkSyzC3iWmM6XTYNJrC4XLCIToDmnHz) |
|[ctdet\_coco\_resdcn18](../experiments/ctdet_coco_resdcn18.sh) | 4 | 28 | 7 / 14 / 81 | 28.1 / 30.0 / 33.2 | [model](https://drive.google.com/file/d/1RtFps3kQAyLjQyzCao7pPDclOBQ64Vyp) |
|[exdet\_coco\_hg](../experiments/exdet_coco_hg.sh) | 5 |215 | 134 / 246/1340 | 35.8 / 39.8 / 42.4 | [model](https://drive.google.com/file/d/1gf9bVWs9htzOaQiAF_mqaa2SCFTvwNvh) |
|[exdet\_coco\_dla](../experiments/exdet_coco_dla.sh) | 8 |133 | 51 / 90 / 481 | 33.0 / 36.5 / 38.5 | [model](https://drive.google.com/file/d/1RtFps3kQAyLjQyzCao7pPDclOBQ64Vyp) |
#### Notes
- All models are trained on COCO train 2017 and evaluated on val 2017.
- We show test time and AP with no augmentation / flip augmentation / multi scale (0.5, 0.75, 1, 1.25, 1.5) augmentation.
- Results on COCO test-dev can be found in the paper or add `--trainval` for `test.py`.
- exdet is our re-implementation of [ExtremeNet](https://github.com/xingyizhou/ExtremeNet). The testing does not include edge aggregation.
- For dla and resnets, `1x` means the training schedule that train 140 epochs with learning rate dropped 10 times at the 90 and 120 epoch (following [SimpleBaseline](https://github.com/Microsoft/human-pose-estimation.pytorch)). `2x` means train 230 epochs with learning rate dropped 10 times at the 180 and 210 epoch. The training schedules are **not** carefully investigated.
- The hourglass trained schedule follows [ExtremeNet](https://github.com/xingyizhou/ExtremeNet): trains 50 epochs (approximately 250000 iterations in batch size 24) and drops learning rate at the 40 epoch.
- Testing time include network forwarding time, decoding time, and nms time (for ExtremeNet).
- We observed up to 0.4 AP performance jitter due to randomness in training.
### Pascal VOC
| Model |GPUs| Train time (h)| Test time (ms) | mAP | Download |
|---------------------------------|----|---------------|----------------|------|-----------|
|[ctdet\_pascal\_dla\_384](../experiments/ctdet_pascal_dla_384.sh) | 1 |15 | 20 | 79.3 | [model](https://drive.google.com/file/d/19J7WoUZKYiSEU7vrhZInz5C2m0-9zmC1) |
|[ctdet\_pascal\_dla\_512](../experiments/ctdet_pascal_dla_512.sh) | 2 |15 | 30 | 80.7 | [model](https://drive.google.com/file/d/1Iqqr_VLtG8T3tUzy-EuMaeuCtFuv6pEU) |
|[ctdet\_pascal\_resdcn18\_384](../experiments/ctdet_pascal_resdcn18_384.sh) | 1 |3 | 7 | 72.6 | [model](https://drive.google.com/file/d/1mpeslWUt0aJqx99_-UcCzJ7GBcD6sCA-) |
|[ctdet\_pascal\_resdcn18\_512](../experiments/ctdet_pascal_resdcn18_512.sh) | 1 |5 | 10 | 75.7 | [model](https://drive.google.com/file/d/1ILnmGrJQiDK2Ib-D7TzBs2fq5bfju-Bd) |
|[ctdet\_pascal\_resdcn101\_384](../experiments/ctdet_pascal_resdcn101_384.sh)| 2 |7 | 22 | 77.1 | [model](https://drive.google.com/file/d/1-Qy4zMhzmBk9fMF0u2s5zNI0Uj9latsk) |
|[ctdet\_pascal\_resdcn101\_512](../experiments/ctdet_pascal_resdcn101_512.sh)| 4 |7 | 33 | 78.7 | [model](https://drive.google.com/file/d/1TiJkPaofzUaEMLi5wr9TIIUY8G2VewCQ) |
#### Notes
- All models are trained on trainval 07+12 and tested on test 2007.
- Flip test is used by default.
- Training schedule: train for 70 epochs with learning rate dropped 10 times at the 45 and 60 epoch.
- We observed up to 1 mAP performance jitter due to randomness in training.
## Human pose estimation
### COCO
| Model | GPUs |Train time(h)| Test time (ms) | AP | Download |
|--------------------------|------|-------------|----------------|-------------|-----------|
|[multi\_pose\_hg_1x](../experiments/multi_pose_hg_1x.sh) | 5 |62 | 151 | 58.7 | [model](https://drive.google.com/file/d/1neg1zfVjRTS45FCdk5hgIV-TxJ0McAew) |
|[multi\_pose\_hg_3x](../experiments/multi_pose_hg_3x.sh) | 5 |188 | 151 | 64.0 | [model](https://drive.google.com/file/d/17-YS11iguOQKwPPHUg8LzakLzrgKSLfA) |
|[multi\_pose\_dla_1x](../experiments/multi_pose_dla_1x.sh) | 8 |30 | 44 | 54.7 | [model](https://drive.google.com/file/d/1WKqVdkIew43SxLTSxi81a-_f4Q9v2Fx5) |
|[multi\_pose\_dla_3x](../experiments/multi_pose_dla_3x.sh) | 8 |70 | 44 | 58.9 | [model](https://drive.google.com/file/d/1mC2PAQT_RuHi_9ZMZgkt4rg7BSY2_Lkd) |
#### Notes
- All models are trained on keypoint train 2017 images which contains at least one human with keypoint annotations (64115 images).
- The evaluation is done on COCO keypoint val 2017 (5000 images).
- Flip test is used by default.
- The models are fine-tuned from the corresponding center point detection models.
- Dla training schedule: `1x`: train for 140 epochs with learning rate dropped 10 times at the 90 and 120 epoch.`3x`: train for 320 epochs with learning rate dropped 10 times at the 270 and 300 epoch.
- Hourglass training schedule: `1x`: train for 50 epochs with learning rate dropped 10 times at the 40 epoch.`3x`: train for 150 epochs with learning rate dropped 10 times at the 130 epoch.
## 3D bounding box detection
#### Notes
- The 3dop split is from [3DOP](https://papers.nips.cc/paper/5644-3d-object-proposals-for-accurate-object-class-detection) and the suborn split is from [SubCNN](https://github.com/tanshen/SubCNN).
- No augmentation is used in testing.
- The models are trained for 70 epochs with learning rate dropped at the 45 and 60 epoch.
### KITTI 3DOP split
|Model |GPUs|Train time|Test time|AP-E|AP-M|AP-H|AOS-E|AOS-M|AOS-H|BEV-E|BEV-M|BEV-H| Download |
|------------|----|----------|---------|----|----|----|-----|-----|-----|-----|-----|-----|----------|
|[ddd_3dop](../experiments/ddd_3dop.sh)|2 | 7h | 31ms |96.9|87.8|79.2|93.9 |84.3 |75.7 |34.0 |30.5 |26.8 | [model](https://drive.google.com/file/d/1LrAzVJqlZECVuyr_NJI_4xd88mA1fL5b)|
### KITTI SubCNN split
|Model |GPUs|Train time|Test time|AP-E|AP-M|AP-H|AOS-E|AOS-M|AOS-H|BEV-E|BEV-M|BEV-H| Download |
|------------|----|----------|---------|----|----|----|-----|-----|-----|-----|-----|-----|----------|
|[ddd_sub](../experiments/ddd_sub.sh) |2 | 7h | 31ms |89.6|79.8|70.3|85.7 |75.2 |65.9 |34.9 |27.7 |26.4 | [model](https://drive.google.com/file/d/1ZUsUqrM_yTjxaJuDBxm0WTKXj1snVuvP)|
================================================
FILE: requirements.txt
================================================
opencv-python
Cython
numba
progress
matplotlib
easydict
scipy
================================================
FILE: src/_init_paths.py
================================================
import os.path as osp
import sys
def add_path(path):
if path not in sys.path:
sys.path.insert(0, path)
this_dir = osp.dirname(__file__)
# Add lib to PYTHONPATH
lib_path = osp.join(this_dir, 'lib')
add_path(lib_path)
================================================
FILE: src/demo.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import _init_paths
import os
import cv2
from opts import opts
from detectors.detector_factory import detector_factory
image_ext = ['jpg', 'jpeg', 'png', 'webp']
video_ext = ['mp4', 'mov', 'avi', 'mkv']
time_stats = ['tot', 'load', 'pre', 'net', 'dec', 'post', 'merge']
def demo(opt):
os.environ['CUDA_VISIBLE_DEVICES'] = opt.gpus_str
opt.debug = max(opt.debug, 1)
Detector = detector_factory[opt.task]
detector = Detector(opt)
if opt.demo == 'webcam' or \
opt.demo[opt.demo.rfind('.') + 1:].lower() in video_ext:
cam = cv2.VideoCapture(0 if opt.demo == 'webcam' else opt.demo)
detector.pause = False
while True:
_, img = cam.read()
cv2.imshow('input', img)
ret = detector.run(img)
time_str = ''
for stat in time_stats:
time_str = time_str + '{} {:.3f}s |'.format(stat, ret[stat])
print(time_str)
if cv2.waitKey(1) == 27:
return # esc to quit
else:
if os.path.isdir(opt.demo):
image_names = []
ls = os.listdir(opt.demo)
for file_name in sorted(ls):
ext = file_name[file_name.rfind('.') + 1:].lower()
if ext in image_ext:
image_names.append(os.path.join(opt.demo, file_name))
else:
image_names = [opt.demo]
for (image_name) in image_names:
ret = detector.run(image_name)
time_str = ''
for stat in time_stats:
time_str = time_str + '{} {:.3f}s |'.format(stat, ret[stat])
print(time_str)
if __name__ == '__main__':
opt = opts().init()
demo(opt)
================================================
FILE: src/lib/datasets/dataset/coco.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import pycocotools.coco as coco
from pycocotools.cocoeval import COCOeval
import numpy as np
import json
import os
import torch.utils.data as data
class COCO(data.Dataset):
num_classes = 80
default_resolution = [512, 512]
mean = np.array([0.40789654, 0.44719302, 0.47026115],
dtype=np.float32).reshape(1, 1, 3)
std = np.array([0.28863828, 0.27408164, 0.27809835],
dtype=np.float32).reshape(1, 1, 3)
def __init__(self, opt, split):
super(COCO, self).__init__()
self.data_dir = os.path.join(opt.data_dir, 'coco')
self.img_dir = os.path.join(self.data_dir, '{}2017'.format(split))
if split == 'test':
self.annot_path = os.path.join(
self.data_dir, 'annotations',
'image_info_test-dev2017.json').format(split)
else:
if opt.task == 'exdet':
self.annot_path = os.path.join(
self.data_dir, 'annotations',
'instances_extreme_{}2017.json').format(split)
else:
self.annot_path = os.path.join(
self.data_dir, 'annotations',
'instances_{}2017.json').format(split)
self.max_objs = 128
self.class_name = [
'__background__', 'person', 'bicycle', 'car', 'motorcycle', 'airplane',
'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant',
'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse',
'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack',
'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis',
'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove',
'skateboard', 'surfboard', 'tennis racket', 'bottle', 'wine glass',
'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich',
'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake',
'chair', 'couch', 'potted plant', 'bed', 'dining table', 'toilet', 'tv',
'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave',
'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase',
'scissors', 'teddy bear', 'hair drier', 'toothbrush']
self._valid_ids = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 27, 28, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65, 67, 70,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
82, 84, 85, 86, 87, 88, 89, 90]
self.cat_ids = {v: i for i, v in enumerate(self._valid_ids)}
self.voc_color = [(v // 32 * 64 + 64, (v // 8) % 4 * 64, v % 8 * 32) \
for v in range(1, self.num_classes + 1)]
self._data_rng = np.random.RandomState(123)
self._eig_val = np.array([0.2141788, 0.01817699, 0.00341571],
dtype=np.float32)
self._eig_vec = np.array([
[-0.58752847, -0.69563484, 0.41340352],
[-0.5832747, 0.00994535, -0.81221408],
[-0.56089297, 0.71832671, 0.41158938]
], dtype=np.float32)
# self.mean = np.array([0.485, 0.456, 0.406], np.float32).reshape(1, 1, 3)
# self.std = np.array([0.229, 0.224, 0.225], np.float32).reshape(1, 1, 3)
self.split = split
self.opt = opt
print('==> initializing coco 2017 {} data.'.format(split))
self.coco = coco.COCO(self.annot_path)
self.images = self.coco.getImgIds()
self.num_samples = len(self.images)
print('Loaded {} {} samples'.format(split, self.num_samples))
def _to_float(self, x):
return float("{:.2f}".format(x))
def convert_eval_format(self, all_bboxes):
# import pdb; pdb.set_trace()
detections = []
for image_id in all_bboxes:
for cls_ind in all_bboxes[image_id]:
category_id = self._valid_ids[cls_ind - 1]
for bbox in all_bboxes[image_id][cls_ind]:
bbox[2] -= bbox[0]
bbox[3] -= bbox[1]
score = bbox[4]
bbox_out = list(map(self._to_float, bbox[0:4]))
detection = {
"image_id": int(image_id),
"category_id": int(category_id),
"bbox": bbox_out,
"score": float("{:.2f}".format(score))
}
if len(bbox) > 5:
extreme_points = list(map(self._to_float, bbox[5:13]))
detection["extreme_points"] = extreme_points
detections.append(detection)
return detections
def __len__(self):
return self.num_samples
def save_results(self, results, save_dir):
json.dump(self.convert_eval_format(results),
open('{}/results.json'.format(save_dir), 'w'))
def run_eval(self, results, save_dir):
# result_json = os.path.join(save_dir, "results.json")
# detections = self.convert_eval_format(results)
# json.dump(detections, open(result_json, "w"))
self.save_results(results, save_dir)
coco_dets = self.coco.loadRes('{}/results.json'.format(save_dir))
coco_eval = COCOeval(self.coco, coco_dets, "bbox")
coco_eval.evaluate()
coco_eval.accumulate()
coco_eval.summarize()
================================================
FILE: src/lib/datasets/dataset/coco_hp.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import pycocotools.coco as coco
from pycocotools.cocoeval import COCOeval
import numpy as np
import json
import os
import torch.utils.data as data
class COCOHP(data.Dataset):
num_classes = 1
num_joints = 17
default_resolution = [512, 512]
mean = np.array([0.40789654, 0.44719302, 0.47026115],
dtype=np.float32).reshape(1, 1, 3)
std = np.array([0.28863828, 0.27408164, 0.27809835],
dtype=np.float32).reshape(1, 1, 3)
flip_idx = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],
[11, 12], [13, 14], [15, 16]]
def __init__(self, opt, split):
super(COCOHP, self).__init__()
self.edges = [[0, 1], [0, 2], [1, 3], [2, 4],
[4, 6], [3, 5], [5, 6],
[5, 7], [7, 9], [6, 8], [8, 10],
[6, 12], [5, 11], [11, 12],
[12, 14], [14, 16], [11, 13], [13, 15]]
self.acc_idxs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
self.data_dir = os.path.join(opt.data_dir, 'coco')
self.img_dir = os.path.join(self.data_dir, '{}2017'.format(split))
if split == 'test':
self.annot_path = os.path.join(
self.data_dir, 'annotations',
'image_info_test-dev2017.json').format(split)
else:
self.annot_path = os.path.join(
self.data_dir, 'annotations',
'person_keypoints_{}2017.json').format(split)
self.max_objs = 32
self._data_rng = np.random.RandomState(123)
self._eig_val = np.array([0.2141788, 0.01817699, 0.00341571],
dtype=np.float32)
self._eig_vec = np.array([
[-0.58752847, -0.69563484, 0.41340352],
[-0.5832747, 0.00994535, -0.81221408],
[-0.56089297, 0.71832671, 0.41158938]
], dtype=np.float32)
self.split = split
self.opt = opt
print('==> initializing coco 2017 {} data.'.format(split))
self.coco = coco.COCO(self.annot_path)
image_ids = self.coco.getImgIds()
if split == 'train':
self.images = []
for img_id in image_ids:
idxs = self.coco.getAnnIds(imgIds=[img_id])
if len(idxs) > 0:
self.images.append(img_id)
else:
self.images = image_ids
self.num_samples = len(self.images)
print('Loaded {} {} samples'.format(split, self.num_samples))
def _to_float(self, x):
return float("{:.2f}".format(x))
def convert_eval_format(self, all_bboxes):
# import pdb; pdb.set_trace()
detections = []
for image_id in all_bboxes:
for cls_ind in all_bboxes[image_id]:
category_id = 1
for dets in all_bboxes[image_id][cls_ind]:
bbox = dets[:4]
bbox[2] -= bbox[0]
bbox[3] -= bbox[1]
score = dets[4]
bbox_out = list(map(self._to_float, bbox))
keypoints = np.concatenate([
np.array(dets[5:39], dtype=np.float32).reshape(-1, 2),
np.ones((17, 1), dtype=np.float32)], axis=1).reshape(51).tolist()
keypoints = list(map(self._to_float, keypoints))
detection = {
"image_id": int(image_id),
"category_id": int(category_id),
"bbox": bbox_out,
"score": float("{:.2f}".format(score)),
"keypoints": keypoints
}
detections.append(detection)
return detections
def __len__(self):
return self.num_samples
def save_results(self, results, save_dir):
json.dump(self.convert_eval_format(results),
open('{}/results.json'.format(save_dir), 'w'))
def run_eval(self, results, save_dir):
# result_json = os.path.join(opt.save_dir, "results.json")
# detections = convert_eval_format(all_boxes)
# json.dump(detections, open(result_json, "w"))
self.save_results(results, save_dir)
coco_dets = self.coco.loadRes('{}/results.json'.format(save_dir))
coco_eval = COCOeval(self.coco, coco_dets, "keypoints")
coco_eval.evaluate()
coco_eval.accumulate()
coco_eval.summarize()
coco_eval = COCOeval(self.coco, coco_dets, "bbox")
coco_eval.evaluate()
coco_eval.accumulate()
coco_eval.summarize()
================================================
FILE: src/lib/datasets/dataset/kitti.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import torch.utils.data as data
import pycocotools.coco as coco
import numpy as np
import torch
import json
import cv2
import os
import math
import torch.utils.data as data
class KITTI(data.Dataset):
num_classes = 3
default_resolution = [384, 1280]
mean = np.array([0.485, 0.456, 0.406], np.float32).reshape(1, 1, 3)
std = np.array([0.229, 0.224, 0.225], np.float32).reshape(1, 1, 3)
def __init__(self, opt, split):
super(KITTI, self).__init__()
self.data_dir = os.path.join(opt.data_dir, 'kitti')
self.img_dir = os.path.join(self.data_dir, 'images', 'trainval')
if opt.trainval:
split = 'trainval' if split == 'train' else 'test'
self.img_dir = os.path.join(self.data_dir, 'images', split)
self.annot_path = os.path.join(
self.data_dir, 'annotations', 'kitti_{}.json').format(split)
else:
self.annot_path = os.path.join(self.data_dir,
'annotations', 'kitti_{}_{}.json').format(opt.kitti_split, split)
self.max_objs = 50
self.class_name = [
'__background__', 'Pedestrian', 'Car', 'Cyclist']
self.cat_ids = {1:0, 2:1, 3:2, 4:-3, 5:-3, 6:-2, 7:-99, 8:-99, 9:-1}
self._data_rng = np.random.RandomState(123)
self._eig_val = np.array([0.2141788, 0.01817699, 0.00341571],
dtype=np.float32)
self._eig_vec = np.array([
[-0.58752847, -0.69563484, 0.41340352],
[-0.5832747, 0.00994535, -0.81221408],
[-0.56089297, 0.71832671, 0.41158938]
], dtype=np.float32)
self.split = split
self.opt = opt
self.alpha_in_degree = False
print('==> initializing kitti {}, {} data.'.format(opt.kitti_split, split))
self.coco = coco.COCO(self.annot_path)
self.images = self.coco.getImgIds()
self.num_samples = len(self.images)
print('Loaded {} {} samples'.format(split, self.num_samples))
def __len__(self):
return self.num_samples
def _to_float(self, x):
return float("{:.2f}".format(x))
def convert_eval_format(self, all_bboxes):
pass
def save_results(self, results, save_dir):
results_dir = os.path.join(save_dir, 'results')
if not os.path.exists(results_dir):
os.mkdir(results_dir)
for img_id in results.keys():
out_path = os.path.join(results_dir, '{:06d}.txt'.format(img_id))
f = open(out_path, 'w')
for cls_ind in results[img_id]:
for j in range(len(results[img_id][cls_ind])):
class_name = self.class_name[cls_ind]
f.write('{} 0.0 0'.format(class_name))
for i in range(len(results[img_id][cls_ind][j])):
f.write(' {:.2f}'.format(results[img_id][cls_ind][j][i]))
f.write('\n')
f.close()
def run_eval(self, results, save_dir):
self.save_results(results, save_dir)
os.system('./tools/kitti_eval/evaluate_object_3d_offline ' + \
'../data/kitti/training/label_val ' + \
'{}/results/'.format(save_dir))
================================================
FILE: src/lib/datasets/dataset/pascal.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import pycocotools.coco as coco
import numpy as np
import torch
import json
import os
import torch.utils.data as data
class PascalVOC(data.Dataset):
num_classes = 20
default_resolution = [384, 384]
mean = np.array([0.485, 0.456, 0.406],
dtype=np.float32).reshape(1, 1, 3)
std = np.array([0.229, 0.224, 0.225],
dtype=np.float32).reshape(1, 1, 3)
def __init__(self, opt, split):
super(PascalVOC, self).__init__()
self.data_dir = os.path.join(opt.data_dir, 'voc')
self.img_dir = os.path.join(self.data_dir, 'images')
_ann_name = {'train': 'trainval0712', 'val': 'test2007'}
self.annot_path = os.path.join(
self.data_dir, 'annotations',
'pascal_{}.json').format(_ann_name[split])
self.max_objs = 50
self.class_name = ['__background__', "aeroplane", "bicycle", "bird", "boat",
"bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog",
"horse", "motorbike", "person", "pottedplant", "sheep", "sofa",
"train", "tvmonitor"]
self._valid_ids = np.arange(1, 21, dtype=np.int32)
self.cat_ids = {v: i for i, v in enumerate(self._valid_ids)}
self._data_rng = np.random.RandomState(123)
self._eig_val = np.array([0.2141788, 0.01817699, 0.00341571],
dtype=np.float32)
self._eig_vec = np.array([
[-0.58752847, -0.69563484, 0.41340352],
[-0.5832747, 0.00994535, -0.81221408],
[-0.56089297, 0.71832671, 0.41158938]
], dtype=np.float32)
self.split = split
self.opt = opt
print('==> initializing pascal {} data.'.format(_ann_name[split]))
self.coco = coco.COCO(self.annot_path)
self.images = sorted(self.coco.getImgIds())
self.num_samples = len(self.images)
print('Loaded {} {} samples'.format(split, self.num_samples))
def _to_float(self, x):
return float("{:.2f}".format(x))
def convert_eval_format(self, all_bboxes):
detections = [[[] for __ in range(self.num_samples)] \
for _ in range(self.num_classes + 1)]
for i in range(self.num_samples):
img_id = self.images[i]
for j in range(1, self.num_classes + 1):
if isinstance(all_bboxes[img_id][j], np.ndarray):
detections[j][i] = all_bboxes[img_id][j].tolist()
else:
detections[j][i] = all_bboxes[img_id][j]
return detections
def __len__(self):
return self.num_samples
def save_results(self, results, save_dir):
json.dump(self.convert_eval_format(results),
open('{}/results.json'.format(save_dir), 'w'))
def run_eval(self, results, save_dir):
# result_json = os.path.join(save_dir, "results.json")
# detections = self.convert_eval_format(results)
# json.dump(detections, open(result_json, "w"))
self.save_results(results, save_dir)
os.system('python tools/reval.py ' + \
'{}/results.json'.format(save_dir))
================================================
FILE: src/lib/datasets/dataset_factory.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from .sample.ddd import DddDataset
from .sample.exdet import EXDetDataset
from .sample.ctdet import CTDetDataset
from .sample.multi_pose import MultiPoseDataset
from .dataset.coco import COCO
from .dataset.pascal import PascalVOC
from .dataset.kitti import KITTI
from .dataset.coco_hp import COCOHP
dataset_factory = {
'coco': COCO,
'pascal': PascalVOC,
'kitti': KITTI,
'coco_hp': COCOHP
}
_sample_factory = {
'exdet': EXDetDataset,
'ctdet': CTDetDataset,
'ddd': DddDataset,
'multi_pose': MultiPoseDataset
}
def get_dataset(dataset, task):
class Dataset(dataset_factory[dataset], _sample_factory[task]):
pass
return Dataset
================================================
FILE: src/lib/datasets/sample/ctdet.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import torch.utils.data as data
import numpy as np
import torch
import json
import cv2
import os
from utils.image import flip, color_aug
from utils.image import get_affine_transform, affine_transform
from utils.image import gaussian_radius, draw_umich_gaussian, draw_msra_gaussian
from utils.image import draw_dense_reg
import math
class CTDetDataset(data.Dataset):
def _coco_box_to_bbox(self, box):
bbox = np.array([box[0], box[1], box[0] + box[2], box[1] + box[3]],
dtype=np.float32)
return bbox
def _get_border(self, border, size):
i = 1
while size - border // i <= border // i:
i *= 2
return border // i
def __getitem__(self, index):
img_id = self.images[index]
file_name = self.coco.loadImgs(ids=[img_id])[0]['file_name']
img_path = os.path.join(self.img_dir, file_name)
ann_ids = self.coco.getAnnIds(imgIds=[img_id])
anns = self.coco.loadAnns(ids=ann_ids)
num_objs = min(len(anns), self.max_objs)
img = cv2.imread(img_path)
height, width = img.shape[0], img.shape[1]
c = np.array([img.shape[1] / 2., img.shape[0] / 2.], dtype=np.float32)
if self.opt.keep_res:
input_h = (height | self.opt.pad) + 1
input_w = (width | self.opt.pad) + 1
s = np.array([input_w, input_h], dtype=np.float32)
else:
s = max(img.shape[0], img.shape[1]) * 1.0
input_h, input_w = self.opt.input_h, self.opt.input_w
flipped = False
if self.split == 'train':
if not self.opt.not_rand_crop:
s = s * np.random.choice(np.arange(0.6, 1.4, 0.1))
w_border = self._get_border(128, img.shape[1])
h_border = self._get_border(128, img.shape[0])
c[0] = np.random.randint(low=w_border, high=img.shape[1] - w_border)
c[1] = np.random.randint(low=h_border, high=img.shape[0] - h_border)
else:
sf = self.opt.scale
cf = self.opt.shift
c[0] += s * np.clip(np.random.randn()*cf, -2*cf, 2*cf)
c[1] += s * np.clip(np.random.randn()*cf, -2*cf, 2*cf)
s = s * np.clip(np.random.randn()*sf + 1, 1 - sf, 1 + sf)
if np.random.random() < self.opt.flip:
flipped = True
img = img[:, ::-1, :]
c[0] = width - c[0] - 1
trans_input = get_affine_transform(
c, s, 0, [input_w, input_h])
inp = cv2.warpAffine(img, trans_input,
(input_w, input_h),
flags=cv2.INTER_LINEAR)
inp = (inp.astype(np.float32) / 255.)
if self.split == 'train' and not self.opt.no_color_aug:
color_aug(self._data_rng, inp, self._eig_val, self._eig_vec)
inp = (inp - self.mean) / self.std
inp = inp.transpose(2, 0, 1)
output_h = input_h // self.opt.down_ratio
output_w = input_w // self.opt.down_ratio
num_classes = self.num_classes
trans_output = get_affine_transform(c, s, 0, [output_w, output_h])
hm = np.zeros((num_classes, output_h, output_w), dtype=np.float32)
wh = np.zeros((self.max_objs, 2), dtype=np.float32)
dense_wh = np.zeros((2, output_h, output_w), dtype=np.float32)
reg = np.zeros((self.max_objs, 2), dtype=np.float32)
ind = np.zeros((self.max_objs), dtype=np.int64)
reg_mask = np.zeros((self.max_objs), dtype=np.uint8)
cat_spec_wh = np.zeros((self.max_objs, num_classes * 2), dtype=np.float32)
cat_spec_mask = np.zeros((self.max_objs, num_classes * 2), dtype=np.uint8)
draw_gaussian = draw_msra_gaussian if self.opt.mse_loss else \
draw_umich_gaussian
gt_det = []
for k in range(num_objs):
ann = anns[k]
bbox = self._coco_box_to_bbox(ann['bbox'])
cls_id = int(self.cat_ids[ann['category_id']])
if flipped:
bbox[[0, 2]] = width - bbox[[2, 0]] - 1
bbox[:2] = affine_transform(bbox[:2], trans_output)
bbox[2:] = affine_transform(bbox[2:], trans_output)
bbox[[0, 2]] = np.clip(bbox[[0, 2]], 0, output_w - 1)
bbox[[1, 3]] = np.clip(bbox[[1, 3]], 0, output_h - 1)
h, w = bbox[3] - bbox[1], bbox[2] - bbox[0]
if h > 0 and w > 0:
radius = gaussian_radius((math.ceil(h), math.ceil(w)))
radius = max(0, int(radius))
radius = self.opt.hm_gauss if self.opt.mse_loss else radius
ct = np.array(
[(bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2], dtype=np.float32)
ct_int = ct.astype(np.int32)
draw_gaussian(hm[cls_id], ct_int, radius)
wh[k] = 1. * w, 1. * h
ind[k] = ct_int[1] * output_w + ct_int[0]
reg[k] = ct - ct_int
reg_mask[k] = 1
cat_spec_wh[k, cls_id * 2: cls_id * 2 + 2] = wh[k]
cat_spec_mask[k, cls_id * 2: cls_id * 2 + 2] = 1
if self.opt.dense_wh:
draw_dense_reg(dense_wh, hm.max(axis=0), ct_int, wh[k], radius)
gt_det.append([ct[0] - w / 2, ct[1] - h / 2,
ct[0] + w / 2, ct[1] + h / 2, 1, cls_id])
ret = {'input': inp, 'hm': hm, 'reg_mask': reg_mask, 'ind': ind, 'wh': wh}
if self.opt.dense_wh:
hm_a = hm.max(axis=0, keepdims=True)
dense_wh_mask = np.concatenate([hm_a, hm_a], axis=0)
ret.update({'dense_wh': dense_wh, 'dense_wh_mask': dense_wh_mask})
del ret['wh']
elif self.opt.cat_spec_wh:
ret.update({'cat_spec_wh': cat_spec_wh, 'cat_spec_mask': cat_spec_mask})
del ret['wh']
if self.opt.reg_offset:
ret.update({'reg': reg})
if self.opt.debug > 0 or not self.split == 'train':
gt_det = np.array(gt_det, dtype=np.float32) if len(gt_det) > 0 else \
np.zeros((1, 6), dtype=np.float32)
meta = {'c': c, 's': s, 'gt_det': gt_det, 'img_id': img_id}
ret['meta'] = meta
return ret
================================================
FILE: src/lib/datasets/sample/ddd.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import torch.utils.data as data
import pycocotools.coco as coco
import numpy as np
import torch
import json
import cv2
import os
import math
from utils.image import flip, color_aug
from utils.image import get_affine_transform, affine_transform
from utils.image import gaussian_radius, draw_umich_gaussian, draw_msra_gaussian
import pycocotools.coco as coco
class DddDataset(data.Dataset):
def _coco_box_to_bbox(self, box):
bbox = np.array([box[0], box[1], box[0] + box[2], box[1] + box[3]],
dtype=np.float32)
return bbox
def _convert_alpha(self, alpha):
return math.radians(alpha + 45) if self.alpha_in_degree else alpha
def __getitem__(self, index):
img_id = self.images[index]
img_info = self.coco.loadImgs(ids=[img_id])[0]
img_path = os.path.join(self.img_dir, img_info['file_name'])
img = cv2.imread(img_path)
if 'calib' in img_info:
calib = np.array(img_info['calib'], dtype=np.float32)
else:
calib = self.calib
height, width = img.shape[0], img.shape[1]
c = np.array([img.shape[1] / 2., img.shape[0] / 2.])
if self.opt.keep_res:
s = np.array([self.opt.input_w, self.opt.input_h], dtype=np.int32)
else:
s = np.array([width, height], dtype=np.int32)
aug = False
if self.split == 'train' and np.random.random() < self.opt.aug_ddd:
aug = True
sf = self.opt.scale
cf = self.opt.shift
s = s * np.clip(np.random.randn()*sf + 1, 1 - sf, 1 + sf)
c[0] += img.shape[1] * np.clip(np.random.randn()*cf, -2*cf, 2*cf)
c[1] += img.shape[0] * np.clip(np.random.randn()*cf, -2*cf, 2*cf)
trans_input = get_affine_transform(
c, s, 0, [self.opt.input_w, self.opt.input_h])
inp = cv2.warpAffine(img, trans_input,
(self.opt.input_w, self.opt.input_h),
flags=cv2.INTER_LINEAR)
inp = (inp.astype(np.float32) / 255.)
# if self.split == 'train' and not self.opt.no_color_aug:
# color_aug(self._data_rng, inp, self._eig_val, self._eig_vec)
inp = (inp - self.mean) / self.std
inp = inp.transpose(2, 0, 1)
num_classes = self.opt.num_classes
trans_output = get_affine_transform(
c, s, 0, [self.opt.output_w, self.opt.output_h])
hm = np.zeros(
(num_classes, self.opt.output_h, self.opt.output_w), dtype=np.float32)
wh = np.zeros((self.max_objs, 2), dtype=np.float32)
reg = np.zeros((self.max_objs, 2), dtype=np.float32)
dep = np.zeros((self.max_objs, 1), dtype=np.float32)
rotbin = np.zeros((self.max_objs, 2), dtype=np.int64)
rotres = np.zeros((self.max_objs, 2), dtype=np.float32)
dim = np.zeros((self.max_objs, 3), dtype=np.float32)
ind = np.zeros((self.max_objs), dtype=np.int64)
reg_mask = np.zeros((self.max_objs), dtype=np.uint8)
rot_mask = np.zeros((self.max_objs), dtype=np.uint8)
ann_ids = self.coco.getAnnIds(imgIds=[img_id])
anns = self.coco.loadAnns(ids=ann_ids)
num_objs = min(len(anns), self.max_objs)
draw_gaussian = draw_msra_gaussian if self.opt.mse_loss else \
draw_umich_gaussian
gt_det = []
for k in range(num_objs):
ann = anns[k]
bbox = self._coco_box_to_bbox(ann['bbox'])
cls_id = int(self.cat_ids[ann['category_id']])
if cls_id <= -99:
continue
# if flipped:
# bbox[[0, 2]] = width - bbox[[2, 0]] - 1
bbox[:2] = affine_transform(bbox[:2], trans_output)
bbox[2:] = affine_transform(bbox[2:], trans_output)
bbox[[0, 2]] = np.clip(bbox[[0, 2]], 0, self.opt.output_w - 1)
bbox[[1, 3]] = np.clip(bbox[[1, 3]], 0, self.opt.output_h - 1)
h, w = bbox[3] - bbox[1], bbox[2] - bbox[0]
if h > 0 and w > 0:
radius = gaussian_radius((h, w))
radius = max(0, int(radius))
ct = np.array(
[(bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2], dtype=np.float32)
ct_int = ct.astype(np.int32)
if cls_id < 0:
ignore_id = [_ for _ in range(num_classes)] \
if cls_id == - 1 else [- cls_id - 2]
if self.opt.rect_mask:
hm[ignore_id, int(bbox[1]): int(bbox[3]) + 1,
int(bbox[0]): int(bbox[2]) + 1] = 0.9999
else:
for cc in ignore_id:
draw_gaussian(hm[cc], ct, radius)
hm[ignore_id, ct_int[1], ct_int[0]] = 0.9999
continue
draw_gaussian(hm[cls_id], ct, radius)
wh[k] = 1. * w, 1. * h
gt_det.append([ct[0], ct[1], 1] + \
self._alpha_to_8(self._convert_alpha(ann['alpha'])) + \
[ann['depth']] + (np.array(ann['dim']) / 1).tolist() + [cls_id])
if self.opt.reg_bbox:
gt_det[-1] = gt_det[-1][:-1] + [w, h] + [gt_det[-1][-1]]
# if (not self.opt.car_only) or cls_id == 1: # Only estimate ADD for cars !!!
if 1:
alpha = self._convert_alpha(ann['alpha'])
# print('img_id cls_id alpha rot_y', img_path, cls_id, alpha, ann['rotation_y'])
if alpha < np.pi / 6. or alpha > 5 * np.pi / 6.:
rotbin[k, 0] = 1
rotres[k, 0] = alpha - (-0.5 * np.pi)
if alpha > -np.pi / 6. or alpha < -5 * np.pi / 6.:
rotbin[k, 1] = 1
rotres[k, 1] = alpha - (0.5 * np.pi)
dep[k] = ann['depth']
dim[k] = ann['dim']
# print(' cat dim', cls_id, dim[k])
ind[k] = ct_int[1] * self.opt.output_w + ct_int[0]
reg[k] = ct - ct_int
reg_mask[k] = 1 if not aug else 0
rot_mask[k] = 1
# print('gt_det', gt_det)
# print('')
ret = {'input': inp, 'hm': hm, 'dep': dep, 'dim': dim, 'ind': ind,
'rotbin': rotbin, 'rotres': rotres, 'reg_mask': reg_mask,
'rot_mask': rot_mask}
if self.opt.reg_bbox:
ret.update({'wh': wh})
if self.opt.reg_offset:
ret.update({'reg': reg})
if self.opt.debug > 0 or not ('train' in self.split):
gt_det = np.array(gt_det, dtype=np.float32) if len(gt_det) > 0 else \
np.zeros((1, 18), dtype=np.float32)
meta = {'c': c, 's': s, 'gt_det': gt_det, 'calib': calib,
'image_path': img_path, 'img_id': img_id}
ret['meta'] = meta
return ret
def _alpha_to_8(self, alpha):
# return [alpha, 0, 0, 0, 0, 0, 0, 0]
ret = [0, 0, 0, 1, 0, 0, 0, 1]
if alpha < np.pi / 6. or alpha > 5 * np.pi / 6.:
r = alpha - (-0.5 * np.pi)
ret[1] = 1
ret[2], ret[3] = np.sin(r), np.cos(r)
if alpha > -np.pi / 6. or alpha < -5 * np.pi / 6.:
r = alpha - (0.5 * np.pi)
ret[5] = 1
ret[6], ret[7] = np.sin(r), np.cos(r)
return ret
================================================
FILE: src/lib/datasets/sample/exdet.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import torch.utils.data as data
import pycocotools.coco as coco
import numpy as np
import torch
import json
import cv2
import os
from utils.image import flip, color_aug
from utils.image import get_affine_transform, affine_transform
from utils.image import gaussian_radius, draw_umich_gaussian, draw_msra_gaussian
import pycocotools.coco as coco
import math
class EXDetDataset(data.Dataset):
def _coco_box_to_bbox(self, box):
bbox = np.array([box[0], box[1], box[0] + box[2], box[1] + box[3]],
dtype=np.float32)
return bbox
def _get_border(self, border, size):
i = 1
while size - border // i <= border // i:
i *= 2
return border // i
def __getitem__(self, index):
img_id = self.images[index]
img_info = self.coco.loadImgs(ids=[img_id])[0]
img_path = os.path.join(self.img_dir, img_info['file_name'])
img = cv2.imread(img_path)
height, width = img.shape[0], img.shape[1]
c = np.array([img.shape[1] / 2., img.shape[0] / 2.])
s = max(img.shape[0], img.shape[1]) * 1.0
flipped = False
if self.split == 'train':
if not self.opt.not_rand_crop:
s = s * np.random.choice(np.arange(0.6, 1.4, 0.1))
w_border = self._get_border(128, img.shape[1])
h_border = self._get_border(128, img.shape[0])
c[0] = np.random.randint(low=w_border, high=img.shape[1] - w_border)
c[1] = np.random.randint(low=h_border, high=img.shape[0] - h_border)
else:
sf = self.opt.scale
cf = self.opt.shift
s = s * np.clip(np.random.randn()*sf + 1, 1 - sf, 1 + sf)
c[0] += img.shape[1] * np.clip(np.random.randn()*cf, -2*cf, 2*cf)
c[1] += img.shape[0] * np.clip(np.random.randn()*cf, -2*cf, 2*cf)
if np.random.random() < self.opt.flip:
flipped = True
img = img[:, ::-1, :]
trans_input = get_affine_transform(
c, s, 0, [self.opt.input_res, self.opt.input_res])
inp = cv2.warpAffine(img, trans_input,
(self.opt.input_res, self.opt.input_res),
flags=cv2.INTER_LINEAR)
inp = (inp.astype(np.float32) / 255.)
if self.split == 'train' and not self.opt.no_color_aug:
color_aug(self._data_rng, inp, self._eig_val, self._eig_vec)
inp = (inp - self.mean) / self.std
inp = inp.transpose(2, 0, 1)
output_res = self.opt.output_res
num_classes = self.opt.num_classes
trans_output = get_affine_transform(c, s, 0, [output_res, output_res])
num_hm = 1 if self.opt.agnostic_ex else num_classes
hm_t = np.zeros((num_hm, output_res, output_res), dtype=np.float32)
hm_l = np.zeros((num_hm, output_res, output_res), dtype=np.float32)
hm_b = np.zeros((num_hm, output_res, output_res), dtype=np.float32)
hm_r = np.zeros((num_hm, output_res, output_res), dtype=np.float32)
hm_c = np.zeros((num_classes, output_res, output_res), dtype=np.float32)
reg_t = np.zeros((self.max_objs, 2), dtype=np.float32)
reg_l = np.zeros((self.max_objs, 2), dtype=np.float32)
reg_b = np.zeros((self.max_objs, 2), dtype=np.float32)
reg_r = np.zeros((self.max_objs, 2), dtype=np.float32)
ind_t = np.zeros((self.max_objs), dtype=np.int64)
ind_l = np.zeros((self.max_objs), dtype=np.int64)
ind_b = np.zeros((self.max_objs), dtype=np.int64)
ind_r = np.zeros((self.max_objs), dtype=np.int64)
reg_mask = np.zeros((self.max_objs), dtype=np.uint8)
ann_ids = self.coco.getAnnIds(imgIds=[img_id])
anns = self.coco.loadAnns(ids=ann_ids)
num_objs = min(len(anns), self.max_objs)
draw_gaussian = draw_msra_gaussian if self.opt.mse_loss else \
draw_umich_gaussian
for k in range(num_objs):
ann = anns[k]
# bbox = self._coco_box_to_bbox(ann['bbox'])
# tlbr
pts = np.array(ann['extreme_points'], dtype=np.float32).reshape(4, 2)
# cls_id = int(self.cat_ids[ann['category_id']] - 1) # bug
cls_id = int(self.cat_ids[ann['category_id']])
hm_id = 0 if self.opt.agnostic_ex else cls_id
if flipped:
pts[:, 0] = width - pts[:, 0] - 1
pts[1], pts[3] = pts[3].copy(), pts[1].copy()
for j in range(4):
pts[j] = affine_transform(pts[j], trans_output)
pts = np.clip(pts, 0, self.opt.output_res - 1)
h, w = pts[2, 1] - pts[0, 1], pts[3, 0] - pts[1, 0]
if h > 0 and w > 0:
radius = gaussian_radius((math.ceil(h), math.ceil(w)))
radius = max(0, int(radius))
pt_int = pts.astype(np.int32)
draw_gaussian(hm_t[hm_id], pt_int[0], radius)
draw_gaussian(hm_l[hm_id], pt_int[1], radius)
draw_gaussian(hm_b[hm_id], pt_int[2], radius)
draw_gaussian(hm_r[hm_id], pt_int[3], radius)
reg_t[k] = pts[0] - pt_int[0]
reg_l[k] = pts[1] - pt_int[1]
reg_b[k] = pts[2] - pt_int[2]
reg_r[k] = pts[3] - pt_int[3]
ind_t[k] = pt_int[0, 1] * output_res + pt_int[0, 0]
ind_l[k] = pt_int[1, 1] * output_res + pt_int[1, 0]
ind_b[k] = pt_int[2, 1] * output_res + pt_int[2, 0]
ind_r[k] = pt_int[3, 1] * output_res + pt_int[3, 0]
ct = [int((pts[3, 0] + pts[1, 0]) / 2), int((pts[0, 1] + pts[2, 1]) / 2)]
draw_gaussian(hm_c[cls_id], ct, radius)
reg_mask[k] = 1
ret = {'input': inp, 'hm_t': hm_t, 'hm_l': hm_l, 'hm_b': hm_b,
'hm_r': hm_r, 'hm_c': hm_c}
if self.opt.reg_offset:
ret.update({'reg_mask': reg_mask,
'reg_t': reg_t, 'reg_l': reg_l, 'reg_b': reg_b, 'reg_r': reg_r,
'ind_t': ind_t, 'ind_l': ind_l, 'ind_b': ind_b, 'ind_r': ind_r})
return ret
================================================
FILE: src/lib/datasets/sample/multi_pose.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import torch.utils.data as data
import numpy as np
import torch
import json
import cv2
import os
from utils.image import flip, color_aug
from utils.image import get_affine_transform, affine_transform
from utils.image import gaussian_radius, draw_umich_gaussian, draw_msra_gaussian
from utils.image import draw_dense_reg
import math
class MultiPoseDataset(data.Dataset):
def _coco_box_to_bbox(self, box):
bbox = np.array([box[0], box[1], box[0] + box[2], box[1] + box[3]],
dtype=np.float32)
return bbox
def _get_border(self, border, size):
i = 1
while size - border // i <= border // i:
i *= 2
return border // i
def __getitem__(self, index):
img_id = self.images[index]
file_name = self.coco.loadImgs(ids=[img_id])[0]['file_name']
img_path = os.path.join(self.img_dir, file_name)
ann_ids = self.coco.getAnnIds(imgIds=[img_id])
anns = self.coco.loadAnns(ids=ann_ids)
num_objs = min(len(anns), self.max_objs)
img = cv2.imread(img_path)
height, width = img.shape[0], img.shape[1]
c = np.array([img.shape[1] / 2., img.shape[0] / 2.], dtype=np.float32)
s = max(img.shape[0], img.shape[1]) * 1.0
rot = 0
flipped = False
if self.split == 'train':
if not self.opt.not_rand_crop:
s = s * np.random.choice(np.arange(0.6, 1.4, 0.1))
w_border = self._get_border(128, img.shape[1])
h_border = self._get_border(128, img.shape[0])
c[0] = np.random.randint(low=w_border, high=img.shape[1] - w_border)
c[1] = np.random.randint(low=h_border, high=img.shape[0] - h_border)
else:
sf = self.opt.scale
cf = self.opt.shift
c[0] += s * np.clip(np.random.randn()*cf, -2*cf, 2*cf)
c[1] += s * np.clip(np.random.randn()*cf, -2*cf, 2*cf)
s = s * np.clip(np.random.randn()*sf + 1, 1 - sf, 1 + sf)
if np.random.random() < self.opt.aug_rot:
rf = self.opt.rotate
rot = np.clip(np.random.randn()*rf, -rf*2, rf*2)
if np.random.random() < self.opt.flip:
flipped = True
img = img[:, ::-1, :]
c[0] = width - c[0] - 1
trans_input = get_affine_transform(
c, s, rot, [self.opt.input_res, self.opt.input_res])
inp = cv2.warpAffine(img, trans_input,
(self.opt.input_res, self.opt.input_res),
flags=cv2.INTER_LINEAR)
inp = (inp.astype(np.float32) / 255.)
if self.split == 'train' and not self.opt.no_color_aug:
color_aug(self._data_rng, inp, self._eig_val, self._eig_vec)
inp = (inp - self.mean) / self.std
inp = inp.transpose(2, 0, 1)
output_res = self.opt.output_res
num_joints = self.num_joints
trans_output_rot = get_affine_transform(c, s, rot, [output_res, output_res])
trans_output = get_affine_transform(c, s, 0, [output_res, output_res])
hm = np.zeros((self.num_classes, output_res, output_res), dtype=np.float32)
hm_hp = np.zeros((num_joints, output_res, output_res), dtype=np.float32)
dense_kps = np.zeros((num_joints, 2, output_res, output_res),
dtype=np.float32)
dense_kps_mask = np.zeros((num_joints, output_res, output_res),
dtype=np.float32)
wh = np.zeros((self.max_objs, 2), dtype=np.float32)
kps = np.zeros((self.max_objs, num_joints * 2), dtype=np.float32)
reg = np.zeros((self.max_objs, 2), dtype=np.float32)
ind = np.zeros((self.max_objs), dtype=np.int64)
reg_mask = np.zeros((self.max_objs), dtype=np.uint8)
kps_mask = np.zeros((self.max_objs, self.num_joints * 2), dtype=np.uint8)
hp_offset = np.zeros((self.max_objs * num_joints, 2), dtype=np.float32)
hp_ind = np.zeros((self.max_objs * num_joints), dtype=np.int64)
hp_mask = np.zeros((self.max_objs * num_joints), dtype=np.int64)
draw_gaussian = draw_msra_gaussian if self.opt.mse_loss else \
draw_umich_gaussian
gt_det = []
for k in range(num_objs):
ann = anns[k]
bbox = self._coco_box_to_bbox(ann['bbox'])
cls_id = int(ann['category_id']) - 1
pts = np.array(ann['keypoints'], np.float32).reshape(num_joints, 3)
if flipped:
bbox[[0, 2]] = width - bbox[[2, 0]] - 1
pts[:, 0] = width - pts[:, 0] - 1
for e in self.flip_idx:
pts[e[0]], pts[e[1]] = pts[e[1]].copy(), pts[e[0]].copy()
bbox[:2] = affine_transform(bbox[:2], trans_output)
bbox[2:] = affine_transform(bbox[2:], trans_output)
bbox = np.clip(bbox, 0, output_res - 1)
h, w = bbox[3] - bbox[1], bbox[2] - bbox[0]
if (h > 0 and w > 0) or (rot != 0):
radius = gaussian_radius((math.ceil(h), math.ceil(w)))
radius = self.opt.hm_gauss if self.opt.mse_loss else max(0, int(radius))
ct = np.array(
[(bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2], dtype=np.float32)
ct_int = ct.astype(np.int32)
wh[k] = 1. * w, 1. * h
ind[k] = ct_int[1] * output_res + ct_int[0]
reg[k] = ct - ct_int
reg_mask[k] = 1
num_kpts = pts[:, 2].sum()
if num_kpts == 0:
hm[cls_id, ct_int[1], ct_int[0]] = 0.9999
reg_mask[k] = 0
hp_radius = gaussian_radius((math.ceil(h), math.ceil(w)))
hp_radius = self.opt.hm_gauss \
if self.opt.mse_loss else max(0, int(hp_radius))
for j in range(num_joints):
if pts[j, 2] > 0:
pts[j, :2] = affine_transform(pts[j, :2], trans_output_rot)
if pts[j, 0] >= 0 and pts[j, 0] < output_res and \
pts[j, 1] >= 0 and pts[j, 1] < output_res:
kps[k, j * 2: j * 2 + 2] = pts[j, :2] - ct_int
kps_mask[k, j * 2: j * 2 + 2] = 1
pt_int = pts[j, :2].astype(np.int32)
hp_offset[k * num_joints + j] = pts[j, :2] - pt_int
hp_ind[k * num_joints + j] = pt_int[1] * output_res + pt_int[0]
hp_mask[k * num_joints + j] = 1
if self.opt.dense_hp:
# must be before draw center hm gaussian
draw_dense_reg(dense_kps[j], hm[cls_id], ct_int,
pts[j, :2] - ct_int, radius, is_offset=True)
draw_gaussian(dense_kps_mask[j], ct_int, radius)
draw_gaussian(hm_hp[j], pt_int, hp_radius)
draw_gaussian(hm[cls_id], ct_int, radius)
gt_det.append([ct[0] - w / 2, ct[1] - h / 2,
ct[0] + w / 2, ct[1] + h / 2, 1] +
pts[:, :2].reshape(num_joints * 2).tolist() + [cls_id])
if rot != 0:
hm = hm * 0 + 0.9999
reg_mask *= 0
kps_mask *= 0
ret = {'input': inp, 'hm': hm, 'reg_mask': reg_mask, 'ind': ind, 'wh': wh,
'hps': kps, 'hps_mask': kps_mask}
if self.opt.dense_hp:
dense_kps = dense_kps.reshape(num_joints * 2, output_res, output_res)
dense_kps_mask = dense_kps_mask.reshape(
num_joints, 1, output_res, output_res)
dense_kps_mask = np.concatenate([dense_kps_mask, dense_kps_mask], axis=1)
dense_kps_mask = dense_kps_mask.reshape(
num_joints * 2, output_res, output_res)
ret.update({'dense_hps': dense_kps, 'dense_hps_mask': dense_kps_mask})
del ret['hps'], ret['hps_mask']
if self.opt.reg_offset:
ret.update({'reg': reg})
if self.opt.hm_hp:
ret.update({'hm_hp': hm_hp})
if self.opt.reg_hp_offset:
ret.update({'hp_offset': hp_offset, 'hp_ind': hp_ind, 'hp_mask': hp_mask})
if self.opt.debug > 0 or not self.split == 'train':
gt_det = np.array(gt_det, dtype=np.float32) if len(gt_det) > 0 else \
np.zeros((1, 40), dtype=np.float32)
meta = {'c': c, 's': s, 'gt_det': gt_det, 'img_id': img_id}
ret['meta'] = meta
return ret
================================================
FILE: src/lib/detectors/base_detector.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import cv2
import numpy as np
from progress.bar import Bar
import time
import torch
from models.model import create_model, load_model
from utils.image import get_affine_transform
from utils.debugger import Debugger
class BaseDetector(object):
def __init__(self, opt):
if opt.gpus[0] >= 0:
opt.device = torch.device('cuda')
else:
opt.device = torch.device('cpu')
print('Creating model...')
self.model = create_model(opt.arch, opt.heads, opt.head_conv)
self.model = load_model(self.model, opt.load_model)
self.model = self.model.to(opt.device)
self.model.eval()
self.mean = np.array(opt.mean, dtype=np.float32).reshape(1, 1, 3)
self.std = np.array(opt.std, dtype=np.float32).reshape(1, 1, 3)
self.max_per_image = 100
self.num_classes = opt.num_classes
self.scales = opt.test_scales
self.opt = opt
self.pause = True
def pre_process(self, image, scale, meta=None):
height, width = image.shape[0:2]
new_height = int(height * scale)
new_width = int(width * scale)
if self.opt.fix_res:
inp_height, inp_width = self.opt.input_h, self.opt.input_w
c = np.array([new_width / 2., new_height / 2.], dtype=np.float32)
s = max(height, width) * 1.0
else:
inp_height = (new_height | self.opt.pad) + 1
inp_width = (new_width | self.opt.pad) + 1
c = np.array([new_width // 2, new_height // 2], dtype=np.float32)
s = np.array([inp_width, inp_height], dtype=np.float32)
trans_input = get_affine_transform(c, s, 0, [inp_width, inp_height])
resized_image = cv2.resize(image, (new_width, new_height))
inp_image = cv2.warpAffine(
resized_image, trans_input, (inp_width, inp_height),
flags=cv2.INTER_LINEAR)
inp_image = ((inp_image / 255. - self.mean) / self.std).astype(np.float32)
images = inp_image.transpose(2, 0, 1).reshape(1, 3, inp_height, inp_width)
if self.opt.flip_test:
images = np.concatenate((images, images[:, :, :, ::-1]), axis=0)
images = torch.from_numpy(images)
meta = {'c': c, 's': s,
'out_height': inp_height // self.opt.down_ratio,
'out_width': inp_width // self.opt.down_ratio}
return images, meta
def process(self, images, return_time=False):
raise NotImplementedError
def post_process(self, dets, meta, scale=1):
raise NotImplementedError
def merge_outputs(self, detections):
raise NotImplementedError
def debug(self, debugger, images, dets, output, scale=1):
raise NotImplementedError
def show_results(self, debugger, image, results):
raise NotImplementedError
def run(self, image_or_path_or_tensor, meta=None):
load_time, pre_time, net_time, dec_time, post_time = 0, 0, 0, 0, 0
merge_time, tot_time = 0, 0
debugger = Debugger(dataset=self.opt.dataset, ipynb=(self.opt.debug==3),
theme=self.opt.debugger_theme)
start_time = time.time()
pre_processed = False
if isinstance(image_or_path_or_tensor, np.ndarray):
image = image_or_path_or_tensor
elif type(image_or_path_or_tensor) == type (''):
image = cv2.imread(image_or_path_or_tensor)
else:
image = image_or_path_or_tensor['image'][0].numpy()
pre_processed_images = image_or_path_or_tensor
pre_processed = True
loaded_time = time.time()
load_time += (loaded_time - start_time)
detections = []
for scale in self.scales:
scale_start_time = time.time()
if not pre_processed:
images, meta = self.pre_process(image, scale, meta)
else:
# import pdb; pdb.set_trace()
images = pre_processed_images['images'][scale][0]
meta = pre_processed_images['meta'][scale]
meta = {k: v.numpy()[0] for k, v in meta.items()}
images = images.to(self.opt.device)
torch.cuda.synchronize()
pre_process_time = time.time()
pre_time += pre_process_time - scale_start_time
output, dets, forward_time = self.process(images, return_time=True)
torch.cuda.synchronize()
net_time += forward_time - pre_process_time
decode_time = time.time()
dec_time += decode_time - forward_time
if self.opt.debug >= 2:
self.debug(debugger, images, dets, output, scale)
dets = self.post_process(dets, meta, scale)
torch.cuda.synchronize()
post_process_time = time.time()
post_time += post_process_time - decode_time
detections.append(dets)
results = self.merge_outputs(detections)
torch.cuda.synchronize()
end_time = time.time()
merge_time += end_time - post_process_time
tot_time += end_time - start_time
if self.opt.debug >= 1:
self.show_results(debugger, image, results)
return {'results': results, 'tot': tot_time, 'load': load_time,
'pre': pre_time, 'net': net_time, 'dec': dec_time,
'post': post_time, 'merge': merge_time}
================================================
FILE: src/lib/detectors/ctdet.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import cv2
import numpy as np
from progress.bar import Bar
import time
import torch
try:
from external.nms import soft_nms
except:
print('NMS not imported! If you need it,'
' do \n cd $CenterNet_ROOT/src/lib/external \n make')
from models.decode import ctdet_decode
from models.utils import flip_tensor
from utils.image import get_affine_transform
from utils.post_process import ctdet_post_process
from utils.debugger import Debugger
from .base_detector import BaseDetector
class CtdetDetector(BaseDetector):
def __init__(self, opt):
super(CtdetDetector, self).__init__(opt)
def process(self, images, return_time=False):
with torch.no_grad():
output = self.model(images)[-1]
hm = output['hm'].sigmoid_()
wh = output['wh']
reg = output['reg'] if self.opt.reg_offset else None
if self.opt.flip_test:
hm = (hm[0:1] + flip_tensor(hm[1:2])) / 2
wh = (wh[0:1] + flip_tensor(wh[1:2])) / 2
reg = reg[0:1] if reg is not None else None
torch.cuda.synchronize()
forward_time = time.time()
dets = ctdet_decode(hm, wh, reg=reg, cat_spec_wh=self.opt.cat_spec_wh, K=self.opt.K)
if return_time:
return output, dets, forward_time
else:
return output, dets
def post_process(self, dets, meta, scale=1):
dets = dets.detach().cpu().numpy()
dets = dets.reshape(1, -1, dets.shape[2])
dets = ctdet_post_process(
dets.copy(), [meta['c']], [meta['s']],
meta['out_height'], meta['out_width'], self.opt.num_classes)
for j in range(1, self.num_classes + 1):
dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 5)
dets[0][j][:, :4] /= scale
return dets[0]
def merge_outputs(self, detections):
results = {}
for j in range(1, self.num_classes + 1):
results[j] = np.concatenate(
[detection[j] for detection in detections], axis=0).astype(np.float32)
if len(self.scales) > 1 or self.opt.nms:
soft_nms(results[j], Nt=0.5, method=2)
scores = np.hstack(
[results[j][:, 4] for j in range(1, self.num_classes + 1)])
if len(scores) > self.max_per_image:
kth = len(scores) - self.max_per_image
thresh = np.partition(scores, kth)[kth]
for j in range(1, self.num_classes + 1):
keep_inds = (results[j][:, 4] >= thresh)
results[j] = results[j][keep_inds]
return results
def debug(self, debugger, images, dets, output, scale=1):
detection = dets.detach().cpu().numpy().copy()
detection[:, :, :4] *= self.opt.down_ratio
for i in range(1):
img = images[i].detach().cpu().numpy().transpose(1, 2, 0)
img = ((img * self.std + self.mean) * 255).astype(np.uint8)
pred = debugger.gen_colormap(output['hm'][i].detach().cpu().numpy())
debugger.add_blend_img(img, pred, 'pred_hm_{:.1f}'.format(scale))
debugger.add_img(img, img_id='out_pred_{:.1f}'.format(scale))
for k in range(len(dets[i])):
if detection[i, k, 4] > self.opt.center_thresh:
debugger.add_coco_bbox(detection[i, k, :4], detection[i, k, -1],
detection[i, k, 4],
img_id='out_pred_{:.1f}'.format(scale))
def show_results(self, debugger, image, results):
debugger.add_img(image, img_id='ctdet')
for j in range(1, self.num_classes + 1):
for bbox in results[j]:
if bbox[4] > self.opt.vis_thresh:
debugger.add_coco_bbox(bbox[:4], j - 1, bbox[4], img_id='ctdet')
debugger.show_all_imgs(pause=self.pause)
================================================
FILE: src/lib/detectors/ddd.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import cv2
import numpy as np
from progress.bar import Bar
import time
import torch
from models.decode import ddd_decode
from models.utils import flip_tensor
from utils.image import get_affine_transform
from utils.post_process import ddd_post_process
from utils.debugger import Debugger
from utils.ddd_utils import compute_box_3d, project_to_image, alpha2rot_y
from utils.ddd_utils import draw_box_3d, unproject_2d_to_3d
from .base_detector import BaseDetector
class DddDetector(BaseDetector):
def __init__(self, opt):
super(DddDetector, self).__init__(opt)
self.calib = np.array([[707.0493, 0, 604.0814, 45.75831],
[0, 707.0493, 180.5066, -0.3454157],
[0, 0, 1., 0.004981016]], dtype=np.float32)
def pre_process(self, image, scale, calib=None):
height, width = image.shape[0:2]
inp_height, inp_width = self.opt.input_h, self.opt.input_w
c = np.array([width / 2, height / 2], dtype=np.float32)
if self.opt.keep_res:
s = np.array([inp_width, inp_height], dtype=np.int32)
else:
s = np.array([width, height], dtype=np.int32)
trans_input = get_affine_transform(c, s, 0, [inp_width, inp_height])
resized_image = image #cv2.resize(image, (width, height))
inp_image = cv2.warpAffine(
resized_image, trans_input, (inp_width, inp_height),
flags=cv2.INTER_LINEAR)
inp_image = (inp_image.astype(np.float32) / 255.)
inp_image = (inp_image - self.mean) / self.std
images = inp_image.transpose(2, 0, 1)[np.newaxis, ...]
calib = np.array(calib, dtype=np.float32) if calib is not None \
else self.calib
images = torch.from_numpy(images)
meta = {'c': c, 's': s,
'out_height': inp_height // self.opt.down_ratio,
'out_width': inp_width // self.opt.down_ratio,
'calib': calib}
return images, meta
def process(self, images, return_time=False):
with torch.no_grad():
torch.cuda.synchronize()
output = self.model(images)[-1]
output['hm'] = output['hm'].sigmoid_()
output['dep'] = 1. / (output['dep'].sigmoid() + 1e-6) - 1.
wh = output['wh'] if self.opt.reg_bbox else None
reg = output['reg'] if self.opt.reg_offset else None
torch.cuda.synchronize()
forward_time = time.time()
dets = ddd_decode(output['hm'], output['rot'], output['dep'],
output['dim'], wh=wh, reg=reg, K=self.opt.K)
if return_time:
return output, dets, forward_time
else:
return output, dets
def post_process(self, dets, meta, scale=1):
dets = dets.detach().cpu().numpy()
detections = ddd_post_process(
dets.copy(), [meta['c']], [meta['s']], [meta['calib']], self.opt)
self.this_calib = meta['calib']
return detections[0]
def merge_outputs(self, detections):
results = detections[0]
for j in range(1, self.num_classes + 1):
if len(results[j] > 0):
keep_inds = (results[j][:, -1] > self.opt.peak_thresh)
results[j] = results[j][keep_inds]
return results
def debug(self, debugger, images, dets, output, scale=1):
dets = dets.detach().cpu().numpy()
img = images[0].detach().cpu().numpy().transpose(1, 2, 0)
img = ((img * self.std + self.mean) * 255).astype(np.uint8)
pred = debugger.gen_colormap(output['hm'][0].detach().cpu().numpy())
debugger.add_blend_img(img, pred, 'pred_hm')
debugger.add_ct_detection(
img, dets[0], show_box=self.opt.reg_bbox,
center_thresh=self.opt.vis_thresh, img_id='det_pred')
def show_results(self, debugger, image, results):
debugger.add_3d_detection(
image, results, self.this_calib,
center_thresh=self.opt.vis_thresh, img_id='add_pred')
debugger.add_bird_view(
results, center_thresh=self.opt.vis_thresh, img_id='bird_pred')
debugger.show_all_imgs(pause=self.pause)
================================================
FILE: src/lib/detectors/detector_factory.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from .exdet import ExdetDetector
from .ddd import DddDetector
from .ctdet import CtdetDetector
from .multi_pose import MultiPoseDetector
detector_factory = {
'exdet': ExdetDetector,
'ddd': DddDetector,
'ctdet': CtdetDetector,
'multi_pose': MultiPoseDetector,
}
================================================
FILE: src/lib/detectors/exdet.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import _init_paths
import os
import cv2
import numpy as np
from progress.bar import Bar
import time
import torch
from models.decode import exct_decode, agnex_ct_decode
from models.utils import flip_tensor
from utils.image import get_affine_transform, transform_preds
from utils.post_process import ctdet_post_process
from utils.debugger import Debugger
from .base_detector import BaseDetector
class ExdetDetector(BaseDetector):
def __init__(self, opt):
super(ExdetDetector, self).__init__(opt)
self.decode = agnex_ct_decode if opt.agnostic_ex else exct_decode
def process(self, images, return_time=False):
with torch.no_grad():
torch.cuda.synchronize()
output = self.model(images)[-1]
t_heat = output['hm_t'].sigmoid_()
l_heat = output['hm_l'].sigmoid_()
b_heat = output['hm_b'].sigmoid_()
r_heat = output['hm_r'].sigmoid_()
c_heat = output['hm_c'].sigmoid_()
torch.cuda.synchronize()
forward_time = time.time()
if self.opt.reg_offset:
dets = self.decode(t_heat, l_heat, b_heat, r_heat, c_heat,
output['reg_t'], output['reg_l'],
output['reg_b'], output['reg_r'],
K=self.opt.K,
scores_thresh=self.opt.scores_thresh,
center_thresh=self.opt.center_thresh,
aggr_weight=self.opt.aggr_weight)
else:
dets = self.decode(t_heat, l_heat, b_heat, r_heat, c_heat, K=self.opt.K,
scores_thresh=self.opt.scores_thresh,
center_thresh=self.opt.center_thresh,
aggr_weight=self.opt.aggr_weight)
if return_time:
return output, dets, forward_time
else:
return output, dets
def debug(self, debugger, images, dets, output, scale=1):
detection = dets.detach().cpu().numpy().copy()
detection[:, :, :4] *= self.opt.down_ratio
for i in range(1):
inp_height, inp_width = images.shape[2], images.shape[3]
pred_hm = np.zeros((inp_height, inp_width, 3), dtype=np.uint8)
img = images[i].detach().cpu().numpy().transpose(1, 2, 0)
img = ((img * self.std + self.mean) * 255).astype(np.uint8)
parts = ['t', 'l', 'b', 'r', 'c']
for p in parts:
tag = 'hm_{}'.format(p)
pred = debugger.gen_colormap(
output[tag][i].detach().cpu().numpy(), (inp_height, inp_width))
if p != 'c':
pred_hm = np.maximum(pred_hm, pred)
else:
debugger.add_blend_img(
img, pred, 'pred_{}_{:.1f}'.format(p, scale))
debugger.add_blend_img(img, pred_hm, 'pred_{:.1f}'.format(scale))
debugger.add_img(img, img_id='out_{:.1f}'.format(scale))
for k in range(len(detection[i])):
# print('detection', detection[i, k, 4], detection[i, k])
if detection[i, k, 4] > 0.01:
# print('detection', detection[i, k, 4], detection[i, k])
debugger.add_coco_bbox(detection[i, k, :4], detection[i, k, -1],
detection[i, k, 4],
img_id='out_{:.1f}'.format(scale))
def post_process(self, dets, meta, scale=1):
out_width, out_height = meta['out_width'], meta['out_height']
dets = dets.detach().cpu().numpy().reshape(2, -1, 14)
dets[1, :, [0, 2]] = out_width - dets[1, :, [2, 0]]
dets = dets.reshape(1, -1, 14)
dets[0, :, 0:2] = transform_preds(
dets[0, :, 0:2], meta['c'], meta['s'], (out_width, out_height))
dets[0, :, 2:4] = transform_preds(
dets[0, :, 2:4], meta['c'], meta['s'], (out_width, out_height))
dets[:, :, 0:4] /= scale
return dets[0]
def merge_outputs(self, detections):
detections = np.concatenate(
[detection for detection in detections], axis=0).astype(np.float32)
classes = detections[..., -1]
keep_inds = (detections[:, 4] > 0)
detections = detections[keep_inds]
classes = classes[keep_inds]
results = {}
for j in range(self.num_classes):
keep_inds = (classes == j)
results[j + 1] = detections[keep_inds][:, 0:7].astype(np.float32)
soft_nms(results[j + 1], Nt=0.5, method=2)
results[j + 1] = results[j + 1][:, 0:5]
scores = np.hstack([
results[j][:, -1]
for j in range(1, self.num_classes + 1)
])
if len(scores) > self.max_per_image:
kth = len(scores) - self.max_per_image
thresh = np.partition(scores, kth)[kth]
for j in range(1, self.num_classes + 1):
keep_inds = (results[j][:, -1] >= thresh)
results[j] = results[j][keep_inds]
return results
def show_results(self, debugger, image, results):
debugger.add_img(image, img_id='exdet')
for j in range(1, self.num_classes + 1):
for bbox in results[j]:
if bbox[4] > self.opt.vis_thresh:
debugger.add_coco_bbox(bbox[:4], j - 1, bbox[4], img_id='exdet')
debugger.show_all_imgs(pause=self.pause)
================================================
FILE: src/lib/detectors/multi_pose.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import cv2
import numpy as np
from progress.bar import Bar
import time
import torch
try:
from external.nms import soft_nms_39
except:
print('NMS not imported! If you need it,'
' do \n cd $CenterNet_ROOT/src/lib/external \n make')
from models.decode import multi_pose_decode
from models.utils import flip_tensor, flip_lr_off, flip_lr
from utils.image import get_affine_transform
from utils.post_process import multi_pose_post_process
from utils.debugger import Debugger
from .base_detector import BaseDetector
class MultiPoseDetector(BaseDetector):
def __init__(self, opt):
super(MultiPoseDetector, self).__init__(opt)
self.flip_idx = opt.flip_idx
def process(self, images, return_time=False):
with torch.no_grad():
torch.cuda.synchronize()
output = self.model(images)[-1]
output['hm'] = output['hm'].sigmoid_()
if self.opt.hm_hp and not self.opt.mse_loss:
output['hm_hp'] = output['hm_hp'].sigmoid_()
reg = output['reg'] if self.opt.reg_offset else None
hm_hp = output['hm_hp'] if self.opt.hm_hp else None
hp_offset = output['hp_offset'] if self.opt.reg_hp_offset else None
torch.cuda.synchronize()
forward_time = time.time()
if self.opt.flip_test:
output['hm'] = (output['hm'][0:1] + flip_tensor(output['hm'][1:2])) / 2
output['wh'] = (output['wh'][0:1] + flip_tensor(output['wh'][1:2])) / 2
output['hps'] = (output['hps'][0:1] +
flip_lr_off(output['hps'][1:2], self.flip_idx)) / 2
hm_hp = (hm_hp[0:1] + flip_lr(hm_hp[1:2], self.flip_idx)) / 2 \
if hm_hp is not None else None
reg = reg[0:1] if reg is not None else None
hp_offset = hp_offset[0:1] if hp_offset is not None else None
dets = multi_pose_decode(
output['hm'], output['wh'], output['hps'],
reg=reg, hm_hp=hm_hp, hp_offset=hp_offset, K=self.opt.K)
if return_time:
return output, dets, forward_time
else:
return output, dets
def post_process(self, dets, meta, scale=1):
dets = dets.detach().cpu().numpy().reshape(1, -1, dets.shape[2])
dets = multi_pose_post_process(
dets.copy(), [meta['c']], [meta['s']],
meta['out_height'], meta['out_width'])
for j in range(1, self.num_classes + 1):
dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 39)
# import pdb; pdb.set_trace()
dets[0][j][:, :4] /= scale
dets[0][j][:, 5:] /= scale
return dets[0]
def merge_outputs(self, detections):
results = {}
results[1] = np.concatenate(
[detection[1] for detection in detections], axis=0).astype(np.float32)
if self.opt.nms or len(self.opt.test_scales) > 1:
soft_nms_39(results[1], Nt=0.5, method=2)
results[1] = results[1].tolist()
return results
def debug(self, debugger, images, dets, output, scale=1):
dets = dets.detach().cpu().numpy().copy()
dets[:, :, :4] *= self.opt.down_ratio
dets[:, :, 5:39] *= self.opt.down_ratio
img = images[0].detach().cpu().numpy().transpose(1, 2, 0)
img = np.clip(((
img * self.std + self.mean) * 255.), 0, 255).astype(np.uint8)
pred = debugger.gen_colormap(output['hm'][0].detach().cpu().numpy())
debugger.add_blend_img(img, pred, 'pred_hm')
if self.opt.hm_hp:
pred = debugger.gen_colormap_hp(
output['hm_hp'][0].detach().cpu().numpy())
debugger.add_blend_img(img, pred, 'pred_hmhp')
def show_results(self, debugger, image, results):
debugger.add_img(image, img_id='multi_pose')
for bbox in results[1]:
if bbox[4] > self.opt.vis_thresh:
debugger.add_coco_bbox(bbox[:4], 0, bbox[4], img_id='multi_pose')
debugger.add_coco_hp(bbox[5:39], img_id='multi_pose')
debugger.show_all_imgs(pause=self.pause)
================================================
FILE: src/lib/external/.gitignore
================================================
bbox.c
bbox.cpython-35m-x86_64-linux-gnu.so
bbox.cpython-36m-x86_64-linux-gnu.so
nms.c
nms.cpython-35m-x86_64-linux-gnu.so
nms.cpython-36m-x86_64-linux-gnu.so
================================================
FILE: src/lib/external/Makefile
================================================
all:
python setup.py build_ext --inplace
rm -rf build
================================================
FILE: src/lib/external/__init__.py
================================================
================================================
FILE: src/lib/external/nms.pyx
================================================
# --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
# ----------------------------------------------------------
# Soft-NMS: Improving Object Detection With One Line of Code
# Copyright (c) University of Maryland, College Park
# Licensed under The MIT License [see LICENSE for details]
# Written by Navaneeth Bodla and Bharat Singh
# ----------------------------------------------------------
import numpy as np
cimport numpy as np
cdef inline np.float32_t max(np.float32_t a, np.float32_t b):
return a if a >= b else b
cdef inline np.float32_t min(np.float32_t a, np.float32_t b):
return a if a <= b else b
def nms(np.ndarray[np.float32_t, ndim=2] dets, np.float thresh):
cdef np.ndarray[np.float32_t, ndim=1] x1 = dets[:, 0]
cdef np.ndarray[np.float32_t, ndim=1] y1 = dets[:, 1]
cdef np.ndarray[np.float32_t, ndim=1] x2 = dets[:, 2]
cdef np.ndarray[np.float32_t, ndim=1] y2 = dets[:, 3]
cdef np.ndarray[np.float32_t, ndim=1] scores = dets[:, 4]
cdef np.ndarray[np.float32_t, ndim=1] areas = (x2 - x1 + 1) * (y2 - y1 + 1)
cdef np.ndarray[np.int_t, ndim=1] order = scores.argsort()[::-1]
cdef int ndets = dets.shape[0]
cdef np.ndarray[np.int_t, ndim=1] suppressed = \
np.zeros((ndets), dtype=np.int)
# nominal indices
cdef int _i, _j
# sorted indices
cdef int i, j
# temp variables for box i's (the box currently under consideration)
cdef np.float32_t ix1, iy1, ix2, iy2, iarea
# variables for computing overlap with box j (lower scoring box)
cdef np.float32_t xx1, yy1, xx2, yy2
cdef np.float32_t w, h
cdef np.float32_t inter, ovr
keep = []
for _i in range(ndets):
i = order[_i]
if suppressed[i] == 1:
continue
keep.append(i)
ix1 = x1[i]
iy1 = y1[i]
ix2 = x2[i]
iy2 = y2[i]
iarea = areas[i]
for _j in range(_i + 1, ndets):
j = order[_j]
if suppressed[j] == 1:
continue
xx1 = max(ix1, x1[j])
yy1 = max(iy1, y1[j])
xx2 = min(ix2, x2[j])
yy2 = min(iy2, y2[j])
w = max(0.0, xx2 - xx1 + 1)
h = max(0.0, yy2 - yy1 + 1)
inter = w * h
ovr = inter / (iarea + areas[j] - inter)
if ovr >= thresh:
suppressed[j] = 1
return keep
def soft_nms(np.ndarray[float, ndim=2] boxes, float sigma=0.5, float Nt=0.3, float threshold=0.001, unsigned int method=0):
cdef unsigned int N = boxes.shape[0]
cdef float iw, ih, box_area
cdef float ua
cdef int pos = 0
cdef float maxscore = 0
cdef int maxpos = 0
cdef float x1,x2,y1,y2,tx1,tx2,ty1,ty2,ts,area,weight,ov
for i in range(N):
maxscore = boxes[i, 4]
maxpos = i
tx1 = boxes[i,0]
ty1 = boxes[i,1]
tx2 = boxes[i,2]
ty2 = boxes[i,3]
ts = boxes[i,4]
pos = i + 1
# get max box
while pos < N:
if maxscore < boxes[pos, 4]:
maxscore = boxes[pos, 4]
maxpos = pos
pos = pos + 1
# add max box as a detection
boxes[i,0] = boxes[maxpos,0]
boxes[i,1] = boxes[maxpos,1]
boxes[i,2] = boxes[maxpos,2]
boxes[i,3] = boxes[maxpos,3]
boxes[i,4] = boxes[maxpos,4]
# swap ith box with position of max box
boxes[maxpos,0] = tx1
boxes[maxpos,1] = ty1
boxes[maxpos,2] = tx2
boxes[maxpos,3] = ty2
boxes[maxpos,4] = ts
tx1 = boxes[i,0]
ty1 = boxes[i,1]
tx2 = boxes[i,2]
ty2 = boxes[i,3]
ts = boxes[i,4]
pos = i + 1
# NMS iterations, note that N changes if detection boxes fall below threshold
while pos < N:
x1 = boxes[pos, 0]
y1 = boxes[pos, 1]
x2 = boxes[pos, 2]
y2 = boxes[pos, 3]
s = boxes[pos, 4]
area = (x2 - x1 + 1) * (y2 - y1 + 1)
iw = (min(tx2, x2) - max(tx1, x1) + 1)
if iw > 0:
ih = (min(ty2, y2) - max(ty1, y1) + 1)
if ih > 0:
ua = float((tx2 - tx1 + 1) * (ty2 - ty1 + 1) + area - iw * ih)
ov = iw * ih / ua #iou between max box and detection box
if method == 1: # linear
if ov > Nt:
weight = 1 - ov
else:
weight = 1
elif method == 2: # gaussian
weight = np.exp(-(ov * ov)/sigma)
else: # original NMS
if ov > Nt:
weight = 0
else:
weight = 1
boxes[pos, 4] = weight*boxes[pos, 4]
# if box score falls below threshold, discard the box by swapping with last box
# update N
if boxes[pos, 4] < threshold:
boxes[pos,0] = boxes[N-1, 0]
boxes[pos,1] = boxes[N-1, 1]
boxes[pos,2] = boxes[N-1, 2]
boxes[pos,3] = boxes[N-1, 3]
boxes[pos,4] = boxes[N-1, 4]
N = N - 1
pos = pos - 1
pos = pos + 1
keep = [i for i in range(N)]
return keep
def soft_nms_39(np.ndarray[float, ndim=2] boxes, float sigma=0.5, float Nt=0.3, float threshold=0.001, unsigned int method=0):
cdef unsigned int N = boxes.shape[0]
cdef float iw, ih, box_area
cdef float ua
cdef int pos = 0
cdef float maxscore = 0
cdef int maxpos = 0
cdef float x1,x2,y1,y2,tx1,tx2,ty1,ty2,ts,area,weight,ov
cdef float tmp
for i in range(N):
maxscore = boxes[i, 4]
maxpos = i
tx1 = boxes[i,0]
ty1 = boxes[i,1]
tx2 = boxes[i,2]
ty2 = boxes[i,3]
ts = boxes[i,4]
pos = i + 1
# get max box
while pos < N:
if maxscore < boxes[pos, 4]:
maxscore = boxes[pos, 4]
maxpos = pos
pos = pos + 1
# add max box as a detection
boxes[i,0] = boxes[maxpos,0]
boxes[i,1] = boxes[maxpos,1]
boxes[i,2] = boxes[maxpos,2]
boxes[i,3] = boxes[maxpos,3]
boxes[i,4] = boxes[maxpos,4]
# swap ith box with position of max box
boxes[maxpos,0] = tx1
boxes[maxpos,1] = ty1
boxes[maxpos,2] = tx2
boxes[maxpos,3] = ty2
boxes[maxpos,4] = ts
for j in range(5, 39):
tmp = boxes[i, j]
boxes[i, j] = boxes[maxpos, j]
boxes[maxpos, j] = tmp
tx1 = boxes[i,0]
ty1 = boxes[i,1]
tx2 = boxes[i,2]
ty2 = boxes[i,3]
ts = boxes[i,4]
pos = i + 1
# NMS iterations, note that N changes if detection boxes fall below threshold
while pos < N:
x1 = boxes[pos, 0]
y1 = boxes[pos, 1]
x2 = boxes[pos, 2]
y2 = boxes[pos, 3]
s = boxes[pos, 4]
area = (x2 - x1 + 1) * (y2 - y1 + 1)
iw = (min(tx2, x2) - max(tx1, x1) + 1)
if iw > 0:
ih = (min(ty2, y2) - max(ty1, y1) + 1)
if ih > 0:
ua = float((tx2 - tx1 + 1) * (ty2 - ty1 + 1) + area - iw * ih)
ov = iw * ih / ua #iou between max box and detection box
if method == 1: # linear
if ov > Nt:
weight = 1 - ov
else:
weight = 1
elif method == 2: # gaussian
weight = np.exp(-(ov * ov)/sigma)
else: # original NMS
if ov > Nt:
weight = 0
else:
weight = 1
boxes[pos, 4] = weight*boxes[pos, 4]
# if box score falls below threshold, discard the box by swapping with last box
# update N
if boxes[pos, 4] < threshold:
boxes[pos,0] = boxes[N-1, 0]
boxes[pos,1] = boxes[N-1, 1]
boxes[pos,2] = boxes[N-1, 2]
boxes[pos,3] = boxes[N-1, 3]
boxes[pos,4] = boxes[N-1, 4]
for j in range(5, 39):
tmp = boxes[pos, j]
boxes[pos, j] = boxes[N - 1, j]
boxes[N - 1, j] = tmp
N = N - 1
pos = pos - 1
pos = pos + 1
keep = [i for i in range(N)]
return keep
def soft_nms_merge(np.ndarray[float, ndim=2] boxes, float sigma=0.5, float Nt=0.3, float threshold=0.001, unsigned int method=0, float weight_exp=6):
cdef unsigned int N = boxes.shape[0]
cdef float iw, ih, box_area
cdef float ua
cdef int pos = 0
cdef float maxscore = 0
cdef int maxpos = 0
cdef float x1,x2,y1,y2,tx1,tx2,ty1,ty2,ts,area,weight,ov
cdef float mx1,mx2,my1,my2,mts,mbs,mw
for i in range(N):
maxscore = boxes[i, 4]
maxpos = i
tx1 = boxes[i,0]
ty1 = boxes[i,1]
tx2 = boxes[i,2]
ty2 = boxes[i,3]
ts = boxes[i,4]
pos = i + 1
# get max box
while pos < N:
if maxscore < boxes[pos, 4]:
maxscore = boxes[pos, 4]
maxpos = pos
pos = pos + 1
# add max box as a detection
boxes[i,0] = boxes[maxpos,0]
boxes[i,1] = boxes[maxpos,1]
boxes[i,2] = boxes[maxpos,2]
boxes[i,3] = boxes[maxpos,3]
boxes[i,4] = boxes[maxpos,4]
mx1 = boxes[i, 0] * boxes[i, 5]
my1 = boxes[i, 1] * boxes[i, 5]
mx2 = boxes[i, 2] * boxes[i, 6]
my2 = boxes[i, 3] * boxes[i, 6]
mts = boxes[i, 5]
mbs = boxes[i, 6]
# swap ith box with position of max box
boxes[maxpos,0] = tx1
boxes[maxpos,1] = ty1
boxes[maxpos,2] = tx2
boxes[maxpos,3] = ty2
boxes[maxpos,4] = ts
tx1 = boxes[i,0]
ty1 = boxes[i,1]
tx2 = boxes[i,2]
ty2 = boxes[i,3]
ts = boxes[i,4]
pos = i + 1
# NMS iterations, note that N changes if detection boxes fall below threshold
while pos < N:
x1 = boxes[pos, 0]
y1 = boxes[pos, 1]
x2 = boxes[pos, 2]
y2 = boxes[pos, 3]
s = boxes[pos, 4]
area = (x2 - x1 + 1) * (y2 - y1 + 1)
iw = (min(tx2, x2) - max(tx1, x1) + 1)
if iw > 0:
ih = (min(ty2, y2) - max(ty1, y1) + 1)
if ih > 0:
ua = float((tx2 - tx1 + 1) * (ty2 - ty1 + 1) + area - iw * ih)
ov = iw * ih / ua #iou between max box and detection box
if method == 1: # linear
if ov > Nt:
weight = 1 - ov
else:
weight = 1
elif method == 2: # gaussian
weight = np.exp(-(ov * ov)/sigma)
else: # original NMS
if ov > Nt:
weight = 0
else:
weight = 1
mw = (1 - weight) ** weight_exp
mx1 = mx1 + boxes[pos, 0] * boxes[pos, 5] * mw
my1 = my1 + boxes[pos, 1] * boxes[pos, 5] * mw
mx2 = mx2 + boxes[pos, 2] * boxes[pos, 6] * mw
my2 = my2 + boxes[pos, 3] * boxes[pos, 6] * mw
mts = mts + boxes[pos, 5] * mw
mbs = mbs + boxes[pos, 6] * mw
boxes[pos, 4] = weight*boxes[pos, 4]
# if box score falls below threshold, discard the box by swapping with last box
# update N
if boxes[pos, 4] < threshold:
boxes[pos,0] = boxes[N-1, 0]
boxes[pos,1] = boxes[N-1, 1]
boxes[pos,2] = boxes[N-1, 2]
boxes[pos,3] = boxes[N-1, 3]
boxes[pos,4] = boxes[N-1, 4]
N = N - 1
pos = pos - 1
pos = pos + 1
boxes[i, 0] = mx1 / mts
boxes[i, 1] = my1 / mts
boxes[i, 2] = mx2 / mbs
boxes[i, 3] = my2 / mbs
keep = [i for i in range(N)]
return keep
================================================
FILE: src/lib/external/setup.py
================================================
import numpy
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
extensions = [
Extension(
"nms",
["nms.pyx"],
extra_compile_args=["-Wno-cpp", "-Wno-unused-function"]
)
]
setup(
name="coco",
ext_modules=cythonize(extensions),
include_dirs=[numpy.get_include()]
)
================================================
FILE: src/lib/logger.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
# Code referenced from https://gist.github.com/gyglim/1f8dfb1b5c82627ae3efcfbbadb9f514
import os
import time
import sys
import torch
USE_TENSORBOARD = True
try:
import tensorboardX
print('Using tensorboardX')
except:
USE_TENSORBOARD = False
class Logger(object):
def __init__(self, opt):
"""Create a summary writer logging to log_dir."""
if not os.path.exists(opt.save_dir):
os.makedirs(opt.save_dir)
if not os.path.exists(opt.debug_dir):
os.makedirs(opt.debug_dir)
time_str = time.strftime('%Y-%m-%d-%H-%M')
args = dict((name, getattr(opt, name)) for name in dir(opt)
if not name.startswith('_'))
file_name = os.path.join(opt.save_dir, 'opt.txt')
with open(file_name, 'wt') as opt_file:
opt_file.write('==> torch version: {}\n'.format(torch.__version__))
opt_file.write('==> cudnn version: {}\n'.format(
torch.backends.cudnn.version()))
opt_file.write('==> Cmd:\n')
opt_file.write(str(sys.argv))
opt_file.write('\n==> Opt:\n')
for k, v in sorted(args.items()):
opt_file.write(' %s: %s\n' % (str(k), str(v)))
log_dir = opt.save_dir + '/logs_{}'.format(time_str)
if USE_TENSORBOARD:
self.writer = tensorboardX.SummaryWriter(log_dir=log_dir)
else:
if not os.path.exists(os.path.dirname(log_dir)):
os.mkdir(os.path.dirname(log_dir))
if not os.path.exists(log_dir):
os.mkdir(log_dir)
self.log = open(log_dir + '/log.txt', 'w')
try:
os.system('cp {}/opt.txt {}/'.format(opt.save_dir, log_dir))
except:
pass
self.start_line = True
def write(self, txt):
if self.start_line:
time_str = time.strftime('%Y-%m-%d-%H-%M')
self.log.write('{}: {}'.format(time_str, txt))
else:
self.log.write(txt)
self.start_line = False
if '\n' in txt:
self.start_line = True
self.log.flush()
def close(self):
self.log.close()
def scalar_summary(self, tag, value, step):
"""Log a scalar variable."""
if USE_TENSORBOARD:
self.writer.add_scalar(tag, value, step)
================================================
FILE: src/lib/models/data_parallel.py
================================================
import torch
from torch.nn.modules import Module
from torch.nn.parallel.scatter_gather import gather
from torch.nn.parallel.replicate import replicate
from torch.nn.parallel.parallel_apply import parallel_apply
from .scatter_gather import scatter_kwargs
class _DataParallel(Module):
r"""Implements data parallelism at the module level.
This container parallelizes the application of the given module by
splitting the input across the specified devices by chunking in the batch
dimension. In the forward pass, the module is replicated on each device,
and each replica handles a portion of the input. During the backwards
pass, gradients from each replica are summed into the original module.
The batch size should be larger than the number of GPUs used. It should
also be an integer multiple of the number of GPUs so that each chunk is the
same size (so that each GPU processes the same number of samples).
See also: :ref:`cuda-nn-dataparallel-instead`
Arbitrary positional and keyword inputs are allowed to be passed into
DataParallel EXCEPT Tensors. All variables will be scattered on dim
specified (default 0). Primitive types will be broadcasted, but all
other types will be a shallow copy and can be corrupted if written to in
the model's forward pass.
Args:
module: module to be parallelized
device_ids: CUDA devices (default: all devices)
output_device: device location of output (default: device_ids[0])
Example::
>>> net = torch.nn.DataParallel(model, device_ids=[0, 1, 2])
>>> output = net(input_var)
"""
# TODO: update notes/cuda.rst when this class handles 8+ GPUs well
def __init__(self, module, device_ids=None, output_device=None, dim=0, chunk_sizes=None):
super(_DataParallel, self).__init__()
if not torch.cuda.is_available():
self.module = module
self.device_ids = []
return
if device_ids is None:
device_ids = list(range(torch.cuda.device_count()))
if output_device is None:
output_device = device_ids[0]
self.dim = dim
self.module = module
self.device_ids = device_ids
self.chunk_sizes = chunk_sizes
self.output_device = output_device
if len(self.device_ids) == 1:
self.module.cuda(device_ids[0])
def forward(self, *inputs, **kwargs):
if not self.device_ids:
return self.module(*inputs, **kwargs)
inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids, self.chunk_sizes)
if len(self.device_ids) == 1:
return self.module(*inputs[0], **kwargs[0])
replicas = self.replicate(self.module, self.device_ids[:len(inputs)])
outputs = self.parallel_apply(replicas, inputs, kwargs)
return self.gather(outputs, self.output_device)
def replicate(self, module, device_ids):
return replicate(module, device_ids)
def scatter(self, inputs, kwargs, device_ids, chunk_sizes):
return scatter_kwargs(inputs, kwargs, device_ids, dim=self.dim, chunk_sizes=self.chunk_sizes)
def parallel_apply(self, replicas, inputs, kwargs):
return parallel_apply(replicas, inputs, kwargs, self.device_ids[:len(replicas)])
def gather(self, outputs, output_device):
return gather(outputs, output_device, dim=self.dim)
def data_parallel(module, inputs, device_ids=None, output_device=None, dim=0, module_kwargs=None):
r"""Evaluates module(input) in parallel across the GPUs given in device_ids.
This is the functional version of the DataParallel module.
Args:
module: the module to evaluate in parallel
inputs: inputs to the module
device_ids: GPU ids on which to replicate module
output_device: GPU location of the output Use -1 to indicate the CPU.
(default: device_ids[0])
Returns:
a Variable containing the result of module(input) located on
output_device
"""
if not isinstance(inputs, tuple):
inputs = (inputs,)
if device_ids is None:
device_ids = list(range(torch.cuda.device_count()))
if output_device is None:
output_device = device_ids[0]
inputs, module_kwargs = scatter_kwargs(inputs, module_kwargs, device_ids, dim)
if len(device_ids) == 1:
return module(*inputs[0], **module_kwargs[0])
used_device_ids = device_ids[:len(inputs)]
replicas = replicate(module, used_device_ids)
outputs = parallel_apply(replicas, inputs, module_kwargs, used_device_ids)
return gather(outputs, output_device, dim)
def DataParallel(module, device_ids=None, output_device=None, dim=0, chunk_sizes=None):
if chunk_sizes is None:
return torch.nn.DataParallel(module, device_ids, output_device, dim)
standard_size = True
for i in range(1, len(chunk_sizes)):
if chunk_sizes[i] != chunk_sizes[0]:
standard_size = False
if standard_size:
return torch.nn.DataParallel(module, device_ids, output_device, dim)
return _DataParallel(module, device_ids, output_device, dim, chunk_sizes)
================================================
FILE: src/lib/models/decode.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import torch
import torch.nn as nn
from .utils import _gather_feat, _transpose_and_gather_feat
def _nms(heat, kernel=3):
pad = (kernel - 1) // 2
hmax = nn.functional.max_pool2d(
heat, (kernel, kernel), stride=1, padding=pad)
keep = (hmax == heat).float()
return heat * keep
def _left_aggregate(heat):
'''
heat: batchsize x channels x h x w
'''
shape = heat.shape
heat = heat.reshape(-1, heat.shape[3])
heat = heat.transpose(1, 0).contiguous()
ret = heat.clone()
for i in range(1, heat.shape[0]):
inds = (heat[i] >= heat[i - 1])
ret[i] += ret[i - 1] * inds.float()
return (ret - heat).transpose(1, 0).reshape(shape)
def _right_aggregate(heat):
'''
heat: batchsize x channels x h x w
'''
shape = heat.shape
heat = heat.reshape(-1, heat.shape[3])
heat = heat.transpose(1, 0).contiguous()
ret = heat.clone()
for i in range(heat.shape[0] - 2, -1, -1):
inds = (heat[i] >= heat[i +1])
ret[i] += ret[i + 1] * inds.float()
return (ret - heat).transpose(1, 0).reshape(shape)
def _top_aggregate(heat):
'''
heat: batchsize x channels x h x w
'''
heat = heat.transpose(3, 2)
shape = heat.shape
heat = heat.reshape(-1, heat.shape[3])
heat = heat.transpose(1, 0).contiguous()
ret = heat.clone()
for i in range(1, heat.shape[0]):
inds = (heat[i] >= heat[i - 1])
ret[i] += ret[i - 1] * inds.float()
return (ret - heat).transpose(1, 0).reshape(shape).transpose(3, 2)
def _bottom_aggregate(heat):
'''
heat: batchsize x channels x h x w
'''
heat = heat.transpose(3, 2)
shape = heat.shape
heat = heat.reshape(-1, heat.shape[3])
heat = heat.transpose(1, 0).contiguous()
ret = heat.clone()
for i in range(heat.shape[0] - 2, -1, -1):
inds = (heat[i] >= heat[i + 1])
ret[i] += ret[i + 1] * inds.float()
return (ret - heat).transpose(1, 0).reshape(shape).transpose(3, 2)
def _h_aggregate(heat, aggr_weight=0.1):
return aggr_weight * _left_aggregate(heat) + \
aggr_weight * _right_aggregate(heat) + heat
def _v_aggregate(heat, aggr_weight=0.1):
return aggr_weight * _top_aggregate(heat) + \
aggr_weight * _bottom_aggregate(heat) + heat
'''
# Slow for large number of categories
def _topk(scores, K=40):
batch, cat, height, width = scores.size()
topk_scores, topk_inds = torch.topk(scores.view(batch, -1), K)
topk_clses = (topk_inds / (height * width)).int()
topk_inds = topk_inds % (height * width)
topk_ys = (topk_inds / width).int().float()
topk_xs = (topk_inds % width).int().float()
return topk_scores, topk_inds, topk_clses, topk_ys, topk_xs
'''
def _topk_channel(scores, K=40):
batch, cat, height, width = scores.size()
topk_scores, topk_inds = torch.topk(scores.view(batch, cat, -1), K)
topk_inds = topk_inds % (height * width)
topk_ys = (topk_inds / width).int().float()
topk_xs = (topk_inds % width).int().float()
return topk_scores, topk_inds, topk_ys, topk_xs
def _topk(scores, K=40):
batch, cat, height, width = scores.size()
topk_scores, topk_inds = torch.topk(scores.view(batch, cat, -1), K)
topk_inds = topk_inds % (height * width)
topk_ys = (topk_inds / width).int().float()
topk_xs = (topk_inds % width).int().float()
topk_score, topk_ind = torch.topk(topk_scores.view(batch, -1), K)
topk_clses = (topk_ind / K).int()
topk_inds = _gather_feat(
topk_inds.view(batch, -1, 1), topk_ind).view(batch, K)
topk_ys = _gather_feat(topk_ys.view(batch, -1, 1), topk_ind).view(batch, K)
topk_xs = _gather_feat(topk_xs.view(batch, -1, 1), topk_ind).view(batch, K)
return topk_score, topk_inds, topk_clses, topk_ys, topk_xs
def agnex_ct_decode(
t_heat, l_heat, b_heat, r_heat, ct_heat,
t_regr=None, l_regr=None, b_regr=None, r_regr=None,
K=40, scores_thresh=0.1, center_thresh=0.1, aggr_weight=0.0, num_dets=1000
):
batch, cat, height, width = t_heat.size()
'''
t_heat = torch.sigmoid(t_heat)
l_heat = torch.sigmoid(l_heat)
b_heat = torch.sigmoid(b_heat)
r_heat = torch.sigmoid(r_heat)
ct_heat = torch.sigmoid(ct_heat)
'''
if aggr_weight > 0:
t_heat = _h_aggregate(t_heat, aggr_weight=aggr_weight)
l_heat = _v_aggregate(l_heat, aggr_weight=aggr_weight)
b_heat = _h_aggregate(b_heat, aggr_weight=aggr_weight)
r_heat = _v_aggregate(r_heat, aggr_weight=aggr_weight)
# perform nms on heatmaps
t_heat = _nms(t_heat)
l_heat = _nms(l_heat)
b_heat = _nms(b_heat)
r_heat = _nms(r_heat)
t_heat[t_heat > 1] = 1
l_heat[l_heat > 1] = 1
b_heat[b_heat > 1] = 1
r_heat[r_heat > 1] = 1
t_scores, t_inds, _, t_ys, t_xs = _topk(t_heat, K=K)
l_scores, l_inds, _, l_ys, l_xs = _topk(l_heat, K=K)
b_scores, b_inds, _, b_ys, b_xs = _topk(b_heat, K=K)
r_scores, r_inds, _, r_ys, r_xs = _topk(r_heat, K=K)
ct_heat_agn, ct_clses = torch.max(ct_heat, dim=1, keepdim=True)
# import pdb; pdb.set_trace()
t_ys = t_ys.view(batch, K, 1, 1, 1).expand(batch, K, K, K, K)
t_xs = t_xs.view(batch, K, 1, 1, 1).expand(batch, K, K, K, K)
l_ys = l_ys.view(batch, 1, K, 1, 1).expand(batch, K, K, K, K)
l_xs = l_xs.view(batch, 1, K, 1, 1).expand(batch, K, K, K, K)
b_ys = b_ys.view(batch, 1, 1, K, 1).expand(batch, K, K, K, K)
b_xs = b_xs.view(batch, 1, 1, K, 1).expand(batch, K, K, K, K)
r_ys = r_ys.view(batch, 1, 1, 1, K).expand(batch, K, K, K, K)
r_xs = r_xs.view(batch, 1, 1, 1, K).expand(batch, K, K, K, K)
box_ct_xs = ((l_xs + r_xs + 0.5) / 2).long()
box_ct_ys = ((t_ys + b_ys + 0.5) / 2).long()
ct_inds = box_ct_ys * width + box_ct_xs
ct_inds = ct_inds.view(batch, -1)
ct_heat_agn = ct_heat_agn.view(batch, -1, 1)
ct_clses = ct_clses.view(batch, -1, 1)
ct_scores = _gather_feat(ct_heat_agn, ct_inds)
clses = _gather_feat(ct_clses, ct_inds)
t_scores = t_scores.view(batch, K, 1, 1, 1).expand(batch, K, K, K, K)
l_scores = l_scores.view(batch, 1, K, 1, 1).expand(batch, K, K, K, K)
b_scores = b_scores.view(batch, 1, 1, K, 1).expand(batch, K, K, K, K)
r_scores = r_scores.view(batch, 1, 1, 1, K).expand(batch, K, K, K, K)
ct_scores = ct_scores.view(batch, K, K, K, K)
scores = (t_scores + l_scores + b_scores + r_scores + 2 * ct_scores) / 6
# reject boxes based on classes
top_inds = (t_ys > l_ys) + (t_ys > b_ys) + (t_ys > r_ys)
top_inds = (top_inds > 0)
left_inds = (l_xs > t_xs) + (l_xs > b_xs) + (l_xs > r_xs)
left_inds = (left_inds > 0)
bottom_inds = (b_ys < t_ys) + (b_ys < l_ys) + (b_ys < r_ys)
bottom_inds = (bottom_inds > 0)
right_inds = (r_xs < t_xs) + (r_xs < l_xs) + (r_xs < b_xs)
right_inds = (right_inds > 0)
sc_inds = (t_scores < scores_thresh) + (l_scores < scores_thresh) + \
(b_scores < scores_thresh) + (r_scores < scores_thresh) + \
(ct_scores < center_thresh)
sc_inds = (sc_inds > 0)
scores = scores - sc_inds.float()
scores = scores - top_inds.float()
scores = scores - left_inds.float()
scores = scores - bottom_inds.float()
scores = scores - right_inds.float()
scores = scores.view(batch, -1)
scores, inds = torch.topk(scores, num_dets)
scores = scores.unsqueeze(2)
if t_regr is not None and l_regr is not None \
and b_regr is not None and r_regr is not None:
t_regr = _transpose_and_gather_feat(t_regr, t_inds)
t_regr = t_regr.view(batch, K, 1, 1, 1, 2)
l_regr = _transpose_and_gather_feat(l_regr, l_inds)
l_regr = l_regr.view(batch, 1, K, 1, 1, 2)
b_regr = _transpose_and_gather_feat(b_regr, b_inds)
b_regr = b_regr.view(batch, 1, 1, K, 1, 2)
r_regr = _transpose_and_gather_feat(r_regr, r_inds)
r_regr = r_regr.view(batch, 1, 1, 1, K, 2)
t_xs = t_xs + t_regr[..., 0]
t_ys = t_ys + t_regr[..., 1]
l_xs = l_xs + l_regr[..., 0]
l_ys = l_ys + l_regr[..., 1]
b_xs = b_xs + b_regr[..., 0]
b_ys = b_ys + b_regr[..., 1]
r_xs = r_xs + r_regr[..., 0]
r_ys = r_ys + r_regr[..., 1]
else:
t_xs = t_xs + 0.5
t_ys = t_ys + 0.5
l_xs = l_xs + 0.5
l_ys = l_ys + 0.5
b_xs = b_xs + 0.5
b_ys = b_ys + 0.5
r_xs = r_xs + 0.5
r_ys = r_ys + 0.5
bboxes = torch.stack((l_xs, t_ys, r_xs, b_ys), dim=5)
bboxes = bboxes.view(batch, -1, 4)
bboxes = _gather_feat(bboxes, inds)
clses = clses.contiguous().view(batch, -1, 1)
clses = _gather_feat(clses, inds).float()
t_xs = t_xs.contiguous().view(batch, -1, 1)
t_xs = _gather_feat(t_xs, inds).float()
t_ys = t_ys.contiguous().view(batch, -1, 1)
t_ys = _gather_feat(t_ys, inds).float()
l_xs = l_xs.contiguous().view(batch, -1, 1)
l_xs = _gather_feat(l_xs, inds).float()
l_ys = l_ys.contiguous().view(batch, -1, 1)
l_ys = _gather_feat(l_ys, inds).float()
b_xs = b_xs.contiguous().view(batch, -1, 1)
b_xs = _gather_feat(b_xs, inds).float()
b_ys = b_ys.contiguous().view(batch, -1, 1)
b_ys = _gather_feat(b_ys, inds).float()
r_xs = r_xs.contiguous().view(batch, -1, 1)
r_xs = _gather_feat(r_xs, inds).float()
r_ys = r_ys.contiguous().view(batch, -1, 1)
r_ys = _gather_feat(r_ys, inds).float()
detections = torch.cat([bboxes, scores, t_xs, t_ys, l_xs, l_ys,
b_xs, b_ys, r_xs, r_ys, clses], dim=2)
return detections
def exct_decode(
t_heat, l_heat, b_heat, r_heat, ct_heat,
t_regr=None, l_regr=None, b_regr=None, r_regr=None,
K=40, scores_thresh=0.1, center_thresh=0.1, aggr_weight=0.0, num_dets=1000
):
batch, cat, height, width = t_heat.size()
'''
t_heat = torch.sigmoid(t_heat)
l_heat = torch.sigmoid(l_heat)
b_heat = torch.sigmoid(b_heat)
r_heat = torch.sigmoid(r_heat)
ct_heat = torch.sigmoid(ct_heat)
'''
if aggr_weight > 0:
t_heat = _h_aggregate(t_heat, aggr_weight=aggr_weight)
l_heat = _v_aggregate(l_heat, aggr_weight=aggr_weight)
b_heat = _h_aggregate(b_heat, aggr_weight=aggr_weight)
r_heat = _v_aggregate(r_heat, aggr_weight=aggr_weight)
# perform nms on heatmaps
t_heat = _nms(t_heat)
l_heat = _nms(l_heat)
b_heat = _nms(b_heat)
r_heat = _nms(r_heat)
t_heat[t_heat > 1] = 1
l_heat[l_heat > 1] = 1
b_heat[b_heat > 1] = 1
r_heat[r_heat > 1] = 1
t_scores, t_inds, t_clses, t_ys, t_xs = _topk(t_heat, K=K)
l_scores, l_inds, l_clses, l_ys, l_xs = _topk(l_heat, K=K)
b_scores, b_inds, b_clses, b_ys, b_xs = _topk(b_heat, K=K)
r_scores, r_inds, r_clses, r_ys, r_xs = _topk(r_heat, K=K)
t_ys = t_ys.view(batch, K, 1, 1, 1).expand(batch, K, K, K, K)
t_xs = t_xs.view(batch, K, 1, 1, 1).expand(batch, K, K, K, K)
l_ys = l_ys.view(batch, 1, K, 1, 1).expand(batch, K, K, K, K)
l_xs = l_xs.view(batch, 1, K, 1, 1).expand(batch, K, K, K, K)
b_ys = b_ys.view(batch, 1, 1, K, 1).expand(batch, K, K, K, K)
b_xs = b_xs.view(batch, 1, 1, K, 1).expand(batch, K, K, K, K)
r_ys = r_ys.view(batch, 1, 1, 1, K).expand(batch, K, K, K, K)
r_xs = r_xs.view(batch, 1, 1, 1, K).expand(batch, K, K, K, K)
t_clses = t_clses.view(batch, K, 1, 1, 1).expand(batch, K, K, K, K)
l_clses = l_clses.view(batch, 1, K, 1, 1).expand(batch, K, K, K, K)
b_clses = b_clses.view(batch, 1, 1, K, 1).expand(batch, K, K, K, K)
r_clses = r_clses.view(batch, 1, 1, 1, K).expand(batch, K, K, K, K)
box_ct_xs = ((l_xs + r_xs + 0.5) / 2).long()
box_ct_ys = ((t_ys + b_ys + 0.5) / 2).long()
ct_inds = t_clses.long() * (height * width) + box_ct_ys * width + box_ct_xs
ct_inds = ct_inds.view(batch, -1)
ct_heat = ct_heat.view(batch, -1, 1)
ct_scores = _gather_feat(ct_heat, ct_inds)
t_scores = t_scores.view(batch, K, 1, 1, 1).expand(batch, K, K, K, K)
l_scores = l_scores.view(batch, 1, K, 1, 1).expand(batch, K, K, K, K)
b_scores = b_scores.view(batch, 1, 1, K, 1).expand(batch, K, K, K, K)
r_scores = r_scores.view(batch, 1, 1, 1, K).expand(batch, K, K, K, K)
ct_scores = ct_scores.view(batch, K, K, K, K)
scores = (t_scores + l_scores + b_scores + r_scores + 2 * ct_scores) / 6
# reject boxes based on classes
cls_inds = (t_clses != l_clses) + (t_clses != b_clses) + \
(t_clses != r_clses)
cls_inds = (cls_inds > 0)
top_inds = (t_ys > l_ys) + (t_ys > b_ys) + (t_ys > r_ys)
top_inds = (top_inds > 0)
left_inds = (l_xs > t_xs) + (l_xs > b_xs) + (l_xs > r_xs)
left_inds = (left_inds > 0)
bottom_inds = (b_ys < t_ys) + (b_ys < l_ys) + (b_ys < r_ys)
bottom_inds = (bottom_inds > 0)
right_inds = (r_xs < t_xs) + (r_xs < l_xs) + (r_xs < b_xs)
right_inds = (right_inds > 0)
sc_inds = (t_scores < scores_thresh) + (l_scores < scores_thresh) + \
(b_scores < scores_thresh) + (r_scores < scores_thresh) + \
(ct_scores < center_thresh)
sc_inds = (sc_inds > 0)
scores = scores - sc_inds.float()
scores = scores - cls_inds.float()
scores = scores - top_inds.float()
scores = scores - left_inds.float()
scores = scores - bottom_inds.float()
scores = scores - right_inds.float()
scores = scores.view(batch, -1)
scores, inds = torch.topk(scores, num_dets)
scores = scores.unsqueeze(2)
if t_regr is not None and l_regr is not None \
and b_regr is not None and r_regr is not None:
t_regr = _transpose_and_gather_feat(t_regr, t_inds)
t_regr = t_regr.view(batch, K, 1, 1, 1, 2)
l_regr = _transpose_and_gather_feat(l_regr, l_inds)
l_regr = l_regr.view(batch, 1, K, 1, 1, 2)
b_regr = _transpose_and_gather_feat(b_regr, b_inds)
b_regr = b_regr.view(batch, 1, 1, K, 1, 2)
r_regr = _transpose_and_gather_feat(r_regr, r_inds)
r_regr = r_regr.view(batch, 1, 1, 1, K, 2)
t_xs = t_xs + t_regr[..., 0]
t_ys = t_ys + t_regr[..., 1]
l_xs = l_xs + l_regr[..., 0]
l_ys = l_ys + l_regr[..., 1]
b_xs = b_xs + b_regr[..., 0]
b_ys = b_ys + b_regr[..., 1]
r_xs = r_xs + r_regr[..., 0]
r_ys = r_ys + r_regr[..., 1]
else:
t_xs = t_xs + 0.5
t_ys = t_ys + 0.5
l_xs = l_xs + 0.5
l_ys = l_ys + 0.5
b_xs = b_xs + 0.5
b_ys = b_ys + 0.5
r_xs = r_xs + 0.5
r_ys = r_ys + 0.5
bboxes = torch.stack((l_xs, t_ys, r_xs, b_ys), dim=5)
bboxes = bboxes.view(batch, -1, 4)
bboxes = _gather_feat(bboxes, inds)
clses = t_clses.contiguous().view(batch, -1, 1)
clses = _gather_feat(clses, inds).float()
t_xs = t_xs.contiguous().view(batch, -1, 1)
t_xs = _gather_feat(t_xs, inds).float()
t_ys = t_ys.contiguous().view(batch, -1, 1)
t_ys = _gather_feat(t_ys, inds).float()
l_xs = l_xs.contiguous().view(batch, -1, 1)
l_xs = _gather_feat(l_xs, inds).float()
l_ys = l_ys.contiguous().view(batch, -1, 1)
l_ys = _gather_feat(l_ys, inds).float()
b_xs = b_xs.contiguous().view(batch, -1, 1)
b_xs = _gather_feat(b_xs, inds).float()
b_ys = b_ys.contiguous().view(batch, -1, 1)
b_ys = _gather_feat(b_ys, inds).float()
r_xs = r_xs.contiguous().view(batch, -1, 1)
r_xs = _gather_feat(r_xs, inds).float()
r_ys = r_ys.contiguous().view(batch, -1, 1)
r_ys = _gather_feat(r_ys, inds).float()
detections = torch.cat([bboxes, scores, t_xs, t_ys, l_xs, l_ys,
b_xs, b_ys, r_xs, r_ys, clses], dim=2)
return detections
def ddd_decode(heat, rot, depth, dim, wh=None, reg=None, K=40):
batch, cat, height, width = heat.size()
# heat = torch.sigmoid(heat)
# perform nms on heatmaps
heat = _nms(heat)
scores, inds, clses, ys, xs = _topk(heat, K=K)
if reg is not None:
reg = _transpose_and_gather_feat(reg, inds)
reg = reg.view(batch, K, 2)
xs = xs.view(batch, K, 1) + reg[:, :, 0:1]
ys = ys.view(batch, K, 1) + reg[:, :, 1:2]
else:
xs = xs.view(batch, K, 1) + 0.5
ys = ys.view(batch, K, 1) + 0.5
rot = _transpose_and_gather_feat(rot, inds)
rot = rot.view(batch, K, 8)
depth = _transpose_and_gather_feat(depth, inds)
depth = depth.view(batch, K, 1)
dim = _transpose_and_gather_feat(dim, inds)
dim = dim.view(batch, K, 3)
clses = clses.view(batch, K, 1).float()
scores = scores.view(batch, K, 1)
xs = xs.view(batch, K, 1)
ys = ys.view(batch, K, 1)
if wh is not None:
wh = _transpose_and_gather_feat(wh, inds)
wh = wh.view(batch, K, 2)
detections = torch.cat(
[xs, ys, scores, rot, depth, dim, wh, clses], dim=2)
else:
detections = torch.cat(
[xs, ys, scores, rot, depth, dim, clses], dim=2)
return detections
def ctdet_decode(heat, wh, reg=None, cat_spec_wh=False, K=100):
batch, cat, height, width = heat.size()
# heat = torch.sigmoid(heat)
# perform nms on heatmaps
heat = _nms(heat)
scores, inds, clses, ys, xs = _topk(heat, K=K)
if reg is not None:
reg = _transpose_and_gather_feat(reg, inds)
reg = reg.view(batch, K, 2)
xs = xs.view(batch, K, 1) + reg[:, :, 0:1]
ys = ys.view(batch, K, 1) + reg[:, :, 1:2]
else:
xs = xs.view(batch, K, 1) + 0.5
ys = ys.view(batch, K, 1) + 0.5
wh = _transpose_and_gather_feat(wh, inds)
if cat_spec_wh:
wh = wh.view(batch, K, cat, 2)
clses_ind = clses.view(batch, K, 1, 1).expand(batch, K, 1, 2).long()
wh = wh.gather(2, clses_ind).view(batch, K, 2)
else:
wh = wh.view(batch, K, 2)
clses = clses.view(batch, K, 1).float()
scores = scores.view(batch, K, 1)
bboxes = torch.cat([xs - wh[..., 0:1] / 2,
ys - wh[..., 1:2] / 2,
xs + wh[..., 0:1] / 2,
ys + wh[..., 1:2] / 2], dim=2)
detections = torch.cat([bboxes, scores, clses], dim=2)
return detections
def multi_pose_decode(
heat, wh, kps, reg=None, hm_hp=None, hp_offset=None, K=100):
batch, cat, height, width = heat.size()
num_joints = kps.shape[1] // 2
# heat = torch.sigmoid(heat)
# perform nms on heatmaps
heat = _nms(heat)
scores, inds, clses, ys, xs = _topk(heat, K=K)
kps = _transpose_and_gather_feat(kps, inds)
kps = kps.view(batch, K, num_joints * 2)
kps[..., ::2] += xs.view(batch, K, 1).expand(batch, K, num_joints)
kps[..., 1::2] += ys.view(batch, K, 1).expand(batch, K, num_joints)
if reg is not None:
reg = _transpose_and_gather_feat(reg, inds)
reg = reg.view(batch, K, 2)
xs = xs.view(batch, K, 1) + reg[:, :, 0:1]
ys = ys.view(batch, K, 1) + reg[:, :, 1:2]
else:
xs = xs.view(batch, K, 1) + 0.5
ys = ys.view(batch, K, 1) + 0.5
wh = _transpose_and_gather_feat(wh, inds)
wh = wh.view(batch, K, 2)
clses = clses.view(batch, K, 1).float()
scores = scores.view(batch, K, 1)
bboxes = torch.cat([xs - wh[..., 0:1] / 2,
ys - wh[..., 1:2] / 2,
xs + wh[..., 0:1] / 2,
ys + wh[..., 1:2] / 2], dim=2)
if hm_hp is not None:
hm_hp = _nms(hm_hp)
thresh = 0.1
kps = kps.view(batch, K, num_joints, 2).permute(
0, 2, 1, 3).contiguous() # b x J x K x 2
reg_kps = kps.unsqueeze(3).expand(batch, num_joints, K, K, 2)
hm_score, hm_inds, hm_ys, hm_xs = _topk_channel(hm_hp, K=K) # b x J x K
if hp_offset is not None:
hp_offset = _transpose_and_gather_feat(
hp_offset, hm_inds.view(batch, -1))
hp_offset = hp_offset.view(batch, num_joints, K, 2)
hm_xs = hm_xs + hp_offset[:, :, :, 0]
hm_ys = hm_ys + hp_offset[:, :, :, 1]
else:
hm_xs = hm_xs + 0.5
hm_ys = hm_ys + 0.5
mask = (hm_score > thresh).float()
hm_score = (1 - mask) * -1 + mask * hm_score
hm_ys = (1 - mask) * (-10000) + mask * hm_ys
hm_xs = (1 - mask) * (-10000) + mask * hm_xs
hm_kps = torch.stack([hm_xs, hm_ys], dim=-1).unsqueeze(
2).expand(batch, num_joints, K, K, 2)
dist = (((reg_kps - hm_kps) ** 2).sum(dim=4) ** 0.5)
min_dist, min_ind = dist.min(dim=3) # b x J x K
hm_score = hm_score.gather(2, min_ind).unsqueeze(-1) # b x J x K x 1
min_dist = min_dist.unsqueeze(-1)
min_ind = min_ind.view(batch, num_joints, K, 1, 1).expand(
batch, num_joints, K, 1, 2)
hm_kps = hm_kps.gather(3, min_ind)
hm_kps = hm_kps.view(batch, num_joints, K, 2)
l = bboxes[:, :, 0].view(batch, 1, K, 1).expand(batch, num_joints, K, 1)
t = bboxes[:, :, 1].view(batch, 1, K, 1).expand(batch, num_joints, K, 1)
r = bboxes[:, :, 2].view(batch, 1, K, 1).expand(batch, num_joints, K, 1)
b = bboxes[:, :, 3].view(batch, 1, K, 1).expand(batch, num_joints, K, 1)
mask = (hm_kps[..., 0:1] < l) + (hm_kps[..., 0:1] > r) + \
(hm_kps[..., 1:2] < t) + (hm_kps[..., 1:2] > b) + \
(hm_score < thresh) + (min_dist > (torch.max(b - t, r - l) * 0.3))
mask = (mask > 0).float().expand(batch, num_joints, K, 2)
kps = (1 - mask) * hm_kps + mask * kps
kps = kps.permute(0, 2, 1, 3).contiguous().view(
batch, K, num_joints * 2)
detections = torch.cat([bboxes, scores, kps, clses], dim=2)
return detections
================================================
FILE: src/lib/models/losses.py
================================================
# ------------------------------------------------------------------------------
# Portions of this code are from
# CornerNet (https://github.com/princeton-vl/CornerNet)
# Copyright (c) 2018, University of Michigan
# Licensed under the BSD 3-Clause License
# ------------------------------------------------------------------------------
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import torch
import torch.nn as nn
from .utils import _transpose_and_gather_feat
import torch.nn.functional as F
def _slow_neg_loss(pred, gt):
'''focal loss from CornerNet'''
pos_inds = gt.eq(1)
neg_inds = gt.lt(1)
neg_weights = torch.pow(1 - gt[neg_inds], 4)
loss = 0
pos_pred = pred[pos_inds]
neg_pred = pred[neg_inds]
pos_loss = torch.log(pos_pred) * torch.pow(1 - pos_pred, 2)
neg_loss = torch.log(1 - neg_pred) * torch.pow(neg_pred, 2) * neg_weights
num_pos = pos_inds.float().sum()
pos_loss = pos_loss.sum()
neg_loss = neg_loss.sum()
if pos_pred.nelement() == 0:
loss = loss - neg_loss
else:
loss = loss - (pos_loss + neg_loss) / num_pos
return loss
def _neg_loss(pred, gt):
''' Modified focal loss. Exactly the same as CornerNet.
Runs faster and costs a little bit more memory
Arguments:
pred (batch x c x h x w)
gt_regr (batch x c x h x w)
'''
pos_inds = gt.eq(1).float()
neg_inds = gt.lt(1).float()
neg_weights = torch.pow(1 - gt, 4)
loss = 0
pos_loss = torch.log(pred) * torch.pow(1 - pred, 2) * pos_inds
neg_loss = torch.log(1 - pred) * torch.pow(pred, 2) * neg_weights * neg_inds
num_pos = pos_inds.float().sum()
pos_loss = pos_loss.sum()
neg_loss = neg_loss.sum()
if num_pos == 0:
loss = loss - neg_loss
else:
loss = loss - (pos_loss + neg_loss) / num_pos
return loss
def _not_faster_neg_loss(pred, gt):
pos_inds = gt.eq(1).float()
neg_inds = gt.lt(1).float()
num_pos = pos_inds.float().sum()
neg_weights = torch.pow(1 - gt, 4)
loss = 0
trans_pred = pred * neg_inds + (1 - pred) * pos_inds
weight = neg_weights * neg_inds + pos_inds
all_loss = torch.log(1 - trans_pred) * torch.pow(trans_pred, 2) * weight
all_loss = all_loss.sum()
if num_pos > 0:
all_loss /= num_pos
loss -= all_loss
return loss
def _slow_reg_loss(regr, gt_regr, mask):
num = mask.float().sum()
mask = mask.unsqueeze(2).expand_as(gt_regr)
regr = regr[mask]
gt_regr = gt_regr[mask]
regr_loss = nn.functional.smooth_l1_loss(regr, gt_regr, size_average=False)
regr_loss = regr_loss / (num + 1e-4)
return regr_loss
def _reg_loss(regr, gt_regr, mask):
''' L1 regression loss
Arguments:
regr (batch x max_objects x dim)
gt_regr (batch x max_objects x dim)
mask (batch x max_objects)
'''
num = mask.float().sum()
mask = mask.unsqueeze(2).expand_as(gt_regr).float()
regr = regr * mask
gt_regr = gt_regr * mask
regr_loss = nn.functional.smooth_l1_loss(regr, gt_regr, size_average=False)
regr_loss = regr_loss / (num + 1e-4)
return regr_loss
class FocalLoss(nn.Module):
'''nn.Module warpper for focal loss'''
def __init__(self):
super(FocalLoss, self).__init__()
self.neg_loss = _neg_loss
def forward(self, out, target):
return self.neg_loss(out, target)
class RegLoss(nn.Module):
'''Regression loss for an output tensor
Arguments:
output (batch x dim x h x w)
mask (batch x max_objects)
ind (batch x max_objects)
target (batch x max_objects x dim)
'''
def __init__(self):
super(RegLoss, self).__init__()
def forward(self, output, mask, ind, target):
pred = _transpose_and_gather_feat(output, ind)
loss = _reg_loss(pred, target, mask)
return loss
class RegL1Loss(nn.Module):
def __init__(self):
super(RegL1Loss, self).__init__()
def forward(self, output, mask, ind, target):
pred = _transpose_and_gather_feat(output, ind)
mask = mask.unsqueeze(2).expand_as(pred).float()
# loss = F.l1_loss(pred * mask, target * mask, reduction='elementwise_mean')
loss = F.l1_loss(pred * mask, target * mask, size_average=False)
loss = loss / (mask.sum() + 1e-4)
return loss
class NormRegL1Loss(nn.Module):
def __init__(self):
super(NormRegL1Loss, self).__init__()
def forward(self, output, mask, ind, target):
pred = _transpose_and_gather_feat(output, ind)
mask = mask.unsqueeze(2).expand_as(pred).float()
# loss = F.l1_loss(pred * mask, target * mask, reduction='elementwise_mean')
pred = pred / (target + 1e-4)
target = target * 0 + 1
loss = F.l1_loss(pred * mask, target * mask, size_average=False)
loss = loss / (mask.sum() + 1e-4)
return loss
class RegWeightedL1Loss(nn.Module):
def __init__(self):
super(RegWeightedL1Loss, self).__init__()
def forward(self, output, mask, ind, target):
pred = _transpose_and_gather_feat(output, ind)
mask = mask.float()
# loss = F.l1_loss(pred * mask, target * mask, reduction='elementwise_mean')
loss = F.l1_loss(pred * mask, target * mask, size_average=False)
loss = loss / (mask.sum() + 1e-4)
return loss
class L1Loss(nn.Module):
def __init__(self):
super(L1Loss, self).__init__()
def forward(self, output, mask, ind, target):
pred = _transpose_and_gather_feat(output, ind)
mask = mask.unsqueeze(2).expand_as(pred).float()
loss = F.l1_loss(pred * mask, target * mask, reduction='elementwise_mean')
return loss
class BinRotLoss(nn.Module):
def __init__(self):
super(BinRotLoss, self).__init__()
def forward(self, output, mask, ind, rotbin, rotres):
pred = _transpose_and_gather_feat(output, ind)
loss = compute_rot_loss(pred, rotbin, rotres, mask)
return loss
def compute_res_loss(output, target):
return F.smooth_l1_loss(output, target, reduction='elementwise_mean')
# TODO: weight
def compute_bin_loss(output, target, mask):
mask = mask.expand_as(output)
output = output * mask.float()
return F.cross_entropy(output, target, reduction='elementwise_mean')
def compute_rot_loss(output, target_bin, target_res, mask):
# output: (B, 128, 8) [bin1_cls[0], bin1_cls[1], bin1_sin, bin1_cos,
# bin2_cls[0], bin2_cls[1], bin2_sin, bin2_cos]
# target_bin: (B, 128, 2) [bin1_cls, bin2_cls]
# target_res: (B, 128, 2) [bin1_res, bin2_res]
# mask: (B, 128, 1)
# import pdb; pdb.set_trace()
output = output.view(-1, 8)
target_bin = target_bin.view(-1, 2)
target_res = target_res.view(-1, 2)
mask = mask.view(-1, 1)
loss_bin1 = compute_bin_loss(output[:, 0:2], target_bin[:, 0], mask)
loss_bin2 = compute_bin_loss(output[:, 4:6], target_bin[:, 1], mask)
loss_res = torch.zeros_like(loss_bin1)
if target_bin[:, 0].nonzero().shape[0] > 0:
idx1 = target_bin[:, 0].nonzero()[:, 0]
valid_output1 = torch.index_select(output, 0, idx1.long())
valid_target_res1 = torch.index_select(target_res, 0, idx1.long())
loss_sin1 = compute_res_loss(
valid_output1[:, 2], torch.sin(valid_target_res1[:, 0]))
loss_cos1 = compute_res_loss(
valid_output1[:, 3], torch.cos(valid_target_res1[:, 0]))
loss_res += loss_sin1 + loss_cos1
if target_bin[:, 1].nonzero().shape[0] > 0:
idx2 = target_bin[:, 1].nonzero()[:, 0]
valid_output2 = torch.index_select(output, 0, idx2.long())
valid_target_res2 = torch.index_select(target_res, 0, idx2.long())
loss_sin2 = compute_res_loss(
valid_output2[:, 6], torch.sin(valid_target_res2[:, 1]))
loss_cos2 = compute_res_loss(
valid_output2[:, 7], torch.cos(valid_target_res2[:, 1]))
loss_res += loss_sin2 + loss_cos2
return loss_bin1 + loss_bin2 + loss_res
================================================
FILE: src/lib/models/model.py
================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import torchvision.models as models
import torch
import torch.nn as nn
import os
from .networks.msra_resnet import get_pose_net
from .networks.dlav0 import get_pose_net as get_dlav0
from .networks.pose_dla_dcn import get_pose_net as get_dla_dcn
from .networks.resnet_dcn import get_pose_net as get_pose_net_dcn
from .networks.large_hourglass import get_large_hourglass_net
_model_factory = {
'res': get_pose_net, # default Resnet with deconv
'dlav0': get_dlav0, # default DLAup
'dla': get_dla_dcn,
'resdcn': get_pose_net_dcn,
'hourglass': get_large_hourglass_net,
}
def create_model(arch, heads, head_conv):
num_layers = int(arch[arch.find('_') + 1:]) if '_' in arch else 0
arch = arch[:arch.find('_')] if '_' in arch else arch
get_model = _model_factory[arch]
model = get_model(num_layers=num_layers, heads=heads, head_conv=head_conv)
return model
def load_model(model, model_path, optimizer=None, resume=False,
lr=None, lr_step=None):
start_epoch = 0
checkpoint = torch.load(model_path, map_location=lambda storage, loc: storage)
print('loaded {}, epoch {}'.format(model_path, checkpoint['epoch']))
state_dict_ = checkpoint['state_dict']
state_dict = {}
# convert data_parallal to model
for k in state_dict_:
if k.startswith('module') and not k.startswith('module_list'):
state_dict[k[7:]] = state_dict_[k]
else:
state_dict[k] = state_dict_[k]
model_state_dict = model.state_dict()
# check loaded parameters and created model parameters
msg = 'If you see this, your model does not fully load the ' + \
'pre-trained weight. Please make sure ' + \
'you have correctly specified --arch xxx ' + \
'or set the correct --num_classes for your own dataset.'
for k in state_dict:
if k in model_state_dict:
if state_dict[k].shape != model_state_dict[k].shape:
print('Skip loading parameter {}, required shape{}, '\
'loaded shape{}. {}'.format(
k, model_state_dict[k].shape, state_dict[k].shape, msg))
state_dict[k] = model_state_dict[k]
else:
print('Drop parameter {}.'.format(k) + msg)
for k in model_state_dict:
if not (k in state_dict):
print('No param {}.'.format(k) + msg)
state_dict[k] = model_state_dict[k]
model.load_state_dict(state_dict, strict=False)
# resume optimizer parameters
if optimizer is not None and resume:
if 'optimizer' in checkpoint:
optimizer.load_state_dict(checkpoint['optimizer'])
start_epoch = checkpoint['epoch']
start_lr = lr
for step in lr_step:
if start_epoch >= step:
start_lr *= 0.1
for param_group in optimizer.param_groups:
param_group['lr'] = start_lr
print('Resumed optimizer with start lr', start_lr)
else:
print('No optimizer parameters in checkpoint.')
if optimizer is not None:
return model, optimizer, start_epoch
else:
return model
def save_model(path, epoch, model, optimizer=None):
if isinstance(model, torch.nn.DataParallel):
state_dict = model.module.state_dict()
else:
state_dict = model.state_dict()
data = {'epoch': epoch,
'state_dict': state_dict}
if not (optimizer is None):
data['optimizer'] = optimizer.state_dict()
torch.save(data, path)
================================================
FILE: src/lib/models/networks/DCNv2/.gitignore
================================================
.vscode
.idea
*.so
*.o
*pyc
_ext
================================================
FILE: src/lib/models/networks/DCNv2/LICENSE
================================================
BSD 3-Clause License
Copyright (c) 2019, Charles Shang
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
================================================
FILE: src/lib/models/networks/DCNv2/README.md
================================================
## Deformable Convolutional Networks V2 with Pytorch
### Build
```bash
./make.sh # build
python test.py # run examples and gradient check
```
### An Example
- deformable conv
```python
from dcn_v2 import DCN
input = torch.randn(2, 64, 128, 128).cuda()
# wrap all things (offset and mask) in DCN
dcn = DCN(64, 64, kernel_size=(3,3), stride=1, padding=1, deformable_groups=2).cuda()
output = dcn(input)
print(output.shape)
```
- deformable roi pooling
```python
from dcn_v2 import DCNPooling
input = torch.randn(2, 32, 64, 64).cuda()
batch_inds = torch.randint(2, (20, 1)).cuda().float()
x = torch.randint(256, (20, 1)).cuda().float()
y = torch.randint(256, (20, 1)).cuda().float()
w = torch.randint(64, (20, 1)).cuda().float()
h = torch.randint(64, (20, 1)).cuda().float()
rois = torch.cat((batch_inds, x, y, x + w, y + h), dim=1)
# mdformable pooling (V2)
# wrap all things (offset and mask) in DCNPooling
dpooling = DCNPooling(spatial_scale=1.0 / 4,
pooled_size=7,
output_dim=32,
no_trans=False,
group_size=1,
trans_std=0.1).cuda()
dout = dpooling(input, rois)
```
### Known Issues:
- [x] Gradient check w.r.t offset (solved)
- [ ] Backward is not reentrant (minor)
This is an adaption of the official [Deformable-ConvNets](https://github.com/msracver/Deformable-ConvNets/tree/master/DCNv2_op).
<s>I have ran the gradient check for many times with DOUBLE type. Every tensor **except offset** passes.
However, when I set the offset to 0.5, it passes. I'm still wondering what cause this problem. Is it because some
non-differential points? </s>
Update: all gradient check passes with double precision.
Another issue is that it raises `RuntimeError: Backward is not reentrant`. However, the error is very small (`<1e-7` for
float `<1e-15` for double),
so it may not be a serious problem (?)
Please post an issue or PR if you have any comments.
================================================
FILE: src/lib/models/networks/DCNv2/__init__.py
================================================
================================================
FILE: src/lib/models/networks/DCNv2/build.py
================================================
import os
import torch
from torch.utils.ffi import create_extension
sources = ['src/dcn_v2.c']
headers = ['src/dcn_v2.h']
defines = []
with_cuda = False
extra_objects = []
if torch.cuda.is_available():
print('Including CUDA code.')
sources += ['src/dcn_v2_cuda.c']
headers += ['src/dcn_v2_cuda.h']
defines += [('WITH_CUDA', None)]
extra_objects += ['src/cuda/dcn_v2_im2col_cuda.cu.o']
extra_objects += ['src/cuda/dcn_v2_psroi_pooling_cuda.cu.o']
with_cuda = True
else:
raise ValueError('CUDA is not available')
extra_compile_args = ['-fopenmp', '-std=c99']
this_file = os.path.dirname(os.path.realpath(__file__))
print(this_file)
sources = [os.path.join(this_file, fname) for fname in sources]
headers = [os.path.join(this_file, fname) for fname in headers]
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
ffi = create_extension(
'_ext.dcn_v2',
headers=headers,
sources=sources,
define_macros=defines,
relative_to=__file__,
with_cuda=with_cuda,
extra_objects=extra_objects,
extra_compile_args=extra_compile_args
)
if __name__ == '__main__':
ffi.build()
================================================
FILE: src/lib/models/networks/DCNv2/build_double.py
================================================
import os
import torch
from torch.utils.ffi import create_extension
sources = ['src/dcn_v2_double.c']
headers = ['src/dcn_v2_double.h']
defines = []
with_cuda = False
extra_objects = []
if torch.cuda.is_available():
print('Including CUDA code.')
sources += ['src/dcn_v2_cuda_double.c']
headers += ['src/dcn_v2_cuda_double.h']
defines += [('WITH_CUDA', None)]
extra_objects += ['src/cuda/dcn_v2_im2col_cuda_double.cu.o']
extra_objects += ['src/cuda/dcn_v2_psroi_pooling_cuda_double.cu.o']
with_cuda = True
else:
raise ValueError('CUDA is not available')
extra_compile_args = ['-fopenmp', '-std=c99']
this_file = os.path.dirname(os.path.realpath(__file__))
print(this_file)
sources = [os.path.join(this_file, fname) for fname in sources]
headers = [os.path.join(this_file, fname) for fname in headers]
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
ffi = create_extension(
'_ext.dcn_v2_double',
headers=headers,
sources=sources,
define_macros=defines,
relative_to=__file__,
with_cuda=with_cuda,
extra_objects=extra_objects,
extra_compile_args=extra_compile_args
)
if __name__ == '__main__':
ffi.build()
================================================
FILE: src/lib/models/networks/DCNv2/dcn_v2.py
================================================
#!/usr/bin/env python
from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
import torch
import math
from torch import nn
from torch.nn.modules.utils import _pair
from .dcn_v2_func import DCNv2Function
from .dcn_v2_func import DCNv2PoolingFunction
class DCNv2(nn.Module):
def __init__(self, in_channels, out_channels,
kernel_size, stride, padding, dilation=1, deformable_groups=1):
super(DCNv2, self).__init__()
self.in_channels = in_channels
self.out_channels = out_channels
self.kernel_size = _pair(kernel_size)
self.stride = stride
self.padding = padding
self.dilation = dilation
self.deformable_groups = deformable_groups
self.weight = nn.Parameter(torch.Tensor(out_channels, in_channels, *self.kernel_size))
self.bias = nn.Parameter(torch.Tensor(out_channels))
self.reset_parameters()
def reset_parameters(self):
n = self.in_channels
for k in self.kernel_size:
n *= k
stdv = 1. / math.sqrt(n)
self.weight.data.uniform_(-stdv, stdv)
self.bias.data.zero_()
def forward(self, input, offset, mask):
func = DCNv2Function(self.stride, self.padding, self.dilation, self.deformable_groups)
return func(input, offset, mask, self.weight, self.bias)
class DCN(DCNv2):
def __init__(self, in_channels, out_channels,
kernel_size, stride, padding,
dilation=1, deformable_groups=1):
super(DCN, self).__init__(in_channels, out_channels,
kernel_size, stride, padding, dilation, deformable_groups)
self.conv_offset_mask = nn.Conv2d(self.in_channels,
self.deformable_groups * 3 * self.kernel_size[0] * self.kernel_size[1],
kernel_size=self.kernel_size,
stride=(self.stride, self.stride),
padding=(self.padding, self.padding),
bias=True)
self.init_offset()
def init_offset(self):
self.conv_offset_mask.weight.data.zero_()
self.conv_offset_mask.bias.data.zero_()
def forward(self, input):
out = self.conv_offset_mask(input)
o1, o2, mask = torch.chunk(out, 3, dim=1)
offset = torch.cat((o1, o2), dim=1)
mask = torch.sigmoid(mask)
func = DCNv2Function(self.stride, self.padding, self.dilation, self.deformable_groups)
return func(input, offset, mask, self.weight, self.bias)
class DCNv2Pooling(nn.Module):
def __init__(self,
spatial_scale,
pooled_size,
output_dim,
no_trans,
group_size=1,
part_size=None,
sample_per_part=4,
trans_std=.0):
super(DCNv2Pooling, self).__init__()
self.spatial_scale = spatial_scale
self.pooled_size = pooled_size
self.output_dim = output_dim
self.no_trans = no_trans
self.group_size = group_size
self.part_size = pooled_size if part_size is None else part_size
self.sample_per_part = sample_per_part
self.trans_std = trans_std
self.func = DCNv2PoolingFunction(self.spatial_scale,
self.pooled_size,
self.output_dim,
self.no_trans,
self.group_size,
self.part_size,
self.sample_per_part,
self.trans_std)
def forward(self, data, rois, offset):
if self.no_trans:
offset = data.new()
return self.func(data, rois, offset)
class DCNPooling(DCNv2Pooling):
def __init__(self,
spatial_scale,
pooled_size,
output_dim,
no_trans,
group_size=1,
part_size=None,
sample_per_part=4,
trans_std=.0,
deform_fc_dim=1024):
super(DCNPooling, self).__init__(spatial_scale,
pooled_size,
output_dim,
no_trans,
group_size,
part_size,
sample_per_part,
trans_std)
self.deform_fc_dim = deform_fc_dim
if not no_trans:
self.func_offset = DCNv2PoolingFunction(self.spatial_scale,
self.pooled_size,
self.output_dim,
True,
self.group_size,
self.part_size,
self.sample_per_part,
self.trans_std)
self.offset_fc = nn.Sequential(
nn.Linear(self.pooled_size * self.pooled_size * self.output_dim, self.deform_fc_dim),
nn.ReLU(inplace=True),
nn.Linear(self.deform_fc_dim, self.deform_fc_dim),
nn.ReLU(inplace=True),
nn.Linear(self.deform_fc_dim, self.pooled_size * self.pooled_size * 2)
)
self.offset_fc[4].weight.data.zero_()
self.offset_fc[4].bias.data.zero_()
self.mask_fc = nn.Sequential(
nn.Linear(self.pooled_size * self.pooled_size * self.output_dim, self.deform_fc_dim),
nn.ReLU(inplace=True),
nn.Linear(self.deform_fc_dim, self.pooled_size * self.pooled_size * 1),
nn.Sigmoid()
)
self.mask_fc[2].weight.data.zero_()
self.mask_fc[2].bias.data.zero_()
def forward(self, data, rois):
if self.no_trans:
offset = data.new()
else:
n = rois.shape[0]
offset = data.new()
x = self.func_offset(data, rois, offset)
offset = self.offset_fc(x.view(n, -1))
offset = offset.view(n, 2, self.pooled_size, self.pooled_size)
mask = self.mask_fc(x.view(n, -1))
mask = mask.view(n, 1, self.pooled_size, self.pooled_size)
feat = self.func(data, rois, offset) * mask
return feat
return self.func(data, rois, offset)
================================================
FILE: src/lib/models/networks/DCNv2/dcn_v2_func.py
================================================
#!/usr/bin/env python
from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
import torch
from torch.autograd import Function
from ._ext import dcn_v2 as _backend
# from _ext import dcn_v2_double as _backend
class DCNv2Function(Function):
def __init__(self, stride, padding, dilation=1, deformable_groups=1):
super(DCNv2Function, self).__init__()
self.stride = stride
self.padding = padding
self.dilation = dilation
self.deformable_groups = deformable_groups
def forward(self, input, offset, mask, weight, bias):
if not input.is_cuda:
raise NotImplementedError
if weight.requires_grad or mask.requires_grad or offset.requires_grad or input.requires_grad:
self.save_for_backward(input, offset, mask, weight, bias)
output = input.new(*self._infer_shape(input, weight))
self._bufs = [input.new(), input.new()]
_backend.dcn_v2_cuda_forward(input, weight,
bias, self._bufs[0],
offset, mask,
output, self._bufs[1],
weight.shape[2], weight.shape[3],
self.stride, self.stride,
self.padding, self.padding,
self.dilation, self.dilation,
self.deformable_groups)
return output
def backward(self, grad_output):
if not grad_output.is_cuda:
raise NotImplementedError
input, offset, mask, weight, bias = self.saved_tensors
grad_input = input.new(*input.size()).zero_()
grad_offset = offset.new(*offset.size()).zero_()
grad_mask = mask.new(*mask.size()).zero_()
grad_weight = weight.new(*weight.size()).zero_()
grad_bias = bias.new(*bias.size()).zero_()
_backend.dcn_v2_cuda_backward(input, weight,
bias, self._bufs[0],
offset, mask,
self._bufs[1],
grad_input, grad_weight,
grad_bias, grad_offset,
grad_mask, grad_output,
weight.shape[2], weight.shape[3],
self.stride, self.stride,
self.padding, self.padding,
self.dilation, self.dilation,
self.deformable_groups)
return grad_input, grad_offset, grad_mask, grad_weight, grad_bias
def _infer_shape(self, input, weight):
n = input.size(0)
channels_out = weight.size(0)
height, width = input.shape[2:4]
kernel_h, kernel_w = weight.shape[2:4]
height_out = (height + 2 * self.padding -
(self.dilation * (kernel_h - 1) + 1)) // self.stride + 1
width_out = (width + 2 * self.padding - (self.dilation *
(kernel_w - 1) + 1)) // self.stride + 1
return (n, channels_out, height_out, width_out)
class DCNv2PoolingFunction(Function):
def __init__(self,
spatial_scale,
pooled_size,
output_dim,
no_trans,
group_size=1,
part_size=None,
sample_per_part=4,
trans_std=.0):
super(DCNv2PoolingFunction, self).__init__()
self.spatial_scale = spatial_scale
self.pooled_size = pooled_size
self.output_dim = output_dim
self.no_trans = no_trans
self.group_size = group_size
self.part_size = pooled_size if part_size is None else part_size
self.sample_per_part = sample_per_part
self.trans_std = trans_std
assert self.trans_std >= 0.0 and self.trans_std <= 1.0
def forward(self, data, rois, offset):
if not data.is_cuda:
raise NotImplementedError
output = data.new(*self._infer_shape(data, rois))
output_count = data.new(*self._infer_shape(data, rois))
_backend.dcn_v2_psroi_pooling_cuda_forward(data, rois, offset,
output, output_count,
self.no_trans, self.spatial_scale,
self.output_dim, self.group_size,
self.pooled_size, self.part_size,
self.sample_per_part, self.trans_std)
if data.requires_grad or rois.requires_grad or offset.requires_grad:
self.save_for_backward(data, rois, offset, output_count)
return output
def backward(self, grad_output):
if not grad_output.is_cuda:
raise NotImplementedError
data, rois, offset, output_count = self.saved_tensors
grad_input = data.new(*data.size()).zero_()
grad_offset = offset.new(*offset.size()).zero_()
_backend.dcn_v2_psroi_pooling_cuda_backward(grad_output,
data,
rois,
offset,
output_count,
grad_input,
grad_offset,
self.no_trans,
self.spatial_scale,
self.output_dim,
self.group_size,
self.pooled_size,
self.part_size,
self.sample_per_part,
self.trans_std)
return grad_input, None, grad_offset
def _infer_shape(self, data, rois):
# _, c, h, w = data.shape[:4]
c = data.shape[1]
n = rois.shape[0]
return (n, self.output_dim, self.pooled_size, self.pooled_size)
================================================
FILE: src/lib/models/networks/DCNv2/make.sh
================================================
#!/usr/bin/env bash
cd src/cuda
# compile dcn
nvcc -c -o dcn_v2_im2col_cuda.cu.o dcn_v2_im2col_cuda.cu -x cu -Xcompiler -fPIC
nvcc -c -o dcn_v2_im2col_cuda_double.cu.o dcn_v2_im2col_cuda_double.cu -x cu -Xcompiler -fPIC
# compile dcn-roi-pooling
nvcc -c -o dcn_v2_psroi_pooling_cuda.cu.o dcn_v2_psroi_pooling_cuda.cu -x cu -Xcompiler -fPIC
nvcc -c -o dcn_v2_psroi_pooling_cuda_double.cu.o dcn_v2_psroi_pooling_cuda_double.cu -x cu -Xcompiler -fPIC
cd -
python build.py
python build_double.py
================================================
FILE: src/lib/models/networks/DCNv2/src/cuda/dcn_v2_im2col_cuda.cu
================================================
#include "dcn_v2_im2col_cuda.h"
#include <cstdio>
#include <algorithm>
#include <cstring>
#define CUDA_KERNEL_LOOP(i, n) \
for (int i = blockIdx.x * blockDim.x + threadIdx.x; \
i < (n); \
i += blockDim.x * gridDim.x)
const int CUDA_NUM_THREADS = 1024;
inline int GET_BLOCKS(const int N)
{
return (N + CUDA_NUM_THREADS - 1) / CUDA_NUM_THREADS;
}
__device__ float dmcn_im2col_bilinear(const float *bottom_data, const int data_width,
const int height, const int width, float h, float w)
{
int h_low = floor(h);
int w_low = floor(w);
int h_high = h_low + 1;
int w_high = w_low + 1;
float lh = h - h_low;
float lw = w - w_low;
float hh = 1 - lh, hw = 1 - lw;
float v1 = 0;
if (h_low >= 0 && w_low >= 0)
v1 = bottom_data[h_low * data_width + w_low];
float v2 = 0;
if (h_low >= 0 && w_high <= width - 1)
v2 = bottom_data[h_low * data_width + w_high];
float v3 = 0;
if (h_high <= height - 1 && w_low >= 0)
v3
gitextract_hokebfv4/
├── .gitignore
├── .travis.yml
├── LICENSE
├── NOTICE
├── README.md
├── data/
│ └── .gitignore
├── exp/
│ └── .gitignore
├── experiments/
│ ├── ctdet_coco_dla_1x.sh
│ ├── ctdet_coco_dla_2x.sh
│ ├── ctdet_coco_hg.sh
│ ├── ctdet_coco_resdcn101.sh
│ ├── ctdet_coco_resdcn18.sh
│ ├── ctdet_pascal_dla_384.sh
│ ├── ctdet_pascal_dla_512.sh
│ ├── ctdet_pascal_resdcn101_384.sh
│ ├── ctdet_pascal_resdcn101_512.sh
│ ├── ctdet_pascal_resdcn18_384.sh
│ ├── ctdet_pascal_resdcn18_512.sh
│ ├── ddd_3dop.sh
│ ├── ddd_sub.sh
│ ├── exdet_coco_dla.sh
│ ├── exdet_coco_hg.sh
│ ├── multi_pose_dla_1x.sh
│ ├── multi_pose_dla_3x.sh
│ ├── multi_pose_hg_1x.sh
│ └── multi_pose_hg_3x.sh
├── images/
│ └── NOTICE
├── models/
│ └── .gitignore
├── readme/
│ ├── DATA.md
│ ├── DEVELOP.md
│ ├── GETTING_STARTED.md
│ ├── INSTALL.md
│ └── MODEL_ZOO.md
├── requirements.txt
└── src/
├── _init_paths.py
├── demo.py
├── lib/
│ ├── datasets/
│ │ ├── dataset/
│ │ │ ├── coco.py
│ │ │ ├── coco_hp.py
│ │ │ ├── kitti.py
│ │ │ └── pascal.py
│ │ ├── dataset_factory.py
│ │ └── sample/
│ │ ├── ctdet.py
│ │ ├── ddd.py
│ │ ├── exdet.py
│ │ └── multi_pose.py
│ ├── detectors/
│ │ ├── base_detector.py
│ │ ├── ctdet.py
│ │ ├── ddd.py
│ │ ├── detector_factory.py
│ │ ├── exdet.py
│ │ └── multi_pose.py
│ ├── external/
│ │ ├── .gitignore
│ │ ├── Makefile
│ │ ├── __init__.py
│ │ ├── nms.pyx
│ │ └── setup.py
│ ├── logger.py
│ ├── models/
│ │ ├── data_parallel.py
│ │ ├── decode.py
│ │ ├── losses.py
│ │ ├── model.py
│ │ ├── networks/
│ │ │ ├── DCNv2/
│ │ │ │ ├── .gitignore
│ │ │ │ ├── LICENSE
│ │ │ │ ├── README.md
│ │ │ │ ├── __init__.py
│ │ │ │ ├── build.py
│ │ │ │ ├── build_double.py
│ │ │ │ ├── dcn_v2.py
│ │ │ │ ├── dcn_v2_func.py
│ │ │ │ ├── make.sh
│ │ │ │ ├── src/
│ │ │ │ │ ├── cuda/
│ │ │ │ │ │ ├── dcn_v2_im2col_cuda.cu
│ │ │ │ │ │ ├── dcn_v2_im2col_cuda.h
│ │ │ │ │ │ ├── dcn_v2_im2col_cuda_double.cu
│ │ │ │ │ │ ├── dcn_v2_im2col_cuda_double.h
│ │ │ │ │ │ ├── dcn_v2_psroi_pooling_cuda.cu
│ │ │ │ │ │ ├── dcn_v2_psroi_pooling_cuda.h
│ │ │ │ │ │ ├── dcn_v2_psroi_pooling_cuda_double.cu
│ │ │ │ │ │ └── dcn_v2_psroi_pooling_cuda_double.h
│ │ │ │ │ ├── dcn_v2.c
│ │ │ │ │ ├── dcn_v2.h
│ │ │ │ │ ├── dcn_v2_cuda.c
│ │ │ │ │ ├── dcn_v2_cuda.h
│ │ │ │ │ ├── dcn_v2_cuda_double.c
│ │ │ │ │ ├── dcn_v2_cuda_double.h
│ │ │ │ │ ├── dcn_v2_double.c
│ │ │ │ │ └── dcn_v2_double.h
│ │ │ │ └── test.py
│ │ │ ├── dlav0.py
│ │ │ ├── large_hourglass.py
│ │ │ ├── msra_resnet.py
│ │ │ ├── pose_dla_dcn.py
│ │ │ └── resnet_dcn.py
│ │ ├── scatter_gather.py
│ │ └── utils.py
│ ├── opts.py
│ ├── trains/
│ │ ├── base_trainer.py
│ │ ├── ctdet.py
│ │ ├── ddd.py
│ │ ├── exdet.py
│ │ ├── multi_pose.py
│ │ └── train_factory.py
│ └── utils/
│ ├── __init__.py
│ ├── ddd_utils.py
│ ├── debugger.py
│ ├── image.py
│ ├── oracle_utils.py
│ ├── post_process.py
│ └── utils.py
├── main.py
├── test.py
└── tools/
├── _init_paths.py
├── calc_coco_overlap.py
├── convert_hourglass_weight.py
├── convert_kitti_to_coco.py
├── eval_coco.py
├── eval_coco_hp.py
├── get_kitti.sh
├── get_pascal_voc.sh
├── kitti_eval/
│ ├── README.md
│ ├── evaluate_object_3d.cpp
│ ├── evaluate_object_3d_offline
│ ├── evaluate_object_3d_offline.cpp
│ └── mail.h
├── merge_pascal_json.py
├── reval.py
├── vis_pred.py
└── voc_eval_lib/
├── LICENSE
├── Makefile
├── __init__.py
├── datasets/
│ ├── __init__.py
│ ├── bbox.pyx
│ ├── ds_utils.py
│ ├── imdb.py
│ ├── pascal_voc.py
│ └── voc_eval.py
├── model/
│ ├── __init__.py
│ ├── bbox_transform.py
│ ├── config.py
│ ├── nms_wrapper.py
│ └── test.py
├── nms/
│ ├── .gitignore
│ ├── __init__.py
│ ├── cpu_nms.c
│ ├── cpu_nms.pyx
│ ├── gpu_nms.cpp
│ ├── gpu_nms.hpp
│ ├── gpu_nms.pyx
│ ├── nms_kernel.cu
│ └── py_cpu_nms.py
├── setup.py
└── utils/
├── .gitignore
├── __init__.py
├── bbox.pyx
├── blob.py
├── timer.py
└── visualization.py
SYMBOL INDEX (911 symbols across 72 files)
FILE: src/_init_paths.py
function add_path (line 4) | def add_path(path):
FILE: src/demo.py
function demo (line 17) | def demo(opt):
FILE: src/lib/datasets/dataset/coco.py
class COCO (line 13) | class COCO(data.Dataset):
method __init__ (line 21) | def __init__(self, opt, split):
method _to_float (line 86) | def _to_float(self, x):
method convert_eval_format (line 89) | def convert_eval_format(self, all_bboxes):
method __len__ (line 113) | def __len__(self):
method save_results (line 116) | def save_results(self, results, save_dir):
method run_eval (line 120) | def run_eval(self, results, save_dir):
FILE: src/lib/datasets/dataset/coco_hp.py
class COCOHP (line 13) | class COCOHP(data.Dataset):
method __init__ (line 23) | def __init__(self, opt, split):
method _to_float (line 69) | def _to_float(self, x):
method convert_eval_format (line 72) | def convert_eval_format(self, all_bboxes):
method __len__ (line 99) | def __len__(self):
method save_results (line 102) | def save_results(self, results, save_dir):
method run_eval (line 107) | def run_eval(self, results, save_dir):
FILE: src/lib/datasets/dataset/kitti.py
class KITTI (line 17) | class KITTI(data.Dataset):
method __init__ (line 23) | def __init__(self, opt, split):
method __len__ (line 59) | def __len__(self):
method _to_float (line 62) | def _to_float(self, x):
method convert_eval_format (line 65) | def convert_eval_format(self, all_bboxes):
method save_results (line 68) | def save_results(self, results, save_dir):
method run_eval (line 84) | def run_eval(self, results, save_dir):
FILE: src/lib/datasets/dataset/pascal.py
class PascalVOC (line 13) | class PascalVOC(data.Dataset):
method __init__ (line 21) | def __init__(self, opt, split):
method _to_float (line 54) | def _to_float(self, x):
method convert_eval_format (line 57) | def convert_eval_format(self, all_bboxes):
method __len__ (line 69) | def __len__(self):
method save_results (line 72) | def save_results(self, results, save_dir):
method run_eval (line 76) | def run_eval(self, results, save_dir):
FILE: src/lib/datasets/dataset_factory.py
function get_dataset (line 31) | def get_dataset(dataset, task):
FILE: src/lib/datasets/sample/ctdet.py
class CTDetDataset (line 17) | class CTDetDataset(data.Dataset):
method _coco_box_to_bbox (line 18) | def _coco_box_to_bbox(self, box):
method _get_border (line 23) | def _get_border(self, border, size):
method __getitem__ (line 29) | def __getitem__(self, index):
FILE: src/lib/datasets/sample/ddd.py
class DddDataset (line 18) | class DddDataset(data.Dataset):
method _coco_box_to_bbox (line 19) | def _coco_box_to_bbox(self, box):
method _convert_alpha (line 24) | def _convert_alpha(self, alpha):
method __getitem__ (line 27) | def __getitem__(self, index):
method _alpha_to_8 (line 159) | def _alpha_to_8(self, alpha):
FILE: src/lib/datasets/sample/exdet.py
class EXDetDataset (line 18) | class EXDetDataset(data.Dataset):
method _coco_box_to_bbox (line 19) | def _coco_box_to_bbox(self, box):
method _get_border (line 24) | def _get_border(self, border, size):
method __getitem__ (line 30) | def __getitem__(self, index):
FILE: src/lib/datasets/sample/multi_pose.py
class MultiPoseDataset (line 17) | class MultiPoseDataset(data.Dataset):
method _coco_box_to_bbox (line 18) | def _coco_box_to_bbox(self, box):
method _get_border (line 23) | def _get_border(self, border, size):
method __getitem__ (line 29) | def __getitem__(self, index):
FILE: src/lib/detectors/base_detector.py
class BaseDetector (line 16) | class BaseDetector(object):
method __init__ (line 17) | def __init__(self, opt):
method pre_process (line 37) | def pre_process(self, image, scale, meta=None):
method process (line 67) | def process(self, images, return_time=False):
method post_process (line 70) | def post_process(self, dets, meta, scale=1):
method merge_outputs (line 73) | def merge_outputs(self, detections):
method debug (line 76) | def debug(self, debugger, images, dets, output, scale=1):
method show_results (line 79) | def show_results(self, debugger, image, results):
method run (line 82) | def run(self, image_or_path_or_tensor, meta=None):
FILE: src/lib/detectors/ctdet.py
class CtdetDetector (line 24) | class CtdetDetector(BaseDetector):
method __init__ (line 25) | def __init__(self, opt):
method process (line 28) | def process(self, images, return_time=False):
method post_process (line 47) | def post_process(self, dets, meta, scale=1):
method merge_outputs (line 58) | def merge_outputs(self, detections):
method debug (line 75) | def debug(self, debugger, images, dets, output, scale=1):
method show_results (line 90) | def show_results(self, debugger, image, results):
FILE: src/lib/detectors/ddd.py
class DddDetector (line 22) | class DddDetector(BaseDetector):
method __init__ (line 23) | def __init__(self, opt):
method pre_process (line 30) | def pre_process(self, image, scale, calib=None):
method process (line 57) | def process(self, images, return_time=False):
method post_process (line 75) | def post_process(self, dets, meta, scale=1):
method merge_outputs (line 82) | def merge_outputs(self, detections):
method debug (line 90) | def debug(self, debugger, images, dets, output, scale=1):
method show_results (line 100) | def show_results(self, debugger, image, results):
FILE: src/lib/detectors/exdet.py
class ExdetDetector (line 23) | class ExdetDetector(BaseDetector):
method __init__ (line 24) | def __init__(self, opt):
method process (line 28) | def process(self, images, return_time=False):
method debug (line 57) | def debug(self, debugger, images, dets, output, scale=1):
method post_process (line 85) | def post_process(self, dets, meta, scale=1):
method merge_outputs (line 97) | def merge_outputs(self, detections):
method show_results (line 125) | def show_results(self, debugger, image, results):
FILE: src/lib/detectors/multi_pose.py
class MultiPoseDetector (line 24) | class MultiPoseDetector(BaseDetector):
method __init__ (line 25) | def __init__(self, opt):
method process (line 29) | def process(self, images, return_time=False):
method post_process (line 62) | def post_process(self, dets, meta, scale=1):
method merge_outputs (line 74) | def merge_outputs(self, detections):
method debug (line 83) | def debug(self, debugger, images, dets, output, scale=1):
method show_results (line 97) | def show_results(self, debugger, image, results):
FILE: src/lib/logger.py
class Logger (line 17) | class Logger(object):
method __init__ (line 18) | def __init__(self, opt):
method write (line 55) | def write(self, txt):
method close (line 66) | def close(self):
method scalar_summary (line 69) | def scalar_summary(self, tag, value, step):
FILE: src/lib/models/data_parallel.py
class _DataParallel (line 10) | class _DataParallel(Module):
method __init__ (line 44) | def __init__(self, module, device_ids=None, output_device=None, dim=0,...
method forward (line 64) | def forward(self, *inputs, **kwargs):
method replicate (line 74) | def replicate(self, module, device_ids):
method scatter (line 77) | def scatter(self, inputs, kwargs, device_ids, chunk_sizes):
method parallel_apply (line 80) | def parallel_apply(self, replicas, inputs, kwargs):
method gather (line 83) | def gather(self, outputs, output_device):
function data_parallel (line 87) | def data_parallel(module, inputs, device_ids=None, output_device=None, d...
function DataParallel (line 119) | def DataParallel(module, device_ids=None, output_device=None, dim=0, chu...
FILE: src/lib/models/decode.py
function _nms (line 9) | def _nms(heat, kernel=3):
function _left_aggregate (line 17) | def _left_aggregate(heat):
function _right_aggregate (line 30) | def _right_aggregate(heat):
function _top_aggregate (line 43) | def _top_aggregate(heat):
function _bottom_aggregate (line 57) | def _bottom_aggregate(heat):
function _h_aggregate (line 71) | def _h_aggregate(heat, aggr_weight=0.1):
function _v_aggregate (line 75) | def _v_aggregate(heat, aggr_weight=0.1):
function _topk_channel (line 92) | def _topk_channel(scores, K=40):
function _topk (line 103) | def _topk(scores, K=40):
function agnex_ct_decode (line 122) | def agnex_ct_decode(
function exct_decode (line 273) | def exct_decode(
function ddd_decode (line 426) | def ddd_decode(heat, rot, depth, dim, wh=None, reg=None, K=40):
function ctdet_decode (line 464) | def ctdet_decode(heat, wh, reg=None, cat_spec_wh=False, K=100):
function multi_pose_decode (line 497) | def multi_pose_decode(
FILE: src/lib/models/losses.py
function _slow_neg_loss (line 17) | def _slow_neg_loss(pred, gt):
function _neg_loss (line 42) | def _neg_loss(pred, gt):
function _not_faster_neg_loss (line 69) | def _not_faster_neg_loss(pred, gt):
function _slow_reg_loss (line 86) | def _slow_reg_loss(regr, gt_regr, mask):
function _reg_loss (line 97) | def _reg_loss(regr, gt_regr, mask):
class FocalLoss (line 114) | class FocalLoss(nn.Module):
method __init__ (line 116) | def __init__(self):
method forward (line 120) | def forward(self, out, target):
class RegLoss (line 123) | class RegLoss(nn.Module):
method __init__ (line 131) | def __init__(self):
method forward (line 134) | def forward(self, output, mask, ind, target):
class RegL1Loss (line 139) | class RegL1Loss(nn.Module):
method __init__ (line 140) | def __init__(self):
method forward (line 143) | def forward(self, output, mask, ind, target):
class NormRegL1Loss (line 151) | class NormRegL1Loss(nn.Module):
method __init__ (line 152) | def __init__(self):
method forward (line 155) | def forward(self, output, mask, ind, target):
class RegWeightedL1Loss (line 165) | class RegWeightedL1Loss(nn.Module):
method __init__ (line 166) | def __init__(self):
method forward (line 169) | def forward(self, output, mask, ind, target):
class L1Loss (line 177) | class L1Loss(nn.Module):
method __init__ (line 178) | def __init__(self):
method forward (line 181) | def forward(self, output, mask, ind, target):
class BinRotLoss (line 187) | class BinRotLoss(nn.Module):
method __init__ (line 188) | def __init__(self):
method forward (line 191) | def forward(self, output, mask, ind, rotbin, rotres):
function compute_res_loss (line 196) | def compute_res_loss(output, target):
function compute_bin_loss (line 200) | def compute_bin_loss(output, target, mask):
function compute_rot_loss (line 205) | def compute_rot_loss(output, target_bin, target_res, mask):
FILE: src/lib/models/model.py
function create_model (line 24) | def create_model(arch, heads, head_conv):
function load_model (line 31) | def load_model(model, model_path, optimizer=None, resume=False,
function save_model (line 86) | def save_model(path, epoch, model, optimizer=None):
FILE: src/lib/models/networks/DCNv2/dcn_v2.py
class DCNv2 (line 14) | class DCNv2(nn.Module):
method __init__ (line 16) | def __init__(self, in_channels, out_channels,
method reset_parameters (line 31) | def reset_parameters(self):
method forward (line 39) | def forward(self, input, offset, mask):
class DCN (line 44) | class DCN(DCNv2):
method __init__ (line 46) | def __init__(self, in_channels, out_channels,
method init_offset (line 60) | def init_offset(self):
method forward (line 64) | def forward(self, input):
class DCNv2Pooling (line 73) | class DCNv2Pooling(nn.Module):
method __init__ (line 75) | def __init__(self,
method forward (line 102) | def forward(self, data, rois, offset):
class DCNPooling (line 108) | class DCNPooling(DCNv2Pooling):
method __init__ (line 110) | def __init__(self,
method forward (line 158) | def forward(self, data, rois):
FILE: src/lib/models/networks/DCNv2/dcn_v2_func.py
class DCNv2Function (line 13) | class DCNv2Function(Function):
method __init__ (line 15) | def __init__(self, stride, padding, dilation=1, deformable_groups=1):
method forward (line 22) | def forward(self, input, offset, mask, weight, bias):
method backward (line 40) | def backward(self, grad_output):
method _infer_shape (line 64) | def _infer_shape(self, input, weight):
class DCNv2PoolingFunction (line 76) | class DCNv2PoolingFunction(Function):
method __init__ (line 78) | def __init__(self,
method forward (line 99) | def forward(self, data, rois, offset):
method backward (line 117) | def backward(self, grad_output):
method _infer_shape (line 142) | def _infer_shape(self, data, rois):
FILE: src/lib/models/networks/DCNv2/src/dcn_v2.c
function dcn_v2_forward (line 5) | void dcn_v2_forward(THFloatTensor *input, THFloatTensor *weight,
function dcn_v2_backward (line 16) | void dcn_v2_backward(THFloatTensor *input, THFloatTensor *weight,
FILE: src/lib/models/networks/DCNv2/src/dcn_v2_cuda.c
function dcn_v2_cuda_forward (line 10) | void dcn_v2_cuda_forward(THCudaTensor *input, THCudaTensor *weight,
function dcn_v2_cuda_backward (line 104) | void dcn_v2_cuda_backward(THCudaTensor *input, THCudaTensor *weight,
function dcn_v2_psroi_pooling_cuda_forward (line 243) | void dcn_v2_psroi_pooling_cuda_forward(THCudaTensor * input, THCudaTenso...
function dcn_v2_psroi_pooling_cuda_backward (line 288) | void dcn_v2_psroi_pooling_cuda_backward(THCudaTensor * out_grad,
FILE: src/lib/models/networks/DCNv2/src/dcn_v2_cuda_double.c
function dcn_v2_cuda_forward (line 10) | void dcn_v2_cuda_forward(THCudaDoubleTensor *input, THCudaDoubleTensor *...
function dcn_v2_cuda_backward (line 114) | void dcn_v2_cuda_backward(THCudaDoubleTensor *input, THCudaDoubleTensor ...
function dcn_v2_psroi_pooling_cuda_forward (line 266) | void dcn_v2_psroi_pooling_cuda_forward(THCudaDoubleTensor * input, THCud...
function dcn_v2_psroi_pooling_cuda_backward (line 311) | void dcn_v2_psroi_pooling_cuda_backward(THCudaDoubleTensor * out_grad,
FILE: src/lib/models/networks/DCNv2/src/dcn_v2_double.c
function dcn_v2_forward (line 5) | void dcn_v2_forward(THDoubleTensor *input, THDoubleTensor *weight,
function dcn_v2_backward (line 16) | void dcn_v2_backward(THDoubleTensor *input, THDoubleTensor *weight,
FILE: src/lib/models/networks/DCNv2/test.py
function conv_identify (line 21) | def conv_identify(weight, bias):
function check_zero_offset (line 32) | def check_zero_offset():
function check_gradient_dconv_double (line 67) | def check_gradient_dconv_double():
function check_gradient_dconv (line 92) | def check_gradient_dconv():
function check_pooling_zero_offset (line 117) | def check_pooling_zero_offset():
function check_gradient_dpooling (line 148) | def check_gradient_dpooling():
function example_dconv (line 169) | def example_dconv():
function example_dpooling (line 181) | def example_dpooling():
function example_mdpooling (line 224) | def example_mdpooling():
FILE: src/lib/models/networks/dlav0.py
function get_model_url (line 18) | def get_model_url(data='imagenet', name='dla34', hash='ba72cf86'):
function conv3x3 (line 22) | def conv3x3(in_planes, out_planes, stride=1):
class BasicBlock (line 28) | class BasicBlock(nn.Module):
method __init__ (line 29) | def __init__(self, inplanes, planes, stride=1, dilation=1):
method forward (line 42) | def forward(self, x, residual=None):
class Bottleneck (line 59) | class Bottleneck(nn.Module):
method __init__ (line 62) | def __init__(self, inplanes, planes, stride=1, dilation=1):
method forward (line 79) | def forward(self, x, residual=None):
class BottleneckX (line 100) | class BottleneckX(nn.Module):
method __init__ (line 104) | def __init__(self, inplanes, planes, stride=1, dilation=1):
method forward (line 123) | def forward(self, x, residual=None):
class Root (line 144) | class Root(nn.Module):
method __init__ (line 145) | def __init__(self, in_channels, out_channels, kernel_size, residual):
method forward (line 154) | def forward(self, *x):
class Tree (line 165) | class Tree(nn.Module):
method __init__ (line 166) | def __init__(self, levels, block, in_channels, out_channels, stride=1,
method forward (line 205) | def forward(self, x, residual=None, children=None):
class DLA (line 221) | class DLA(nn.Module):
method __init__ (line 222) | def __init__(self, levels, channels, num_classes=1000,
method _make_level (line 260) | def _make_level(self, block, inplanes, planes, blocks, stride=1):
method _make_conv_level (line 277) | def _make_conv_level(self, inplanes, planes, convs, stride=1, dilation...
method forward (line 289) | def forward(self, x):
method load_pretrained_model (line 304) | def load_pretrained_model(self, data='imagenet', name='dla34', hash='...
function dla34 (line 319) | def dla34(pretrained, **kwargs): # DLA-34
function dla46_c (line 328) | def dla46_c(pretrained=None, **kwargs): # DLA-46-C
function dla46x_c (line 338) | def dla46x_c(pretrained=None, **kwargs): # DLA-X-46-C
function dla60x_c (line 348) | def dla60x_c(pretrained, **kwargs): # DLA-X-60-C
function dla60 (line 358) | def dla60(pretrained=None, **kwargs): # DLA-60
function dla60x (line 368) | def dla60x(pretrained=None, **kwargs): # DLA-X-60
function dla102 (line 378) | def dla102(pretrained=None, **kwargs): # DLA-102
function dla102x (line 387) | def dla102x(pretrained=None, **kwargs): # DLA-X-102
function dla102x2 (line 396) | def dla102x2(pretrained=None, **kwargs): # DLA-X-102 64
function dla169 (line 405) | def dla169(pretrained=None, **kwargs): # DLA-169
function set_bn (line 414) | def set_bn(bn):
class Identity (line 420) | class Identity(nn.Module):
method __init__ (line 421) | def __init__(self):
method forward (line 424) | def forward(self, x):
function fill_up_weights (line 428) | def fill_up_weights(up):
class IDAUp (line 440) | class IDAUp(nn.Module):
method __init__ (line 441) | def __init__(self, node_kernel, out_dim, channels, up_factors):
method forward (line 482) | def forward(self, layers):
class DLAUp (line 499) | class DLAUp(nn.Module):
method __init__ (line 500) | def __init__(self, channels, scales=(1, 2, 4, 8, 16), in_channels=None):
method forward (line 515) | def forward(self, layers):
function fill_fc_weights (line 524) | def fill_fc_weights(layers):
class DLASeg (line 533) | class DLASeg(nn.Module):
method __init__ (line 534) | def __init__(self, base_name, heads,
method forward (line 600) | def forward(self, x):
function get_pose_net (line 642) | def get_pose_net(num_layers, heads, head_conv=256, down_ratio=4):
FILE: src/lib/models/networks/large_hourglass.py
class convolution (line 17) | class convolution(nn.Module):
method __init__ (line 18) | def __init__(self, k, inp_dim, out_dim, stride=1, with_bn=True):
method forward (line 26) | def forward(self, x):
class fully_connected (line 32) | class fully_connected(nn.Module):
method __init__ (line 33) | def __init__(self, inp_dim, out_dim, with_bn=True):
method forward (line 42) | def forward(self, x):
class residual (line 48) | class residual(nn.Module):
method __init__ (line 49) | def __init__(self, k, inp_dim, out_dim, stride=1, with_bn=True):
method forward (line 65) | def forward(self, x):
function make_layer (line 76) | def make_layer(k, inp_dim, out_dim, modules, layer=convolution, **kwargs):
function make_layer_revr (line 82) | def make_layer_revr(k, inp_dim, out_dim, modules, layer=convolution, **k...
class MergeUp (line 89) | class MergeUp(nn.Module):
method forward (line 90) | def forward(self, up1, up2):
function make_merge_layer (line 93) | def make_merge_layer(dim):
function make_pool_layer (line 99) | def make_pool_layer(dim):
function make_unpool_layer (line 102) | def make_unpool_layer(dim):
function make_kp_layer (line 105) | def make_kp_layer(cnv_dim, curr_dim, out_dim):
function make_inter_layer (line 111) | def make_inter_layer(dim):
function make_cnv_layer (line 114) | def make_cnv_layer(inp_dim, out_dim):
class kp_module (line 117) | class kp_module(nn.Module):
method __init__ (line 118) | def __init__(
method forward (line 167) | def forward(self, x):
class exkp (line 176) | class exkp(nn.Module):
method __init__ (line 177) | def __init__(
method forward (line 253) | def forward(self, image):
function make_hg_layer (line 277) | def make_hg_layer(kernel, dim0, dim1, mod, layer=convolution, **kwargs):
class HourglassNet (line 283) | class HourglassNet(exkp):
method __init__ (line 284) | def __init__(self, heads, num_stacks=2):
function get_large_hourglass_net (line 298) | def get_large_hourglass_net(num_layers, heads, head_conv):
FILE: src/lib/models/networks/msra_resnet.py
function conv3x3 (line 28) | def conv3x3(in_planes, out_planes, stride=1):
class BasicBlock (line 34) | class BasicBlock(nn.Module):
method __init__ (line 37) | def __init__(self, inplanes, planes, stride=1, downsample=None):
method forward (line 47) | def forward(self, x):
class Bottleneck (line 66) | class Bottleneck(nn.Module):
method __init__ (line 69) | def __init__(self, inplanes, planes, stride=1, downsample=None):
method forward (line 84) | def forward(self, x):
class PoseResNet (line 107) | class PoseResNet(nn.Module):
method __init__ (line 109) | def __init__(self, block, layers, heads, head_conv, **kwargs):
method _make_layer (line 154) | def _make_layer(self, block, planes, blocks, stride=1):
method _get_deconv_cfg (line 171) | def _get_deconv_cfg(self, deconv_kernel, index):
method _make_deconv_layer (line 184) | def _make_deconv_layer(self, num_layers, num_filters, num_kernels):
method forward (line 211) | def forward(self, x):
method init_weights (line 228) | def init_weights(self, num_layers, pretrained=True):
function get_pose_net (line 275) | def get_pose_net(num_layers, heads, head_conv):
FILE: src/lib/models/networks/pose_dla_dcn.py
function get_model_url (line 21) | def get_model_url(data='imagenet', name='dla34', hash='ba72cf86'):
function conv3x3 (line 25) | def conv3x3(in_planes, out_planes, stride=1):
class BasicBlock (line 31) | class BasicBlock(nn.Module):
method __init__ (line 32) | def __init__(self, inplanes, planes, stride=1, dilation=1):
method forward (line 45) | def forward(self, x, residual=None):
class Bottleneck (line 62) | class Bottleneck(nn.Module):
method __init__ (line 65) | def __init__(self, inplanes, planes, stride=1, dilation=1):
method forward (line 82) | def forward(self, x, residual=None):
class BottleneckX (line 103) | class BottleneckX(nn.Module):
method __init__ (line 107) | def __init__(self, inplanes, planes, stride=1, dilation=1):
method forward (line 126) | def forward(self, x, residual=None):
class Root (line 147) | class Root(nn.Module):
method __init__ (line 148) | def __init__(self, in_channels, out_channels, kernel_size, residual):
method forward (line 157) | def forward(self, *x):
class Tree (line 168) | class Tree(nn.Module):
method __init__ (line 169) | def __init__(self, levels, block, in_channels, out_channels, stride=1,
method forward (line 208) | def forward(self, x, residual=None, children=None):
class DLA (line 224) | class DLA(nn.Module):
method __init__ (line 225) | def __init__(self, levels, channels, num_classes=1000,
method _make_level (line 257) | def _make_level(self, block, inplanes, planes, blocks, stride=1):
method _make_conv_level (line 274) | def _make_conv_level(self, inplanes, planes, convs, stride=1, dilation...
method forward (line 286) | def forward(self, x):
method load_pretrained_model (line 294) | def load_pretrained_model(self, data='imagenet', name='dla34', hash='b...
function dla34 (line 309) | def dla34(pretrained=True, **kwargs): # DLA-34
class Identity (line 317) | class Identity(nn.Module):
method __init__ (line 319) | def __init__(self):
method forward (line 322) | def forward(self, x):
function fill_fc_weights (line 326) | def fill_fc_weights(layers):
function fill_up_weights (line 333) | def fill_up_weights(up):
class DeformConv (line 345) | class DeformConv(nn.Module):
method __init__ (line 346) | def __init__(self, chi, cho):
method forward (line 354) | def forward(self, x):
class IDAUp (line 360) | class IDAUp(nn.Module):
method __init__ (line 362) | def __init__(self, o, channels, up_f):
method forward (line 380) | def forward(self, layers, startp, endp):
class DLAUp (line 390) | class DLAUp(nn.Module):
method __init__ (line 391) | def __init__(self, startp, channels, scales, in_channels=None):
method forward (line 407) | def forward(self, layers):
class Interpolate (line 416) | class Interpolate(nn.Module):
method __init__ (line 417) | def __init__(self, scale, mode):
method forward (line 422) | def forward(self, x):
class DLASeg (line 427) | class DLASeg(nn.Module):
method __init__ (line 428) | def __init__(self, base_name, heads, pretrained, down_ratio, final_ker...
method forward (line 470) | def forward(self, x):
function get_pose_net (line 485) | def get_pose_net(num_layers, heads, head_conv=256, down_ratio=4):
FILE: src/lib/models/networks/resnet_dcn.py
function conv3x3 (line 32) | def conv3x3(in_planes, out_planes, stride=1):
class BasicBlock (line 38) | class BasicBlock(nn.Module):
method __init__ (line 41) | def __init__(self, inplanes, planes, stride=1, downsample=None):
method forward (line 51) | def forward(self, x):
class Bottleneck (line 70) | class Bottleneck(nn.Module):
method __init__ (line 73) | def __init__(self, inplanes, planes, stride=1, downsample=None):
method forward (line 88) | def forward(self, x):
function fill_up_weights (line 110) | def fill_up_weights(up):
function fill_fc_weights (line 121) | def fill_fc_weights(layers):
class PoseResNet (line 130) | class PoseResNet(nn.Module):
method __init__ (line 132) | def __init__(self, block, layers, heads, head_conv):
method _make_layer (line 179) | def _make_layer(self, block, planes, blocks, stride=1):
method _get_deconv_cfg (line 196) | def _get_deconv_cfg(self, deconv_kernel, index):
method _make_deconv_layer (line 209) | def _make_deconv_layer(self, num_layers, num_filters, num_kernels):
method forward (line 248) | def forward(self, x):
method init_weights (line 265) | def init_weights(self, num_layers):
function get_pose_net (line 285) | def get_pose_net(num_layers, heads, head_conv=256):
FILE: src/lib/models/scatter_gather.py
function scatter (line 6) | def scatter(inputs, target_gpus, dim=0, chunk_sizes=None):
function scatter_kwargs (line 28) | def scatter_kwargs(inputs, kwargs, target_gpus, dim=0, chunk_sizes=None):
FILE: src/lib/models/utils.py
function _sigmoid (line 8) | def _sigmoid(x):
function _gather_feat (line 12) | def _gather_feat(feat, ind, mask=None):
function _transpose_and_gather_feat (line 22) | def _transpose_and_gather_feat(feat, ind):
function flip_tensor (line 28) | def flip_tensor(x):
function flip_lr (line 33) | def flip_lr(x, flip_idx):
function flip_lr_off (line 41) | def flip_lr_off(x, flip_idx):
FILE: src/lib/opts.py
class opts (line 9) | class opts(object):
method __init__ (line 10) | def __init__(self):
method parse (line 227) | def parse(self, args=''):
method update_dataset_info_and_set_heads (line 284) | def update_dataset_info_and_set_heads(self, opt, dataset):
method init (line 336) | def init(self, args=''):
FILE: src/lib/trains/base_trainer.py
class ModelWithLoss (line 12) | class ModelWithLoss(torch.nn.Module):
method __init__ (line 13) | def __init__(self, model, loss):
method forward (line 18) | def forward(self, batch):
class BaseTrainer (line 23) | class BaseTrainer(object):
method __init__ (line 24) | def __init__(
method set_device (line 31) | def set_device(self, gpus, chunk_sizes, device):
method run_epoch (line 44) | def run_epoch(self, phase, epoch, data_loader):
method debug (line 106) | def debug(self, batch, output, iter_id):
method save_result (line 109) | def save_result(self, output, batch, results):
method _get_losses (line 112) | def _get_losses(self, opt):
method val (line 115) | def val(self, epoch, data_loader):
method train (line 118) | def train(self, epoch, data_loader):
FILE: src/lib/trains/ctdet.py
class CtdetLoss (line 17) | class CtdetLoss(torch.nn.Module):
method __init__ (line 18) | def __init__(self, opt):
method forward (line 28) | def forward(self, outputs, batch):
class CtdetTrainer (line 76) | class CtdetTrainer(BaseTrainer):
method __init__ (line 77) | def __init__(self, opt, model, optimizer=None):
method _get_losses (line 80) | def _get_losses(self, opt):
method debug (line 85) | def debug(self, batch, output, iter_id):
method save_result (line 122) | def save_result(self, output, batch, results):
FILE: src/lib/trains/ddd.py
class DddLoss (line 16) | class DddLoss(torch.nn.Module):
method __init__ (line 17) | def __init__(self, opt):
method forward (line 24) | def forward(self, outputs, batch):
class DddTrainer (line 66) | class DddTrainer(BaseTrainer):
method __init__ (line 67) | def __init__(self, opt, model, optimizer=None):
method _get_losses (line 70) | def _get_losses(self, opt):
method debug (line 76) | def debug(self, batch, output, iter_id):
method save_result (line 137) | def save_result(self, output, batch, results):
FILE: src/lib/trains/exdet.py
class ExdetLoss (line 17) | class ExdetLoss(torch.nn.Module):
method __init__ (line 18) | def __init__(self, opt):
method forward (line 25) | def forward(self, outputs, batch):
class ExdetTrainer (line 43) | class ExdetTrainer(BaseTrainer):
method __init__ (line 44) | def __init__(self, opt, model, optimizer=None):
method _get_losses (line 48) | def _get_losses(self, opt):
method debug (line 53) | def debug(self, batch, output, iter_id):
FILE: src/lib/trains/multi_pose.py
class MultiPoseLoss (line 16) | class MultiPoseLoss(torch.nn.Module):
method __init__ (line 17) | def __init__(self, opt):
method forward (line 27) | def forward(self, outputs, batch):
class MultiPoseTrainer (line 87) | class MultiPoseTrainer(BaseTrainer):
method __init__ (line 88) | def __init__(self, opt, model, optimizer=None):
method _get_losses (line 91) | def _get_losses(self, opt):
method debug (line 97) | def debug(self, batch, output, iter_id):
method save_result (line 148) | def save_result(self, output, batch, results):
FILE: src/lib/utils/ddd_utils.py
function compute_box_3d (line 8) | def compute_box_3d(dim, location, rotation_y):
function project_to_image (line 25) | def project_to_image(pts_3d, P):
function compute_orientation_3d (line 36) | def compute_orientation_3d(dim, location, rotation_y):
function draw_box_3d (line 49) | def draw_box_3d(image, corners, c=(0, 0, 255)):
function unproject_2d_to_3d (line 66) | def unproject_2d_to_3d(pt_2d, depth, P):
function alpha2rot_y (line 77) | def alpha2rot_y(alpha, x, cx, fx):
function rot_y2alpha (line 91) | def rot_y2alpha(rot_y, x, cx, fx):
function ddd2locrot (line 106) | def ddd2locrot(center, alpha, dim, depth, calib):
function project_3d_bbox (line 113) | def project_3d_bbox(location, dim, rotation_y, calib):
FILE: src/lib/utils/debugger.py
class Debugger (line 9) | class Debugger(object):
method __init__ (line 10) | def __init__(self, ipynb=False, theme='black',
method add_img (line 71) | def add_img(self, img, img_id='default', revert_color=False):
method add_mask (line 76) | def add_mask(self, mask, bg, imgId = 'default', trans = 0.8):
method show_img (line 81) | def show_img(self, pause = False, imgId = 'default'):
method add_blend_img (line 86) | def add_blend_img(self, back, fore, img_id='blend', trans=0.7):
method gen_colormap (line 117) | def gen_colormap(self, img, output_res=None):
method gen_colormap_hp (line 148) | def gen_colormap_hp(self, img, output_res=None):
method add_rect (line 162) | def add_rect(self, rect1, rect2, c, conf=1, img_id='default'):
method add_coco_bbox (line 171) | def add_coco_bbox(self, bbox, cat, conf=1, show_txt=True, img_id='defa...
method add_coco_hp (line 191) | def add_coco_hp(self, points, img_id='default'):
method add_points (line 202) | def add_points(self, points, img_id='default'):
method show_all_imgs (line 215) | def show_all_imgs(self, pause=False, time=0):
method save_img (line 236) | def save_img(self, imgId='default', path='./cache/debug/'):
method save_all_imgs (line 239) | def save_all_imgs(self, path='./cache/debug/', prefix='', genID=False):
method remove_side (line 250) | def remove_side(self, img_id, img):
method project_3d_to_bird (line 269) | def project_3d_to_bird(self, pt):
method add_ct_detection (line 275) | def add_ct_detection(
method add_3d_detection (line 311) | def add_3d_detection(
method compose_vis_add (line 332) | def compose_vis_add(
method add_2d_detection (line 360) | def add_2d_detection(
method add_bird_view (line 373) | def add_bird_view(self, dets, center_thresh=0.3, img_id='bird'):
method add_bird_views (line 397) | def add_bird_views(self, dets_dt, dets_gt, center_thresh=0.3, img_id='...
FILE: src/lib/utils/image.py
function flip (line 16) | def flip(img):
function transform_preds (line 19) | def transform_preds(coords, center, scale, output_size):
function get_affine_transform (line 27) | def get_affine_transform(center,
function affine_transform (line 63) | def affine_transform(pt, t):
function get_3rd_point (line 69) | def get_3rd_point(a, b):
function get_dir (line 74) | def get_dir(src_point, rot_rad):
function crop (line 84) | def crop(img, center, scale, output_size, rot=0):
function gaussian_radius (line 95) | def gaussian_radius(det_size, min_overlap=0.7):
function gaussian2D (line 118) | def gaussian2D(shape, sigma=1):
function draw_umich_gaussian (line 126) | def draw_umich_gaussian(heatmap, center, radius, k=1):
function draw_dense_reg (line 143) | def draw_dense_reg(regmap, heatmap, center, value, radius, is_offset=Fal...
function draw_msra_gaussian (line 175) | def draw_msra_gaussian(heatmap, center, sigma):
function grayscale (line 198) | def grayscale(image):
function lighting_ (line 201) | def lighting_(data_rng, image, alphastd, eigval, eigvec):
function blend_ (line 205) | def blend_(alpha, image1, image2):
function saturation_ (line 210) | def saturation_(data_rng, image, gs, gs_mean, var):
function brightness_ (line 214) | def brightness_(data_rng, image, gs, gs_mean, var):
function contrast_ (line 218) | def contrast_(data_rng, image, gs, gs_mean, var):
function color_aug (line 222) | def color_aug(data_rng, image, eig_val, eig_vec):
FILE: src/lib/utils/oracle_utils.py
function gen_oracle_map (line 9) | def gen_oracle_map(feat, ind, w, h):
FILE: src/lib/utils/post_process.py
function get_pred_depth (line 10) | def get_pred_depth(depth):
function get_alpha (line 13) | def get_alpha(rot):
function ddd_post_process_2d (line 23) | def ddd_post_process_2d(dets, c, s, opt):
function ddd_post_process_3d (line 49) | def ddd_post_process_3d(dets, calibs):
function ddd_post_process (line 75) | def ddd_post_process(dets, c, s, calibs, opt):
function ctdet_post_process (line 83) | def ctdet_post_process(dets, c, s, h, w, num_classes):
function multi_pose_post_process (line 103) | def multi_pose_post_process(dets, c, s, h, w):
FILE: src/lib/utils/utils.py
class AverageMeter (line 7) | class AverageMeter(object):
method __init__ (line 9) | def __init__(self):
method reset (line 12) | def reset(self):
method update (line 18) | def update(self, val, n=1):
FILE: src/main.py
function main (line 19) | def main(opt):
FILE: src/test.py
class PrefetchDataset (line 22) | class PrefetchDataset(torch.utils.data.Dataset):
method __init__ (line 23) | def __init__(self, opt, dataset, pre_process_func):
method __getitem__ (line 30) | def __getitem__(self, index):
method __len__ (line 44) | def __len__(self):
function prefetch_test (line 47) | def prefetch_test(opt):
function test (line 82) | def test(opt):
FILE: src/tools/_init_paths.py
function add_path (line 4) | def add_path(path):
FILE: src/tools/calc_coco_overlap.py
function iou (line 32) | def iou(box1, box2):
function generate_anchors (line 40) | def generate_anchors(
function _generate_anchors (line 54) | def _generate_anchors(base_size, scales, aspect_ratios):
function _whctrs (line 66) | def _whctrs(anchor):
function _mkanchors (line 75) | def _mkanchors(ws, hs, x_ctr, y_ctr):
function _ratio_enum (line 92) | def _ratio_enum(anchor, ratios):
function _scale_enum (line 103) | def _scale_enum(anchor, scales):
function _coco_box_to_bbox (line 112) | def _coco_box_to_bbox(box):
function count_agnostic (line 117) | def count_agnostic(split):
function count (line 135) | def count(split):
function count_iou (line 168) | def count_iou(split):
function count_anchor (line 201) | def count_anchor(split):
function count_size (line 284) | def count_size(split):
FILE: src/tools/convert_kitti_to_coco.py
function _bbox_to_coco_bbox (line 39) | def _bbox_to_coco_bbox(bbox):
function read_clib (line 43) | def read_clib(calib_path):
FILE: src/tools/kitti_eval/evaluate_object_3d.cpp
type DIFFICULTY (line 38) | enum DIFFICULTY{EASY=0, MODERATE=1, HARD=2}
type METRIC (line 41) | enum METRIC{IMAGE=0, GROUND=1, BOX3D=2}
type CLASSES (line 49) | enum CLASSES{CAR=0, PEDESTRIAN=1, CYCLIST=2}
function initGlobals (line 62) | void initGlobals () {
type tPrData (line 73) | struct tPrData {
method tPrData (line 79) | tPrData () :
type tBox (line 84) | struct tBox {
method tBox (line 91) | tBox (string type, double x1,double y1,double x2,double y2,double alph...
type tGroundtruth (line 96) | struct tGroundtruth {
method tGroundtruth (line 103) | tGroundtruth () :
method tGroundtruth (line 105) | tGroundtruth (tBox box,double truncation,int32_t occlusion) :
method tGroundtruth (line 107) | tGroundtruth (string type,double x1,double y1,double x2,double y2,doub...
type tDetection (line 112) | struct tDetection {
method tDetection (line 118) | tDetection ():
method tDetection (line 120) | tDetection (tBox box,double thresh) :
method tDetection (line 122) | tDetection (string type,double x1,double y1,double x2,double y2,double...
function loadDetections (line 132) | vector<tDetection> loadDetections(string file_name, bool &compute_aos,
function loadGroundtruth (line 179) | vector<tGroundtruth> loadGroundtruth(string file_name,bool &success) {
function saveStats (line 205) | void saveStats (const vector<double> &precision, const vector<double> &a...
function imageBoxOverlap (line 228) | inline double imageBoxOverlap(tBox a, tBox b, int32_t criterion=-1){
function imageBoxOverlap (line 264) | inline double imageBoxOverlap(tDetection a, tGroundtruth b, int32_t crit...
function Polygon (line 270) | Polygon toPolygon(const T& g) {
function groundBoxOverlap (line 295) | inline double groundBoxOverlap(tDetection d, tGroundtruth g, int32_t cri...
function box3DOverlap (line 318) | inline double box3DOverlap(tDetection d, tGroundtruth g, int32_t criteri...
function getThresholds (line 347) | vector<double> getThresholds(vector<double> &v, double n_groundtruth){
function cleanData (line 382) | void cleanData(CLASSES current_class, const vector<tGroundtruth> >, co...
function tPrData (line 456) | tPrData computeStatistics(CLASSES current_class, const vector<tGroundtru...
method tPrData (line 79) | tPrData () :
function eval_class (line 620) | bool eval_class (FILE *fp_det, FILE *fp_ori, CLASSES current_class,
function saveAndPlotPlots (line 706) | void saveAndPlotPlots(string dir_name,string file_name,string obj_type,v...
function eval (line 769) | bool eval(string result_sha,Mail* mail){
function main (line 888) | int32_t main (int32_t argc,char *argv[]) {
FILE: src/tools/kitti_eval/evaluate_object_3d_offline.cpp
type DIFFICULTY (line 37) | enum DIFFICULTY{EASY=0, MODERATE=1, HARD=2}
type METRIC (line 40) | enum METRIC{IMAGE=0, GROUND=1, BOX3D=2}
type CLASSES (line 48) | enum CLASSES{CAR=0, PEDESTRIAN=1, CYCLIST=2}
function initGlobals (line 62) | void initGlobals () {
type tPrData (line 73) | struct tPrData {
method tPrData (line 79) | tPrData () :
type tBox (line 84) | struct tBox {
method tBox (line 91) | tBox (string type, double x1,double y1,double x2,double y2,double alph...
type tGroundtruth (line 96) | struct tGroundtruth {
method tGroundtruth (line 103) | tGroundtruth () :
method tGroundtruth (line 105) | tGroundtruth (tBox box,double truncation,int32_t occlusion) :
method tGroundtruth (line 107) | tGroundtruth (string type,double x1,double y1,double x2,double y2,doub...
type tDetection (line 112) | struct tDetection {
method tDetection (line 118) | tDetection ():
method tDetection (line 120) | tDetection (tBox box,double thresh) :
method tDetection (line 122) | tDetection (string type,double x1,double y1,double x2,double y2,double...
function loadDetections (line 132) | vector<tDetection> loadDetections(string file_name, bool &compute_aos,
function loadGroundtruth (line 179) | vector<tGroundtruth> loadGroundtruth(string file_name,bool &success) {
function saveStats (line 205) | void saveStats (const vector<double> &precision, const vector<double> &a...
function imageBoxOverlap (line 228) | inline double imageBoxOverlap(tBox a, tBox b, int32_t criterion=-1){
function imageBoxOverlap (line 264) | inline double imageBoxOverlap(tDetection a, tGroundtruth b, int32_t crit...
function Polygon (line 270) | Polygon toPolygon(const T& g) {
function groundBoxOverlap (line 295) | inline double groundBoxOverlap(tDetection d, tGroundtruth g, int32_t cri...
function box3DOverlap (line 318) | inline double box3DOverlap(tDetection d, tGroundtruth g, int32_t criteri...
function getThresholds (line 347) | vector<double> getThresholds(vector<double> &v, double n_groundtruth){
function cleanData (line 382) | void cleanData(CLASSES current_class, const vector<tGroundtruth> >, co...
function tPrData (line 457) | tPrData computeStatistics(CLASSES current_class, const vector<tGroundtru...
method tPrData (line 79) | tPrData () :
function eval_class (line 621) | bool eval_class (FILE *fp_det, FILE *fp_ori, CLASSES current_class,
function saveAndPlotPlots (line 707) | void saveAndPlotPlots(string dir_name,string file_name,string obj_type,v...
function getEvalIndices (line 777) | vector<int32_t> getEvalIndices(const string& result_dir) {
function eval (line 794) | bool eval(string gt_dir, string result_dir, Mail* mail){
function main (line 916) | int32_t main (int32_t argc,char *argv[]) {
FILE: src/tools/kitti_eval/mail.h
function class (line 8) | class Mail {
FILE: src/tools/reval.py
function parse_args (line 27) | def parse_args():
function from_dets (line 53) | def from_dets(imdb_name, detection_file, args):
FILE: src/tools/vis_pred.py
function _coco_box_to_bbox (line 11) | def _coco_box_to_bbox(box):
function add_box (line 38) | def add_box(image, bbox, sc, cat_id):
FILE: src/tools/voc_eval_lib/datasets/ds_utils.py
function unique_boxes (line 13) | def unique_boxes(boxes, scale=1.0):
function xywh_to_xyxy (line 21) | def xywh_to_xyxy(boxes):
function xyxy_to_xywh (line 26) | def xyxy_to_xywh(boxes):
function validate_boxes (line 31) | def validate_boxes(boxes, width=0, height=0):
function filter_small_boxes (line 45) | def filter_small_boxes(boxes, min_size):
FILE: src/tools/voc_eval_lib/datasets/imdb.py
function bbox_overlaps (line 20) | def bbox_overlaps(box1, box2):
class imdb (line 28) | class imdb(object):
method __init__ (line 31) | def __init__(self, name, classes=None):
method name (line 46) | def name(self):
method num_classes (line 50) | def num_classes(self):
method classes (line 54) | def classes(self):
method image_index (line 58) | def image_index(self):
method roidb_handler (line 62) | def roidb_handler(self):
method roidb_handler (line 66) | def roidb_handler(self, val):
method set_proposal_method (line 69) | def set_proposal_method(self, method):
method roidb (line 74) | def roidb(self):
method cache_path (line 86) | def cache_path(self):
method num_images (line 93) | def num_images(self):
method image_path_at (line 96) | def image_path_at(self, i):
method default_roidb (line 99) | def default_roidb(self):
method evaluate_detections (line 102) | def evaluate_detections(self, all_boxes, output_dir=None):
method _get_widths (line 113) | def _get_widths(self):
method append_flipped_images (line 117) | def append_flipped_images(self):
method evaluate_recall (line 134) | def evaluate_recall(self, candidate_boxes=None, thresholds=None,
method create_roidb_from_box_list (line 224) | def create_roidb_from_box_list(self, box_list, gt_roidb):
method merge_roidbs (line 254) | def merge_roidbs(a, b):
method competition_mode (line 266) | def competition_mode(self, on):
FILE: src/tools/voc_eval_lib/datasets/pascal_voc.py
class pascal_voc (line 26) | class pascal_voc(imdb):
method __init__ (line 27) | def __init__(self, image_set, year, use_diff=False):
method image_path_at (line 62) | def image_path_at(self, i):
method image_path_from_index (line 68) | def image_path_from_index(self, index):
method _load_image_set_index (line 78) | def _load_image_set_index(self):
method _get_default_path (line 92) | def _get_default_path(self):
method gt_roidb (line 98) | def gt_roidb(self):
method rpn_roidb (line 122) | def rpn_roidb(self):
method _load_rpn_roidb (line 132) | def _load_rpn_roidb(self, gt_roidb):
method _load_pascal_annotation (line 141) | def _load_pascal_annotation(self, index):
method _get_comp_id (line 187) | def _get_comp_id(self):
method _get_voc_results_file_template (line 192) | def _get_voc_results_file_template(self):
method _write_voc_results_file (line 203) | def _write_voc_results_file(self, all_boxes):
method _do_python_eval (line 222) | def _do_python_eval(self, output_dir=None):
method _do_matlab_eval (line 270) | def _do_matlab_eval(self, output_dir='output'):
method evaluate_detections (line 285) | def evaluate_detections(self, all_boxes, output_dir=None):
method competition_mode (line 297) | def competition_mode(self, on):
FILE: src/tools/voc_eval_lib/datasets/voc_eval.py
function parse_rec (line 15) | def parse_rec(filename):
function voc_ap (line 35) | def voc_ap(rec, prec, use_07_metric=False):
function voc_eval (line 70) | def voc_eval(detpath,
FILE: src/tools/voc_eval_lib/model/bbox_transform.py
function bbox_transform (line 13) | def bbox_transform(ex_rois, gt_rois):
function bbox_transform_inv (line 34) | def bbox_transform_inv(boxes, deltas):
function clip_boxes (line 67) | def clip_boxes(boxes, im_shape):
FILE: src/tools/voc_eval_lib/model/config.py
function get_output_dir (line 293) | def get_output_dir(imdb, weights_filename):
function get_output_tb_dir (line 309) | def get_output_tb_dir(imdb, weights_filename):
function _merge_a_into_b (line 325) | def _merge_a_into_b(a, b):
function cfg_from_file (line 358) | def cfg_from_file(filename):
function cfg_from_list (line 367) | def cfg_from_list(cfg_list):
FILE: src/tools/voc_eval_lib/model/nms_wrapper.py
function nms (line 15) | def nms(dets, thresh, force_cpu=False):
FILE: src/tools/voc_eval_lib/model/test.py
function _get_image_blob (line 27) | def _get_image_blob(im):
function _get_blobs (line 61) | def _get_blobs(im):
function _clip_boxes (line 68) | def _clip_boxes(boxes, im_shape):
function _rescale_boxes (line 80) | def _rescale_boxes(boxes, inds, scales):
function im_detect (line 87) | def im_detect(sess, net, im):
function apply_nms (line 110) | def apply_nms(all_boxes, thresh):
function test_net (line 139) | def test_net(sess, net, imdb, weights_filename, max_per_image=100, thres...
FILE: src/tools/voc_eval_lib/nms/cpu_nms.c
type Py_ssize_t (line 61) | typedef int Py_ssize_t;
type Py_buffer (line 89) | typedef struct {
type Py_hash_t (line 241) | typedef long Py_hash_t;
function CYTHON_INLINE (line 310) | static CYTHON_INLINE float __PYX_NAN() {
type __Pyx_StringTabEntry (line 369) | typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* e...
function CYTHON_INLINE (line 409) | static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
function __Pyx_init_sys_getdefaultencoding_params (line 435) | static int __Pyx_init_sys_getdefaultencoding_params(void) {
function __Pyx_init_sys_getdefaultencoding_params (line 484) | static int __Pyx_init_sys_getdefaultencoding_params(void) {
type __Pyx_StructField_ (line 559) | struct __Pyx_StructField_
type __Pyx_TypeInfo (line 561) | typedef struct {
type __Pyx_StructField (line 571) | typedef struct __Pyx_StructField_ {
type __Pyx_BufFmt_StackElem (line 576) | typedef struct {
type __Pyx_BufFmt_Context (line 580) | typedef struct {
type npy_int8 (line 601) | typedef npy_int8 __pyx_t_5numpy_int8_t;
type npy_int16 (line 610) | typedef npy_int16 __pyx_t_5numpy_int16_t;
type npy_int32 (line 619) | typedef npy_int32 __pyx_t_5numpy_int32_t;
type npy_int64 (line 628) | typedef npy_int64 __pyx_t_5numpy_int64_t;
type npy_uint8 (line 637) | typedef npy_uint8 __pyx_t_5numpy_uint8_t;
type npy_uint16 (line 646) | typedef npy_uint16 __pyx_t_5numpy_uint16_t;
type npy_uint32 (line 655) | typedef npy_uint32 __pyx_t_5numpy_uint32_t;
type npy_uint64 (line 664) | typedef npy_uint64 __pyx_t_5numpy_uint64_t;
type npy_float32 (line 673) | typedef npy_float32 __pyx_t_5numpy_float32_t;
type npy_float64 (line 682) | typedef npy_float64 __pyx_t_5numpy_float64_t;
type npy_long (line 691) | typedef npy_long __pyx_t_5numpy_int_t;
type npy_longlong (line 700) | typedef npy_longlong __pyx_t_5numpy_long_t;
type npy_longlong (line 709) | typedef npy_longlong __pyx_t_5numpy_longlong_t;
type npy_ulong (line 718) | typedef npy_ulong __pyx_t_5numpy_uint_t;
type npy_ulonglong (line 727) | typedef npy_ulonglong __pyx_t_5numpy_ulong_t;
type npy_ulonglong (line 736) | typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t;
type npy_intp (line 745) | typedef npy_intp __pyx_t_5numpy_intp_t;
type npy_uintp (line 754) | typedef npy_uintp __pyx_t_5numpy_uintp_t;
type npy_double (line 763) | typedef npy_double __pyx_t_5numpy_float_t;
type npy_double (line 772) | typedef npy_double __pyx_t_5numpy_double_t;
type npy_longdouble (line 781) | typedef npy_longdouble __pyx_t_5numpy_longdouble_t;
type std (line 784) | typedef ::std::complex< float > __pyx_t_float_complex;
type __pyx_t_float_complex (line 786) | typedef float _Complex __pyx_t_float_complex;
type __pyx_t_float_complex (line 789) | typedef struct { float real, imag; } __pyx_t_float_complex;
type std (line 794) | typedef ::std::complex< double > __pyx_t_double_complex;
type __pyx_t_double_complex (line 796) | typedef double _Complex __pyx_t_double_complex;
type __pyx_t_double_complex (line 799) | typedef struct { double real, imag; } __pyx_t_double_complex;
type npy_cfloat (line 812) | typedef npy_cfloat __pyx_t_5numpy_cfloat_t;
type npy_cdouble (line 821) | typedef npy_cdouble __pyx_t_5numpy_cdouble_t;
type npy_clongdouble (line 830) | typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t;
type npy_cdouble (line 839) | typedef npy_cdouble __pyx_t_5numpy_complex_t;
type __Pyx_RefNannyAPIStruct (line 844) | typedef struct {
function CYTHON_INLINE (line 903) | static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, ...
function CYTHON_INLINE (line 949) | static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
type __Pyx_Buf_DimInfo (line 979) | typedef struct {
type __Pyx_Buffer (line 982) | typedef struct {
type __Pyx_LocalBuf_ND (line 986) | typedef struct {
type __Pyx_CodeObjectCacheEntry (line 1126) | typedef struct {
type __Pyx_CodeObjectCache (line 1130) | struct __Pyx_CodeObjectCache {
type __Pyx_CodeObjectCache (line 1135) | struct __Pyx_CodeObjectCache
function CYTHON_INLINE (line 1341) | static CYTHON_INLINE __pyx_t_5numpy_float32_t __pyx_f_3nms_7cpu_nms_max(...
function CYTHON_INLINE (line 1384) | static CYTHON_INLINE __pyx_t_5numpy_float32_t __pyx_f_3nms_7cpu_nms_min(...
function PyObject (line 1430) | static PyObject *__pyx_pw_3nms_7cpu_nms_1cpu_nms(PyObject *__pyx_self, P...
function PyObject (line 1495) | static PyObject *__pyx_pf_3nms_7cpu_nms_cpu_nms(CYTHON_UNUSED PyObject *...
function CYTHON_UNUSED (line 2348) | static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObjec...
function __pyx_pf_5numpy_7ndarray___getbuffer__ (line 2359) | static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v...
function CYTHON_UNUSED (line 3144) | static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(Py...
function __pyx_pf_5numpy_7ndarray_2__releasebuffer__ (line 3153) | static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *_...
function CYTHON_INLINE (line 3222) | static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyOb...
function CYTHON_INLINE (line 3272) | static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyOb...
function CYTHON_INLINE (line 3322) | static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyOb...
function CYTHON_INLINE (line 3372) | static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyOb...
function CYTHON_INLINE (line 3422) | static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyOb...
function CYTHON_INLINE (line 3472) | static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Desc...
function CYTHON_INLINE (line 4176) | static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *_...
function CYTHON_INLINE (line 4264) | static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObje...
type PyModuleDef (line 4325) | struct PyModuleDef
function __Pyx_InitCachedBuiltins (line 4397) | static int __Pyx_InitCachedBuiltins(void) {
function __Pyx_InitCachedConstants (line 4406) | static int __Pyx_InitCachedConstants(void) {
function __Pyx_InitGlobals (line 4575) | static int __Pyx_InitGlobals(void) {
function PyMODINIT_FUNC (line 4593) | PyMODINIT_FUNC PyInit_cpu_nms(void)
function __Pyx_RefNannyAPIStruct (line 4746) | static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modn...
function PyObject (line 4761) | static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
function __Pyx_RaiseArgtupleInvalid (line 4774) | static void __Pyx_RaiseArgtupleInvalid(
function __Pyx_RaiseDoubleKeywordsError (line 4799) | static void __Pyx_RaiseDoubleKeywordsError(
function __Pyx_ParseOptionalKeywords (line 4812) | static int __Pyx_ParseOptionalKeywords(
function __Pyx_RaiseArgumentTypeInvalid (line 4913) | static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *o...
function CYTHON_INLINE (line 4918) | static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *...
function CYTHON_INLINE (line 4939) | static CYTHON_INLINE int __Pyx_IsLittleEndian(void) {
function __Pyx_BufFmt_Init (line 4943) | static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx,
function __Pyx_BufFmt_ParseNumber (line 4970) | static int __Pyx_BufFmt_ParseNumber(const char** ts) {
function __Pyx_BufFmt_ExpectNumber (line 4985) | static int __Pyx_BufFmt_ExpectNumber(const char **ts) {
function __Pyx_BufFmt_RaiseUnexpectedChar (line 4992) | static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) {
function __Pyx_BufFmt_TypeCharToStandardSize (line 5020) | static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_comple...
function __Pyx_BufFmt_TypeCharToNativeSize (line 5038) | static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) {
type __Pyx_st_short (line 5057) | typedef struct { char c; short x; } __Pyx_st_short;
type __Pyx_st_int (line 5058) | typedef struct { char c; int x; } __Pyx_st_int;
type __Pyx_st_long (line 5059) | typedef struct { char c; long x; } __Pyx_st_long;
type __Pyx_st_float (line 5060) | typedef struct { char c; float x; } __Pyx_st_float;
type __Pyx_st_double (line 5061) | typedef struct { char c; double x; } __Pyx_st_double;
type __Pyx_st_longdouble (line 5062) | typedef struct { char c; long double x; } __Pyx_st_longdouble;
type __Pyx_st_void_p (line 5063) | typedef struct { char c; void *x; } __Pyx_st_void_p;
type __Pyx_st_longlong (line 5065) | typedef struct { char c; PY_LONG_LONG x; } __Pyx_st_longlong;
function __Pyx_BufFmt_TypeCharToAlignment (line 5067) | static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, CYTHON_UNUSED in...
type __Pyx_pad_short (line 5089) | typedef struct { short x; char c; } __Pyx_pad_short;
type __Pyx_pad_int (line 5090) | typedef struct { int x; char c; } __Pyx_pad_int;
type __Pyx_pad_long (line 5091) | typedef struct { long x; char c; } __Pyx_pad_long;
type __Pyx_pad_float (line 5092) | typedef struct { float x; char c; } __Pyx_pad_float;
type __Pyx_pad_double (line 5093) | typedef struct { double x; char c; } __Pyx_pad_double;
type __Pyx_pad_longdouble (line 5094) | typedef struct { long double x; char c; } __Pyx_pad_longdouble;
type __Pyx_pad_void_p (line 5095) | typedef struct { void *x; char c; } __Pyx_pad_void_p;
type __Pyx_pad_longlong (line 5097) | typedef struct { PY_LONG_LONG x; char c; } __Pyx_pad_longlong;
function __Pyx_BufFmt_TypeCharToPadding (line 5099) | static size_t __Pyx_BufFmt_TypeCharToPadding(char ch, CYTHON_UNUSED int ...
function __Pyx_BufFmt_TypeCharToGroup (line 5117) | static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) {
function __Pyx_BufFmt_RaiseExpected (line 5138) | static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) {
function __Pyx_BufFmt_ProcessTypeChunk (line 5162) | static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) {
function CYTHON_INLINE (line 5264) | static CYTHON_INLINE PyObject *
function CYTHON_INLINE (line 5437) | static CYTHON_INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) {
function CYTHON_INLINE (line 5444) | static CYTHON_INLINE int __Pyx_GetBufferAndValidate(
function CYTHON_INLINE (line 5478) | static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) {
function CYTHON_INLINE (line 5484) | static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *typ...
function CYTHON_INLINE (line 5497) | static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObj...
function __Pyx_RaiseBufferIndexError (line 5536) | static void __Pyx_RaiseBufferIndexError(int axis) {
function CYTHON_INLINE (line 5541) | static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *val...
function CYTHON_INLINE (line 5558) | static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **val...
function CYTHON_INLINE (line 5737) | static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expec...
function CYTHON_INLINE (line 5742) | static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t inde...
function CYTHON_INLINE (line 5748) | static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
function __Pyx_GetBuffer (line 5753) | static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
function __Pyx_ReleaseBuffer (line 5779) | static void __Pyx_ReleaseBuffer(Py_buffer *view) {
function PyObject (line 5817) | static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int l...
function CYTHON_INLINE (line 5899) | static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
function CYTHON_INLINE (line 5946) | static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
function CYTHON_INLINE (line 6041) | static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
function CYTHON_INLINE (line 6069) | static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_pa...
function CYTHON_INLINE (line 6073) | static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_pa...
function CYTHON_INLINE (line 6078) | static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_pa...
function CYTHON_INLINE (line 6088) | static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex a, __pyx_t_fl...
function CYTHON_INLINE (line 6091) | static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_co...
function CYTHON_INLINE (line 6097) | static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_c...
function CYTHON_INLINE (line 6103) | static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_c...
function CYTHON_INLINE (line 6109) | static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_c...
function CYTHON_INLINE (line 6116) | static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_co...
function CYTHON_INLINE (line 6122) | static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex a) {
function CYTHON_INLINE (line 6125) | static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_c...
function CYTHON_INLINE (line 6132) | static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex z) {
function CYTHON_INLINE (line 6139) | static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_powf(__pyx_t_float_co...
function CYTHON_INLINE (line 6189) | static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_...
function CYTHON_INLINE (line 6193) | static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_...
function CYTHON_INLINE (line 6198) | static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_...
function CYTHON_INLINE (line 6208) | static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex a, __pyx_t_do...
function CYTHON_INLINE (line 6211) | static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_c...
function CYTHON_INLINE (line 6217) | static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_...
function CYTHON_INLINE (line 6223) | static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_...
function CYTHON_INLINE (line 6229) | static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_...
function CYTHON_INLINE (line 6236) | static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_c...
function CYTHON_INLINE (line 6242) | static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex a) {
function CYTHON_INLINE (line 6245) | static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_...
function CYTHON_INLINE (line 6252) | static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex z) {
function CYTHON_INLINE (line 6259) | static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_c...
function __Pyx_PyInt_As_long (line 6312) | static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
function __Pyx_check_binary_version (line 6407) | static int __Pyx_check_binary_version(void) {
function PyObject (line 6428) | static PyObject *__Pyx_ImportModule(const char *name) {
function PyTypeObject (line 6445) | static PyTypeObject *__Pyx_ImportType(const char *module_name, const cha...
function __pyx_bisect_code_objects (line 6511) | static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries...
function PyCodeObject (line 6532) | static PyCodeObject *__pyx_find_code_object(int code_line) {
function __pyx_insert_code_object (line 6546) | static void __pyx_insert_code_object(int code_line, PyCodeObject* code_o...
function PyCodeObject (line 6593) | static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
function __Pyx_AddTraceback (line 6645) | static void __Pyx_AddTraceback(const char *funcname, int c_line,
function __Pyx_InitStrings (line 6673) | static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
function CYTHON_INLINE (line 6703) | static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(char* c_str) {
function CYTHON_INLINE (line 6706) | static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
function CYTHON_INLINE (line 6770) | static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
function CYTHON_INLINE (line 6825) | static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
function CYTHON_INLINE (line 6854) | static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
FILE: src/tools/voc_eval_lib/nms/gpu_nms.cpp
function CYTHON_INLINE (line 310) | static CYTHON_INLINE float __PYX_NAN() {
function CYTHON_INLINE (line 410) | static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
function __Pyx_init_sys_getdefaultencoding_params (line 436) | static int __Pyx_init_sys_getdefaultencoding_params(void) {
function __Pyx_init_sys_getdefaultencoding_params (line 485) | static int __Pyx_init_sys_getdefaultencoding_params(void) {
type __Pyx_StructField_ (line 560) | struct __Pyx_StructField_
type __Pyx_StructField_ (line 564) | struct __Pyx_StructField_
type __Pyx_StructField_ (line 572) | struct __Pyx_StructField_ {
function CYTHON_INLINE (line 920) | static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, ...
type __Pyx_CodeObjectCache (line 1121) | struct __Pyx_CodeObjectCache {
type __Pyx_CodeObjectCache (line 1126) | struct __Pyx_CodeObjectCache
function PyObject (line 1287) | static PyObject *__pyx_pw_3nms_7gpu_nms_1gpu_nms(PyObject *__pyx_self, P...
function PyObject (line 1367) | static PyObject *__pyx_pf_3nms_7gpu_nms_gpu_nms(CYTHON_UNUSED PyObject *...
function CYTHON_UNUSED (line 1720) | static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObjec...
function __pyx_pf_5numpy_7ndarray___getbuffer__ (line 1731) | static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v...
function CYTHON_UNUSED (line 2516) | static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(Py...
function __pyx_pf_5numpy_7ndarray_2__releasebuffer__ (line 2525) | static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *_...
function CYTHON_INLINE (line 2594) | static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyOb...
function CYTHON_INLINE (line 2644) | static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyOb...
function CYTHON_INLINE (line 2694) | static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyOb...
function CYTHON_INLINE (line 2744) | static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyOb...
function CYTHON_INLINE (line 2794) | static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyOb...
function CYTHON_INLINE (line 2844) | static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Desc...
function CYTHON_INLINE (line 3548) | static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *_...
function CYTHON_INLINE (line 3636) | static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObje...
type PyModuleDef (line 3697) | struct PyModuleDef
function __Pyx_InitCachedBuiltins (line 3750) | static int __Pyx_InitCachedBuiltins(void) {
function __Pyx_InitCachedConstants (line 3759) | static int __Pyx_InitCachedConstants(void) {
function __Pyx_InitGlobals (line 3883) | static int __Pyx_InitGlobals(void) {
function PyMODINIT_FUNC (line 3897) | PyMODINIT_FUNC PyInit_gpu_nms(void)
function __Pyx_RefNannyAPIStruct (line 4066) | static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modn...
function __Pyx_RaiseArgtupleInvalid (line 4081) | static void __Pyx_RaiseArgtupleInvalid(
function __Pyx_RaiseDoubleKeywordsError (line 4106) | static void __Pyx_RaiseDoubleKeywordsError(
function __Pyx_ParseOptionalKeywords (line 4119) | static int __Pyx_ParseOptionalKeywords(
function __Pyx_RaiseArgumentTypeInvalid (line 4220) | static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *o...
function CYTHON_INLINE (line 4225) | static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *...
function CYTHON_INLINE (line 4246) | static CYTHON_INLINE int __Pyx_IsLittleEndian(void) {
function __Pyx_BufFmt_Init (line 4250) | static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx,
function __Pyx_BufFmt_ParseNumber (line 4277) | static int __Pyx_BufFmt_ParseNumber(const char** ts) {
function __Pyx_BufFmt_ExpectNumber (line 4292) | static int __Pyx_BufFmt_ExpectNumber(const char **ts) {
function __Pyx_BufFmt_RaiseUnexpectedChar (line 4299) | static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) {
function __Pyx_BufFmt_TypeCharToStandardSize (line 4327) | static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_comple...
function __Pyx_BufFmt_TypeCharToNativeSize (line 4345) | static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) {
function __Pyx_BufFmt_TypeCharToAlignment (line 4374) | static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, CYTHON_UNUSED in...
function __Pyx_BufFmt_TypeCharToPadding (line 4406) | static size_t __Pyx_BufFmt_TypeCharToPadding(char ch, CYTHON_UNUSED int ...
function __Pyx_BufFmt_TypeCharToGroup (line 4424) | static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) {
function __Pyx_BufFmt_RaiseExpected (line 4445) | static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) {
function __Pyx_BufFmt_ProcessTypeChunk (line 4469) | static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) {
function CYTHON_INLINE (line 4571) | static CYTHON_INLINE PyObject *
function CYTHON_INLINE (line 4744) | static CYTHON_INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) {
function CYTHON_INLINE (line 4751) | static CYTHON_INLINE int __Pyx_GetBufferAndValidate(
function CYTHON_INLINE (line 4785) | static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) {
function PyObject (line 4791) | static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
function CYTHON_INLINE (line 4822) | static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObj...
function CYTHON_INLINE (line 4844) | static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *typ...
function __Pyx_RaiseBufferIndexError (line 4856) | static void __Pyx_RaiseBufferIndexError(int axis) {
function CYTHON_INLINE (line 4861) | static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
function __Pyx_RaiseBufferFallbackError (line 4958) | static void __Pyx_RaiseBufferFallbackError(void) {
function CYTHON_INLINE (line 4963) | static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *val...
function CYTHON_INLINE (line 4980) | static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **val...
function CYTHON_INLINE (line 5159) | static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expec...
function CYTHON_INLINE (line 5164) | static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t inde...
function CYTHON_INLINE (line 5170) | static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
function __Pyx_GetBuffer (line 5175) | static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
function __Pyx_ReleaseBuffer (line 5201) | static void __Pyx_ReleaseBuffer(Py_buffer *view) {
function PyObject (line 5239) | static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int l...
function CYTHON_INLINE (line 5342) | static CYTHON_INLINE npy_int32 __Pyx_PyInt_As_npy_int32(PyObject *x) {
function CYTHON_INLINE (line 5437) | static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
function CYTHON_INLINE (line 5465) | static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_pa...
function CYTHON_INLINE (line 5469) | static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_pa...
function CYTHON_INLINE (line 5474) | static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_pa...
function CYTHON_INLINE (line 5484) | static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex a, __pyx_t_fl...
function CYTHON_INLINE (line 5487) | static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_co...
function CYTHON_INLINE (line 5493) | static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_c...
function CYTHON_INLINE (line 5499) | static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_c...
function CYTHON_INLINE (line 5505) | static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_c...
function CYTHON_INLINE (line 5512) | static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_co...
function CYTHON_INLINE (line 5518) | static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex a) {
function CYTHON_INLINE (line 5521) | static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_c...
function CYTHON_INLINE (line 5528) | static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex z) {
function CYTHON_INLINE (line 5535) | static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_powf(__pyx_t_float_co...
function CYTHON_INLINE (line 5585) | static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_...
function CYTHON_INLINE (line 5589) | static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_...
function CYTHON_INLINE (line 5594) | static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_...
function CYTHON_INLINE (line 5604) | static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex a, __pyx_t_do...
function CYTHON_INLINE (line 5607) | static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_c...
function CYTHON_INLINE (line 5613) | static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_...
function CYTHON_INLINE (line 5619) | static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_...
function CYTHON_INLINE (line 5625) | static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_...
function CYTHON_INLINE (line 5632) | static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_c...
function CYTHON_INLINE (line 5638) | static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex a) {
function CYTHON_INLINE (line 5641) | static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_...
function CYTHON_INLINE (line 5648) | static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex z) {
function CYTHON_INLINE (line 5655) | static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_c...
function CYTHON_INLINE (line 5708) | static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
function CYTHON_INLINE (line 5803) | static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
function __Pyx_PyInt_As_long (line 5834) | static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
function __Pyx_check_binary_version (line 5929) | static int __Pyx_check_binary_version(void) {
function PyObject (line 5950) | static PyObject *__Pyx_ImportModule(const char *name) {
function PyTypeObject (line 5967) | static PyTypeObject *__Pyx_ImportType(const char *module_name, const cha...
function __pyx_bisect_code_objects (line 6033) | static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries...
function PyCodeObject (line 6054) | static PyCodeObject *__pyx_find_code_object(int code_line) {
function __pyx_insert_code_object (line 6068) | static void __pyx_insert_code_object(int code_line, PyCodeObject* code_o...
function PyCodeObject (line 6115) | static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
function __Pyx_AddTraceback (line 6167) | static void __Pyx_AddTraceback(const char *funcname, int c_line,
function __Pyx_InitStrings (line 6195) | static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
function CYTHON_INLINE (line 6225) | static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(char* c_str) {
function CYTHON_INLINE (line 6228) | static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
function CYTHON_INLINE (line 6292) | static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
function CYTHON_INLINE (line 6347) | static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
function CYTHON_INLINE (line 6376) | static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
FILE: src/tools/voc_eval_lib/nms/py_cpu_nms.py
function py_cpu_nms (line 10) | def py_cpu_nms(dets, thresh):
FILE: src/tools/voc_eval_lib/setup.py
function find_in_path (line 15) | def find_in_path(name, path):
function locate_cuda (line 24) | def locate_cuda():
function customize_compiler_for_nvcc (line 63) | def customize_compiler_for_nvcc(self):
class custom_build_ext (line 102) | class custom_build_ext(build_ext):
method build_extensions (line 103) | def build_extensions(self):
FILE: src/tools/voc_eval_lib/utils/blob.py
function im_list_to_blob (line 17) | def im_list_to_blob(ims):
function prep_im_for_blob (line 33) | def prep_im_for_blob(im, pixel_means, target_size, max_size):
FILE: src/tools/voc_eval_lib/utils/timer.py
class Timer (line 10) | class Timer(object):
method __init__ (line 12) | def __init__(self):
method tic (line 19) | def tic(self):
method toc (line 24) | def toc(self, average=True):
FILE: src/tools/voc_eval_lib/utils/visualization.py
function _draw_single_box (line 50) | def _draw_single_box(image, xmin, ymin, xmax, ymax, display_str, font, c...
function draw_bounding_boxes (line 71) | def draw_bounding_boxes(image, gt_boxes, im_info):
Condensed preview — 156 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (1,280K chars).
[
{
"path": ".gitignore",
"chars": 1249,
"preview": "legacy/*\n.DS_Store\ndebug/*\n*.DS_Store\n*.json\n*.mat\nsrc/.vscode/*\npreds/*\n*.h5\n*.pth\n*.checkpoint\n# Byte-compiled / optim"
},
{
"path": ".travis.yml",
"chars": 657,
"preview": "group: travis_latest\ndist: xenial # ubuntu-16.04\nlanguage: python\ncache: pip\npython:\n - 3.6\n - 3.7\ninstall:\n - pip i"
},
{
"path": "LICENSE",
"chars": 1090,
"preview": "MIT License\n\nCopyright (c) 2019 Xingyi Zhou\nAll rights reserved.\n\nPermission is hereby granted, free of charge, to any p"
},
{
"path": "NOTICE",
"chars": 7862,
"preview": "Portions of this software are derived from tf-faster-rcnn.\n\n============================================================"
},
{
"path": "README.md",
"chars": 8976,
"preview": "# Objects as Points\nObject detection, 3D detection, and pose estimation using center point detection:\n Python 3.6 and "
},
{
"path": "readme/MODEL_ZOO.md",
"chars": 7832,
"preview": "# MODEL ZOO\n\n### Common settings and notes\n\n- The experiments are run with pytorch 0.4.1, CUDA 9.0, and CUDNN 7.1.\n- Tra"
},
{
"path": "requirements.txt",
"chars": 62,
"preview": "opencv-python\nCython\nnumba\nprogress\nmatplotlib\neasydict\nscipy\n"
},
{
"path": "src/_init_paths.py",
"chars": 231,
"preview": "import os.path as osp\nimport sys\n\ndef add_path(path):\n if path not in sys.path:\n sys.path.insert(0, path)\n\nthi"
},
{
"path": "src/demo.py",
"chars": 1674,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport _in"
},
{
"path": "src/lib/datasets/dataset/coco.py",
"chars": 5214,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport pyc"
},
{
"path": "src/lib/datasets/dataset/coco_hp.py",
"chars": 4242,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport pyc"
},
{
"path": "src/lib/datasets/dataset/kitti.py",
"chars": 3058,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport tor"
},
{
"path": "src/lib/datasets/dataset/pascal.py",
"chars": 3032,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport pyc"
},
{
"path": "src/lib/datasets/dataset_factory.py",
"chars": 767,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nfrom .samp"
},
{
"path": "src/lib/datasets/sample/ctdet.py",
"chars": 5803,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport tor"
},
{
"path": "src/lib/datasets/sample/ddd.py",
"chars": 6801,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport tor"
},
{
"path": "src/lib/datasets/sample/exdet.py",
"chars": 5722,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport tor"
},
{
"path": "src/lib/datasets/sample/multi_pose.py",
"chars": 7913,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport tor"
},
{
"path": "src/lib/detectors/base_detector.py",
"chars": 5061,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport cv2"
},
{
"path": "src/lib/detectors/ctdet.py",
"chars": 3674,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport cv2"
},
{
"path": "src/lib/detectors/ddd.py",
"chars": 4013,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport cv2"
},
{
"path": "src/lib/detectors/detector_factory.py",
"chars": 382,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nfrom .exde"
},
{
"path": "src/lib/detectors/exdet.py",
"chars": 5063,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport _in"
},
{
"path": "src/lib/detectors/multi_pose.py",
"chars": 3923,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport cv2"
},
{
"path": "src/lib/external/.gitignore",
"chars": 160,
"preview": "bbox.c\nbbox.cpython-35m-x86_64-linux-gnu.so\nbbox.cpython-36m-x86_64-linux-gnu.so\n\nnms.c\nnms.cpython-35m-x86_64-linux-gnu"
},
{
"path": "src/lib/external/Makefile",
"chars": 56,
"preview": "all:\n\tpython setup.py build_ext --inplace\n\trm -rf build\n"
},
{
"path": "src/lib/external/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "src/lib/external/nms.pyx",
"chars": 13152,
"preview": "# --------------------------------------------------------\n# Fast R-CNN\n# Copyright (c) 2015 Microsoft\n# Licensed under "
},
{
"path": "src/lib/external/setup.py",
"chars": 368,
"preview": "import numpy\nfrom distutils.core import setup\nfrom distutils.extension import Extension\nfrom Cython.Build import cythoni"
},
{
"path": "src/lib/logger.py",
"chars": 2228,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\n# Code ref"
},
{
"path": "src/lib/models/data_parallel.py",
"chars": 5176,
"preview": "import torch\nfrom torch.nn.modules import Module\nfrom torch.nn.parallel.scatter_gather import gather\nfrom torch.nn.paral"
},
{
"path": "src/lib/models/decode.py",
"chars": 21763,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport tor"
},
{
"path": "src/lib/models/losses.py",
"chars": 7843,
"preview": "# ------------------------------------------------------------------------------\n# Portions of this code are from\n# Corn"
},
{
"path": "src/lib/models/model.py",
"chars": 3415,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport tor"
},
{
"path": "src/lib/models/networks/DCNv2/.gitignore",
"chars": 32,
"preview": ".vscode\n.idea\n*.so\n*.o\n*pyc\n_ext"
},
{
"path": "src/lib/models/networks/DCNv2/LICENSE",
"chars": 1521,
"preview": "BSD 3-Clause License\n\nCopyright (c) 2019, Charles Shang\nAll rights reserved.\n\nRedistribution and use in source and binar"
},
{
"path": "src/lib/models/networks/DCNv2/README.md",
"chars": 2078,
"preview": "## Deformable Convolutional Networks V2 with Pytorch\n\n### Build\n```bash\n ./make.sh # build\n python test.py"
},
{
"path": "src/lib/models/networks/DCNv2/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "src/lib/models/networks/DCNv2/build.py",
"chars": 1156,
"preview": "import os\nimport torch\nfrom torch.utils.ffi import create_extension\n\n\nsources = ['src/dcn_v2.c']\nheaders = ['src/dcn_v2."
},
{
"path": "src/lib/models/networks/DCNv2/build_double.py",
"chars": 1205,
"preview": "import os\nimport torch\nfrom torch.utils.ffi import create_extension\n\n\nsources = ['src/dcn_v2_double.c']\nheaders = ['src/"
},
{
"path": "src/lib/models/networks/DCNv2/dcn_v2.py",
"chars": 6797,
"preview": "#!/usr/bin/env python\nfrom __future__ import absolute_import\nfrom __future__ import print_function\nfrom __future__ impor"
},
{
"path": "src/lib/models/networks/DCNv2/dcn_v2_func.py",
"chars": 6526,
"preview": "#!/usr/bin/env python\nfrom __future__ import absolute_import\nfrom __future__ import print_function\nfrom __future__ impor"
},
{
"path": "src/lib/models/networks/DCNv2/make.sh",
"chars": 495,
"preview": "#!/usr/bin/env bash\ncd src/cuda\n\n# compile dcn\nnvcc -c -o dcn_v2_im2col_cuda.cu.o dcn_v2_im2col_cuda.cu -x cu -Xcompiler"
},
{
"path": "src/lib/models/networks/DCNv2/src/cuda/dcn_v2_im2col_cuda.cu",
"chars": 19537,
"preview": "#include \"dcn_v2_im2col_cuda.h\"\n#include <cstdio>\n#include <algorithm>\n#include <cstring>\n\n#define CUDA_KERNEL_LOOP(i, n"
},
{
"path": "src/lib/models/networks/DCNv2/src/cuda/dcn_v2_im2col_cuda.h",
"chars": 5225,
"preview": "/*!\n ******************* BEGIN Caffe Copyright Notice and Disclaimer ****************\n *\n * COPYRIGHT\n *\n * All contribu"
},
{
"path": "src/lib/models/networks/DCNv2/src/cuda/dcn_v2_im2col_cuda_double.cu",
"chars": 20897,
"preview": "#include \"dcn_v2_im2col_cuda_double.h\"\n#include <cstdio>\n#include <algorithm>\n#include <cstring>\n\n#define CUDA_KERNEL_LO"
},
{
"path": "src/lib/models/networks/DCNv2/src/cuda/dcn_v2_im2col_cuda_double.h",
"chars": 5253,
"preview": "/*!\n ******************* BEGIN Caffe Copyright Notice and Disclaimer ****************\n *\n * COPYRIGHT\n *\n * All contribu"
},
{
"path": "src/lib/models/networks/DCNv2/src/cuda/dcn_v2_psroi_pooling_cuda.cu",
"chars": 14827,
"preview": "/*!\n * Copyright (c) 2017 Microsoft\n * Licensed under The MIT License [see LICENSE for details]\n * \\file deformable_psro"
},
{
"path": "src/lib/models/networks/DCNv2/src/cuda/dcn_v2_psroi_pooling_cuda.h",
"chars": 2882,
"preview": "/*!\n * Copyright (c) 2017 Microsoft\n * Licensed under The MIT License [see LICENSE for details]\n * \\file deformable_psro"
},
{
"path": "src/lib/models/networks/DCNv2/src/cuda/dcn_v2_psroi_pooling_cuda_double.cu",
"chars": 15465,
"preview": "/*!\n * Copyright (c) 2017 Microsoft\n * Licensed under The MIT License [see LICENSE for details]\n * \\file deformable_psro"
},
{
"path": "src/lib/models/networks/DCNv2/src/cuda/dcn_v2_psroi_pooling_cuda_double.h",
"chars": 2912,
"preview": "/*!\n * Copyright (c) 2017 Microsoft\n * Licensed under The MIT License [see LICENSE for details]\n * \\file deformable_psro"
},
{
"path": "src/lib/models/networks/DCNv2/src/dcn_v2.c",
"chars": 1427,
"preview": "#include <TH/TH.h>\n#include <stdio.h>\n#include <math.h>\n\nvoid dcn_v2_forward(THFloatTensor *input, THFloatTensor *weight"
},
{
"path": "src/lib/models/networks/DCNv2/src/dcn_v2.h",
"chars": 1271,
"preview": "void dcn_v2_forward(THFloatTensor *input, THFloatTensor *weight,\n THFloatTensor *bias, THFloatTen"
},
{
"path": "src/lib/models/networks/DCNv2/src/dcn_v2_cuda.c",
"chars": 17737,
"preview": "#include <THC/THC.h>\n#include \"cuda/dcn_v2_im2col_cuda.h\"\n#include \"cuda/dcn_v2_psroi_pooling_cuda.h\"\n\nextern THCState *"
},
{
"path": "src/lib/models/networks/DCNv2/src/dcn_v2_cuda.h",
"chars": 3033,
"preview": "// #ifndef DCN_V2_CUDA\n// #define DCN_V2_CUDA\n\n// #ifdef __cplusplus\n// extern \"C\"\n// {\n// #endif\n\nvoid dcn_v2_cuda_forw"
},
{
"path": "src/lib/models/networks/DCNv2/src/dcn_v2_cuda_double.c",
"chars": 19812,
"preview": "#include <THC/THC.h>\n#include \"cuda/dcn_v2_im2col_cuda_double.h\"\n#include \"cuda/dcn_v2_psroi_pooling_cuda_double.h\"\n\next"
},
{
"path": "src/lib/models/networks/DCNv2/src/dcn_v2_cuda_double.h",
"chars": 3236,
"preview": "// #ifndef DCN_V2_CUDA\n// #define DCN_V2_CUDA\n\n// #ifdef __cplusplus\n// extern \"C\"\n// {\n// #endif\n\nvoid dcn_v2_cuda_forw"
},
{
"path": "src/lib/models/networks/DCNv2/src/dcn_v2_double.c",
"chars": 1373,
"preview": "#include <TH/TH.h>\n#include <stdio.h>\n#include <math.h>\n\nvoid dcn_v2_forward(THDoubleTensor *input, THDoubleTensor *weig"
},
{
"path": "src/lib/models/networks/DCNv2/src/dcn_v2_double.h",
"chars": 1232,
"preview": "void dcn_v2_forward(THDoubleTensor *input, THDoubleTensor *weight,\n THDoubleTensor *bias, THDoubleTen"
},
{
"path": "src/lib/models/networks/DCNv2/test.py",
"chars": 9286,
"preview": "#!/usr/bin/env python\nfrom __future__ import absolute_import\nfrom __future__ import print_function\nfrom __future__ impor"
},
{
"path": "src/lib/models/networks/dlav0.py",
"chars": 22682,
"preview": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nfrom __future__ import absolute_import\nfrom __future__ import division\nfro"
},
{
"path": "src/lib/models/networks/large_hourglass.py",
"chars": 9942,
"preview": "# ------------------------------------------------------------------------------\n# This code is base on \n# CornerNet (ht"
},
{
"path": "src/lib/models/networks/msra_resnet.py",
"chars": 10167,
"preview": "# ------------------------------------------------------------------------------\n# Copyright (c) Microsoft\n# Licensed un"
},
{
"path": "src/lib/models/networks/pose_dla_dcn.py",
"chars": 17594,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport os\n"
},
{
"path": "src/lib/models/networks/resnet_dcn.py",
"chars": 10054,
"preview": "# ------------------------------------------------------------------------------\n# Copyright (c) Microsoft\n# Licensed un"
},
{
"path": "src/lib/models/scatter_gather.py",
"chars": 1535,
"preview": "import torch\nfrom torch.autograd import Variable\nfrom torch.nn.parallel._functions import Scatter, Gather\n\n\ndef scatter("
},
{
"path": "src/lib/models/utils.py",
"chars": 1571,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport tor"
},
{
"path": "src/lib/opts.py",
"chars": 18696,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport arg"
},
{
"path": "src/lib/trains/base_trainer.py",
"chars": 3913,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport tim"
},
{
"path": "src/lib/trains/ctdet.py",
"chars": 5518,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport tor"
},
{
"path": "src/lib/trains/ddd.py",
"chars": 6919,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport tor"
},
{
"path": "src/lib/trains/exdet.py",
"chars": 3605,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport tor"
},
{
"path": "src/lib/trains/multi_pose.py",
"chars": 7252,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport tor"
},
{
"path": "src/lib/trains/train_factory.py",
"chars": 371,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nfrom .ctde"
},
{
"path": "src/lib/utils/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "src/lib/utils/ddd_utils.py",
"chars": 4548,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport num"
},
{
"path": "src/lib/utils/debugger.py",
"chars": 21225,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport num"
},
{
"path": "src/lib/utils/image.py",
"chars": 7690,
"preview": "# ------------------------------------------------------------------------------\n# Copyright (c) Microsoft\n# Licensed un"
},
{
"path": "src/lib/utils/oracle_utils.py",
"chars": 1317,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport num"
},
{
"path": "src/lib/utils/post_process.py",
"chars": 3958,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport num"
},
{
"path": "src/lib/utils/utils.py",
"chars": 542,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport tor"
},
{
"path": "src/main.py",
"chars": 3348,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport _in"
},
{
"path": "src/test.py",
"chars": 4092,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport _in"
},
{
"path": "src/tools/_init_paths.py",
"chars": 234,
"preview": "import os.path as osp\nimport sys\n\ndef add_path(path):\n if path not in sys.path:\n sys.path.insert(0, path)\n\nthi"
},
{
"path": "src/tools/calc_coco_overlap.py",
"chars": 10869,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport pyc"
},
{
"path": "src/tools/convert_hourglass_weight.py",
"chars": 905,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nMODEL_PATH"
},
{
"path": "src/tools/convert_kitti_to_coco.py",
"chars": 5935,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport pic"
},
{
"path": "src/tools/eval_coco.py",
"chars": 669,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport pyc"
},
{
"path": "src/tools/eval_coco_hp.py",
"chars": 795,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport pyc"
},
{
"path": "src/tools/get_kitti.sh",
"chars": 315,
"preview": "mkdir kitti\ncd kitti\nwget http://www.cvlibs.net/download.php?file=data_object_image_2.zip\nwget http://www.cvlibs.net/dow"
},
{
"path": "src/tools/get_pascal_voc.sh",
"chars": 998,
"preview": "mkdir voc\ncd voc\nwget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar\nwget http://host.robots"
},
{
"path": "src/tools/kitti_eval/README.md",
"chars": 798,
"preview": "# kitti_eval\n\n`evaluate_object_3d_offline.cpp`evaluates your KITTI detection locally on your own computer using your val"
},
{
"path": "src/tools/kitti_eval/evaluate_object_3d.cpp",
"chars": 33092,
"preview": "// from https://github.com/prclibo/kitti_eval\n#include <iostream>\n#include <algorithm>\n#include <stdio.h>\n#include <math"
},
{
"path": "src/tools/kitti_eval/evaluate_object_3d_offline.cpp",
"chars": 33774,
"preview": "#include <iostream>\n#include <algorithm>\n#include <stdio.h>\n#include <math.h>\n#include <vector>\n#include <numeric>\n#incl"
},
{
"path": "src/tools/kitti_eval/mail.h",
"chars": 811,
"preview": "#ifndef MAIL_H\n#define MAIL_H\n\n#include <stdio.h>\n#include <stdarg.h>\n#include <string.h>\n\nclass Mail {\n\npublic:\n\n Mail"
},
{
"path": "src/tools/merge_pascal_json.py",
"chars": 1058,
"preview": "import json\n\n# ANNOT_PATH = '/home/zxy/Datasets/VOC/annotations/'\nANNOT_PATH = 'voc/annotations/'\nOUT_PATH = ANNOT_PATH\n"
},
{
"path": "src/tools/reval.py",
"chars": 2331,
"preview": "#!/usr/bin/env python\n\n# --------------------------------------------------------\n# Fast R-CNN\n# Copyright (c) 2015 Micr"
},
{
"path": "src/tools/vis_pred.py",
"chars": 3571,
"preview": "import pycocotools.coco as coco\nfrom pycocotools.cocoeval import COCOeval\nimport sys\nimport cv2\nimport numpy as np\nimpor"
},
{
"path": "src/tools/voc_eval_lib/LICENSE",
"chars": 1068,
"preview": "MIT License\n\nCopyright (c) 2017 Xinlei Chen\n\nPermission is hereby granted, free of charge, to any person obtaining a cop"
},
{
"path": "src/tools/voc_eval_lib/Makefile",
"chars": 94,
"preview": "all:\n\tpython setup.py build_ext --inplace\n\trm -rf build\nclean:\n\trm -rf */*.pyc\n\trm -rf */*.so\n"
},
{
"path": "src/tools/voc_eval_lib/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "src/tools/voc_eval_lib/datasets/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "src/tools/voc_eval_lib/datasets/bbox.pyx",
"chars": 1757,
"preview": "# --------------------------------------------------------\n# Fast R-CNN\n# Copyright (c) 2015 Microsoft\n# Licensed under "
},
{
"path": "src/tools/voc_eval_lib/datasets/ds_utils.py",
"chars": 1402,
"preview": "# --------------------------------------------------------\n# Fast/er R-CNN\n# Licensed under The MIT License [see LICENSE"
},
{
"path": "src/tools/voc_eval_lib/datasets/imdb.py",
"chars": 9351,
"preview": "# --------------------------------------------------------\n# Fast R-CNN\n# Copyright (c) 2015 Microsoft\n# Licensed under "
},
{
"path": "src/tools/voc_eval_lib/datasets/pascal_voc.py",
"chars": 11345,
"preview": "# --------------------------------------------------------\n# Fast R-CNN\n# Copyright (c) 2015 Microsoft\n# Licensed under "
},
{
"path": "src/tools/voc_eval_lib/datasets/voc_eval.py",
"chars": 6802,
"preview": "# --------------------------------------------------------\n# Fast/er R-CNN\n# Licensed under The MIT License [see LICENSE"
},
{
"path": "src/tools/voc_eval_lib/model/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "src/tools/voc_eval_lib/model/bbox_transform.py",
"chars": 2549,
"preview": "# --------------------------------------------------------\n# Fast R-CNN\n# Copyright (c) 2015 Microsoft\n# Licensed under "
},
{
"path": "src/tools/voc_eval_lib/model/config.py",
"chars": 11010,
"preview": "from __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport os\n"
},
{
"path": "src/tools/voc_eval_lib/model/nms_wrapper.py",
"chars": 718,
"preview": "# --------------------------------------------------------\n# Fast R-CNN\n# Copyright (c) 2015 Microsoft\n# Licensed under "
},
{
"path": "src/tools/voc_eval_lib/model/test.py",
"chars": 6398,
"preview": "# --------------------------------------------------------\n# Tensorflow Faster R-CNN\n# Licensed under The MIT License [s"
},
{
"path": "src/tools/voc_eval_lib/nms/.gitignore",
"chars": 0,
"preview": ""
},
{
"path": "src/tools/voc_eval_lib/nms/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "src/tools/voc_eval_lib/nms/cpu_nms.c",
"chars": 292233,
"preview": "/* Generated by Cython 0.20.1 on Wed Oct 5 13:15:30 2016 */\n\n#define PY_SSIZE_T_CLEAN\n#ifndef CYTHON_USE_PYLONG_INTERNA"
},
{
"path": "src/tools/voc_eval_lib/nms/cpu_nms.pyx",
"chars": 2241,
"preview": "# --------------------------------------------------------\n# Fast R-CNN\n# Copyright (c) 2015 Microsoft\n# Licensed under "
},
{
"path": "src/tools/voc_eval_lib/nms/gpu_nms.cpp",
"chars": 269661,
"preview": "/* Generated by Cython 0.20.1 on Wed Oct 5 13:15:30 2016 */\n\n#define PY_SSIZE_T_CLEAN\n#ifndef CYTHON_USE_PYLONG_INTERNA"
},
{
"path": "src/tools/voc_eval_lib/nms/gpu_nms.hpp",
"chars": 146,
"preview": "void _nms(int* keep_out, int* num_out, const float* boxes_host, int boxes_num,\n int boxes_dim, float nms_overla"
},
{
"path": "src/tools/voc_eval_lib/nms/gpu_nms.pyx",
"chars": 1110,
"preview": "# --------------------------------------------------------\n# Faster R-CNN\n# Copyright (c) 2015 Microsoft\n# Licensed unde"
},
{
"path": "src/tools/voc_eval_lib/nms/nms_kernel.cu",
"chars": 5064,
"preview": "// ------------------------------------------------------------------\n// Faster R-CNN\n// Copyright (c) 2015 Microsoft\n//"
},
{
"path": "src/tools/voc_eval_lib/nms/py_cpu_nms.py",
"chars": 1051,
"preview": "# --------------------------------------------------------\n# Fast R-CNN\n# Copyright (c) 2015 Microsoft\n# Licensed under "
},
{
"path": "src/tools/voc_eval_lib/setup.py",
"chars": 5397,
"preview": "# --------------------------------------------------------\n# Fast R-CNN\n# Copyright (c) 2015 Microsoft\n# Licensed under "
},
{
"path": "src/tools/voc_eval_lib/utils/.gitignore",
"chars": 20,
"preview": "*.c\n*.cpp\n*.h\n*.hpp\n"
},
{
"path": "src/tools/voc_eval_lib/utils/__init__.py",
"chars": 248,
"preview": "# --------------------------------------------------------\n# Fast R-CNN\n# Copyright (c) 2015 Microsoft\n# Licensed under "
},
{
"path": "src/tools/voc_eval_lib/utils/bbox.pyx",
"chars": 1757,
"preview": "# --------------------------------------------------------\n# Fast R-CNN\n# Copyright (c) 2015 Microsoft\n# Licensed under "
},
{
"path": "src/tools/voc_eval_lib/utils/blob.py",
"chars": 1504,
"preview": "# --------------------------------------------------------\n# Fast R-CNN\n# Copyright (c) 2015 Microsoft\n# Licensed under "
},
{
"path": "src/tools/voc_eval_lib/utils/timer.py",
"chars": 948,
"preview": "# --------------------------------------------------------\n# Fast R-CNN\n# Copyright (c) 2015 Microsoft\n# Licensed under "
},
{
"path": "src/tools/voc_eval_lib/utils/visualization.py",
"chars": 4016,
"preview": "# --------------------------------------------------------\n# Tensorflow Faster R-CNN\n# Licensed under The MIT License [s"
}
]
// ... and 1 more files (download for full content)
About this extraction
This page contains the full source code of the xingyizhou/CenterNet GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 156 files (1.2 MB), approximately 370.4k tokens, and a symbol index with 911 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.