├── fasterRCNN
├── lib
│ ├── model
│ │ ├── __init__.py
│ │ ├── nms
│ │ │ ├── __init__.py
│ │ │ ├── _ext
│ │ │ │ ├── __init__.py
│ │ │ │ └── nms
│ │ │ │ │ └── __init__.py
│ │ │ ├── .gitignore
│ │ │ ├── make.sh
│ │ │ ├── src
│ │ │ │ ├── nms_cuda_kernel.h
│ │ │ │ └── nms_cuda.h
│ │ │ ├── nms_gpu.py
│ │ │ ├── nms_wrapper.py
│ │ │ ├── build.py
│ │ │ └── nms_cpu.py
│ │ ├── rpn
│ │ │ ├── __init__.py
│ │ │ ├── __pycache__
│ │ │ │ ├── rpn.cpython-36.pyc
│ │ │ │ ├── __init__.cpython-36.pyc
│ │ │ │ ├── bbox_transform.cpython-36.pyc
│ │ │ │ ├── proposal_layer.cpython-36.pyc
│ │ │ │ ├── generate_anchors.cpython-36.pyc
│ │ │ │ ├── anchor_target_layer.cpython-36.pyc
│ │ │ │ └── proposal_target_layer_cascade.cpython-36.pyc
│ │ │ └── generate_anchors.py
│ │ ├── utils
│ │ │ ├── __init__.py
│ │ │ ├── .gitignore
│ │ │ ├── __pycache__
│ │ │ │ ├── blob.cpython-36.pyc
│ │ │ │ ├── __init__.cpython-36.pyc
│ │ │ │ ├── config.cpython-36.pyc
│ │ │ │ └── net_utils.cpython-36.pyc
│ │ │ ├── blob.py
│ │ │ ├── logger.py
│ │ │ └── bbox.pyx
│ │ ├── roi_align
│ │ │ ├── __init__.py
│ │ │ ├── _ext
│ │ │ │ ├── __init__.py
│ │ │ │ └── roi_align
│ │ │ │ │ └── __init__.py
│ │ │ ├── functions
│ │ │ │ ├── __init__.py
│ │ │ │ └── roi_align.py
│ │ │ ├── modules
│ │ │ │ ├── __init__.py
│ │ │ │ └── roi_align.py
│ │ │ ├── make.sh
│ │ │ ├── src
│ │ │ │ ├── roi_align.h
│ │ │ │ ├── roi_align_cuda.h
│ │ │ │ ├── roi_align_kernel.h
│ │ │ │ └── roi_align_cuda.c
│ │ │ └── build.py
│ │ ├── roi_crop
│ │ │ ├── __init__.py
│ │ │ ├── _ext
│ │ │ │ ├── __init__.py
│ │ │ │ ├── crop_resize
│ │ │ │ │ ├── _crop_resize.so
│ │ │ │ │ └── __init__.py
│ │ │ │ └── roi_crop
│ │ │ │ │ └── __init__.py
│ │ │ ├── functions
│ │ │ │ ├── __init__.py
│ │ │ │ ├── roi_crop.py
│ │ │ │ ├── crop_resize.py
│ │ │ │ └── gridgen.py
│ │ │ ├── modules
│ │ │ │ ├── __init__.py
│ │ │ │ └── roi_crop.py
│ │ │ ├── make.sh
│ │ │ ├── src
│ │ │ │ ├── roi_crop_cuda.h
│ │ │ │ ├── roi_crop.h
│ │ │ │ └── roi_crop_cuda_kernel.h
│ │ │ └── build.py
│ │ ├── faster_rcnn
│ │ │ ├── __init__.py
│ │ │ ├── __pycache__
│ │ │ │ ├── resnet.cpython-36.pyc
│ │ │ │ ├── vgg16.cpython-36.pyc
│ │ │ │ ├── __init__.cpython-36.pyc
│ │ │ │ └── faster_rcnn.cpython-36.pyc
│ │ │ └── vgg16.py
│ │ ├── roi_pooling
│ │ │ ├── __init__.py
│ │ │ ├── _ext
│ │ │ │ ├── __init__.py
│ │ │ │ └── roi_pooling
│ │ │ │ │ └── __init__.py
│ │ │ ├── modules
│ │ │ │ ├── __init__.py
│ │ │ │ └── roi_pool.py
│ │ │ ├── functions
│ │ │ │ ├── __init__.py
│ │ │ │ └── roi_pool.py
│ │ │ ├── src
│ │ │ │ ├── roi_pooling.h
│ │ │ │ ├── roi_pooling_cuda.h
│ │ │ │ ├── roi_pooling_kernel.h
│ │ │ │ ├── roi_pooling_cuda.c
│ │ │ │ └── roi_pooling.c
│ │ │ └── build.py
│ │ ├── _C.cpython-36m-x86_64-linux-gnu.so
│ │ ├── __pycache__
│ │ │ └── __init__.cpython-36.pyc
│ │ ├── roi_layers
│ │ │ ├── __pycache__
│ │ │ │ ├── nms.cpython-36.pyc
│ │ │ │ ├── __init__.cpython-36.pyc
│ │ │ │ ├── roi_pool.cpython-36.pyc
│ │ │ │ └── roi_align.cpython-36.pyc
│ │ │ ├── nms.py
│ │ │ ├── __init__.py
│ │ │ ├── roi_pool.py
│ │ │ └── roi_align.py
│ │ └── csrc
│ │ │ ├── vision.cpp
│ │ │ ├── cpu
│ │ │ ├── vision.h
│ │ │ └── nms_cpu.cpp
│ │ │ ├── nms.h
│ │ │ ├── ROIPool.h
│ │ │ ├── ROIAlign.h
│ │ │ └── cuda
│ │ │ └── vision.h
│ ├── build
│ │ └── lib.linux-x86_64-3.6
│ │ │ ├── model
│ │ │ ├── __init__.py
│ │ │ ├── nms
│ │ │ │ ├── __init__.py
│ │ │ │ ├── _ext
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ └── nms
│ │ │ │ │ │ └── __init__.py
│ │ │ │ ├── nms_gpu.py
│ │ │ │ ├── nms_wrapper.py
│ │ │ │ ├── build.py
│ │ │ │ └── nms_cpu.py
│ │ │ ├── rpn
│ │ │ │ ├── __init__.py
│ │ │ │ └── generate_anchors.py
│ │ │ ├── roi_crop
│ │ │ │ ├── __init__.py
│ │ │ │ ├── _ext
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ ├── crop_resize
│ │ │ │ │ │ └── __init__.py
│ │ │ │ │ └── roi_crop
│ │ │ │ │ │ └── __init__.py
│ │ │ │ ├── functions
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ ├── roi_crop.py
│ │ │ │ │ ├── crop_resize.py
│ │ │ │ │ └── gridgen.py
│ │ │ │ ├── modules
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ └── roi_crop.py
│ │ │ │ └── build.py
│ │ │ ├── utils
│ │ │ │ ├── __init__.py
│ │ │ │ ├── blob.py
│ │ │ │ └── logger.py
│ │ │ ├── faster_rcnn
│ │ │ │ ├── __init__.py
│ │ │ │ └── vgg16.py
│ │ │ ├── roi_align
│ │ │ │ ├── __init__.py
│ │ │ │ ├── _ext
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ └── roi_align
│ │ │ │ │ │ └── __init__.py
│ │ │ │ ├── modules
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ └── roi_align.py
│ │ │ │ ├── functions
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ └── roi_align.py
│ │ │ │ └── build.py
│ │ │ ├── roi_pooling
│ │ │ │ ├── __init__.py
│ │ │ │ ├── _ext
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ └── roi_pooling
│ │ │ │ │ │ └── __init__.py
│ │ │ │ ├── functions
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ └── roi_pool.py
│ │ │ │ ├── modules
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ └── roi_pool.py
│ │ │ │ └── build.py
│ │ │ ├── _C.cpython-36m-x86_64-linux-gnu.so
│ │ │ └── roi_layers
│ │ │ │ ├── nms.py
│ │ │ │ ├── __init__.py
│ │ │ │ ├── roi_pool.py
│ │ │ │ └── roi_align.py
│ │ │ ├── pycocotools
│ │ │ ├── __init__.py
│ │ │ └── mask.py
│ │ │ ├── datasets
│ │ │ ├── __init__.py
│ │ │ ├── ds_utils.py
│ │ │ └── factory.py
│ │ │ └── roi_data_layer
│ │ │ ├── __init__.py
│ │ │ └── minibatch.py
│ ├── faster_rcnn.egg-info
│ │ ├── dependency_links.txt
│ │ ├── top_level.txt
│ │ ├── PKG-INFO
│ │ └── SOURCES.txt
│ ├── pycocotools
│ │ ├── __init__.py
│ │ ├── UPSTREAM_REV
│ │ ├── license.txt
│ │ ├── maskApi.h
│ │ └── mask.py
│ ├── datasets
│ │ ├── __pycache__
│ │ │ ├── vg.cpython-36.pyc
│ │ │ ├── coco.cpython-36.pyc
│ │ │ ├── imdb.cpython-36.pyc
│ │ │ ├── __init__.cpython-36.pyc
│ │ │ ├── ds_utils.cpython-36.pyc
│ │ │ ├── factory.cpython-36.pyc
│ │ │ ├── imagenet.cpython-36.pyc
│ │ │ ├── vg_eval.cpython-36.pyc
│ │ │ ├── voc_eval.cpython-36.pyc
│ │ │ └── pascal_voc.cpython-36.pyc
│ │ ├── __init__.py
│ │ ├── VOCdevkit-matlab-wrapper
│ │ │ ├── get_voc_opts.m
│ │ │ ├── xVOCap.m
│ │ │ └── voc_eval.m
│ │ ├── ds_utils.py
│ │ ├── tools
│ │ │ └── mcg_munge.py
│ │ ├── factory.py
│ │ └── vg_eval.py
│ ├── roi_data_layer
│ │ ├── __pycache__
│ │ │ ├── roidb.cpython-36.pyc
│ │ │ ├── __init__.cpython-36.pyc
│ │ │ ├── minibatch.cpython-36.pyc
│ │ │ └── roibatchLoader.cpython-36.pyc
│ │ ├── __init__.py
│ │ └── minibatch.py
│ └── setup.py
├── models
│ └── model.txt
├── data
│ └── coco
│ │ └── PythonAPI
│ │ ├── pycocotools.egg-info
│ │ ├── dependency_links.txt
│ │ ├── top_level.txt
│ │ ├── requires.txt
│ │ ├── PKG-INFO
│ │ └── SOURCES.txt
│ │ ├── pycocotools
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ │ ├── coco.cpython-36.pyc
│ │ │ ├── mask.cpython-36.pyc
│ │ │ ├── __init__.cpython-36.pyc
│ │ │ └── cocoeval.cpython-36.pyc
│ │ └── _mask.cpython-36m-x86_64-linux-gnu.so
│ │ ├── build
│ │ └── lib.linux-x86_64-3.6
│ │ │ └── pycocotools
│ │ │ ├── __init__.py
│ │ │ └── _mask.cpython-36m-x86_64-linux-gnu.so
│ │ ├── dist
│ │ └── pycocotools-2.0-py3.6-linux-x86_64.egg
│ │ ├── Makefile
│ │ └── setup.py
├── __pycache__
│ └── _init_paths.cpython-36.pyc
├── requirements.txt
├── .idea
│ ├── vcs.xml
│ ├── misc.xml
│ ├── modules.xml
│ ├── faster-rcnn.pytorch.iml
│ └── inspectionProfiles
│ │ └── Project_Default.xml
├── cfgs
│ ├── vgg16.yml
│ ├── res50.yml
│ ├── res101.yml
│ └── res101_ls.yml
├── _init_paths.py
└── LICENSE
├── data
└── framework.png
├── lib
├── __pycache__
│ ├── AdamW.cpython-36.pyc
│ ├── config.cpython-36.pyc
│ ├── funcs.cpython-36.pyc
│ ├── sttran.cpython-36.pyc
│ ├── transformer.cpython-36.pyc
│ ├── gaussian_drop.cpython-36.pyc
│ ├── message_pass.cpython-36.pyc
│ ├── model_motifs.cpython-36.pyc
│ ├── pytorch_misc.cpython-36.pyc
│ ├── word_vectors.cpython-36.pyc
│ ├── model_framework.cpython-36.pyc
│ ├── object_detector.cpython-36.pyc
│ ├── evaluation_recall.cpython-36.pyc
│ ├── adaptive_weight_loss.cpython-36.pyc
│ └── scene_graph_generator.cpython-36.pyc
├── fpn
│ ├── __pycache__
│ │ ├── box_utils.cpython-36.pyc
│ │ ├── anchor_targets.cpython-36.pyc
│ │ └── generate_anchors.cpython-36.pyc
│ └── box_intersections_cpu
│ │ ├── build
│ │ └── temp.linux-x86_64-3.6
│ │ │ └── bbox.o
│ │ ├── bbox.cpython-36m-x86_64-linux-gnu.so
│ │ ├── setup.py
│ │ └── bbox.pyx
├── ults
│ └── __pycache__
│ │ └── pytorch_misc.cpython-36.pyc
├── draw_rectangles
│ ├── build
│ │ └── temp.linux-x86_64-3.6
│ │ │ └── draw_rectangles.o
│ ├── draw_rectangles.cpython-36m-x86_64-linux-gnu.so
│ ├── setup.py
│ └── draw_rectangles.pyx
└── config.py
├── dataloader
└── __pycache__
│ └── action_genome.cpython-36.pyc
├── .idea
├── misc.xml
├── vcs.xml
├── modules.xml
└── STTran.iml
├── LICENSE
├── test.py
└── README.md
/fasterRCNN/lib/model/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/models/model.txt:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/nms/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/rpn/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/utils/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/nms/_ext/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_align/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/faster_rcnn/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_align/_ext/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/_ext/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_pooling/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_align/functions/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_align/modules/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/functions/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/modules/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_pooling/_ext/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_pooling/modules/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_pooling/functions/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/nms/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/rpn/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/faster_rcnn.egg-info/dependency_links.txt:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/nms/.gitignore:
--------------------------------------------------------------------------------
1 | *.c
2 | *.cpp
3 | *.so
4 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/pycocotools/__init__.py:
--------------------------------------------------------------------------------
1 | __author__ = 'tylin'
2 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/nms/_ext/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_crop/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/utils/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/utils/.gitignore:
--------------------------------------------------------------------------------
1 | *.c
2 | *.cpp
3 | *.so
4 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/faster_rcnn/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_align/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_crop/_ext/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_pooling/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/pycocotools.egg-info/dependency_links.txt:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_align/_ext/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_align/modules/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_crop/functions/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_crop/modules/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_pooling/_ext/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/pycocotools.egg-info/top_level.txt:
--------------------------------------------------------------------------------
1 | pycocotools
2 |
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/pycocotools/__init__.py:
--------------------------------------------------------------------------------
1 | __author__ = 'tylin'
2 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_align/functions/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_pooling/functions/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_pooling/modules/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/data/framework.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/data/framework.png
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/pycocotools/__init__.py:
--------------------------------------------------------------------------------
1 | __author__ = 'tylin'
2 |
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/build/lib.linux-x86_64-3.6/pycocotools/__init__.py:
--------------------------------------------------------------------------------
1 | __author__ = 'tylin'
2 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/faster_rcnn.egg-info/top_level.txt:
--------------------------------------------------------------------------------
1 | datasets
2 | model
3 | pycocotools
4 | roi_data_layer
5 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/pycocotools/UPSTREAM_REV:
--------------------------------------------------------------------------------
1 | https://github.com/pdollar/coco/commit/3ac47c77ebd5a1ed4254a98b7fbf2ef4765a3574
2 |
--------------------------------------------------------------------------------
/lib/__pycache__/AdamW.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/__pycache__/AdamW.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/__pycache__/config.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/__pycache__/config.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/__pycache__/funcs.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/__pycache__/funcs.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/__pycache__/sttran.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/__pycache__/sttran.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/pycocotools.egg-info/requires.txt:
--------------------------------------------------------------------------------
1 | setuptools>=18.0
2 | cython>=0.27.3
3 | matplotlib>=2.1.0
4 |
--------------------------------------------------------------------------------
/lib/__pycache__/transformer.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/__pycache__/transformer.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/__pycache__/gaussian_drop.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/__pycache__/gaussian_drop.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/__pycache__/message_pass.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/__pycache__/message_pass.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/__pycache__/model_motifs.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/__pycache__/model_motifs.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/__pycache__/pytorch_misc.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/__pycache__/pytorch_misc.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/__pycache__/word_vectors.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/__pycache__/word_vectors.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/fpn/__pycache__/box_utils.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/fpn/__pycache__/box_utils.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/__pycache__/model_framework.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/__pycache__/model_framework.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/__pycache__/object_detector.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/__pycache__/object_detector.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/__pycache__/_init_paths.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/__pycache__/_init_paths.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/__pycache__/evaluation_recall.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/__pycache__/evaluation_recall.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/fpn/__pycache__/anchor_targets.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/fpn/__pycache__/anchor_targets.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/ults/__pycache__/pytorch_misc.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/ults/__pycache__/pytorch_misc.cpython-36.pyc
--------------------------------------------------------------------------------
/dataloader/__pycache__/action_genome.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/dataloader/__pycache__/action_genome.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/requirements.txt:
--------------------------------------------------------------------------------
1 | cython
2 | cffi
3 | opencv-python
4 | scipy
5 | msgpack
6 | easydict
7 | matplotlib
8 | pyyaml
9 | tensorboardX
10 |
--------------------------------------------------------------------------------
/lib/__pycache__/adaptive_weight_loss.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/__pycache__/adaptive_weight_loss.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/__pycache__/scene_graph_generator.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/__pycache__/scene_graph_generator.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/fpn/__pycache__/generate_anchors.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/fpn/__pycache__/generate_anchors.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/__pycache__/vg.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/datasets/__pycache__/vg.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/__pycache__/coco.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/datasets/__pycache__/coco.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/__pycache__/imdb.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/datasets/__pycache__/imdb.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/_C.cpython-36m-x86_64-linux-gnu.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/_C.cpython-36m-x86_64-linux-gnu.so
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/__pycache__/__init__.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/__pycache__/__init__.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/rpn/__pycache__/rpn.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/rpn/__pycache__/rpn.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/__pycache__/__init__.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/datasets/__pycache__/__init__.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/__pycache__/ds_utils.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/datasets/__pycache__/ds_utils.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/__pycache__/factory.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/datasets/__pycache__/factory.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/__pycache__/imagenet.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/datasets/__pycache__/imagenet.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/__pycache__/vg_eval.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/datasets/__pycache__/vg_eval.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/__pycache__/voc_eval.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/datasets/__pycache__/voc_eval.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/utils/__pycache__/blob.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/utils/__pycache__/blob.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/__pycache__/pascal_voc.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/datasets/__pycache__/pascal_voc.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/_ext/crop_resize/_crop_resize.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/roi_crop/_ext/crop_resize/_crop_resize.so
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_layers/__pycache__/nms.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/roi_layers/__pycache__/nms.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/rpn/__pycache__/__init__.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/rpn/__pycache__/__init__.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/utils/__pycache__/__init__.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/utils/__pycache__/__init__.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/utils/__pycache__/config.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/utils/__pycache__/config.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/roi_data_layer/__pycache__/roidb.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/roi_data_layer/__pycache__/roidb.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/utils/__pycache__/net_utils.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/utils/__pycache__/net_utils.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/fpn/box_intersections_cpu/build/temp.linux-x86_64-3.6/bbox.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/fpn/box_intersections_cpu/build/temp.linux-x86_64-3.6/bbox.o
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/faster_rcnn/__pycache__/resnet.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/faster_rcnn/__pycache__/resnet.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/faster_rcnn/__pycache__/vgg16.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/faster_rcnn/__pycache__/vgg16.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_layers/__pycache__/__init__.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/roi_layers/__pycache__/__init__.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_layers/__pycache__/roi_pool.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/roi_layers/__pycache__/roi_pool.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/rpn/__pycache__/bbox_transform.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/rpn/__pycache__/bbox_transform.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/rpn/__pycache__/proposal_layer.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/rpn/__pycache__/proposal_layer.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/roi_data_layer/__pycache__/__init__.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/roi_data_layer/__pycache__/__init__.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/roi_data_layer/__pycache__/minibatch.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/roi_data_layer/__pycache__/minibatch.cpython-36.pyc
--------------------------------------------------------------------------------
/lib/draw_rectangles/build/temp.linux-x86_64-3.6/draw_rectangles.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/draw_rectangles/build/temp.linux-x86_64-3.6/draw_rectangles.o
--------------------------------------------------------------------------------
/lib/draw_rectangles/draw_rectangles.cpython-36m-x86_64-linux-gnu.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/draw_rectangles/draw_rectangles.cpython-36m-x86_64-linux-gnu.so
--------------------------------------------------------------------------------
/lib/fpn/box_intersections_cpu/bbox.cpython-36m-x86_64-linux-gnu.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/lib/fpn/box_intersections_cpu/bbox.cpython-36m-x86_64-linux-gnu.so
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/faster_rcnn/__pycache__/__init__.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/faster_rcnn/__pycache__/__init__.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_layers/__pycache__/roi_align.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/roi_layers/__pycache__/roi_align.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/rpn/__pycache__/generate_anchors.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/rpn/__pycache__/generate_anchors.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/faster_rcnn/__pycache__/faster_rcnn.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/faster_rcnn/__pycache__/faster_rcnn.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/rpn/__pycache__/anchor_target_layer.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/rpn/__pycache__/anchor_target_layer.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/lib/roi_data_layer/__pycache__/roibatchLoader.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/roi_data_layer/__pycache__/roibatchLoader.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/dist/pycocotools-2.0-py3.6-linux-x86_64.egg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/data/coco/PythonAPI/dist/pycocotools-2.0-py3.6-linux-x86_64.egg
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/pycocotools/__pycache__/coco.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/data/coco/PythonAPI/pycocotools/__pycache__/coco.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/pycocotools/__pycache__/mask.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/data/coco/PythonAPI/pycocotools/__pycache__/mask.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/pycocotools/__pycache__/__init__.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/data/coco/PythonAPI/pycocotools/__pycache__/__init__.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/pycocotools/__pycache__/cocoeval.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/data/coco/PythonAPI/pycocotools/__pycache__/cocoeval.cpython-36.pyc
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/pycocotools/_mask.cpython-36m-x86_64-linux-gnu.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/data/coco/PythonAPI/pycocotools/_mask.cpython-36m-x86_64-linux-gnu.so
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/_C.cpython-36m-x86_64-linux-gnu.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/_C.cpython-36m-x86_64-linux-gnu.so
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/rpn/__pycache__/proposal_target_layer_cascade.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/lib/model/rpn/__pycache__/proposal_target_layer_cascade.cpython-36.pyc
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/fasterRCNN/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/fasterRCNN/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_pooling/src/roi_pooling.h:
--------------------------------------------------------------------------------
1 | int roi_pooling_forward(int pooled_height, int pooled_width, float spatial_scale,
2 | THFloatTensor * features, THFloatTensor * rois, THFloatTensor * output);
--------------------------------------------------------------------------------
/lib/fpn/box_intersections_cpu/setup.py:
--------------------------------------------------------------------------------
1 | from distutils.core import setup
2 | from Cython.Build import cythonize
3 | import numpy
4 |
5 | setup(name="bbox_cython", ext_modules=cythonize('bbox.pyx'), include_dirs=[numpy.get_include()])
--------------------------------------------------------------------------------
/lib/draw_rectangles/setup.py:
--------------------------------------------------------------------------------
1 | from distutils.core import setup
2 | from Cython.Build import cythonize
3 | import numpy
4 |
5 | setup(name="draw_rectangles_cython", ext_modules=cythonize('draw_rectangles.pyx'), include_dirs=[numpy.get_include()])
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/build/lib.linux-x86_64-3.6/pycocotools/_mask.cpython-36m-x86_64-linux-gnu.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrcong/STTran/HEAD/fasterRCNN/data/coco/PythonAPI/build/lib.linux-x86_64-3.6/pycocotools/_mask.cpython-36m-x86_64-linux-gnu.so
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | # install pycocotools locally
3 | python setup.py build_ext --inplace
4 | rm -rf build
5 |
6 | install:
7 | # install pycocotools to the Python site-packages
8 | python setup.py build_ext install
9 | rm -rf build
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_layers/nms.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | # from ._utils import _C
3 | from fasterRCNN.lib.model import _C
4 |
5 | nms = _C.nms
6 | # nms.__doc__ = """
7 | # This function performs Non-maximum suppresion"""
8 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/nms/make.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # CUDA_PATH=/usr/local/cuda/
4 |
5 | cd src
6 | echo "Compiling stnm kernels by nvcc..."
7 | nvcc -c -o nms_cuda_kernel.cu.o nms_cuda_kernel.cu -x cu -Xcompiler -fPIC -arch=sm_52
8 |
9 | cd ../
10 | python build.py
11 |
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/pycocotools.egg-info/PKG-INFO:
--------------------------------------------------------------------------------
1 | Metadata-Version: 1.0
2 | Name: pycocotools
3 | Version: 2.0
4 | Summary: UNKNOWN
5 | Home-page: UNKNOWN
6 | Author: UNKNOWN
7 | Author-email: UNKNOWN
8 | License: UNKNOWN
9 | Description: UNKNOWN
10 | Platform: UNKNOWN
11 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_layers/nms.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | # from ._utils import _C
3 | from model import _C
4 |
5 | nms = _C.nms
6 | # nms.__doc__ = """
7 | # This function performs Non-maximum suppresion"""
8 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/faster_rcnn.egg-info/PKG-INFO:
--------------------------------------------------------------------------------
1 | Metadata-Version: 1.0
2 | Name: faster-rcnn
3 | Version: 0.1
4 | Summary: object detection in pytorch
5 | Home-page: UNKNOWN
6 | Author: UNKNOWN
7 | Author-email: UNKNOWN
8 | License: UNKNOWN
9 | Description: UNKNOWN
10 | Platform: UNKNOWN
11 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/nms/src/nms_cuda_kernel.h:
--------------------------------------------------------------------------------
1 | #ifdef __cplusplus
2 | extern "C" {
3 | #endif
4 |
5 | void nms_cuda_compute(int* keep_out, int *num_out, float* boxes_host, int boxes_num,
6 | int boxes_dim, float nms_overlap_thresh);
7 |
8 | #ifdef __cplusplus
9 | }
10 | #endif
11 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_align/make.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | CUDA_PATH=/usr/local/cuda/
4 |
5 | cd src
6 | echo "Compiling my_lib kernels by nvcc..."
7 | nvcc -c -o roi_align_kernel.cu.o roi_align_kernel.cu -x cu -Xcompiler -fPIC -arch=sm_52
8 |
9 | cd ../
10 | python build.py
11 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/__init__.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast R-CNN
3 | # Copyright (c) 2015 Microsoft
4 | # Licensed under The MIT License [see LICENSE for details]
5 | # Written by Ross Girshick
6 | # --------------------------------------------------------
7 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/make.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | CUDA_PATH=/usr/local/cuda/
4 |
5 | cd src
6 | echo "Compiling my_lib kernels by nvcc..."
7 | nvcc -c -o roi_crop_cuda_kernel.cu.o roi_crop_cuda_kernel.cu -x cu -Xcompiler -fPIC -arch=sm_52
8 |
9 | cd ../
10 | python build.py
11 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/roi_data_layer/__init__.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast R-CNN
3 | # Copyright (c) 2015 Microsoft
4 | # Licensed under The MIT License [see LICENSE for details]
5 | # Written by Ross Girshick
6 | # --------------------------------------------------------
7 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/nms/src/nms_cuda.h:
--------------------------------------------------------------------------------
1 | // int nms_cuda(THCudaTensor *keep_out, THCudaTensor *num_out,
2 | // THCudaTensor *boxes_host, THCudaTensor *nms_overlap_thresh);
3 |
4 | int nms_cuda(THCudaIntTensor *keep_out, THCudaTensor *boxes_host,
5 | THCudaIntTensor *num_out, float nms_overlap_thresh);
6 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/datasets/__init__.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast R-CNN
3 | # Copyright (c) 2015 Microsoft
4 | # Licensed under The MIT License [see LICENSE for details]
5 | # Written by Ross Girshick
6 | # --------------------------------------------------------
7 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/roi_data_layer/__init__.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast R-CNN
3 | # Copyright (c) 2015 Microsoft
4 | # Licensed under The MIT License [see LICENSE for details]
5 | # Written by Ross Girshick
6 | # --------------------------------------------------------
7 |
--------------------------------------------------------------------------------
/fasterRCNN/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/VOCdevkit-matlab-wrapper/get_voc_opts.m:
--------------------------------------------------------------------------------
1 | function VOCopts = get_voc_opts(path)
2 |
3 | tmp = pwd;
4 | cd(path);
5 | try
6 | addpath('VOCcode');
7 | VOCinit;
8 | catch
9 | rmpath('VOCcode');
10 | cd(tmp);
11 | error(sprintf('VOCcode directory not found under %s', path));
12 | end
13 | rmpath('VOCcode');
14 | cd(tmp);
15 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/VOCdevkit-matlab-wrapper/xVOCap.m:
--------------------------------------------------------------------------------
1 | function ap = xVOCap(rec,prec)
2 | % From the PASCAL VOC 2011 devkit
3 |
4 | mrec=[0 ; rec ; 1];
5 | mpre=[0 ; prec ; 0];
6 | for i=numel(mpre)-1:-1:1
7 | mpre(i)=max(mpre(i),mpre(i+1));
8 | end
9 | i=find(mrec(2:end)~=mrec(1:end-1))+1;
10 | ap=sum((mrec(i)-mrec(i-1)).*mpre(i));
11 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/modules/roi_crop.py:
--------------------------------------------------------------------------------
1 | from torch.nn.modules.module import Module
2 | from ..functions.roi_crop import RoICropFunction
3 |
4 | class _RoICrop(Module):
5 | def __init__(self, layout = 'BHWD'):
6 | super(_RoICrop, self).__init__()
7 | def forward(self, input1, input2):
8 | return RoICropFunction()(input1, input2)
9 |
--------------------------------------------------------------------------------
/fasterRCNN/cfgs/vgg16.yml:
--------------------------------------------------------------------------------
1 | EXP_DIR: vgg16
2 | TRAIN:
3 | HAS_RPN: True
4 | BBOX_NORMALIZE_TARGETS_PRECOMPUTED: True
5 | RPN_POSITIVE_OVERLAP: 0.7
6 | RPN_BATCHSIZE: 256
7 | PROPOSAL_METHOD: gt
8 | BG_THRESH_LO: 0.0
9 | BATCH_SIZE: 256
10 | LEARNING_RATE: 0.01
11 | TEST:
12 | HAS_RPN: True
13 | POOLING_MODE: align
14 | CROP_RESIZE_WITH_MAX_POOL: False
15 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_layers/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | import torch
3 | from .nms import nms
4 | from .roi_align import ROIAlign
5 | from .roi_align import roi_align
6 | from .roi_pool import ROIPool
7 | from .roi_pool import roi_pool
8 |
9 | __all__ = ["nms", "roi_align", "ROIAlign", "roi_pool", "ROIPool"]
10 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_crop/modules/roi_crop.py:
--------------------------------------------------------------------------------
1 | from torch.nn.modules.module import Module
2 | from ..functions.roi_crop import RoICropFunction
3 |
4 | class _RoICrop(Module):
5 | def __init__(self, layout = 'BHWD'):
6 | super(_RoICrop, self).__init__()
7 | def forward(self, input1, input2):
8 | return RoICropFunction()(input1, input2)
9 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/nms/nms_gpu.py:
--------------------------------------------------------------------------------
1 | from __future__ import absolute_import
2 | import torch
3 | import numpy as np
4 | from ._ext import nms
5 | import pdb
6 |
7 | def nms_gpu(dets, thresh):
8 | keep = dets.new(dets.size(0), 1).zero_().int()
9 | num_out = dets.new(1).zero_().int()
10 | nms.nms_cuda(keep, dets, num_out, thresh)
11 | keep = keep[:num_out[0]]
12 | return keep
13 |
--------------------------------------------------------------------------------
/fasterRCNN/_init_paths.py:
--------------------------------------------------------------------------------
1 | import os.path as osp
2 | import sys
3 |
4 | def add_path(path):
5 | if path not in sys.path:
6 | sys.path.insert(0, path)
7 |
8 | this_dir = osp.dirname(__file__)
9 |
10 | # Add lib to PYTHONPATH
11 | lib_path = osp.join(this_dir, 'lib')
12 | add_path(lib_path)
13 |
14 | coco_path = osp.join(this_dir, 'data', 'coco', 'PythonAPI')
15 | add_path(coco_path)
16 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_layers/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | import torch
3 | from .nms import nms
4 | from .roi_align import ROIAlign
5 | from .roi_align import roi_align
6 | from .roi_pool import ROIPool
7 | from .roi_pool import roi_pool
8 |
9 | __all__ = ["nms", "roi_align", "ROIAlign", "roi_pool", "ROIPool"]
10 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/nms/nms_gpu.py:
--------------------------------------------------------------------------------
1 | from __future__ import absolute_import
2 | import torch
3 | import numpy as np
4 | from ._ext import nms
5 | import pdb
6 |
7 | def nms_gpu(dets, thresh):
8 | keep = dets.new(dets.size(0), 1).zero_().int()
9 | num_out = dets.new(1).zero_().int()
10 | nms.nms_cuda(keep, dets, num_out, thresh)
11 | keep = keep[:num_out[0]]
12 | return keep
13 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_align/src/roi_align.h:
--------------------------------------------------------------------------------
1 | int roi_align_forward(int aligned_height, int aligned_width, float spatial_scale,
2 | THFloatTensor * features, THFloatTensor * rois, THFloatTensor * output);
3 |
4 | int roi_align_backward(int aligned_height, int aligned_width, float spatial_scale,
5 | THFloatTensor * top_grad, THFloatTensor * rois, THFloatTensor * bottom_grad);
6 |
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/pycocotools.egg-info/SOURCES.txt:
--------------------------------------------------------------------------------
1 | setup.py
2 | ../common/maskApi.c
3 | pycocotools/__init__.py
4 | pycocotools/_mask.c
5 | pycocotools/coco.py
6 | pycocotools/cocoeval.py
7 | pycocotools/mask.py
8 | pycocotools.egg-info/PKG-INFO
9 | pycocotools.egg-info/SOURCES.txt
10 | pycocotools.egg-info/dependency_links.txt
11 | pycocotools.egg-info/requires.txt
12 | pycocotools.egg-info/top_level.txt
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/_ext/crop_resize/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | from torch.utils.ffi import _wrap_function
3 | from ._crop_resize import lib as _lib, ffi as _ffi
4 |
5 | __all__ = []
6 | def _import_symbols(locals):
7 | for symbol in dir(_lib):
8 | fn = getattr(_lib, symbol)
9 | locals[symbol] = _wrap_function(fn, _ffi)
10 | __all__.append(symbol)
11 |
12 | _import_symbols(locals())
13 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_align/src/roi_align_cuda.h:
--------------------------------------------------------------------------------
1 | int roi_align_forward_cuda(int aligned_height, int aligned_width, float spatial_scale,
2 | THCudaTensor * features, THCudaTensor * rois, THCudaTensor * output);
3 |
4 | int roi_align_backward_cuda(int aligned_height, int aligned_width, float spatial_scale,
5 | THCudaTensor * top_grad, THCudaTensor * rois, THCudaTensor * bottom_grad);
6 |
--------------------------------------------------------------------------------
/fasterRCNN/cfgs/res50.yml:
--------------------------------------------------------------------------------
1 | EXP_DIR: res50
2 | TRAIN:
3 | HAS_RPN: True
4 | # IMS_PER_BATCH: 1
5 | BBOX_NORMALIZE_TARGETS_PRECOMPUTED: True
6 | RPN_POSITIVE_OVERLAP: 0.7
7 | RPN_BATCHSIZE: 256
8 | PROPOSAL_METHOD: gt
9 | BG_THRESH_LO: 0.0
10 | DISPLAY: 20
11 | BATCH_SIZE: 256
12 | WEIGHT_DECAY: 0.0001
13 | DOUBLE_BIAS: False
14 | SNAPSHOT_PREFIX: res50_faster_rcnn
15 | TEST:
16 | HAS_RPN: True
17 | POOLING_MODE: crop
18 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_crop/_ext/crop_resize/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | from torch.utils.ffi import _wrap_function
3 | from ._crop_resize import lib as _lib, ffi as _ffi
4 |
5 | __all__ = []
6 | def _import_symbols(locals):
7 | for symbol in dir(_lib):
8 | fn = getattr(_lib, symbol)
9 | locals[symbol] = _wrap_function(fn, _ffi)
10 | __all__.append(symbol)
11 |
12 | _import_symbols(locals())
13 |
--------------------------------------------------------------------------------
/fasterRCNN/cfgs/res101.yml:
--------------------------------------------------------------------------------
1 | EXP_DIR: res101
2 | TRAIN:
3 | HAS_RPN: True
4 | BBOX_NORMALIZE_TARGETS_PRECOMPUTED: True
5 | RPN_POSITIVE_OVERLAP: 0.7
6 | RPN_BATCHSIZE: 256
7 | PROPOSAL_METHOD: gt
8 | BG_THRESH_LO: 0.0
9 | DISPLAY: 20
10 | BATCH_SIZE: 128
11 | WEIGHT_DECAY: 0.0001
12 | DOUBLE_BIAS: False
13 | LEARNING_RATE: 0.001
14 | TEST:
15 | HAS_RPN: True
16 | POOLING_SIZE: 7
17 | POOLING_MODE: align
18 | CROP_RESIZE_WITH_MAX_POOL: False
19 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_pooling/src/roi_pooling_cuda.h:
--------------------------------------------------------------------------------
1 | int roi_pooling_forward_cuda(int pooled_height, int pooled_width, float spatial_scale,
2 | THCudaTensor * features, THCudaTensor * rois, THCudaTensor * output, THCudaIntTensor * argmax);
3 |
4 | int roi_pooling_backward_cuda(int pooled_height, int pooled_width, float spatial_scale,
5 | THCudaTensor * top_grad, THCudaTensor * rois, THCudaTensor * bottom_grad, THCudaIntTensor * argmax);
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/nms/_ext/nms/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | from torch.utils.ffi import _wrap_function
3 | from ._nms import lib as _lib, ffi as _ffi
4 |
5 | __all__ = []
6 | def _import_symbols(locals):
7 | for symbol in dir(_lib):
8 | fn = getattr(_lib, symbol)
9 | if callable(fn):
10 | locals[symbol] = _wrap_function(fn, _ffi)
11 | else:
12 | locals[symbol] = fn
13 | __all__.append(symbol)
14 |
15 | _import_symbols(locals())
16 |
--------------------------------------------------------------------------------
/.idea/STTran.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/_ext/roi_crop/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | from torch.utils.ffi import _wrap_function
3 | from ._roi_crop import lib as _lib, ffi as _ffi
4 |
5 | __all__ = []
6 | def _import_symbols(locals):
7 | for symbol in dir(_lib):
8 | fn = getattr(_lib, symbol)
9 | if callable(fn):
10 | locals[symbol] = _wrap_function(fn, _ffi)
11 | else:
12 | locals[symbol] = fn
13 | __all__.append(symbol)
14 |
15 | _import_symbols(locals())
16 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_align/_ext/roi_align/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | from torch.utils.ffi import _wrap_function
3 | from ._roi_align import lib as _lib, ffi as _ffi
4 |
5 | __all__ = []
6 | def _import_symbols(locals):
7 | for symbol in dir(_lib):
8 | fn = getattr(_lib, symbol)
9 | if callable(fn):
10 | locals[symbol] = _wrap_function(fn, _ffi)
11 | else:
12 | locals[symbol] = fn
13 | __all__.append(symbol)
14 |
15 | _import_symbols(locals())
16 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_pooling/_ext/roi_pooling/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | from torch.utils.ffi import _wrap_function
3 | from ._roi_pooling import lib as _lib, ffi as _ffi
4 |
5 | __all__ = []
6 | def _import_symbols(locals):
7 | for symbol in dir(_lib):
8 | fn = getattr(_lib, symbol)
9 | if callable(fn):
10 | locals[symbol] = _wrap_function(fn, _ffi)
11 | else:
12 | locals[symbol] = fn
13 | __all__.append(symbol)
14 |
15 | _import_symbols(locals())
16 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/nms/_ext/nms/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | from torch.utils.ffi import _wrap_function
3 | from ._nms import lib as _lib, ffi as _ffi
4 |
5 | __all__ = []
6 | def _import_symbols(locals):
7 | for symbol in dir(_lib):
8 | fn = getattr(_lib, symbol)
9 | if callable(fn):
10 | locals[symbol] = _wrap_function(fn, _ffi)
11 | else:
12 | locals[symbol] = fn
13 | __all__.append(symbol)
14 |
15 | _import_symbols(locals())
16 |
--------------------------------------------------------------------------------
/fasterRCNN/.idea/faster-rcnn.pytorch.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_align/_ext/roi_align/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | from torch.utils.ffi import _wrap_function
3 | from ._roi_align import lib as _lib, ffi as _ffi
4 |
5 | __all__ = []
6 | def _import_symbols(locals):
7 | for symbol in dir(_lib):
8 | fn = getattr(_lib, symbol)
9 | if callable(fn):
10 | locals[symbol] = _wrap_function(fn, _ffi)
11 | else:
12 | locals[symbol] = fn
13 | __all__.append(symbol)
14 |
15 | _import_symbols(locals())
16 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_crop/_ext/roi_crop/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | from torch.utils.ffi import _wrap_function
3 | from ._roi_crop import lib as _lib, ffi as _ffi
4 |
5 | __all__ = []
6 | def _import_symbols(locals):
7 | for symbol in dir(_lib):
8 | fn = getattr(_lib, symbol)
9 | if callable(fn):
10 | locals[symbol] = _wrap_function(fn, _ffi)
11 | else:
12 | locals[symbol] = fn
13 | __all__.append(symbol)
14 |
15 | _import_symbols(locals())
16 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_pooling/_ext/roi_pooling/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | from torch.utils.ffi import _wrap_function
3 | from ._roi_pooling import lib as _lib, ffi as _ffi
4 |
5 | __all__ = []
6 | def _import_symbols(locals):
7 | for symbol in dir(_lib):
8 | fn = getattr(_lib, symbol)
9 | if callable(fn):
10 | locals[symbol] = _wrap_function(fn, _ffi)
11 | else:
12 | locals[symbol] = fn
13 | __all__.append(symbol)
14 |
15 | _import_symbols(locals())
16 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/src/roi_crop_cuda.h:
--------------------------------------------------------------------------------
1 | // Bilinear sampling is done in BHWD (coalescing is not obvious in BDHW)
2 | // we assume BHWD format in inputImages
3 | // we assume BHW(YX) format on grids
4 |
5 | int BilinearSamplerBHWD_updateOutput_cuda(THCudaTensor *inputImages, THCudaTensor *grids, THCudaTensor *output);
6 |
7 | int BilinearSamplerBHWD_updateGradInput_cuda(THCudaTensor *inputImages, THCudaTensor *grids, THCudaTensor *gradInputImages,
8 | THCudaTensor *gradGrids, THCudaTensor *gradOutput);
9 |
--------------------------------------------------------------------------------
/fasterRCNN/cfgs/res101_ls.yml:
--------------------------------------------------------------------------------
1 | EXP_DIR: res101
2 | TRAIN:
3 | HAS_RPN: True
4 | BBOX_NORMALIZE_TARGETS_PRECOMPUTED: True
5 | RPN_POSITIVE_OVERLAP: 0.7
6 | RPN_BATCHSIZE: 256
7 | PROPOSAL_METHOD: gt
8 | BG_THRESH_LO: 0.0
9 | DISPLAY: 20
10 | BATCH_SIZE: 128
11 | WEIGHT_DECAY: 0.0001
12 | SCALES: [800]
13 | DOUBLE_BIAS: False
14 | LEARNING_RATE: 0.001
15 | TEST:
16 | HAS_RPN: True
17 | SCALES: [800]
18 | MAX_SIZE: 1200
19 | RPN_POST_NMS_TOP_N: 1000
20 | POOLING_SIZE: 7
21 | POOLING_MODE: align
22 | CROP_RESIZE_WITH_MAX_POOL: False
23 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/csrc/vision.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | #include "nms.h"
3 | #include "ROIAlign.h"
4 | #include "ROIPool.h"
5 |
6 |
7 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
8 | m.def("nms", &nms, "non-maximum suppression");
9 | m.def("roi_align_forward", &ROIAlign_forward, "ROIAlign_forward");
10 | m.def("roi_align_backward", &ROIAlign_backward, "ROIAlign_backward");
11 | m.def("roi_pool_forward", &ROIPool_forward, "ROIPool_forward");
12 | m.def("roi_pool_backward", &ROIPool_backward, "ROIPool_backward");
13 | }
14 |
--------------------------------------------------------------------------------
/fasterRCNN/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_pooling/modules/roi_pool.py:
--------------------------------------------------------------------------------
1 | from torch.nn.modules.module import Module
2 | from ..functions.roi_pool import RoIPoolFunction
3 |
4 |
5 | class _RoIPooling(Module):
6 | def __init__(self, pooled_height, pooled_width, spatial_scale):
7 | super(_RoIPooling, self).__init__()
8 |
9 | self.pooled_width = int(pooled_width)
10 | self.pooled_height = int(pooled_height)
11 | self.spatial_scale = float(spatial_scale)
12 |
13 | def forward(self, features, rois):
14 | return RoIPoolFunction(self.pooled_height, self.pooled_width, self.spatial_scale)(features, rois)
15 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_pooling/modules/roi_pool.py:
--------------------------------------------------------------------------------
1 | from torch.nn.modules.module import Module
2 | from ..functions.roi_pool import RoIPoolFunction
3 |
4 |
5 | class _RoIPooling(Module):
6 | def __init__(self, pooled_height, pooled_width, spatial_scale):
7 | super(_RoIPooling, self).__init__()
8 |
9 | self.pooled_width = int(pooled_width)
10 | self.pooled_height = int(pooled_height)
11 | self.spatial_scale = float(spatial_scale)
12 |
13 | def forward(self, features, rois):
14 | return RoIPoolFunction(self.pooled_height, self.pooled_width, self.spatial_scale)(features, rois)
15 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/csrc/cpu/vision.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | #pragma once
3 | #include
4 |
5 |
6 | at::Tensor ROIAlign_forward_cpu(const at::Tensor& input,
7 | const at::Tensor& rois,
8 | const float spatial_scale,
9 | const int pooled_height,
10 | const int pooled_width,
11 | const int sampling_ratio);
12 |
13 |
14 | at::Tensor nms_cpu(const at::Tensor& dets,
15 | const at::Tensor& scores,
16 | const float threshold);
17 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/src/roi_crop.h:
--------------------------------------------------------------------------------
1 | int BilinearSamplerBHWD_updateOutput(THFloatTensor *inputImages, THFloatTensor *grids, THFloatTensor *output);
2 |
3 | int BilinearSamplerBHWD_updateGradInput(THFloatTensor *inputImages, THFloatTensor *grids, THFloatTensor *gradInputImages,
4 | THFloatTensor *gradGrids, THFloatTensor *gradOutput);
5 |
6 |
7 |
8 | int BilinearSamplerBCHW_updateOutput(THFloatTensor *inputImages, THFloatTensor *grids, THFloatTensor *output);
9 |
10 | int BilinearSamplerBCHW_updateGradInput(THFloatTensor *inputImages, THFloatTensor *grids, THFloatTensor *gradInputImages,
11 | THFloatTensor *gradGrids, THFloatTensor *gradOutput);
12 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/csrc/nms.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | #pragma once
3 | #include "cpu/vision.h"
4 |
5 | #ifdef WITH_CUDA
6 | #include "cuda/vision.h"
7 | #endif
8 |
9 |
10 | at::Tensor nms(const at::Tensor& dets,
11 | const at::Tensor& scores,
12 | const float threshold) {
13 |
14 | if (dets.type().is_cuda()) {
15 | #ifdef WITH_CUDA
16 | // TODO raise error if not compiled with CUDA
17 | if (dets.numel() == 0)
18 | return at::empty({0}, dets.options().dtype(at::kLong).device(at::kCPU));
19 | auto b = at::cat({dets, scores.unsqueeze(1)}, 1);
20 | return nms_cuda(b, threshold);
21 | #else
22 | AT_ERROR("Not compiled with GPU support");
23 | #endif
24 | }
25 |
26 | at::Tensor result = nms_cpu(dets, scores, threshold);
27 | return result;
28 | }
29 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/nms/nms_wrapper.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast R-CNN
3 | # Copyright (c) 2015 Microsoft
4 | # Licensed under The MIT License [see LICENSE for details]
5 | # Written by Ross Girshick
6 | # --------------------------------------------------------
7 | import torch
8 | from model.utils.config import cfg
9 | if torch.cuda.is_available():
10 | from model.nms.nms_gpu import nms_gpu
11 | from model.nms.nms_cpu import nms_cpu
12 |
13 | def nms(dets, thresh, force_cpu=False):
14 | """Dispatch to either CPU or GPU NMS implementations."""
15 | if dets.shape[0] == 0:
16 | return []
17 | # ---numpy version---
18 | # original: return gpu_nms(dets, thresh, device_id=cfg.GPU_ID)
19 | # ---pytorch version---
20 |
21 | return nms_gpu(dets, thresh) if force_cpu == False else nms_cpu(dets, thresh)
22 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/nms/nms_wrapper.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast R-CNN
3 | # Copyright (c) 2015 Microsoft
4 | # Licensed under The MIT License [see LICENSE for details]
5 | # Written by Ross Girshick
6 | # --------------------------------------------------------
7 | import torch
8 | from model.utils.config import cfg
9 | if torch.cuda.is_available():
10 | from model.nms.nms_gpu import nms_gpu
11 | from model.nms.nms_cpu import nms_cpu
12 |
13 | def nms(dets, thresh, force_cpu=False):
14 | """Dispatch to either CPU or GPU NMS implementations."""
15 | if dets.shape[0] == 0:
16 | return []
17 | # ---numpy version---
18 | # original: return gpu_nms(dets, thresh, device_id=cfg.GPU_ID)
19 | # ---pytorch version---
20 |
21 | return nms_gpu(dets, thresh) if force_cpu == False else nms_cpu(dets, thresh)
22 |
--------------------------------------------------------------------------------
/fasterRCNN/data/coco/PythonAPI/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import setup, Extension
2 | import numpy as np
3 |
4 | # To compile and install locally run "python setup.py build_ext --inplace"
5 | # To install library to Python site-packages run "python setup.py build_ext install"
6 |
7 | ext_modules = [
8 | Extension(
9 | 'pycocotools._mask',
10 | sources=['../common/maskApi.c', 'pycocotools/_mask.pyx'],
11 | include_dirs = [np.get_include(), '../common'],
12 | extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'],
13 | )
14 | ]
15 |
16 | setup(
17 | name='pycocotools',
18 | packages=['pycocotools'],
19 | package_dir = {'pycocotools': 'pycocotools'},
20 | install_requires=[
21 | 'setuptools>=18.0',
22 | 'cython>=0.27.3',
23 | 'matplotlib>=2.1.0'
24 | ],
25 | version='2.0',
26 | ext_modules= ext_modules
27 | )
28 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_pooling/src/roi_pooling_kernel.h:
--------------------------------------------------------------------------------
1 | #ifndef _ROI_POOLING_KERNEL
2 | #define _ROI_POOLING_KERNEL
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | int ROIPoolForwardLaucher(
9 | const float* bottom_data, const float spatial_scale, const int num_rois, const int height,
10 | const int width, const int channels, const int pooled_height,
11 | const int pooled_width, const float* bottom_rois,
12 | float* top_data, int* argmax_data, cudaStream_t stream);
13 |
14 |
15 | int ROIPoolBackwardLaucher(const float* top_diff, const float spatial_scale, const int batch_size, const int num_rois,
16 | const int height, const int width, const int channels, const int pooled_height,
17 | const int pooled_width, const float* bottom_rois,
18 | float* bottom_diff, const int* argmax_data, cudaStream_t stream);
19 |
20 | #ifdef __cplusplus
21 | }
22 | #endif
23 |
24 | #endif
25 |
26 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/nms/build.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | import os
3 | import torch
4 | from torch.utils.ffi import create_extension
5 |
6 | #this_file = os.path.dirname(__file__)
7 |
8 | sources = []
9 | headers = []
10 | defines = []
11 | with_cuda = False
12 |
13 | if torch.cuda.is_available():
14 | print('Including CUDA code.')
15 | sources += ['src/nms_cuda.c']
16 | headers += ['src/nms_cuda.h']
17 | defines += [('WITH_CUDA', None)]
18 | with_cuda = True
19 |
20 | this_file = os.path.dirname(os.path.realpath(__file__))
21 | print(this_file)
22 | extra_objects = ['src/nms_cuda_kernel.cu.o']
23 | extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
24 | print(extra_objects)
25 |
26 | ffi = create_extension(
27 | '_ext.nms',
28 | headers=headers,
29 | sources=sources,
30 | define_macros=defines,
31 | relative_to=__file__,
32 | with_cuda=with_cuda,
33 | extra_objects=extra_objects
34 | )
35 |
36 | if __name__ == '__main__':
37 | ffi.build()
38 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/nms/nms_cpu.py:
--------------------------------------------------------------------------------
1 | from __future__ import absolute_import
2 |
3 | import numpy as np
4 | import torch
5 |
6 | def nms_cpu(dets, thresh):
7 | dets = dets.numpy()
8 | x1 = dets[:, 0]
9 | y1 = dets[:, 1]
10 | x2 = dets[:, 2]
11 | y2 = dets[:, 3]
12 | scores = dets[:, 4]
13 |
14 | areas = (x2 - x1 + 1) * (y2 - y1 + 1)
15 | order = scores.argsort()[::-1]
16 |
17 | keep = []
18 | while order.size > 0:
19 | i = order.item(0)
20 | keep.append(i)
21 | xx1 = np.maximum(x1[i], x1[order[1:]])
22 | yy1 = np.maximum(y1[i], y1[order[1:]])
23 | xx2 = np.maximum(x2[i], x2[order[1:]])
24 | yy2 = np.maximum(y2[i], y2[order[1:]])
25 |
26 | w = np.maximum(0.0, xx2 - xx1 + 1)
27 | h = np.maximum(0.0, yy2 - yy1 + 1)
28 | inter = w * h
29 | ovr = inter / (areas[i] + areas[order[1:]] - inter)
30 |
31 | inds = np.where(ovr <= thresh)[0]
32 | order = order[inds + 1]
33 |
34 | return torch.IntTensor(keep)
35 |
36 |
37 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/nms/build.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | import os
3 | import torch
4 | from torch.utils.ffi import create_extension
5 |
6 | #this_file = os.path.dirname(__file__)
7 |
8 | sources = []
9 | headers = []
10 | defines = []
11 | with_cuda = False
12 |
13 | if torch.cuda.is_available():
14 | print('Including CUDA code.')
15 | sources += ['src/nms_cuda.c']
16 | headers += ['src/nms_cuda.h']
17 | defines += [('WITH_CUDA', None)]
18 | with_cuda = True
19 |
20 | this_file = os.path.dirname(os.path.realpath(__file__))
21 | print(this_file)
22 | extra_objects = ['src/nms_cuda_kernel.cu.o']
23 | extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
24 | print(extra_objects)
25 |
26 | ffi = create_extension(
27 | '_ext.nms',
28 | headers=headers,
29 | sources=sources,
30 | define_macros=defines,
31 | relative_to=__file__,
32 | with_cuda=with_cuda,
33 | extra_objects=extra_objects
34 | )
35 |
36 | if __name__ == '__main__':
37 | ffi.build()
38 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_pooling/build.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | import os
3 | import torch
4 | from torch.utils.ffi import create_extension
5 |
6 |
7 | sources = ['src/roi_pooling.c']
8 | headers = ['src/roi_pooling.h']
9 | extra_objects = []
10 | defines = []
11 | with_cuda = False
12 |
13 | this_file = os.path.dirname(os.path.realpath(__file__))
14 | print(this_file)
15 |
16 | if torch.cuda.is_available():
17 | print('Including CUDA code.')
18 | sources += ['src/roi_pooling_cuda.c']
19 | headers += ['src/roi_pooling_cuda.h']
20 | defines += [('WITH_CUDA', None)]
21 | with_cuda = True
22 | extra_objects = ['src/roi_pooling.cu.o']
23 | extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
24 |
25 | ffi = create_extension(
26 | '_ext.roi_pooling',
27 | headers=headers,
28 | sources=sources,
29 | define_macros=defines,
30 | relative_to=__file__,
31 | with_cuda=with_cuda,
32 | extra_objects=extra_objects
33 | )
34 |
35 | if __name__ == '__main__':
36 | ffi.build()
37 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/build.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | import os
3 | import torch
4 | from torch.utils.ffi import create_extension
5 |
6 | #this_file = os.path.dirname(__file__)
7 |
8 | sources = ['src/roi_crop.c']
9 | headers = ['src/roi_crop.h']
10 | defines = []
11 | with_cuda = False
12 |
13 | if torch.cuda.is_available():
14 | print('Including CUDA code.')
15 | sources += ['src/roi_crop_cuda.c']
16 | headers += ['src/roi_crop_cuda.h']
17 | defines += [('WITH_CUDA', None)]
18 | with_cuda = True
19 |
20 | this_file = os.path.dirname(os.path.realpath(__file__))
21 | print(this_file)
22 | extra_objects = ['src/roi_crop_cuda_kernel.cu.o']
23 | extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
24 |
25 | ffi = create_extension(
26 | '_ext.roi_crop',
27 | headers=headers,
28 | sources=sources,
29 | define_macros=defines,
30 | relative_to=__file__,
31 | with_cuda=with_cuda,
32 | extra_objects=extra_objects
33 | )
34 |
35 | if __name__ == '__main__':
36 | ffi.build()
37 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/nms/nms_cpu.py:
--------------------------------------------------------------------------------
1 | from __future__ import absolute_import
2 |
3 | import numpy as np
4 | import torch
5 |
6 | def nms_cpu(dets, thresh):
7 | dets = dets.numpy()
8 | x1 = dets[:, 0]
9 | y1 = dets[:, 1]
10 | x2 = dets[:, 2]
11 | y2 = dets[:, 3]
12 | scores = dets[:, 4]
13 |
14 | areas = (x2 - x1 + 1) * (y2 - y1 + 1)
15 | order = scores.argsort()[::-1]
16 |
17 | keep = []
18 | while order.size > 0:
19 | i = order.item(0)
20 | keep.append(i)
21 | xx1 = np.maximum(x1[i], x1[order[1:]])
22 | yy1 = np.maximum(y1[i], y1[order[1:]])
23 | xx2 = np.maximum(x2[i], x2[order[1:]])
24 | yy2 = np.maximum(y2[i], y2[order[1:]])
25 |
26 | w = np.maximum(0.0, xx2 - xx1 + 1)
27 | h = np.maximum(0.0, yy2 - yy1 + 1)
28 | inter = w * h
29 | ovr = inter / (areas[i] + areas[order[1:]] - inter)
30 |
31 | inds = np.where(ovr <= thresh)[0]
32 | order = order[inds + 1]
33 |
34 | return torch.IntTensor(keep)
35 |
36 |
37 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_crop/build.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | import os
3 | import torch
4 | from torch.utils.ffi import create_extension
5 |
6 | #this_file = os.path.dirname(__file__)
7 |
8 | sources = ['src/roi_crop.c']
9 | headers = ['src/roi_crop.h']
10 | defines = []
11 | with_cuda = False
12 |
13 | if torch.cuda.is_available():
14 | print('Including CUDA code.')
15 | sources += ['src/roi_crop_cuda.c']
16 | headers += ['src/roi_crop_cuda.h']
17 | defines += [('WITH_CUDA', None)]
18 | with_cuda = True
19 |
20 | this_file = os.path.dirname(os.path.realpath(__file__))
21 | print(this_file)
22 | extra_objects = ['src/roi_crop_cuda_kernel.cu.o']
23 | extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
24 |
25 | ffi = create_extension(
26 | '_ext.roi_crop',
27 | headers=headers,
28 | sources=sources,
29 | define_macros=defines,
30 | relative_to=__file__,
31 | with_cuda=with_cuda,
32 | extra_objects=extra_objects
33 | )
34 |
35 | if __name__ == '__main__':
36 | ffi.build()
37 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_pooling/build.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | import os
3 | import torch
4 | from torch.utils.ffi import create_extension
5 |
6 |
7 | sources = ['src/roi_pooling.c']
8 | headers = ['src/roi_pooling.h']
9 | extra_objects = []
10 | defines = []
11 | with_cuda = False
12 |
13 | this_file = os.path.dirname(os.path.realpath(__file__))
14 | print(this_file)
15 |
16 | if torch.cuda.is_available():
17 | print('Including CUDA code.')
18 | sources += ['src/roi_pooling_cuda.c']
19 | headers += ['src/roi_pooling_cuda.h']
20 | defines += [('WITH_CUDA', None)]
21 | with_cuda = True
22 | extra_objects = ['src/roi_pooling.cu.o']
23 | extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
24 |
25 | ffi = create_extension(
26 | '_ext.roi_pooling',
27 | headers=headers,
28 | sources=sources,
29 | define_macros=defines,
30 | relative_to=__file__,
31 | with_cuda=with_cuda,
32 | extra_objects=extra_objects
33 | )
34 |
35 | if __name__ == '__main__':
36 | ffi.build()
37 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_align/build.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | import os
3 | import torch
4 | from torch.utils.ffi import create_extension
5 |
6 | sources = ['src/roi_align.c']
7 | headers = ['src/roi_align.h']
8 | extra_objects = []
9 | #sources = []
10 | #headers = []
11 | defines = []
12 | with_cuda = False
13 |
14 | this_file = os.path.dirname(os.path.realpath(__file__))
15 | print(this_file)
16 |
17 | if torch.cuda.is_available():
18 | print('Including CUDA code.')
19 | sources += ['src/roi_align_cuda.c']
20 | headers += ['src/roi_align_cuda.h']
21 | defines += [('WITH_CUDA', None)]
22 | with_cuda = True
23 |
24 | extra_objects = ['src/roi_align_kernel.cu.o']
25 | extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
26 |
27 | ffi = create_extension(
28 | '_ext.roi_align',
29 | headers=headers,
30 | sources=sources,
31 | define_macros=defines,
32 | relative_to=__file__,
33 | with_cuda=with_cuda,
34 | extra_objects=extra_objects
35 | )
36 |
37 | if __name__ == '__main__':
38 | ffi.build()
39 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_align/build.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | import os
3 | import torch
4 | from torch.utils.ffi import create_extension
5 |
6 | sources = ['src/roi_align.c']
7 | headers = ['src/roi_align.h']
8 | extra_objects = []
9 | #sources = []
10 | #headers = []
11 | defines = []
12 | with_cuda = False
13 |
14 | this_file = os.path.dirname(os.path.realpath(__file__))
15 | print(this_file)
16 |
17 | if torch.cuda.is_available():
18 | print('Including CUDA code.')
19 | sources += ['src/roi_align_cuda.c']
20 | headers += ['src/roi_align_cuda.h']
21 | defines += [('WITH_CUDA', None)]
22 | with_cuda = True
23 |
24 | extra_objects = ['src/roi_align_kernel.cu.o']
25 | extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
26 |
27 | ffi = create_extension(
28 | '_ext.roi_align',
29 | headers=headers,
30 | sources=sources,
31 | define_macros=defines,
32 | relative_to=__file__,
33 | with_cuda=with_cuda,
34 | extra_objects=extra_objects
35 | )
36 |
37 | if __name__ == '__main__':
38 | ffi.build()
39 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/functions/roi_crop.py:
--------------------------------------------------------------------------------
1 | # functions/add.py
2 | import torch
3 | from torch.autograd import Function
4 | from .._ext import roi_crop
5 | import pdb
6 |
7 | class RoICropFunction(Function):
8 | def forward(self, input1, input2):
9 | self.input1 = input1.clone()
10 | self.input2 = input2.clone()
11 | output = input2.new(input2.size()[0], input1.size()[1], input2.size()[1], input2.size()[2]).zero_()
12 | assert output.get_device() == input1.get_device(), "output and input1 must on the same device"
13 | assert output.get_device() == input2.get_device(), "output and input2 must on the same device"
14 | roi_crop.BilinearSamplerBHWD_updateOutput_cuda(input1, input2, output)
15 | return output
16 |
17 | def backward(self, grad_output):
18 | grad_input1 = self.input1.new(self.input1.size()).zero_()
19 | grad_input2 = self.input2.new(self.input2.size()).zero_()
20 | roi_crop.BilinearSamplerBHWD_updateGradInput_cuda(self.input1, self.input2, grad_input1, grad_input2, grad_output)
21 | return grad_input1, grad_input2
22 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Yuren Cong
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_crop/functions/roi_crop.py:
--------------------------------------------------------------------------------
1 | # functions/add.py
2 | import torch
3 | from torch.autograd import Function
4 | from .._ext import roi_crop
5 | import pdb
6 |
7 | class RoICropFunction(Function):
8 | def forward(self, input1, input2):
9 | self.input1 = input1.clone()
10 | self.input2 = input2.clone()
11 | output = input2.new(input2.size()[0], input1.size()[1], input2.size()[1], input2.size()[2]).zero_()
12 | assert output.get_device() == input1.get_device(), "output and input1 must on the same device"
13 | assert output.get_device() == input2.get_device(), "output and input2 must on the same device"
14 | roi_crop.BilinearSamplerBHWD_updateOutput_cuda(input1, input2, output)
15 | return output
16 |
17 | def backward(self, grad_output):
18 | grad_input1 = self.input1.new(self.input1.size()).zero_()
19 | grad_input2 = self.input2.new(self.input2.size()).zero_()
20 | roi_crop.BilinearSamplerBHWD_updateGradInput_cuda(self.input1, self.input2, grad_input1, grad_input2, grad_output)
21 | return grad_input1, grad_input2
22 |
--------------------------------------------------------------------------------
/fasterRCNN/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Jianwei Yang
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_align/src/roi_align_kernel.h:
--------------------------------------------------------------------------------
1 | #ifndef _ROI_ALIGN_KERNEL
2 | #define _ROI_ALIGN_KERNEL
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | __global__ void ROIAlignForward(const int nthreads, const float* bottom_data,
9 | const float spatial_scale, const int height, const int width,
10 | const int channels, const int aligned_height, const int aligned_width,
11 | const float* bottom_rois, float* top_data);
12 |
13 | int ROIAlignForwardLaucher(
14 | const float* bottom_data, const float spatial_scale, const int num_rois, const int height,
15 | const int width, const int channels, const int aligned_height,
16 | const int aligned_width, const float* bottom_rois,
17 | float* top_data, cudaStream_t stream);
18 |
19 | __global__ void ROIAlignBackward(const int nthreads, const float* top_diff,
20 | const float spatial_scale, const int height, const int width,
21 | const int channels, const int aligned_height, const int aligned_width,
22 | float* bottom_diff, const float* bottom_rois);
23 |
24 | int ROIAlignBackwardLaucher(const float* top_diff, const float spatial_scale, const int batch_size, const int num_rois,
25 | const int height, const int width, const int channels, const int aligned_height,
26 | const int aligned_width, const float* bottom_rois,
27 | float* bottom_diff, cudaStream_t stream);
28 |
29 | #ifdef __cplusplus
30 | }
31 | #endif
32 |
33 | #endif
34 |
35 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/VOCdevkit-matlab-wrapper/voc_eval.m:
--------------------------------------------------------------------------------
1 | function res = voc_eval(path, comp_id, test_set, output_dir)
2 |
3 | VOCopts = get_voc_opts(path);
4 | VOCopts.testset = test_set;
5 |
6 | for i = 1:length(VOCopts.classes)
7 | cls = VOCopts.classes{i};
8 | res(i) = voc_eval_cls(cls, VOCopts, comp_id, output_dir);
9 | end
10 |
11 | fprintf('\n~~~~~~~~~~~~~~~~~~~~\n');
12 | fprintf('Results:\n');
13 | aps = [res(:).ap]';
14 | fprintf('%.1f\n', aps * 100);
15 | fprintf('%.1f\n', mean(aps) * 100);
16 | fprintf('~~~~~~~~~~~~~~~~~~~~\n');
17 |
18 | function res = voc_eval_cls(cls, VOCopts, comp_id, output_dir)
19 |
20 | test_set = VOCopts.testset;
21 | year = VOCopts.dataset(4:end);
22 |
23 | addpath(fullfile(VOCopts.datadir, 'VOCcode'));
24 |
25 | res_fn = sprintf(VOCopts.detrespath, comp_id, cls);
26 |
27 | recall = [];
28 | prec = [];
29 | ap = 0;
30 | ap_auc = 0;
31 |
32 | do_eval = (str2num(year) <= 2007) | ~strcmp(test_set, 'test');
33 | if do_eval
34 | % Bug in VOCevaldet requires that tic has been called first
35 | tic;
36 | [recall, prec, ap] = VOCevaldet(VOCopts, comp_id, cls, true);
37 | ap_auc = xVOCap(recall, prec);
38 |
39 | % force plot limits
40 | ylim([0 1]);
41 | xlim([0 1]);
42 |
43 | print(gcf, '-djpeg', '-r0', ...
44 | [output_dir '/' cls '_pr.jpg']);
45 | end
46 | fprintf('!!! %s : %.4f %.4f\n', cls, ap, ap_auc);
47 |
48 | res.recall = recall;
49 | res.prec = prec;
50 | res.ap = ap;
51 | res.ap_auc = ap_auc;
52 |
53 | save([output_dir '/' cls '_pr.mat'], ...
54 | 'res', 'recall', 'prec', 'ap', 'ap_auc');
55 |
56 | rmpath(fullfile(VOCopts.datadir, 'VOCcode'));
57 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/ds_utils.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast/er R-CNN
3 | # Licensed under The MIT License [see LICENSE for details]
4 | # Written by Ross Girshick
5 | # --------------------------------------------------------
6 | from __future__ import absolute_import
7 | from __future__ import division
8 | from __future__ import print_function
9 |
10 | import numpy as np
11 |
12 |
13 | def unique_boxes(boxes, scale=1.0):
14 | """Return indices of unique boxes."""
15 | v = np.array([1, 1e3, 1e6, 1e9])
16 | hashes = np.round(boxes * scale).dot(v)
17 | _, index = np.unique(hashes, return_index=True)
18 | return np.sort(index)
19 |
20 |
21 | def xywh_to_xyxy(boxes):
22 | """Convert [x y w h] box format to [x1 y1 x2 y2] format."""
23 | return np.hstack((boxes[:, 0:2], boxes[:, 0:2] + boxes[:, 2:4] - 1))
24 |
25 |
26 | def xyxy_to_xywh(boxes):
27 | """Convert [x1 y1 x2 y2] box format to [x y w h] format."""
28 | return np.hstack((boxes[:, 0:2], boxes[:, 2:4] - boxes[:, 0:2] + 1))
29 |
30 |
31 | def validate_boxes(boxes, width=0, height=0):
32 | """Check that a set of boxes are valid."""
33 | x1 = boxes[:, 0]
34 | y1 = boxes[:, 1]
35 | x2 = boxes[:, 2]
36 | y2 = boxes[:, 3]
37 | assert (x1 >= 0).all()
38 | assert (y1 >= 0).all()
39 | assert (x2 >= x1).all()
40 | assert (y2 >= y1).all()
41 | assert (x2 < width).all()
42 | assert (y2 < height).all()
43 |
44 |
45 | def filter_small_boxes(boxes, min_size):
46 | w = boxes[:, 2] - boxes[:, 0]
47 | h = boxes[:, 3] - boxes[:, 1]
48 | keep = np.where((w >= min_size) & (h > min_size))[0]
49 | return keep
50 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/pycocotools/license.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014, Piotr Dollar and Tsung-Yi Lin
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | 1. Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 | 2. Redistributions in binary form must reproduce the above copyright notice,
10 | this list of conditions and the following disclaimer in the documentation
11 | and/or other materials provided with the distribution.
12 |
13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 |
24 | The views and conclusions contained in the software and documentation are those
25 | of the authors and should not be interpreted as representing official policies,
26 | either expressed or implied, of the FreeBSD Project.
27 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/datasets/ds_utils.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast/er R-CNN
3 | # Licensed under The MIT License [see LICENSE for details]
4 | # Written by Ross Girshick
5 | # --------------------------------------------------------
6 | from __future__ import absolute_import
7 | from __future__ import division
8 | from __future__ import print_function
9 |
10 | import numpy as np
11 |
12 |
13 | def unique_boxes(boxes, scale=1.0):
14 | """Return indices of unique boxes."""
15 | v = np.array([1, 1e3, 1e6, 1e9])
16 | hashes = np.round(boxes * scale).dot(v)
17 | _, index = np.unique(hashes, return_index=True)
18 | return np.sort(index)
19 |
20 |
21 | def xywh_to_xyxy(boxes):
22 | """Convert [x y w h] box format to [x1 y1 x2 y2] format."""
23 | return np.hstack((boxes[:, 0:2], boxes[:, 0:2] + boxes[:, 2:4] - 1))
24 |
25 |
26 | def xyxy_to_xywh(boxes):
27 | """Convert [x1 y1 x2 y2] box format to [x y w h] format."""
28 | return np.hstack((boxes[:, 0:2], boxes[:, 2:4] - boxes[:, 0:2] + 1))
29 |
30 |
31 | def validate_boxes(boxes, width=0, height=0):
32 | """Check that a set of boxes are valid."""
33 | x1 = boxes[:, 0]
34 | y1 = boxes[:, 1]
35 | x2 = boxes[:, 2]
36 | y2 = boxes[:, 3]
37 | assert (x1 >= 0).all()
38 | assert (y1 >= 0).all()
39 | assert (x2 >= x1).all()
40 | assert (y2 >= y1).all()
41 | assert (x2 < width).all()
42 | assert (y2 < height).all()
43 |
44 |
45 | def filter_small_boxes(boxes, min_size):
46 | w = boxes[:, 2] - boxes[:, 0]
47 | h = boxes[:, 3] - boxes[:, 1]
48 | keep = np.where((w >= min_size) & (h > min_size))[0]
49 | return keep
50 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/tools/mcg_munge.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | import os
3 | import sys
4 |
5 | """Hacky tool to convert file system layout of MCG boxes downloaded from
6 | http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/mcg/
7 | so that it's consistent with those computed by Jan Hosang (see:
8 | http://www.mpi-inf.mpg.de/departments/computer-vision-and-multimodal-
9 | computing/research/object-recognition-and-scene-understanding/how-
10 | good-are-detection-proposals-really/)
11 |
12 | NB: Boxes from the MCG website are in (y1, x1, y2, x2) order.
13 | Boxes from Hosang et al. are in (x1, y1, x2, y2) order.
14 | """
15 |
16 | def munge(src_dir):
17 | # stored as: ./MCG-COCO-val2014-boxes/COCO_val2014_000000193401.mat
18 | # want: ./MCG/mat/COCO_val2014_0/COCO_val2014_000000141/COCO_val2014_000000141334.mat
19 |
20 | files = os.listdir(src_dir)
21 | for fn in files:
22 | base, ext = os.path.splitext(fn)
23 | # first 14 chars / first 22 chars / all chars + .mat
24 | # COCO_val2014_0/COCO_val2014_000000447/COCO_val2014_000000447991.mat
25 | first = base[:14]
26 | second = base[:22]
27 | dst_dir = os.path.join('MCG', 'mat', first, second)
28 | if not os.path.exists(dst_dir):
29 | os.makedirs(dst_dir)
30 | src = os.path.join(src_dir, fn)
31 | dst = os.path.join(dst_dir, fn)
32 | print('MV: {} -> {}'.format(src, dst))
33 | os.rename(src, dst)
34 |
35 | if __name__ == '__main__':
36 | # src_dir should look something like:
37 | # src_dir = 'MCG-COCO-val2014-boxes'
38 | src_dir = sys.argv[1]
39 | munge(src_dir)
40 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/functions/crop_resize.py:
--------------------------------------------------------------------------------
1 | # functions/add.py
2 | import torch
3 | from torch.autograd import Function
4 | from .._ext import roi_crop
5 | from cffi import FFI
6 | ffi = FFI()
7 |
8 | class RoICropFunction(Function):
9 | def forward(self, input1, input2):
10 | self.input1 = input1
11 | self.input2 = input2
12 | self.device_c = ffi.new("int *")
13 | output = torch.zeros(input2.size()[0], input1.size()[1], input2.size()[1], input2.size()[2])
14 | #print('decice %d' % torch.cuda.current_device())
15 | if input1.is_cuda:
16 | self.device = torch.cuda.current_device()
17 | else:
18 | self.device = -1
19 | self.device_c[0] = self.device
20 | if not input1.is_cuda:
21 | roi_crop.BilinearSamplerBHWD_updateOutput(input1, input2, output)
22 | else:
23 | output = output.cuda(self.device)
24 | roi_crop.BilinearSamplerBHWD_updateOutput_cuda(input1, input2, output)
25 | return output
26 |
27 | def backward(self, grad_output):
28 | grad_input1 = torch.zeros(self.input1.size())
29 | grad_input2 = torch.zeros(self.input2.size())
30 | #print('backward decice %d' % self.device)
31 | if not grad_output.is_cuda:
32 | roi_crop.BilinearSamplerBHWD_updateGradInput(self.input1, self.input2, grad_input1, grad_input2, grad_output)
33 | else:
34 | grad_input1 = grad_input1.cuda(self.device)
35 | grad_input2 = grad_input2.cuda(self.device)
36 | roi_crop.BilinearSamplerBHWD_updateGradInput_cuda(self.input1, self.input2, grad_input1, grad_input2, grad_output)
37 | return grad_input1, grad_input2
38 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_crop/functions/crop_resize.py:
--------------------------------------------------------------------------------
1 | # functions/add.py
2 | import torch
3 | from torch.autograd import Function
4 | from .._ext import roi_crop
5 | from cffi import FFI
6 | ffi = FFI()
7 |
8 | class RoICropFunction(Function):
9 | def forward(self, input1, input2):
10 | self.input1 = input1
11 | self.input2 = input2
12 | self.device_c = ffi.new("int *")
13 | output = torch.zeros(input2.size()[0], input1.size()[1], input2.size()[1], input2.size()[2])
14 | #print('decice %d' % torch.cuda.current_device())
15 | if input1.is_cuda:
16 | self.device = torch.cuda.current_device()
17 | else:
18 | self.device = -1
19 | self.device_c[0] = self.device
20 | if not input1.is_cuda:
21 | roi_crop.BilinearSamplerBHWD_updateOutput(input1, input2, output)
22 | else:
23 | output = output.cuda(self.device)
24 | roi_crop.BilinearSamplerBHWD_updateOutput_cuda(input1, input2, output)
25 | return output
26 |
27 | def backward(self, grad_output):
28 | grad_input1 = torch.zeros(self.input1.size())
29 | grad_input2 = torch.zeros(self.input2.size())
30 | #print('backward decice %d' % self.device)
31 | if not grad_output.is_cuda:
32 | roi_crop.BilinearSamplerBHWD_updateGradInput(self.input1, self.input2, grad_input1, grad_input2, grad_output)
33 | else:
34 | grad_input1 = grad_input1.cuda(self.device)
35 | grad_input2 = grad_input2.cuda(self.device)
36 | roi_crop.BilinearSamplerBHWD_updateGradInput_cuda(self.input1, self.input2, grad_input1, grad_input2, grad_output)
37 | return grad_input1, grad_input2
38 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/csrc/ROIPool.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | #pragma once
3 |
4 | #include "cpu/vision.h"
5 |
6 | #ifdef WITH_CUDA
7 | #include "cuda/vision.h"
8 | #endif
9 |
10 |
11 | std::tuple ROIPool_forward(const at::Tensor& input,
12 | const at::Tensor& rois,
13 | const float spatial_scale,
14 | const int pooled_height,
15 | const int pooled_width) {
16 | if (input.type().is_cuda()) {
17 | #ifdef WITH_CUDA
18 | return ROIPool_forward_cuda(input, rois, spatial_scale, pooled_height, pooled_width);
19 | #else
20 | AT_ERROR("Not compiled with GPU support");
21 | #endif
22 | }
23 | AT_ERROR("Not implemented on the CPU");
24 | }
25 |
26 | at::Tensor ROIPool_backward(const at::Tensor& grad,
27 | const at::Tensor& input,
28 | const at::Tensor& rois,
29 | const at::Tensor& argmax,
30 | const float spatial_scale,
31 | const int pooled_height,
32 | const int pooled_width,
33 | const int batch_size,
34 | const int channels,
35 | const int height,
36 | const int width) {
37 | if (grad.type().is_cuda()) {
38 | #ifdef WITH_CUDA
39 | return ROIPool_backward_cuda(grad, input, rois, argmax, spatial_scale, pooled_height, pooled_width, batch_size, channels, height, width);
40 | #else
41 | AT_ERROR("Not compiled with GPU support");
42 | #endif
43 | }
44 | AT_ERROR("Not implemented on the CPU");
45 | }
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/csrc/ROIAlign.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | #pragma once
3 |
4 | #include "cpu/vision.h"
5 |
6 | #ifdef WITH_CUDA
7 | #include "cuda/vision.h"
8 | #endif
9 |
10 | // Interface for Python
11 | at::Tensor ROIAlign_forward(const at::Tensor& input,
12 | const at::Tensor& rois,
13 | const float spatial_scale,
14 | const int pooled_height,
15 | const int pooled_width,
16 | const int sampling_ratio) {
17 | if (input.type().is_cuda()) {
18 | #ifdef WITH_CUDA
19 | return ROIAlign_forward_cuda(input, rois, spatial_scale, pooled_height, pooled_width, sampling_ratio);
20 | #else
21 | AT_ERROR("Not compiled with GPU support");
22 | #endif
23 | }
24 | return ROIAlign_forward_cpu(input, rois, spatial_scale, pooled_height, pooled_width, sampling_ratio);
25 | }
26 |
27 | at::Tensor ROIAlign_backward(const at::Tensor& grad,
28 | const at::Tensor& rois,
29 | const float spatial_scale,
30 | const int pooled_height,
31 | const int pooled_width,
32 | const int batch_size,
33 | const int channels,
34 | const int height,
35 | const int width,
36 | const int sampling_ratio) {
37 | if (grad.type().is_cuda()) {
38 | #ifdef WITH_CUDA
39 | return ROIAlign_backward_cuda(grad, rois, spatial_scale, pooled_height, pooled_width, batch_size, channels, height, width, sampling_ratio);
40 | #else
41 | AT_ERROR("Not compiled with GPU support");
42 | #endif
43 | }
44 | AT_ERROR("Not implemented on the CPU");
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_align/modules/roi_align.py:
--------------------------------------------------------------------------------
1 | from torch.nn.modules.module import Module
2 | from torch.nn.functional import avg_pool2d, max_pool2d
3 | from ..functions.roi_align import RoIAlignFunction
4 |
5 |
6 | class RoIAlign(Module):
7 | def __init__(self, aligned_height, aligned_width, spatial_scale):
8 | super(RoIAlign, self).__init__()
9 |
10 | self.aligned_width = int(aligned_width)
11 | self.aligned_height = int(aligned_height)
12 | self.spatial_scale = float(spatial_scale)
13 |
14 | def forward(self, features, rois):
15 | return RoIAlignFunction(self.aligned_height, self.aligned_width,
16 | self.spatial_scale)(features, rois)
17 |
18 | class RoIAlignAvg(Module):
19 | def __init__(self, aligned_height, aligned_width, spatial_scale):
20 | super(RoIAlignAvg, self).__init__()
21 |
22 | self.aligned_width = int(aligned_width)
23 | self.aligned_height = int(aligned_height)
24 | self.spatial_scale = float(spatial_scale)
25 |
26 | def forward(self, features, rois):
27 | x = RoIAlignFunction(self.aligned_height+1, self.aligned_width+1,
28 | self.spatial_scale)(features, rois)
29 | return avg_pool2d(x, kernel_size=2, stride=1)
30 |
31 | class RoIAlignMax(Module):
32 | def __init__(self, aligned_height, aligned_width, spatial_scale):
33 | super(RoIAlignMax, self).__init__()
34 |
35 | self.aligned_width = int(aligned_width)
36 | self.aligned_height = int(aligned_height)
37 | self.spatial_scale = float(spatial_scale)
38 |
39 | def forward(self, features, rois):
40 | x = RoIAlignFunction(self.aligned_height+1, self.aligned_width+1,
41 | self.spatial_scale)(features, rois)
42 | return max_pool2d(x, kernel_size=2, stride=1)
43 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/utils/blob.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast R-CNN
3 | # Copyright (c) 2015 Microsoft
4 | # Licensed under The MIT License [see LICENSE for details]
5 | # Written by Ross Girshick
6 | # --------------------------------------------------------
7 |
8 | """Blob helper functions."""
9 |
10 | import numpy as np
11 | # from scipy.misc import imread, imresize
12 | import cv2
13 |
14 | try:
15 | xrange # Python 2
16 | except NameError:
17 | xrange = range # Python 3
18 |
19 |
20 | def im_list_to_blob(ims):
21 | """Convert a list of images into a network input.
22 |
23 | Assumes images are already prepared (means subtracted, BGR order, ...).
24 | """
25 | max_shape = np.array([im.shape for im in ims]).max(axis=0)
26 | num_images = len(ims)
27 | blob = np.zeros((num_images, max_shape[0], max_shape[1], 3),
28 | dtype=np.float32)
29 | for i in xrange(num_images):
30 | im = ims[i]
31 | blob[i, 0:im.shape[0], 0:im.shape[1], :] = im
32 |
33 | return blob
34 |
35 | def prep_im_for_blob(im, pixel_means, target_size, max_size):
36 | """Mean subtract and scale an image for use in a blob."""
37 |
38 | im = im.astype(np.float32, copy=False)
39 | im -= pixel_means
40 | # im = im[:, :, ::-1]
41 | im_shape = im.shape
42 | im_size_min = np.min(im_shape[0:2])
43 | im_size_max = np.max(im_shape[0:2])
44 | im_scale = float(target_size) / float(im_size_min)
45 | # Prevent the biggest axis from being more than MAX_SIZE
46 | # if np.round(im_scale * im_size_max) > max_size:
47 | # im_scale = float(max_size) / float(im_size_max)
48 | # im = imresize(im, im_scale)
49 | im = cv2.resize(im, None, None, fx=im_scale, fy=im_scale,
50 | interpolation=cv2.INTER_LINEAR)
51 |
52 | return im, im_scale
53 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_align/modules/roi_align.py:
--------------------------------------------------------------------------------
1 | from torch.nn.modules.module import Module
2 | from torch.nn.functional import avg_pool2d, max_pool2d
3 | from ..functions.roi_align import RoIAlignFunction
4 |
5 |
6 | class RoIAlign(Module):
7 | def __init__(self, aligned_height, aligned_width, spatial_scale):
8 | super(RoIAlign, self).__init__()
9 |
10 | self.aligned_width = int(aligned_width)
11 | self.aligned_height = int(aligned_height)
12 | self.spatial_scale = float(spatial_scale)
13 |
14 | def forward(self, features, rois):
15 | return RoIAlignFunction(self.aligned_height, self.aligned_width,
16 | self.spatial_scale)(features, rois)
17 |
18 | class RoIAlignAvg(Module):
19 | def __init__(self, aligned_height, aligned_width, spatial_scale):
20 | super(RoIAlignAvg, self).__init__()
21 |
22 | self.aligned_width = int(aligned_width)
23 | self.aligned_height = int(aligned_height)
24 | self.spatial_scale = float(spatial_scale)
25 |
26 | def forward(self, features, rois):
27 | x = RoIAlignFunction(self.aligned_height+1, self.aligned_width+1,
28 | self.spatial_scale)(features, rois)
29 | return avg_pool2d(x, kernel_size=2, stride=1)
30 |
31 | class RoIAlignMax(Module):
32 | def __init__(self, aligned_height, aligned_width, spatial_scale):
33 | super(RoIAlignMax, self).__init__()
34 |
35 | self.aligned_width = int(aligned_width)
36 | self.aligned_height = int(aligned_height)
37 | self.spatial_scale = float(spatial_scale)
38 |
39 | def forward(self, features, rois):
40 | x = RoIAlignFunction(self.aligned_height+1, self.aligned_width+1,
41 | self.spatial_scale)(features, rois)
42 | return max_pool2d(x, kernel_size=2, stride=1)
43 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/utils/blob.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast R-CNN
3 | # Copyright (c) 2015 Microsoft
4 | # Licensed under The MIT License [see LICENSE for details]
5 | # Written by Ross Girshick
6 | # --------------------------------------------------------
7 |
8 | """Blob helper functions."""
9 |
10 | import numpy as np
11 | # from scipy.misc import imread, imresize
12 | import cv2
13 |
14 | try:
15 | xrange # Python 2
16 | except NameError:
17 | xrange = range # Python 3
18 |
19 |
20 | def im_list_to_blob(ims):
21 | """Convert a list of images into a network input.
22 |
23 | Assumes images are already prepared (means subtracted, BGR order, ...).
24 | """
25 | max_shape = np.array([im.shape for im in ims]).max(axis=0)
26 | num_images = len(ims)
27 | blob = np.zeros((num_images, max_shape[0], max_shape[1], 3),
28 | dtype=np.float32)
29 | for i in xrange(num_images):
30 | im = ims[i]
31 | blob[i, 0:im.shape[0], 0:im.shape[1], :] = im
32 |
33 | return blob
34 |
35 | def prep_im_for_blob(im, pixel_means, target_size, max_size):
36 | """Mean subtract and scale an image for use in a blob."""
37 |
38 | im = im.astype(np.float32, copy=False)
39 | im -= pixel_means
40 | # im = im[:, :, ::-1]
41 | im_shape = im.shape
42 | im_size_min = np.min(im_shape[0:2])
43 | im_size_max = np.max(im_shape[0:2])
44 | im_scale = float(target_size) / float(im_size_min)
45 | # Prevent the biggest axis from being more than MAX_SIZE
46 | # if np.round(im_scale * im_size_max) > max_size:
47 | # im_scale = float(max_size) / float(im_size_max)
48 | # im = imresize(im, im_scale)
49 | im = cv2.resize(im, None, None, fx=im_scale, fy=im_scale,
50 | interpolation=cv2.INTER_LINEAR)
51 |
52 | return im, im_scale
53 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_pooling/functions/roi_pool.py:
--------------------------------------------------------------------------------
1 | import torch
2 | from torch.autograd import Function
3 | from .._ext import roi_pooling
4 | import pdb
5 |
6 | class RoIPoolFunction(Function):
7 | def __init__(ctx, pooled_height, pooled_width, spatial_scale):
8 | ctx.pooled_width = pooled_width
9 | ctx.pooled_height = pooled_height
10 | ctx.spatial_scale = spatial_scale
11 | ctx.feature_size = None
12 |
13 | def forward(ctx, features, rois):
14 | ctx.feature_size = features.size()
15 | batch_size, num_channels, data_height, data_width = ctx.feature_size
16 | num_rois = rois.size(0)
17 | output = features.new(num_rois, num_channels, ctx.pooled_height, ctx.pooled_width).zero_()
18 | ctx.argmax = features.new(num_rois, num_channels, ctx.pooled_height, ctx.pooled_width).zero_().int()
19 | ctx.rois = rois
20 | if not features.is_cuda:
21 | _features = features.permute(0, 2, 3, 1)
22 | roi_pooling.roi_pooling_forward(ctx.pooled_height, ctx.pooled_width, ctx.spatial_scale,
23 | _features, rois, output)
24 | else:
25 | roi_pooling.roi_pooling_forward_cuda(ctx.pooled_height, ctx.pooled_width, ctx.spatial_scale,
26 | features, rois, output, ctx.argmax)
27 |
28 | return output
29 |
30 | def backward(ctx, grad_output):
31 | assert(ctx.feature_size is not None and grad_output.is_cuda)
32 | batch_size, num_channels, data_height, data_width = ctx.feature_size
33 | grad_input = grad_output.new(batch_size, num_channels, data_height, data_width).zero_()
34 |
35 | roi_pooling.roi_pooling_backward_cuda(ctx.pooled_height, ctx.pooled_width, ctx.spatial_scale,
36 | grad_output, ctx.rois, grad_input, ctx.argmax)
37 |
38 | return grad_input, None
39 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_pooling/functions/roi_pool.py:
--------------------------------------------------------------------------------
1 | import torch
2 | from torch.autograd import Function
3 | from .._ext import roi_pooling
4 | import pdb
5 |
6 | class RoIPoolFunction(Function):
7 | def __init__(ctx, pooled_height, pooled_width, spatial_scale):
8 | ctx.pooled_width = pooled_width
9 | ctx.pooled_height = pooled_height
10 | ctx.spatial_scale = spatial_scale
11 | ctx.feature_size = None
12 |
13 | def forward(ctx, features, rois):
14 | ctx.feature_size = features.size()
15 | batch_size, num_channels, data_height, data_width = ctx.feature_size
16 | num_rois = rois.size(0)
17 | output = features.new(num_rois, num_channels, ctx.pooled_height, ctx.pooled_width).zero_()
18 | ctx.argmax = features.new(num_rois, num_channels, ctx.pooled_height, ctx.pooled_width).zero_().int()
19 | ctx.rois = rois
20 | if not features.is_cuda:
21 | _features = features.permute(0, 2, 3, 1)
22 | roi_pooling.roi_pooling_forward(ctx.pooled_height, ctx.pooled_width, ctx.spatial_scale,
23 | _features, rois, output)
24 | else:
25 | roi_pooling.roi_pooling_forward_cuda(ctx.pooled_height, ctx.pooled_width, ctx.spatial_scale,
26 | features, rois, output, ctx.argmax)
27 |
28 | return output
29 |
30 | def backward(ctx, grad_output):
31 | assert(ctx.feature_size is not None and grad_output.is_cuda)
32 | batch_size, num_channels, data_height, data_width = ctx.feature_size
33 | grad_input = grad_output.new(batch_size, num_channels, data_height, data_width).zero_()
34 |
35 | roi_pooling.roi_pooling_backward_cuda(ctx.pooled_height, ctx.pooled_width, ctx.spatial_scale,
36 | grad_output, ctx.rois, grad_input, ctx.argmax)
37 |
38 | return grad_input, None
39 |
--------------------------------------------------------------------------------
/lib/config.py:
--------------------------------------------------------------------------------
1 | from argparse import ArgumentParser
2 |
3 | BATCHNORM_MOMENTUM = 0.01
4 |
5 | class Config(object):
6 | """Wrapper class for model hyperparameters."""
7 |
8 | def __init__(self):
9 | """
10 | Defaults
11 | """
12 | self.mode = None
13 | self.save_path = None
14 | self.model_path = None
15 | self.data_path = None
16 | self.datasize = None
17 | self.ckpt = None
18 | self.optimizer = None
19 | self.bce_loss = None
20 | self.lr = 1e-5
21 | self.enc_layer = 1
22 | self.dec_layer = 3
23 | self.nepoch = 10
24 | self.parser = self.setup_parser()
25 | self.args = vars(self.parser.parse_args())
26 | self.__dict__.update(self.args)
27 |
28 | def setup_parser(self):
29 | """
30 | Sets up an argument parser
31 | :return:
32 | """
33 | parser = ArgumentParser(description='training code')
34 | parser.add_argument('-mode', dest='mode', help='predcls/sgcls/sgdet', default='predcls', type=str)
35 | parser.add_argument('-save_path', default='data/', type=str)
36 | parser.add_argument('-model_path', default=None, type=str)
37 | parser.add_argument('-data_path', default='/data/scene_understanding/action_genome/', type=str)
38 | parser.add_argument('-datasize', dest='datasize', help='mini dataset or whole', default='large', type=str)
39 | parser.add_argument('-ckpt', dest='ckpt', help='checkpoint', default=None, type=str)
40 | parser.add_argument('-optimizer', help='adamw/adam/sgd', default='adamw', type=str)
41 | parser.add_argument('-lr', dest='lr', help='learning rate', default=1e-5, type=float)
42 | parser.add_argument('-nepoch', help='epoch number', default=10, type=float)
43 | parser.add_argument('-enc_layer', dest='enc_layer', help='spatial encoder layer', default=1, type=int)
44 | parser.add_argument('-dec_layer', dest='dec_layer', help='temporal decoder layer', default=3, type=int)
45 | parser.add_argument('-bce_loss', action='store_true')
46 | return parser
47 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_layers/roi_pool.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | import torch
3 | from torch import nn
4 | from torch.autograd import Function
5 | from torch.autograd.function import once_differentiable
6 | from torch.nn.modules.utils import _pair
7 |
8 | from fasterRCNN.lib.model import _C
9 |
10 |
11 | class _ROIPool(Function):
12 | @staticmethod
13 | def forward(ctx, input, roi, output_size, spatial_scale):
14 | ctx.output_size = _pair(output_size)
15 | ctx.spatial_scale = spatial_scale
16 | ctx.input_shape = input.size()
17 | output, argmax = _C.roi_pool_forward(
18 | input, roi, spatial_scale, output_size[0], output_size[1]
19 | )
20 | ctx.save_for_backward(input, roi, argmax)
21 | return output
22 |
23 | @staticmethod
24 | @once_differentiable
25 | def backward(ctx, grad_output):
26 | input, rois, argmax = ctx.saved_tensors
27 | output_size = ctx.output_size
28 | spatial_scale = ctx.spatial_scale
29 | bs, ch, h, w = ctx.input_shape
30 | grad_input = _C.roi_pool_backward(
31 | grad_output,
32 | input,
33 | rois,
34 | argmax,
35 | spatial_scale,
36 | output_size[0],
37 | output_size[1],
38 | bs,
39 | ch,
40 | h,
41 | w,
42 | )
43 | return grad_input, None, None, None
44 |
45 |
46 | roi_pool = _ROIPool.apply
47 |
48 |
49 | class ROIPool(nn.Module):
50 | def __init__(self, output_size, spatial_scale):
51 | super(ROIPool, self).__init__()
52 | self.output_size = output_size
53 | self.spatial_scale = spatial_scale
54 |
55 | def forward(self, input, rois):
56 | return roi_pool(input, rois, self.output_size, self.spatial_scale)
57 |
58 | def __repr__(self):
59 | tmpstr = self.__class__.__name__ + "("
60 | tmpstr += "output_size=" + str(self.output_size)
61 | tmpstr += ", spatial_scale=" + str(self.spatial_scale)
62 | tmpstr += ")"
63 | return tmpstr
64 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_layers/roi_pool.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | import torch
3 | from torch import nn
4 | from torch.autograd import Function
5 | from torch.autograd.function import once_differentiable
6 | from torch.nn.modules.utils import _pair
7 |
8 | from model import _C
9 |
10 |
11 | class _ROIPool(Function):
12 | @staticmethod
13 | def forward(ctx, input, roi, output_size, spatial_scale):
14 | ctx.output_size = _pair(output_size)
15 | ctx.spatial_scale = spatial_scale
16 | ctx.input_shape = input.size()
17 | output, argmax = _C.roi_pool_forward(
18 | input, roi, spatial_scale, output_size[0], output_size[1]
19 | )
20 | ctx.save_for_backward(input, roi, argmax)
21 | return output
22 |
23 | @staticmethod
24 | @once_differentiable
25 | def backward(ctx, grad_output):
26 | input, rois, argmax = ctx.saved_tensors
27 | output_size = ctx.output_size
28 | spatial_scale = ctx.spatial_scale
29 | bs, ch, h, w = ctx.input_shape
30 | grad_input = _C.roi_pool_backward(
31 | grad_output,
32 | input,
33 | rois,
34 | argmax,
35 | spatial_scale,
36 | output_size[0],
37 | output_size[1],
38 | bs,
39 | ch,
40 | h,
41 | w,
42 | )
43 | return grad_input, None, None, None
44 |
45 |
46 | roi_pool = _ROIPool.apply
47 |
48 |
49 | class ROIPool(nn.Module):
50 | def __init__(self, output_size, spatial_scale):
51 | super(ROIPool, self).__init__()
52 | self.output_size = output_size
53 | self.spatial_scale = spatial_scale
54 |
55 | def forward(self, input, rois):
56 | return roi_pool(input, rois, self.output_size, self.spatial_scale)
57 |
58 | def __repr__(self):
59 | tmpstr = self.__class__.__name__ + "("
60 | tmpstr += "output_size=" + str(self.output_size)
61 | tmpstr += ", spatial_scale=" + str(self.spatial_scale)
62 | tmpstr += ")"
63 | return tmpstr
64 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/pycocotools/maskApi.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************
2 | * Microsoft COCO Toolbox. version 2.0
3 | * Data, paper, and tutorials available at: http://mscoco.org/
4 | * Code written by Piotr Dollar and Tsung-Yi Lin, 2015.
5 | * Licensed under the Simplified BSD License [see coco/license.txt]
6 | **************************************************************************/
7 | #pragma once
8 | #include
9 |
10 | typedef unsigned int uint;
11 | typedef unsigned long siz;
12 | typedef unsigned char byte;
13 | typedef double* BB;
14 | typedef struct { siz h, w, m; uint *cnts; } RLE;
15 |
16 | // Initialize/destroy RLE.
17 | void rleInit( RLE *R, siz h, siz w, siz m, uint *cnts );
18 | void rleFree( RLE *R );
19 |
20 | // Initialize/destroy RLE array.
21 | void rlesInit( RLE **R, siz n );
22 | void rlesFree( RLE **R, siz n );
23 |
24 | // Encode binary masks using RLE.
25 | void rleEncode( RLE *R, const byte *mask, siz h, siz w, siz n );
26 |
27 | // Decode binary masks encoded via RLE.
28 | void rleDecode( const RLE *R, byte *mask, siz n );
29 |
30 | // Compute union or intersection of encoded masks.
31 | void rleMerge( const RLE *R, RLE *M, siz n, bool intersect );
32 |
33 | // Compute area of encoded masks.
34 | void rleArea( const RLE *R, siz n, uint *a );
35 |
36 | // Compute intersection over union between masks.
37 | void rleIou( RLE *dt, RLE *gt, siz m, siz n, byte *iscrowd, double *o );
38 |
39 | // Compute intersection over union between bounding boxes.
40 | void bbIou( BB dt, BB gt, siz m, siz n, byte *iscrowd, double *o );
41 |
42 | // Get bounding boxes surrounding encoded masks.
43 | void rleToBbox( const RLE *R, BB bb, siz n );
44 |
45 | // Convert bounding boxes to encoded masks.
46 | void rleFrBbox( RLE *R, const BB bb, siz h, siz w, siz n );
47 |
48 | // Convert polygon to encoded mask.
49 | void rleFrPoly( RLE *R, const double *xy, siz k, siz h, siz w );
50 |
51 | // Get compressed string representation of encoded mask.
52 | char* rleToString( const RLE *R );
53 |
54 | // Convert from compressed string representation of encoded mask.
55 | void rleFrString( RLE *R, char *s, siz h, siz w );
56 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/setup.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | #!/usr/bin/env python
3 |
4 | import glob
5 | import os
6 |
7 | import torch
8 | from setuptools import find_packages
9 | from setuptools import setup
10 | from torch.utils.cpp_extension import CUDA_HOME
11 | from torch.utils.cpp_extension import CppExtension
12 | from torch.utils.cpp_extension import CUDAExtension
13 |
14 | requirements = ["torch", "torchvision"]
15 |
16 |
17 | def get_extensions():
18 | this_dir = os.path.dirname(os.path.abspath(__file__))
19 | extensions_dir = os.path.join(this_dir, "model", "csrc")
20 |
21 | main_file = glob.glob(os.path.join(extensions_dir, "*.cpp"))
22 | source_cpu = glob.glob(os.path.join(extensions_dir, "cpu", "*.cpp"))
23 | source_cuda = glob.glob(os.path.join(extensions_dir, "cuda", "*.cu"))
24 |
25 | sources = main_file + source_cpu
26 | extension = CppExtension
27 |
28 | extra_compile_args = {"cxx": []}
29 | define_macros = []
30 |
31 | if torch.cuda.is_available() and CUDA_HOME is not None:
32 | extension = CUDAExtension
33 | sources += source_cuda
34 | define_macros += [("WITH_CUDA", None)]
35 | extra_compile_args["nvcc"] = [
36 | "-DCUDA_HAS_FP16=1",
37 | "-D__CUDA_NO_HALF_OPERATORS__",
38 | "-D__CUDA_NO_HALF_CONVERSIONS__",
39 | "-D__CUDA_NO_HALF2_OPERATORS__",
40 | ]
41 |
42 | sources = [os.path.join(extensions_dir, s) for s in sources]
43 |
44 | include_dirs = [extensions_dir]
45 |
46 | ext_modules = [
47 | extension(
48 | "model._C",
49 | sources,
50 | include_dirs=include_dirs,
51 | define_macros=define_macros,
52 | extra_compile_args=extra_compile_args,
53 | )
54 | ]
55 |
56 | return ext_modules
57 |
58 |
59 | setup(
60 | name="faster_rcnn",
61 | version="0.1",
62 | description="object detection in pytorch",
63 | packages=find_packages(exclude=("configs", "tests",)),
64 | # install_requires=requirements,
65 | ext_modules=get_extensions(),
66 | cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension},
67 | )
68 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_align/functions/roi_align.py:
--------------------------------------------------------------------------------
1 | import torch
2 | from torch.autograd import Function
3 | from .._ext import roi_align
4 |
5 |
6 | # TODO use save_for_backward instead
7 | class RoIAlignFunction(Function):
8 | def __init__(self, aligned_height, aligned_width, spatial_scale):
9 | self.aligned_width = int(aligned_width)
10 | self.aligned_height = int(aligned_height)
11 | self.spatial_scale = float(spatial_scale)
12 | self.rois = None
13 | self.feature_size = None
14 |
15 | def forward(self, features, rois):
16 | self.rois = rois
17 | self.feature_size = features.size()
18 |
19 | batch_size, num_channels, data_height, data_width = features.size()
20 | num_rois = rois.size(0)
21 |
22 | output = features.new(num_rois, num_channels, self.aligned_height, self.aligned_width).zero_()
23 | if features.is_cuda:
24 | roi_align.roi_align_forward_cuda(self.aligned_height,
25 | self.aligned_width,
26 | self.spatial_scale, features,
27 | rois, output)
28 | else:
29 | roi_align.roi_align_forward(self.aligned_height,
30 | self.aligned_width,
31 | self.spatial_scale, features,
32 | rois, output)
33 | # raise NotImplementedError
34 |
35 | return output
36 |
37 | def backward(self, grad_output):
38 | assert(self.feature_size is not None and grad_output.is_cuda)
39 |
40 | batch_size, num_channels, data_height, data_width = self.feature_size
41 |
42 | grad_input = self.rois.new(batch_size, num_channels, data_height,
43 | data_width).zero_()
44 | roi_align.roi_align_backward_cuda(self.aligned_height,
45 | self.aligned_width,
46 | self.spatial_scale, grad_output,
47 | self.rois, grad_input)
48 |
49 | # print grad_input
50 |
51 | return grad_input, None
52 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_align/functions/roi_align.py:
--------------------------------------------------------------------------------
1 | import torch
2 | from torch.autograd import Function
3 | from .._ext import roi_align
4 |
5 |
6 | # TODO use save_for_backward instead
7 | class RoIAlignFunction(Function):
8 | def __init__(self, aligned_height, aligned_width, spatial_scale):
9 | self.aligned_width = int(aligned_width)
10 | self.aligned_height = int(aligned_height)
11 | self.spatial_scale = float(spatial_scale)
12 | self.rois = None
13 | self.feature_size = None
14 |
15 | def forward(self, features, rois):
16 | self.rois = rois
17 | self.feature_size = features.size()
18 |
19 | batch_size, num_channels, data_height, data_width = features.size()
20 | num_rois = rois.size(0)
21 |
22 | output = features.new(num_rois, num_channels, self.aligned_height, self.aligned_width).zero_()
23 | if features.is_cuda:
24 | roi_align.roi_align_forward_cuda(self.aligned_height,
25 | self.aligned_width,
26 | self.spatial_scale, features,
27 | rois, output)
28 | else:
29 | roi_align.roi_align_forward(self.aligned_height,
30 | self.aligned_width,
31 | self.spatial_scale, features,
32 | rois, output)
33 | # raise NotImplementedError
34 |
35 | return output
36 |
37 | def backward(self, grad_output):
38 | assert(self.feature_size is not None and grad_output.is_cuda)
39 |
40 | batch_size, num_channels, data_height, data_width = self.feature_size
41 |
42 | grad_input = self.rois.new(batch_size, num_channels, data_height,
43 | data_width).zero_()
44 | roi_align.roi_align_backward_cuda(self.aligned_height,
45 | self.aligned_width,
46 | self.spatial_scale, grad_output,
47 | self.rois, grad_input)
48 |
49 | # print grad_input
50 |
51 | return grad_input, None
52 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/faster_rcnn/vgg16.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Tensorflow Faster R-CNN
3 | # Licensed under The MIT License [see LICENSE for details]
4 | # Written by Xinlei Chen
5 | # --------------------------------------------------------
6 | from __future__ import absolute_import
7 | from __future__ import division
8 | from __future__ import print_function
9 |
10 | import torch
11 | import torch.nn as nn
12 | import torch.nn.functional as F
13 | from torch.autograd import Variable
14 | import math
15 | import torchvision.models as models
16 | from model.faster_rcnn.faster_rcnn import _fasterRCNN
17 | import pdb
18 |
19 | class vgg16(_fasterRCNN):
20 | def __init__(self, classes, pretrained=False, class_agnostic=False):
21 | self.model_path = 'data/pretrained_model/vgg16_caffe.pth'
22 | self.dout_base_model = 512
23 | self.pretrained = pretrained
24 | self.class_agnostic = class_agnostic
25 |
26 | _fasterRCNN.__init__(self, classes, class_agnostic)
27 |
28 | def _init_modules(self):
29 | vgg = models.vgg16()
30 | if self.pretrained:
31 | print("Loading pretrained weights from %s" %(self.model_path))
32 | state_dict = torch.load(self.model_path)
33 | vgg.load_state_dict({k:v for k,v in state_dict.items() if k in vgg.state_dict()})
34 |
35 | vgg.classifier = nn.Sequential(*list(vgg.classifier._modules.values())[:-1])
36 |
37 | # not using the last maxpool layer
38 | self.RCNN_base = nn.Sequential(*list(vgg.features._modules.values())[:-1])
39 |
40 | # Fix the layers before conv3:
41 | for layer in range(10):
42 | for p in self.RCNN_base[layer].parameters(): p.requires_grad = False
43 |
44 | # self.RCNN_base = _RCNN_base(vgg.features, self.classes, self.dout_base_model)
45 |
46 | self.RCNN_top = vgg.classifier
47 |
48 | # not using the last maxpool layer
49 | self.RCNN_cls_score = nn.Linear(4096, self.n_classes)
50 |
51 | if self.class_agnostic:
52 | self.RCNN_bbox_pred = nn.Linear(4096, 4)
53 | else:
54 | self.RCNN_bbox_pred = nn.Linear(4096, 4 * self.n_classes)
55 |
56 | def _head_to_tail(self, pool5):
57 |
58 | pool5_flat = pool5.view(pool5.size(0), -1)
59 | fc7 = self.RCNN_top(pool5_flat)
60 |
61 | return fc7
62 |
63 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/faster_rcnn/vgg16.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Tensorflow Faster R-CNN
3 | # Licensed under The MIT License [see LICENSE for details]
4 | # Written by Xinlei Chen
5 | # --------------------------------------------------------
6 | from __future__ import absolute_import
7 | from __future__ import division
8 | from __future__ import print_function
9 |
10 | import torch
11 | import torch.nn as nn
12 | import torch.nn.functional as F
13 | from torch.autograd import Variable
14 | import math
15 | import torchvision.models as models
16 | from model.faster_rcnn.faster_rcnn import _fasterRCNN
17 | import pdb
18 |
19 | class vgg16(_fasterRCNN):
20 | def __init__(self, classes, pretrained=False, class_agnostic=False):
21 | self.model_path = 'data/pretrained_model/vgg16_caffe.pth'
22 | self.dout_base_model = 512
23 | self.pretrained = pretrained
24 | self.class_agnostic = class_agnostic
25 |
26 | _fasterRCNN.__init__(self, classes, class_agnostic)
27 |
28 | def _init_modules(self):
29 | vgg = models.vgg16()
30 | if self.pretrained:
31 | print("Loading pretrained weights from %s" %(self.model_path))
32 | state_dict = torch.load(self.model_path)
33 | vgg.load_state_dict({k:v for k,v in state_dict.items() if k in vgg.state_dict()})
34 |
35 | vgg.classifier = nn.Sequential(*list(vgg.classifier._modules.values())[:-1])
36 |
37 | # not using the last maxpool layer
38 | self.RCNN_base = nn.Sequential(*list(vgg.features._modules.values())[:-1])
39 |
40 | # Fix the layers before conv3:
41 | for layer in range(10):
42 | for p in self.RCNN_base[layer].parameters(): p.requires_grad = False
43 |
44 | # self.RCNN_base = _RCNN_base(vgg.features, self.classes, self.dout_base_model)
45 |
46 | self.RCNN_top = vgg.classifier
47 |
48 | # not using the last maxpool layer
49 | self.RCNN_cls_score = nn.Linear(4096, self.n_classes)
50 |
51 | if self.class_agnostic:
52 | self.RCNN_bbox_pred = nn.Linear(4096, 4)
53 | else:
54 | self.RCNN_bbox_pred = nn.Linear(4096, 4 * self.n_classes)
55 |
56 | def _head_to_tail(self, pool5):
57 |
58 | pool5_flat = pool5.view(pool5.size(0), -1)
59 | fc7 = self.RCNN_top(pool5_flat)
60 |
61 | return fc7
62 |
63 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/csrc/cuda/vision.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | #pragma once
3 | #include
4 |
5 |
6 | at::Tensor ROIAlign_forward_cuda(const at::Tensor& input,
7 | const at::Tensor& rois,
8 | const float spatial_scale,
9 | const int pooled_height,
10 | const int pooled_width,
11 | const int sampling_ratio);
12 |
13 | at::Tensor ROIAlign_backward_cuda(const at::Tensor& grad,
14 | const at::Tensor& rois,
15 | const float spatial_scale,
16 | const int pooled_height,
17 | const int pooled_width,
18 | const int batch_size,
19 | const int channels,
20 | const int height,
21 | const int width,
22 | const int sampling_ratio);
23 |
24 |
25 | std::tuple ROIPool_forward_cuda(const at::Tensor& input,
26 | const at::Tensor& rois,
27 | const float spatial_scale,
28 | const int pooled_height,
29 | const int pooled_width);
30 |
31 | at::Tensor ROIPool_backward_cuda(const at::Tensor& grad,
32 | const at::Tensor& input,
33 | const at::Tensor& rois,
34 | const at::Tensor& argmax,
35 | const float spatial_scale,
36 | const int pooled_height,
37 | const int pooled_width,
38 | const int batch_size,
39 | const int channels,
40 | const int height,
41 | const int width);
42 |
43 | at::Tensor nms_cuda(const at::Tensor boxes, float nms_overlap_thresh);
44 |
45 |
46 | at::Tensor compute_flow_cuda(const at::Tensor& boxes,
47 | const int height,
48 | const int width);
49 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_layers/roi_align.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | import torch
3 | from torch import nn
4 | from torch.autograd import Function
5 | from torch.autograd.function import once_differentiable
6 | from torch.nn.modules.utils import _pair
7 |
8 | from fasterRCNN.lib.model import _C
9 |
10 | import pdb
11 |
12 | class _ROIAlign(Function):
13 | @staticmethod
14 | def forward(ctx, input, roi, output_size, spatial_scale, sampling_ratio):
15 | ctx.save_for_backward(roi)
16 | ctx.output_size = _pair(output_size)
17 | ctx.spatial_scale = spatial_scale
18 | ctx.sampling_ratio = sampling_ratio
19 | ctx.input_shape = input.size()
20 | output = _C.roi_align_forward(input, roi, spatial_scale, output_size[0], output_size[1], sampling_ratio)
21 | return output
22 |
23 | @staticmethod
24 | @once_differentiable
25 | def backward(ctx, grad_output):
26 | rois, = ctx.saved_tensors
27 | output_size = ctx.output_size
28 | spatial_scale = ctx.spatial_scale
29 | sampling_ratio = ctx.sampling_ratio
30 | bs, ch, h, w = ctx.input_shape
31 | grad_input = _C.roi_align_backward(
32 | grad_output,
33 | rois,
34 | spatial_scale,
35 | output_size[0],
36 | output_size[1],
37 | bs,
38 | ch,
39 | h,
40 | w,
41 | sampling_ratio,
42 | )
43 | return grad_input, None, None, None, None
44 |
45 |
46 | roi_align = _ROIAlign.apply
47 |
48 |
49 | class ROIAlign(nn.Module):
50 | def __init__(self, output_size, spatial_scale, sampling_ratio):
51 | super(ROIAlign, self).__init__()
52 | self.output_size = output_size
53 | self.spatial_scale = spatial_scale
54 | self.sampling_ratio = sampling_ratio
55 |
56 | def forward(self, input, rois):
57 | return roi_align(
58 | input, rois, self.output_size, self.spatial_scale, self.sampling_ratio
59 | )
60 |
61 | def __repr__(self):
62 | tmpstr = self.__class__.__name__ + "("
63 | tmpstr += "output_size=" + str(self.output_size)
64 | tmpstr += ", spatial_scale=" + str(self.spatial_scale)
65 | tmpstr += ", sampling_ratio=" + str(self.sampling_ratio)
66 | tmpstr += ")"
67 | return tmpstr
68 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_layers/roi_align.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | import torch
3 | from torch import nn
4 | from torch.autograd import Function
5 | from torch.autograd.function import once_differentiable
6 | from torch.nn.modules.utils import _pair
7 |
8 | from model import _C
9 |
10 | import pdb
11 |
12 | class _ROIAlign(Function):
13 | @staticmethod
14 | def forward(ctx, input, roi, output_size, spatial_scale, sampling_ratio):
15 | ctx.save_for_backward(roi)
16 | ctx.output_size = _pair(output_size)
17 | ctx.spatial_scale = spatial_scale
18 | ctx.sampling_ratio = sampling_ratio
19 | ctx.input_shape = input.size()
20 | output = _C.roi_align_forward(input, roi, spatial_scale, output_size[0], output_size[1], sampling_ratio)
21 | return output
22 |
23 | @staticmethod
24 | @once_differentiable
25 | def backward(ctx, grad_output):
26 | rois, = ctx.saved_tensors
27 | output_size = ctx.output_size
28 | spatial_scale = ctx.spatial_scale
29 | sampling_ratio = ctx.sampling_ratio
30 | bs, ch, h, w = ctx.input_shape
31 | grad_input = _C.roi_align_backward(
32 | grad_output,
33 | rois,
34 | spatial_scale,
35 | output_size[0],
36 | output_size[1],
37 | bs,
38 | ch,
39 | h,
40 | w,
41 | sampling_ratio,
42 | )
43 | return grad_input, None, None, None, None
44 |
45 |
46 | roi_align = _ROIAlign.apply
47 |
48 |
49 | class ROIAlign(nn.Module):
50 | def __init__(self, output_size, spatial_scale, sampling_ratio):
51 | super(ROIAlign, self).__init__()
52 | self.output_size = output_size
53 | self.spatial_scale = spatial_scale
54 | self.sampling_ratio = sampling_ratio
55 |
56 | def forward(self, input, rois):
57 | return roi_align(
58 | input, rois, self.output_size, self.spatial_scale, self.sampling_ratio
59 | )
60 |
61 | def __repr__(self):
62 | tmpstr = self.__class__.__name__ + "("
63 | tmpstr += "output_size=" + str(self.output_size)
64 | tmpstr += ", spatial_scale=" + str(self.spatial_scale)
65 | tmpstr += ", sampling_ratio=" + str(self.sampling_ratio)
66 | tmpstr += ")"
67 | return tmpstr
68 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/functions/gridgen.py:
--------------------------------------------------------------------------------
1 | # functions/add.py
2 | import torch
3 | from torch.autograd import Function
4 | import numpy as np
5 |
6 |
7 | class AffineGridGenFunction(Function):
8 | def __init__(self, height, width,lr=1):
9 | super(AffineGridGenFunction, self).__init__()
10 | self.lr = lr
11 | self.height, self.width = height, width
12 | self.grid = np.zeros( [self.height, self.width, 3], dtype=np.float32)
13 | self.grid[:,:,0] = np.expand_dims(np.repeat(np.expand_dims(np.arange(-1, 1, 2.0/(self.height)), 0), repeats = self.width, axis = 0).T, 0)
14 | self.grid[:,:,1] = np.expand_dims(np.repeat(np.expand_dims(np.arange(-1, 1, 2.0/(self.width)), 0), repeats = self.height, axis = 0), 0)
15 | # self.grid[:,:,0] = np.expand_dims(np.repeat(np.expand_dims(np.arange(-1, 1, 2.0/(self.height - 1)), 0), repeats = self.width, axis = 0).T, 0)
16 | # self.grid[:,:,1] = np.expand_dims(np.repeat(np.expand_dims(np.arange(-1, 1, 2.0/(self.width - 1)), 0), repeats = self.height, axis = 0), 0)
17 | self.grid[:,:,2] = np.ones([self.height, width])
18 | self.grid = torch.from_numpy(self.grid.astype(np.float32))
19 | #print(self.grid)
20 |
21 | def forward(self, input1):
22 | self.input1 = input1
23 | output = input1.new(torch.Size([input1.size(0)]) + self.grid.size()).zero_()
24 | self.batchgrid = input1.new(torch.Size([input1.size(0)]) + self.grid.size()).zero_()
25 | for i in range(input1.size(0)):
26 | self.batchgrid[i] = self.grid.astype(self.batchgrid[i])
27 |
28 | # if input1.is_cuda:
29 | # self.batchgrid = self.batchgrid.cuda()
30 | # output = output.cuda()
31 |
32 | for i in range(input1.size(0)):
33 | output = torch.bmm(self.batchgrid.view(-1, self.height*self.width, 3), torch.transpose(input1, 1, 2)).view(-1, self.height, self.width, 2)
34 |
35 | return output
36 |
37 | def backward(self, grad_output):
38 |
39 | grad_input1 = self.input1.new(self.input1.size()).zero_()
40 |
41 | # if grad_output.is_cuda:
42 | # self.batchgrid = self.batchgrid.cuda()
43 | # grad_input1 = grad_input1.cuda()
44 |
45 | grad_input1 = torch.baddbmm(grad_input1, torch.transpose(grad_output.view(-1, self.height*self.width, 2), 1,2), self.batchgrid.view(-1, self.height*self.width, 3))
46 | return grad_input1
47 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/roi_crop/functions/gridgen.py:
--------------------------------------------------------------------------------
1 | # functions/add.py
2 | import torch
3 | from torch.autograd import Function
4 | import numpy as np
5 |
6 |
7 | class AffineGridGenFunction(Function):
8 | def __init__(self, height, width,lr=1):
9 | super(AffineGridGenFunction, self).__init__()
10 | self.lr = lr
11 | self.height, self.width = height, width
12 | self.grid = np.zeros( [self.height, self.width, 3], dtype=np.float32)
13 | self.grid[:,:,0] = np.expand_dims(np.repeat(np.expand_dims(np.arange(-1, 1, 2.0/(self.height)), 0), repeats = self.width, axis = 0).T, 0)
14 | self.grid[:,:,1] = np.expand_dims(np.repeat(np.expand_dims(np.arange(-1, 1, 2.0/(self.width)), 0), repeats = self.height, axis = 0), 0)
15 | # self.grid[:,:,0] = np.expand_dims(np.repeat(np.expand_dims(np.arange(-1, 1, 2.0/(self.height - 1)), 0), repeats = self.width, axis = 0).T, 0)
16 | # self.grid[:,:,1] = np.expand_dims(np.repeat(np.expand_dims(np.arange(-1, 1, 2.0/(self.width - 1)), 0), repeats = self.height, axis = 0), 0)
17 | self.grid[:,:,2] = np.ones([self.height, width])
18 | self.grid = torch.from_numpy(self.grid.astype(np.float32))
19 | #print(self.grid)
20 |
21 | def forward(self, input1):
22 | self.input1 = input1
23 | output = input1.new(torch.Size([input1.size(0)]) + self.grid.size()).zero_()
24 | self.batchgrid = input1.new(torch.Size([input1.size(0)]) + self.grid.size()).zero_()
25 | for i in range(input1.size(0)):
26 | self.batchgrid[i] = self.grid.astype(self.batchgrid[i])
27 |
28 | # if input1.is_cuda:
29 | # self.batchgrid = self.batchgrid.cuda()
30 | # output = output.cuda()
31 |
32 | for i in range(input1.size(0)):
33 | output = torch.bmm(self.batchgrid.view(-1, self.height*self.width, 3), torch.transpose(input1, 1, 2)).view(-1, self.height, self.width, 2)
34 |
35 | return output
36 |
37 | def backward(self, grad_output):
38 |
39 | grad_input1 = self.input1.new(self.input1.size()).zero_()
40 |
41 | # if grad_output.is_cuda:
42 | # self.batchgrid = self.batchgrid.cuda()
43 | # grad_input1 = grad_input1.cuda()
44 |
45 | grad_input1 = torch.baddbmm(grad_input1, torch.transpose(grad_output.view(-1, self.height*self.width, 2), 1,2), self.batchgrid.view(-1, self.height*self.width, 3))
46 | return grad_input1
47 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_align/src/roi_align_cuda.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "roi_align_kernel.h"
4 |
5 | extern THCState *state;
6 |
7 | int roi_align_forward_cuda(int aligned_height, int aligned_width, float spatial_scale,
8 | THCudaTensor * features, THCudaTensor * rois, THCudaTensor * output)
9 | {
10 | // Grab the input tensor
11 | float * data_flat = THCudaTensor_data(state, features);
12 | float * rois_flat = THCudaTensor_data(state, rois);
13 |
14 | float * output_flat = THCudaTensor_data(state, output);
15 |
16 | // Number of ROIs
17 | int num_rois = THCudaTensor_size(state, rois, 0);
18 | int size_rois = THCudaTensor_size(state, rois, 1);
19 | if (size_rois != 5)
20 | {
21 | return 0;
22 | }
23 |
24 | // data height
25 | int data_height = THCudaTensor_size(state, features, 2);
26 | // data width
27 | int data_width = THCudaTensor_size(state, features, 3);
28 | // Number of channels
29 | int num_channels = THCudaTensor_size(state, features, 1);
30 |
31 | cudaStream_t stream = THCState_getCurrentStream(state);
32 |
33 | ROIAlignForwardLaucher(
34 | data_flat, spatial_scale, num_rois, data_height,
35 | data_width, num_channels, aligned_height,
36 | aligned_width, rois_flat,
37 | output_flat, stream);
38 |
39 | return 1;
40 | }
41 |
42 | int roi_align_backward_cuda(int aligned_height, int aligned_width, float spatial_scale,
43 | THCudaTensor * top_grad, THCudaTensor * rois, THCudaTensor * bottom_grad)
44 | {
45 | // Grab the input tensor
46 | float * top_grad_flat = THCudaTensor_data(state, top_grad);
47 | float * rois_flat = THCudaTensor_data(state, rois);
48 |
49 | float * bottom_grad_flat = THCudaTensor_data(state, bottom_grad);
50 |
51 | // Number of ROIs
52 | int num_rois = THCudaTensor_size(state, rois, 0);
53 | int size_rois = THCudaTensor_size(state, rois, 1);
54 | if (size_rois != 5)
55 | {
56 | return 0;
57 | }
58 |
59 | // batch size
60 | int batch_size = THCudaTensor_size(state, bottom_grad, 0);
61 | // data height
62 | int data_height = THCudaTensor_size(state, bottom_grad, 2);
63 | // data width
64 | int data_width = THCudaTensor_size(state, bottom_grad, 3);
65 | // Number of channels
66 | int num_channels = THCudaTensor_size(state, bottom_grad, 1);
67 |
68 | cudaStream_t stream = THCState_getCurrentStream(state);
69 | ROIAlignBackwardLaucher(
70 | top_grad_flat, spatial_scale, batch_size, num_rois, data_height,
71 | data_width, num_channels, aligned_height,
72 | aligned_width, rois_flat,
73 | bottom_grad_flat, stream);
74 |
75 | return 1;
76 | }
77 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/utils/logger.py:
--------------------------------------------------------------------------------
1 | # Code referenced from https://gist.github.com/gyglim/1f8dfb1b5c82627ae3efcfbbadb9f514
2 | import tensorflow as tf
3 | import numpy as np
4 | import scipy.misc
5 | try:
6 | from StringIO import StringIO # Python 2.7
7 | except ImportError:
8 | from io import BytesIO # Python 3.x
9 |
10 |
11 | class Logger(object):
12 |
13 | def __init__(self, log_dir):
14 | """Create a summary writer logging to log_dir."""
15 | self.writer = tf.summary.FileWriter(log_dir)
16 |
17 | def scalar_summary(self, tag, value, step):
18 | """Log a scalar variable."""
19 | summary = tf.Summary(value=[tf.Summary.Value(tag=tag, simple_value=value)])
20 | self.writer.add_summary(summary, step)
21 |
22 | def image_summary(self, tag, images, step):
23 | """Log a list of images."""
24 |
25 | img_summaries = []
26 | for i, img in enumerate(images):
27 | # Write the image to a string
28 | try:
29 | s = StringIO()
30 | except:
31 | s = BytesIO()
32 | scipy.misc.toimage(img).save(s, format="png")
33 |
34 | # Create an Image object
35 | img_sum = tf.Summary.Image(encoded_image_string=s.getvalue(),
36 | height=img.shape[0],
37 | width=img.shape[1])
38 | # Create a Summary value
39 | img_summaries.append(tf.Summary.Value(tag='%s/%d' % (tag, i), image=img_sum))
40 |
41 | # Create and write Summary
42 | summary = tf.Summary(value=img_summaries)
43 | self.writer.add_summary(summary, step)
44 |
45 | def histo_summary(self, tag, values, step, bins=1000):
46 | """Log a histogram of the tensor of values."""
47 |
48 | # Create a histogram using numpy
49 | counts, bin_edges = np.histogram(values, bins=bins)
50 |
51 | # Fill the fields of the histogram proto
52 | hist = tf.HistogramProto()
53 | hist.min = float(np.min(values))
54 | hist.max = float(np.max(values))
55 | hist.num = int(np.prod(values.shape))
56 | hist.sum = float(np.sum(values))
57 | hist.sum_squares = float(np.sum(values**2))
58 |
59 | # Drop the start of the first bin
60 | bin_edges = bin_edges[1:]
61 |
62 | # Add bin edges and counts
63 | for edge in bin_edges:
64 | hist.bucket_limit.append(edge)
65 | for c in counts:
66 | hist.bucket.append(c)
67 |
68 | # Create and write Summary
69 | summary = tf.Summary(value=[tf.Summary.Value(tag=tag, histo=hist)])
70 | self.writer.add_summary(summary, step)
71 | self.writer.flush()
72 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/csrc/cpu/nms_cpu.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 | #include "cpu/vision.h"
3 |
4 |
5 | template
6 | at::Tensor nms_cpu_kernel(const at::Tensor& dets,
7 | const at::Tensor& scores,
8 | const float threshold) {
9 | AT_ASSERTM(!dets.type().is_cuda(), "dets must be a CPU tensor");
10 | AT_ASSERTM(!scores.type().is_cuda(), "scores must be a CPU tensor");
11 | AT_ASSERTM(dets.type() == scores.type(), "dets should have the same type as scores");
12 |
13 | if (dets.numel() == 0) {
14 | return at::empty({0}, dets.options().dtype(at::kLong).device(at::kCPU));
15 | }
16 |
17 | auto x1_t = dets.select(1, 0).contiguous();
18 | auto y1_t = dets.select(1, 1).contiguous();
19 | auto x2_t = dets.select(1, 2).contiguous();
20 | auto y2_t = dets.select(1, 3).contiguous();
21 |
22 | at::Tensor areas_t = (x2_t - x1_t + 1) * (y2_t - y1_t + 1);
23 |
24 | auto order_t = std::get<1>(scores.sort(0, /* descending=*/true));
25 |
26 | auto ndets = dets.size(0);
27 | at::Tensor suppressed_t = at::zeros({ndets}, dets.options().dtype(at::kByte).device(at::kCPU));
28 |
29 | auto suppressed = suppressed_t.data();
30 | auto order = order_t.data();
31 | auto x1 = x1_t.data();
32 | auto y1 = y1_t.data();
33 | auto x2 = x2_t.data();
34 | auto y2 = y2_t.data();
35 | auto areas = areas_t.data();
36 |
37 | for (int64_t _i = 0; _i < ndets; _i++) {
38 | auto i = order[_i];
39 | if (suppressed[i] == 1)
40 | continue;
41 | auto ix1 = x1[i];
42 | auto iy1 = y1[i];
43 | auto ix2 = x2[i];
44 | auto iy2 = y2[i];
45 | auto iarea = areas[i];
46 |
47 | for (int64_t _j = _i + 1; _j < ndets; _j++) {
48 | auto j = order[_j];
49 | if (suppressed[j] == 1)
50 | continue;
51 | auto xx1 = std::max(ix1, x1[j]);
52 | auto yy1 = std::max(iy1, y1[j]);
53 | auto xx2 = std::min(ix2, x2[j]);
54 | auto yy2 = std::min(iy2, y2[j]);
55 |
56 | auto w = std::max(static_cast(0), xx2 - xx1 + 1);
57 | auto h = std::max(static_cast(0), yy2 - yy1 + 1);
58 | auto inter = w * h;
59 | auto ovr = inter / (iarea + areas[j] - inter);
60 | if (ovr >= threshold)
61 | suppressed[j] = 1;
62 | }
63 | }
64 | return at::nonzero(suppressed_t == 0).squeeze(1);
65 | }
66 |
67 | at::Tensor nms_cpu(const at::Tensor& dets,
68 | const at::Tensor& scores,
69 | const float threshold) {
70 | at::Tensor result;
71 | AT_DISPATCH_FLOATING_TYPES(dets.type(), "nms", [&] {
72 | result = nms_cpu_kernel(dets, scores, threshold);
73 | });
74 | return result;
75 | }
76 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/utils/logger.py:
--------------------------------------------------------------------------------
1 | # Code referenced from https://gist.github.com/gyglim/1f8dfb1b5c82627ae3efcfbbadb9f514
2 | import tensorflow as tf
3 | import numpy as np
4 | import scipy.misc
5 | try:
6 | from StringIO import StringIO # Python 2.7
7 | except ImportError:
8 | from io import BytesIO # Python 3.x
9 |
10 |
11 | class Logger(object):
12 |
13 | def __init__(self, log_dir):
14 | """Create a summary writer logging to log_dir."""
15 | self.writer = tf.summary.FileWriter(log_dir)
16 |
17 | def scalar_summary(self, tag, value, step):
18 | """Log a scalar variable."""
19 | summary = tf.Summary(value=[tf.Summary.Value(tag=tag, simple_value=value)])
20 | self.writer.add_summary(summary, step)
21 |
22 | def image_summary(self, tag, images, step):
23 | """Log a list of images."""
24 |
25 | img_summaries = []
26 | for i, img in enumerate(images):
27 | # Write the image to a string
28 | try:
29 | s = StringIO()
30 | except:
31 | s = BytesIO()
32 | scipy.misc.toimage(img).save(s, format="png")
33 |
34 | # Create an Image object
35 | img_sum = tf.Summary.Image(encoded_image_string=s.getvalue(),
36 | height=img.shape[0],
37 | width=img.shape[1])
38 | # Create a Summary value
39 | img_summaries.append(tf.Summary.Value(tag='%s/%d' % (tag, i), image=img_sum))
40 |
41 | # Create and write Summary
42 | summary = tf.Summary(value=img_summaries)
43 | self.writer.add_summary(summary, step)
44 |
45 | def histo_summary(self, tag, values, step, bins=1000):
46 | """Log a histogram of the tensor of values."""
47 |
48 | # Create a histogram using numpy
49 | counts, bin_edges = np.histogram(values, bins=bins)
50 |
51 | # Fill the fields of the histogram proto
52 | hist = tf.HistogramProto()
53 | hist.min = float(np.min(values))
54 | hist.max = float(np.max(values))
55 | hist.num = int(np.prod(values.shape))
56 | hist.sum = float(np.sum(values))
57 | hist.sum_squares = float(np.sum(values**2))
58 |
59 | # Drop the start of the first bin
60 | bin_edges = bin_edges[1:]
61 |
62 | # Add bin edges and counts
63 | for edge in bin_edges:
64 | hist.bucket_limit.append(edge)
65 | for c in counts:
66 | hist.bucket.append(c)
67 |
68 | # Create and write Summary
69 | summary = tf.Summary(value=[tf.Summary.Value(tag=tag, histo=hist)])
70 | self.writer.add_summary(summary, step)
71 | self.writer.flush()
72 |
--------------------------------------------------------------------------------
/lib/draw_rectangles/draw_rectangles.pyx:
--------------------------------------------------------------------------------
1 | ######
2 | # Draws rectangles
3 | ######
4 |
5 | cimport cython
6 | import numpy as np
7 | cimport numpy as np
8 |
9 | DTYPE = np.float32
10 | ctypedef np.float32_t DTYPE_t
11 |
12 | def draw_union_boxes(bbox_pairs, pooling_size, padding=0):
13 | """
14 | Draws union boxes for the image.
15 | :param box_pairs: [num_pairs, 8]
16 | :param fmap_size: Size of the original feature map
17 | :param stride: ratio between fmap size and original img (<1)
18 | :param pooling_size: resize everything to this size
19 | :return: [num_pairs, 2, pooling_size, pooling_size arr
20 | """
21 | assert padding == 0, "Padding>0 not supported yet"
22 | return draw_union_boxes_c(bbox_pairs, pooling_size)
23 |
24 | cdef DTYPE_t minmax(DTYPE_t x):
25 | return min(max(x, 0), 1)
26 |
27 | cdef np.ndarray[DTYPE_t, ndim=4] draw_union_boxes_c(
28 | np.ndarray[DTYPE_t, ndim=2] box_pairs, unsigned int pooling_size):
29 | """
30 | Parameters
31 | ----------
32 | boxes: (N, 4) ndarray of float. everything has arbitrary ratios
33 | query_boxes: (K, 4) ndarray of float
34 | Returns
35 | -------
36 | overlaps: (N, K) ndarray of overlap between boxes and query_boxes
37 | """
38 | cdef unsigned int N = box_pairs.shape[0]
39 |
40 | cdef np.ndarray[DTYPE_t, ndim = 4] uboxes = np.zeros(
41 | (N, 2, pooling_size, pooling_size), dtype=DTYPE)
42 | cdef DTYPE_t x1_union, y1_union, x2_union, y2_union, w, h, x1_box, y1_box, x2_box, y2_box, y_contrib, x_contrib
43 | cdef unsigned int n, i, j, k
44 |
45 | for n in range(N):
46 | x1_union = min(box_pairs[n, 0], box_pairs[n, 4])
47 | y1_union = min(box_pairs[n, 1], box_pairs[n, 5])
48 | x2_union = max(box_pairs[n, 2], box_pairs[n, 6])
49 | y2_union = max(box_pairs[n, 3], box_pairs[n, 7])
50 |
51 | w = x2_union - x1_union
52 | h = y2_union - y1_union
53 |
54 | for i in range(2):
55 | # Now everything is in the range [0, pooling_size].
56 | x1_box = (box_pairs[n, 0+4*i] - x1_union)*pooling_size / w
57 | y1_box = (box_pairs[n, 1+4*i] - y1_union)*pooling_size / h
58 | x2_box = (box_pairs[n, 2+4*i] - x1_union)*pooling_size / w
59 | y2_box = (box_pairs[n, 3+4*i] - y1_union)*pooling_size / h
60 | # print("{:.3f}, {:.3f}, {:.3f}, {:.3f}".format(x1_box, y1_box, x2_box, y2_box))
61 | for j in range(pooling_size):
62 | y_contrib = minmax(j+1-y1_box)*minmax(y2_box-j)
63 | for k in range(pooling_size):
64 | x_contrib = minmax(k+1-x1_box)*minmax(x2_box-k)
65 | # print("j {} yc {} k {} xc {}".format(j, y_contrib, k, x_contrib))
66 | uboxes[n,i,j,k] = x_contrib*y_contrib
67 | return uboxes
68 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_crop/src/roi_crop_cuda_kernel.h:
--------------------------------------------------------------------------------
1 | #ifdef __cplusplus
2 | extern "C" {
3 | #endif
4 |
5 |
6 | int BilinearSamplerBHWD_updateOutput_cuda_kernel(/*output->size[3]*/int oc,
7 | /*output->size[2]*/int ow,
8 | /*output->size[1]*/int oh,
9 | /*output->size[0]*/int ob,
10 | /*THCudaTensor_size(state, inputImages, 3)*/int ic,
11 | /*THCudaTensor_size(state, inputImages, 1)*/int ih,
12 | /*THCudaTensor_size(state, inputImages, 2)*/int iw,
13 | /*THCudaTensor_size(state, inputImages, 0)*/int ib,
14 | /*THCudaTensor *inputImages*/float *inputImages, int isb, int isc, int ish, int isw,
15 | /*THCudaTensor *grids*/float *grids, int gsb, int gsc, int gsh, int gsw,
16 | /*THCudaTensor *output*/float *output, int osb, int osc, int osh, int osw,
17 | /*THCState_getCurrentStream(state)*/cudaStream_t stream);
18 |
19 | int BilinearSamplerBHWD_updateGradInput_cuda_kernel(/*gradOutput->size[3]*/int goc,
20 | /*gradOutput->size[2]*/int gow,
21 | /*gradOutput->size[1]*/int goh,
22 | /*gradOutput->size[0]*/int gob,
23 | /*THCudaTensor_size(state, inputImages, 3)*/int ic,
24 | /*THCudaTensor_size(state, inputImages, 1)*/int ih,
25 | /*THCudaTensor_size(state, inputImages, 2)*/int iw,
26 | /*THCudaTensor_size(state, inputImages, 0)*/int ib,
27 | /*THCudaTensor *inputImages*/float *inputImages, int isb, int isc, int ish, int isw,
28 | /*THCudaTensor *grids*/float *grids, int gsb, int gsc, int gsh, int gsw,
29 | /*THCudaTensor *gradInputImages*/float *gradInputImages, int gisb, int gisc, int gish, int gisw,
30 | /*THCudaTensor *gradGrids*/float *gradGrids, int ggsb, int ggsc, int ggsh, int ggsw,
31 | /*THCudaTensor *gradOutput*/float *gradOutput, int gosb, int gosc, int gosh, int gosw,
32 | /*THCState_getCurrentStream(state)*/cudaStream_t stream);
33 |
34 |
35 | #ifdef __cplusplus
36 | }
37 | #endif
38 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/factory.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast R-CNN
3 | # Copyright (c) 2015 Microsoft
4 | # Licensed under The MIT License [see LICENSE for details]
5 | # Written by Ross Girshick
6 | # --------------------------------------------------------
7 |
8 | """Factory method for easily getting imdbs by name."""
9 | from __future__ import absolute_import
10 | from __future__ import division
11 | from __future__ import print_function
12 |
13 | __sets = {}
14 | from datasets.pascal_voc import pascal_voc
15 | from datasets.coco import coco
16 | from datasets.imagenet import imagenet
17 | from datasets.vg import vg
18 |
19 | import numpy as np
20 |
21 | # Set up voc__
22 | for year in ['2007', '2012']:
23 | for split in ['train', 'val', 'trainval', 'test']:
24 | name = 'voc_{}_{}'.format(year, split)
25 | __sets[name] = (lambda split=split, year=year: pascal_voc(split, year))
26 |
27 | # Set up coco_2014_
28 | for year in ['2014']:
29 | for split in ['train', 'val', 'minival', 'valminusminival', 'trainval']:
30 | name = 'coco_{}_{}'.format(year, split)
31 | __sets[name] = (lambda split=split, year=year: coco(split, year))
32 |
33 | # Set up coco_2014_cap_
34 | for year in ['2014']:
35 | for split in ['train', 'val', 'capval', 'valminuscapval', 'trainval']:
36 | name = 'coco_{}_{}'.format(year, split)
37 | __sets[name] = (lambda split=split, year=year: coco(split, year))
38 |
39 | # Set up coco_2015_
40 | for year in ['2015']:
41 | for split in ['test', 'test-dev']:
42 | name = 'coco_{}_{}'.format(year, split)
43 | __sets[name] = (lambda split=split, year=year: coco(split, year))
44 |
45 | # Set up vg_
46 | # for version in ['1600-400-20']:
47 | # for split in ['minitrain', 'train', 'minival', 'val', 'test']:
48 | # name = 'vg_{}_{}'.format(version,split)
49 | # __sets[name] = (lambda split=split, version=version: vg(version, split))
50 | for version in ['150-50-20', '150-50-50', '500-150-80', '750-250-150', '1750-700-450', '1600-400-20']:
51 | for split in ['minitrain', 'smalltrain', 'train', 'minival', 'smallval', 'val', 'test']:
52 | name = 'vg_{}_{}'.format(version,split)
53 | __sets[name] = (lambda split=split, version=version: vg(version, split))
54 |
55 | # set up image net.
56 | for split in ['train', 'val', 'val1', 'val2', 'test']:
57 | name = 'imagenet_{}'.format(split)
58 | devkit_path = 'data/imagenet/ILSVRC/devkit'
59 | data_path = 'data/imagenet/ILSVRC'
60 | __sets[name] = (lambda split=split, devkit_path=devkit_path, data_path=data_path: imagenet(split,devkit_path,data_path))
61 |
62 | def get_imdb(name):
63 | """Get an imdb (image database) by name."""
64 | if name not in __sets:
65 | raise KeyError('Unknown dataset: {}'.format(name))
66 | return __sets[name]()
67 |
68 |
69 | def list_imdbs():
70 | """List all registered imdbs."""
71 | return list(__sets.keys())
72 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/datasets/factory.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast R-CNN
3 | # Copyright (c) 2015 Microsoft
4 | # Licensed under The MIT License [see LICENSE for details]
5 | # Written by Ross Girshick
6 | # --------------------------------------------------------
7 |
8 | """Factory method for easily getting imdbs by name."""
9 | from __future__ import absolute_import
10 | from __future__ import division
11 | from __future__ import print_function
12 |
13 | __sets = {}
14 | from datasets.pascal_voc import pascal_voc
15 | from datasets.coco import coco
16 | from datasets.imagenet import imagenet
17 | from datasets.vg import vg
18 |
19 | import numpy as np
20 |
21 | # Set up voc__
22 | for year in ['2007', '2012']:
23 | for split in ['train', 'val', 'trainval', 'test']:
24 | name = 'voc_{}_{}'.format(year, split)
25 | __sets[name] = (lambda split=split, year=year: pascal_voc(split, year))
26 |
27 | # Set up coco_2014_
28 | for year in ['2014']:
29 | for split in ['train', 'val', 'minival', 'valminusminival', 'trainval']:
30 | name = 'coco_{}_{}'.format(year, split)
31 | __sets[name] = (lambda split=split, year=year: coco(split, year))
32 |
33 | # Set up coco_2014_cap_
34 | for year in ['2014']:
35 | for split in ['train', 'val', 'capval', 'valminuscapval', 'trainval']:
36 | name = 'coco_{}_{}'.format(year, split)
37 | __sets[name] = (lambda split=split, year=year: coco(split, year))
38 |
39 | # Set up coco_2015_
40 | for year in ['2015']:
41 | for split in ['test', 'test-dev']:
42 | name = 'coco_{}_{}'.format(year, split)
43 | __sets[name] = (lambda split=split, year=year: coco(split, year))
44 |
45 | # Set up vg_
46 | # for version in ['1600-400-20']:
47 | # for split in ['minitrain', 'train', 'minival', 'val', 'test']:
48 | # name = 'vg_{}_{}'.format(version,split)
49 | # __sets[name] = (lambda split=split, version=version: vg(version, split))
50 | for version in ['150-50-20', '150-50-50', '500-150-80', '750-250-150', '1750-700-450', '1600-400-20']:
51 | for split in ['minitrain', 'smalltrain', 'train', 'minival', 'smallval', 'val', 'test']:
52 | name = 'vg_{}_{}'.format(version,split)
53 | __sets[name] = (lambda split=split, version=version: vg(version, split))
54 |
55 | # set up image net.
56 | for split in ['train', 'val', 'val1', 'val2', 'test']:
57 | name = 'imagenet_{}'.format(split)
58 | devkit_path = 'data/imagenet/ILSVRC/devkit'
59 | data_path = 'data/imagenet/ILSVRC'
60 | __sets[name] = (lambda split=split, devkit_path=devkit_path, data_path=data_path: imagenet(split,devkit_path,data_path))
61 |
62 | def get_imdb(name):
63 | """Get an imdb (image database) by name."""
64 | if name not in __sets:
65 | raise KeyError('Unknown dataset: {}'.format(name))
66 | return __sets[name]()
67 |
68 |
69 | def list_imdbs():
70 | """List all registered imdbs."""
71 | return list(__sets.keys())
72 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/faster_rcnn.egg-info/SOURCES.txt:
--------------------------------------------------------------------------------
1 | setup.py
2 | /home/cong/Dokumente/faster-rcnn.pytorch/lib/model/csrc/vision.cpp
3 | /home/cong/Dokumente/faster-rcnn.pytorch/lib/model/csrc/cpu/ROIAlign_cpu.cpp
4 | /home/cong/Dokumente/faster-rcnn.pytorch/lib/model/csrc/cpu/nms_cpu.cpp
5 | /home/cong/Dokumente/faster-rcnn.pytorch/lib/model/csrc/cuda/ROIAlign_cuda.cu
6 | /home/cong/Dokumente/faster-rcnn.pytorch/lib/model/csrc/cuda/ROIPool_cuda.cu
7 | /home/cong/Dokumente/faster-rcnn.pytorch/lib/model/csrc/cuda/nms.cu
8 | datasets/__init__.py
9 | datasets/coco.py
10 | datasets/ds_utils.py
11 | datasets/factory.py
12 | datasets/imagenet.py
13 | datasets/imdb.py
14 | datasets/pascal_voc.py
15 | datasets/pascal_voc_rbg.py
16 | datasets/vg.py
17 | datasets/vg_eval.py
18 | datasets/voc_eval.py
19 | faster_rcnn.egg-info/PKG-INFO
20 | faster_rcnn.egg-info/SOURCES.txt
21 | faster_rcnn.egg-info/dependency_links.txt
22 | faster_rcnn.egg-info/top_level.txt
23 | model/__init__.py
24 | model/faster_rcnn/__init__.py
25 | model/faster_rcnn/faster_rcnn.py
26 | model/faster_rcnn/resnet.py
27 | model/faster_rcnn/vgg16.py
28 | model/nms/__init__.py
29 | model/nms/build.py
30 | model/nms/nms_cpu.py
31 | model/nms/nms_gpu.py
32 | model/nms/nms_wrapper.py
33 | model/nms/_ext/__init__.py
34 | model/nms/_ext/nms/__init__.py
35 | model/roi_align/__init__.py
36 | model/roi_align/build.py
37 | model/roi_align/_ext/__init__.py
38 | model/roi_align/_ext/roi_align/__init__.py
39 | model/roi_align/functions/__init__.py
40 | model/roi_align/functions/roi_align.py
41 | model/roi_align/modules/__init__.py
42 | model/roi_align/modules/roi_align.py
43 | model/roi_crop/__init__.py
44 | model/roi_crop/build.py
45 | model/roi_crop/_ext/__init__.py
46 | model/roi_crop/_ext/crop_resize/__init__.py
47 | model/roi_crop/_ext/roi_crop/__init__.py
48 | model/roi_crop/functions/__init__.py
49 | model/roi_crop/functions/crop_resize.py
50 | model/roi_crop/functions/gridgen.py
51 | model/roi_crop/functions/roi_crop.py
52 | model/roi_crop/modules/__init__.py
53 | model/roi_crop/modules/gridgen.py
54 | model/roi_crop/modules/roi_crop.py
55 | model/roi_layers/__init__.py
56 | model/roi_layers/nms.py
57 | model/roi_layers/roi_align.py
58 | model/roi_layers/roi_pool.py
59 | model/roi_pooling/__init__.py
60 | model/roi_pooling/build.py
61 | model/roi_pooling/_ext/__init__.py
62 | model/roi_pooling/_ext/roi_pooling/__init__.py
63 | model/roi_pooling/functions/__init__.py
64 | model/roi_pooling/functions/roi_pool.py
65 | model/roi_pooling/modules/__init__.py
66 | model/roi_pooling/modules/roi_pool.py
67 | model/rpn/__init__.py
68 | model/rpn/anchor_target_layer.py
69 | model/rpn/bbox_transform.py
70 | model/rpn/generate_anchors.py
71 | model/rpn/proposal_layer.py
72 | model/rpn/proposal_target_layer_cascade.py
73 | model/rpn/rpn.py
74 | model/utils/__init__.py
75 | model/utils/blob.py
76 | model/utils/config.py
77 | model/utils/logger.py
78 | model/utils/net_utils.py
79 | pycocotools/__init__.py
80 | pycocotools/coco.py
81 | pycocotools/cocoeval.py
82 | pycocotools/mask.py
83 | roi_data_layer/__init__.py
84 | roi_data_layer/minibatch.py
85 | roi_data_layer/roibatchLoader.py
86 | roi_data_layer/roidb.py
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_pooling/src/roi_pooling_cuda.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "roi_pooling_kernel.h"
4 |
5 | extern THCState *state;
6 |
7 | int roi_pooling_forward_cuda(int pooled_height, int pooled_width, float spatial_scale,
8 | THCudaTensor * features, THCudaTensor * rois, THCudaTensor * output, THCudaIntTensor * argmax)
9 | {
10 | // Grab the input tensor
11 | float * data_flat = THCudaTensor_data(state, features);
12 | float * rois_flat = THCudaTensor_data(state, rois);
13 |
14 | float * output_flat = THCudaTensor_data(state, output);
15 | int * argmax_flat = THCudaIntTensor_data(state, argmax);
16 |
17 | // Number of ROIs
18 | int num_rois = THCudaTensor_size(state, rois, 0);
19 | int size_rois = THCudaTensor_size(state, rois, 1);
20 | if (size_rois != 5)
21 | {
22 | return 0;
23 | }
24 |
25 | // batch size
26 | // int batch_size = THCudaTensor_size(state, features, 0);
27 | // if (batch_size != 1)
28 | // {
29 | // return 0;
30 | // }
31 | // data height
32 | int data_height = THCudaTensor_size(state, features, 2);
33 | // data width
34 | int data_width = THCudaTensor_size(state, features, 3);
35 | // Number of channels
36 | int num_channels = THCudaTensor_size(state, features, 1);
37 |
38 | cudaStream_t stream = THCState_getCurrentStream(state);
39 |
40 | ROIPoolForwardLaucher(
41 | data_flat, spatial_scale, num_rois, data_height,
42 | data_width, num_channels, pooled_height,
43 | pooled_width, rois_flat,
44 | output_flat, argmax_flat, stream);
45 |
46 | return 1;
47 | }
48 |
49 | int roi_pooling_backward_cuda(int pooled_height, int pooled_width, float spatial_scale,
50 | THCudaTensor * top_grad, THCudaTensor * rois, THCudaTensor * bottom_grad, THCudaIntTensor * argmax)
51 | {
52 | // Grab the input tensor
53 | float * top_grad_flat = THCudaTensor_data(state, top_grad);
54 | float * rois_flat = THCudaTensor_data(state, rois);
55 |
56 | float * bottom_grad_flat = THCudaTensor_data(state, bottom_grad);
57 | int * argmax_flat = THCudaIntTensor_data(state, argmax);
58 |
59 | // Number of ROIs
60 | int num_rois = THCudaTensor_size(state, rois, 0);
61 | int size_rois = THCudaTensor_size(state, rois, 1);
62 | if (size_rois != 5)
63 | {
64 | return 0;
65 | }
66 |
67 | // batch size
68 | int batch_size = THCudaTensor_size(state, bottom_grad, 0);
69 | // if (batch_size != 1)
70 | // {
71 | // return 0;
72 | // }
73 | // data height
74 | int data_height = THCudaTensor_size(state, bottom_grad, 2);
75 | // data width
76 | int data_width = THCudaTensor_size(state, bottom_grad, 3);
77 | // Number of channels
78 | int num_channels = THCudaTensor_size(state, bottom_grad, 1);
79 |
80 | cudaStream_t stream = THCState_getCurrentStream(state);
81 | ROIPoolBackwardLaucher(
82 | top_grad_flat, spatial_scale, batch_size, num_rois, data_height,
83 | data_width, num_channels, pooled_height,
84 | pooled_width, rois_flat,
85 | bottom_grad_flat, argmax_flat, stream);
86 |
87 | return 1;
88 | }
89 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/roi_data_layer/minibatch.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast R-CNN
3 | # Copyright (c) 2015 Microsoft
4 | # Licensed under The MIT License [see LICENSE for details]
5 | # Written by Ross Girshick and Xinlei Chen
6 | # --------------------------------------------------------
7 |
8 | """Compute minibatch blobs for training a Fast R-CNN network."""
9 | from __future__ import absolute_import
10 | from __future__ import division
11 | from __future__ import print_function
12 |
13 | import numpy as np
14 | import numpy.random as npr
15 | from scipy.misc import imread
16 | from model.utils.config import cfg
17 | from model.utils.blob import prep_im_for_blob, im_list_to_blob
18 | import pdb
19 | def get_minibatch(roidb, num_classes):
20 | """Given a roidb, construct a minibatch sampled from it."""
21 | num_images = len(roidb)
22 | # Sample random scales to use for each image in this batch
23 | random_scale_inds = npr.randint(0, high=len(cfg.TRAIN.SCALES),
24 | size=num_images)
25 | assert(cfg.TRAIN.BATCH_SIZE % num_images == 0), \
26 | 'num_images ({}) must divide BATCH_SIZE ({})'. \
27 | format(num_images, cfg.TRAIN.BATCH_SIZE)
28 |
29 | # Get the input image blob, formatted for caffe
30 | im_blob, im_scales = _get_image_blob(roidb, random_scale_inds)
31 |
32 | blobs = {'data': im_blob}
33 |
34 | assert len(im_scales) == 1, "Single batch only"
35 | assert len(roidb) == 1, "Single batch only"
36 |
37 | # gt boxes: (x1, y1, x2, y2, cls)
38 | if cfg.TRAIN.USE_ALL_GT:
39 | # Include all ground truth boxes
40 | gt_inds = np.where(roidb[0]['gt_classes'] != 0)[0]
41 | else:
42 | # For the COCO ground truth boxes, exclude the ones that are ''iscrowd''
43 | gt_inds = np.where((roidb[0]['gt_classes'] != 0) & np.all(roidb[0]['gt_overlaps'].toarray() > -1.0, axis=1))[0]
44 | gt_boxes = np.empty((len(gt_inds), 5), dtype=np.float32)
45 | gt_boxes[:, 0:4] = roidb[0]['boxes'][gt_inds, :] * im_scales[0]
46 | gt_boxes[:, 4] = roidb[0]['gt_classes'][gt_inds]
47 | blobs['gt_boxes'] = gt_boxes
48 | blobs['im_info'] = np.array(
49 | [[im_blob.shape[1], im_blob.shape[2], im_scales[0]]],
50 | dtype=np.float32)
51 |
52 | blobs['img_id'] = roidb[0]['img_id']
53 |
54 | return blobs
55 |
56 | def _get_image_blob(roidb, scale_inds):
57 | """Builds an input blob from the images in the roidb at the specified
58 | scales.
59 | """
60 | num_images = len(roidb)
61 |
62 | processed_ims = []
63 | im_scales = []
64 | for i in range(num_images):
65 | #im = cv2.imread(roidb[i]['image'])
66 | im = imread(roidb[i]['image'])
67 |
68 | if len(im.shape) == 2:
69 | im = im[:,:,np.newaxis]
70 | im = np.concatenate((im,im,im), axis=2)
71 | # flip the channel, since the original one using cv2
72 | # rgb -> bgr
73 | im = im[:,:,::-1]
74 |
75 | if roidb[i]['flipped']:
76 | im = im[:, ::-1, :]
77 | target_size = cfg.TRAIN.SCALES[scale_inds[i]]
78 | im, im_scale = prep_im_for_blob(im, cfg.PIXEL_MEANS, target_size,
79 | cfg.TRAIN.MAX_SIZE)
80 | im_scales.append(im_scale)
81 | processed_ims.append(im)
82 |
83 | # Create a blob to hold the input images
84 | blob = im_list_to_blob(processed_ims)
85 |
86 | return blob, im_scales
87 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/roi_data_layer/minibatch.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast R-CNN
3 | # Copyright (c) 2015 Microsoft
4 | # Licensed under The MIT License [see LICENSE for details]
5 | # Written by Ross Girshick and Xinlei Chen
6 | # --------------------------------------------------------
7 |
8 | """Compute minibatch blobs for training a Fast R-CNN network."""
9 | from __future__ import absolute_import
10 | from __future__ import division
11 | from __future__ import print_function
12 |
13 | import numpy as np
14 | import numpy.random as npr
15 | from scipy.misc import imread
16 | from model.utils.config import cfg
17 | from model.utils.blob import prep_im_for_blob, im_list_to_blob
18 | import pdb
19 | def get_minibatch(roidb, num_classes):
20 | """Given a roidb, construct a minibatch sampled from it."""
21 | num_images = len(roidb)
22 | # Sample random scales to use for each image in this batch
23 | random_scale_inds = npr.randint(0, high=len(cfg.TRAIN.SCALES),
24 | size=num_images)
25 | assert(cfg.TRAIN.BATCH_SIZE % num_images == 0), \
26 | 'num_images ({}) must divide BATCH_SIZE ({})'. \
27 | format(num_images, cfg.TRAIN.BATCH_SIZE)
28 |
29 | # Get the input image blob, formatted for caffe
30 | im_blob, im_scales = _get_image_blob(roidb, random_scale_inds)
31 |
32 | blobs = {'data': im_blob}
33 |
34 | assert len(im_scales) == 1, "Single batch only"
35 | assert len(roidb) == 1, "Single batch only"
36 |
37 | # gt boxes: (x1, y1, x2, y2, cls)
38 | if cfg.TRAIN.USE_ALL_GT:
39 | # Include all ground truth boxes
40 | gt_inds = np.where(roidb[0]['gt_classes'] != 0)[0]
41 | else:
42 | # For the COCO ground truth boxes, exclude the ones that are ''iscrowd''
43 | gt_inds = np.where((roidb[0]['gt_classes'] != 0) & np.all(roidb[0]['gt_overlaps'].toarray() > -1.0, axis=1))[0]
44 | gt_boxes = np.empty((len(gt_inds), 5), dtype=np.float32)
45 | gt_boxes[:, 0:4] = roidb[0]['boxes'][gt_inds, :] * im_scales[0]
46 | gt_boxes[:, 4] = roidb[0]['gt_classes'][gt_inds]
47 | blobs['gt_boxes'] = gt_boxes
48 | blobs['im_info'] = np.array(
49 | [[im_blob.shape[1], im_blob.shape[2], im_scales[0]]],
50 | dtype=np.float32)
51 |
52 | blobs['img_id'] = roidb[0]['img_id']
53 |
54 | return blobs
55 |
56 | def _get_image_blob(roidb, scale_inds):
57 | """Builds an input blob from the images in the roidb at the specified
58 | scales.
59 | """
60 | num_images = len(roidb)
61 |
62 | processed_ims = []
63 | im_scales = []
64 | for i in range(num_images):
65 | #im = cv2.imread(roidb[i]['image'])
66 | im = imread(roidb[i]['image'])
67 |
68 | if len(im.shape) == 2:
69 | im = im[:,:,np.newaxis]
70 | im = np.concatenate((im,im,im), axis=2)
71 | # flip the channel, since the original one using cv2
72 | # rgb -> bgr
73 | im = im[:,:,::-1]
74 |
75 | if roidb[i]['flipped']:
76 | im = im[:, ::-1, :]
77 | target_size = cfg.TRAIN.SCALES[scale_inds[i]]
78 | im, im_scale = prep_im_for_blob(im, cfg.PIXEL_MEANS, target_size,
79 | cfg.TRAIN.MAX_SIZE)
80 | im_scales.append(im_scale)
81 | processed_ims.append(im)
82 |
83 | # Create a blob to hold the input images
84 | blob = im_list_to_blob(processed_ims)
85 |
86 | return blob, im_scales
87 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/rpn/generate_anchors.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | # --------------------------------------------------------
3 | # Faster R-CNN
4 | # Copyright (c) 2015 Microsoft
5 | # Licensed under The MIT License [see LICENSE for details]
6 | # Written by Ross Girshick and Sean Bell
7 | # --------------------------------------------------------
8 |
9 | import numpy as np
10 | import pdb
11 |
12 | # Verify that we compute the same anchors as Shaoqing's matlab implementation:
13 | #
14 | # >> load output/rpn_cachedir/faster_rcnn_VOC2007_ZF_stage1_rpn/anchors.mat
15 | # >> anchors
16 | #
17 | # anchors =
18 | #
19 | # -83 -39 100 56
20 | # -175 -87 192 104
21 | # -359 -183 376 200
22 | # -55 -55 72 72
23 | # -119 -119 136 136
24 | # -247 -247 264 264
25 | # -35 -79 52 96
26 | # -79 -167 96 184
27 | # -167 -343 184 360
28 |
29 | #array([[ -83., -39., 100., 56.],
30 | # [-175., -87., 192., 104.],
31 | # [-359., -183., 376., 200.],
32 | # [ -55., -55., 72., 72.],
33 | # [-119., -119., 136., 136.],
34 | # [-247., -247., 264., 264.],
35 | # [ -35., -79., 52., 96.],
36 | # [ -79., -167., 96., 184.],
37 | # [-167., -343., 184., 360.]])
38 |
39 | try:
40 | xrange # Python 2
41 | except NameError:
42 | xrange = range # Python 3
43 |
44 |
45 | def generate_anchors(base_size=16, ratios=[0.5, 1, 2],
46 | scales=2**np.arange(3, 6)):
47 | """
48 | Generate anchor (reference) windows by enumerating aspect ratios X
49 | scales wrt a reference (0, 0, 15, 15) window.
50 | """
51 |
52 | base_anchor = np.array([1, 1, base_size, base_size]) - 1
53 | ratio_anchors = _ratio_enum(base_anchor, ratios)
54 | anchors = np.vstack([_scale_enum(ratio_anchors[i, :], scales)
55 | for i in xrange(ratio_anchors.shape[0])])
56 | return anchors
57 |
58 | def _whctrs(anchor):
59 | """
60 | Return width, height, x center, and y center for an anchor (window).
61 | """
62 |
63 | w = anchor[2] - anchor[0] + 1
64 | h = anchor[3] - anchor[1] + 1
65 | x_ctr = anchor[0] + 0.5 * (w - 1)
66 | y_ctr = anchor[1] + 0.5 * (h - 1)
67 | return w, h, x_ctr, y_ctr
68 |
69 | def _mkanchors(ws, hs, x_ctr, y_ctr):
70 | """
71 | Given a vector of widths (ws) and heights (hs) around a center
72 | (x_ctr, y_ctr), output a set of anchors (windows).
73 | """
74 |
75 | ws = ws[:, np.newaxis]
76 | hs = hs[:, np.newaxis]
77 | anchors = np.hstack((x_ctr - 0.5 * (ws - 1),
78 | y_ctr - 0.5 * (hs - 1),
79 | x_ctr + 0.5 * (ws - 1),
80 | y_ctr + 0.5 * (hs - 1)))
81 | return anchors
82 |
83 | def _ratio_enum(anchor, ratios):
84 | """
85 | Enumerate a set of anchors for each aspect ratio wrt an anchor.
86 | """
87 |
88 | w, h, x_ctr, y_ctr = _whctrs(anchor)
89 | size = w * h
90 | size_ratios = size / ratios
91 | ws = np.round(np.sqrt(size_ratios))
92 | hs = np.round(ws * ratios)
93 | anchors = _mkanchors(ws, hs, x_ctr, y_ctr)
94 | return anchors
95 |
96 | def _scale_enum(anchor, scales):
97 | """
98 | Enumerate a set of anchors for each scale wrt an anchor.
99 | """
100 |
101 | w, h, x_ctr, y_ctr = _whctrs(anchor)
102 | ws = w * scales
103 | hs = h * scales
104 | anchors = _mkanchors(ws, hs, x_ctr, y_ctr)
105 | return anchors
106 |
107 | if __name__ == '__main__':
108 | import time
109 | t = time.time()
110 | a = generate_anchors()
111 | print(time.time() - t)
112 | print(a)
113 | from IPython import embed; embed()
114 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/model/rpn/generate_anchors.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | # --------------------------------------------------------
3 | # Faster R-CNN
4 | # Copyright (c) 2015 Microsoft
5 | # Licensed under The MIT License [see LICENSE for details]
6 | # Written by Ross Girshick and Sean Bell
7 | # --------------------------------------------------------
8 |
9 | import numpy as np
10 | import pdb
11 |
12 | # Verify that we compute the same anchors as Shaoqing's matlab implementation:
13 | #
14 | # >> load output/rpn_cachedir/faster_rcnn_VOC2007_ZF_stage1_rpn/anchors.mat
15 | # >> anchors
16 | #
17 | # anchors =
18 | #
19 | # -83 -39 100 56
20 | # -175 -87 192 104
21 | # -359 -183 376 200
22 | # -55 -55 72 72
23 | # -119 -119 136 136
24 | # -247 -247 264 264
25 | # -35 -79 52 96
26 | # -79 -167 96 184
27 | # -167 -343 184 360
28 |
29 | #array([[ -83., -39., 100., 56.],
30 | # [-175., -87., 192., 104.],
31 | # [-359., -183., 376., 200.],
32 | # [ -55., -55., 72., 72.],
33 | # [-119., -119., 136., 136.],
34 | # [-247., -247., 264., 264.],
35 | # [ -35., -79., 52., 96.],
36 | # [ -79., -167., 96., 184.],
37 | # [-167., -343., 184., 360.]])
38 |
39 | try:
40 | xrange # Python 2
41 | except NameError:
42 | xrange = range # Python 3
43 |
44 |
45 | def generate_anchors(base_size=16, ratios=[0.5, 1, 2],
46 | scales=2**np.arange(3, 6)):
47 | """
48 | Generate anchor (reference) windows by enumerating aspect ratios X
49 | scales wrt a reference (0, 0, 15, 15) window.
50 | """
51 |
52 | base_anchor = np.array([1, 1, base_size, base_size]) - 1
53 | ratio_anchors = _ratio_enum(base_anchor, ratios)
54 | anchors = np.vstack([_scale_enum(ratio_anchors[i, :], scales)
55 | for i in xrange(ratio_anchors.shape[0])])
56 | return anchors
57 |
58 | def _whctrs(anchor):
59 | """
60 | Return width, height, x center, and y center for an anchor (window).
61 | """
62 |
63 | w = anchor[2] - anchor[0] + 1
64 | h = anchor[3] - anchor[1] + 1
65 | x_ctr = anchor[0] + 0.5 * (w - 1)
66 | y_ctr = anchor[1] + 0.5 * (h - 1)
67 | return w, h, x_ctr, y_ctr
68 |
69 | def _mkanchors(ws, hs, x_ctr, y_ctr):
70 | """
71 | Given a vector of widths (ws) and heights (hs) around a center
72 | (x_ctr, y_ctr), output a set of anchors (windows).
73 | """
74 |
75 | ws = ws[:, np.newaxis]
76 | hs = hs[:, np.newaxis]
77 | anchors = np.hstack((x_ctr - 0.5 * (ws - 1),
78 | y_ctr - 0.5 * (hs - 1),
79 | x_ctr + 0.5 * (ws - 1),
80 | y_ctr + 0.5 * (hs - 1)))
81 | return anchors
82 |
83 | def _ratio_enum(anchor, ratios):
84 | """
85 | Enumerate a set of anchors for each aspect ratio wrt an anchor.
86 | """
87 |
88 | w, h, x_ctr, y_ctr = _whctrs(anchor)
89 | size = w * h
90 | size_ratios = size / ratios
91 | ws = np.round(np.sqrt(size_ratios))
92 | hs = np.round(ws * ratios)
93 | anchors = _mkanchors(ws, hs, x_ctr, y_ctr)
94 | return anchors
95 |
96 | def _scale_enum(anchor, scales):
97 | """
98 | Enumerate a set of anchors for each scale wrt an anchor.
99 | """
100 |
101 | w, h, x_ctr, y_ctr = _whctrs(anchor)
102 | ws = w * scales
103 | hs = h * scales
104 | anchors = _mkanchors(ws, hs, x_ctr, y_ctr)
105 | return anchors
106 |
107 | if __name__ == '__main__':
108 | import time
109 | t = time.time()
110 | a = generate_anchors()
111 | print(time.time() - t)
112 | print(a)
113 | from IPython import embed; embed()
114 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/utils/bbox.pyx:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast R-CNN
3 | # Copyright (c) 2015 Microsoft
4 | # Licensed under The MIT License [see LICENSE for details]
5 | # Written by Sergey Karayev
6 | # --------------------------------------------------------
7 |
8 | cimport cython
9 | import numpy as np
10 | cimport numpy as np
11 |
12 | DTYPE = np.float
13 | ctypedef np.float_t DTYPE_t
14 |
15 | def bbox_overlaps(np.ndarray[DTYPE_t, ndim=2] boxes,
16 | np.ndarray[DTYPE_t, ndim=2] query_boxes):
17 | return bbox_overlaps_c(boxes, query_boxes)
18 |
19 | cdef np.ndarray[DTYPE_t, ndim=2] bbox_overlaps_c(
20 | np.ndarray[DTYPE_t, ndim=2] boxes,
21 | np.ndarray[DTYPE_t, ndim=2] query_boxes):
22 | """
23 | Parameters
24 | ----------
25 | boxes: (N, 4) ndarray of float
26 | query_boxes: (K, 4) ndarray of float
27 | Returns
28 | -------
29 | overlaps: (N, K) ndarray of overlap between boxes and query_boxes
30 | """
31 | cdef unsigned int N = boxes.shape[0]
32 | cdef unsigned int K = query_boxes.shape[0]
33 | cdef np.ndarray[DTYPE_t, ndim=2] overlaps = np.zeros((N, K), dtype=DTYPE)
34 | cdef DTYPE_t iw, ih, box_area
35 | cdef DTYPE_t ua
36 | cdef unsigned int k, n
37 | for k in range(K):
38 | box_area = (
39 | (query_boxes[k, 2] - query_boxes[k, 0] + 1) *
40 | (query_boxes[k, 3] - query_boxes[k, 1] + 1)
41 | )
42 | for n in range(N):
43 | iw = (
44 | min(boxes[n, 2], query_boxes[k, 2]) -
45 | max(boxes[n, 0], query_boxes[k, 0]) + 1
46 | )
47 | if iw > 0:
48 | ih = (
49 | min(boxes[n, 3], query_boxes[k, 3]) -
50 | max(boxes[n, 1], query_boxes[k, 1]) + 1
51 | )
52 | if ih > 0:
53 | ua = float(
54 | (boxes[n, 2] - boxes[n, 0] + 1) *
55 | (boxes[n, 3] - boxes[n, 1] + 1) +
56 | box_area - iw * ih
57 | )
58 | overlaps[n, k] = iw * ih / ua
59 | return overlaps
60 |
61 |
62 | def bbox_intersections(
63 | np.ndarray[DTYPE_t, ndim=2] boxes,
64 | np.ndarray[DTYPE_t, ndim=2] query_boxes):
65 | return bbox_intersections_c(boxes, query_boxes)
66 |
67 |
68 | cdef np.ndarray[DTYPE_t, ndim=2] bbox_intersections_c(
69 | np.ndarray[DTYPE_t, ndim=2] boxes,
70 | np.ndarray[DTYPE_t, ndim=2] query_boxes):
71 | """
72 | For each query box compute the intersection ratio covered by boxes
73 | ----------
74 | Parameters
75 | ----------
76 | boxes: (N, 4) ndarray of float
77 | query_boxes: (K, 4) ndarray of float
78 | Returns
79 | -------
80 | overlaps: (N, K) ndarray of intersec between boxes and query_boxes
81 | """
82 | cdef unsigned int N = boxes.shape[0]
83 | cdef unsigned int K = query_boxes.shape[0]
84 | cdef np.ndarray[DTYPE_t, ndim=2] intersec = np.zeros((N, K), dtype=DTYPE)
85 | cdef DTYPE_t iw, ih, box_area
86 | cdef DTYPE_t ua
87 | cdef unsigned int k, n
88 | for k in range(K):
89 | box_area = (
90 | (query_boxes[k, 2] - query_boxes[k, 0] + 1) *
91 | (query_boxes[k, 3] - query_boxes[k, 1] + 1)
92 | )
93 | for n in range(N):
94 | iw = (
95 | min(boxes[n, 2], query_boxes[k, 2]) -
96 | max(boxes[n, 0], query_boxes[k, 0]) + 1
97 | )
98 | if iw > 0:
99 | ih = (
100 | min(boxes[n, 3], query_boxes[k, 3]) -
101 | max(boxes[n, 1], query_boxes[k, 1]) + 1
102 | )
103 | if ih > 0:
104 | intersec[n, k] = iw * ih / box_area
105 | return intersec
--------------------------------------------------------------------------------
/test.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | np.set_printoptions(precision=4)
3 | import copy
4 | import torch
5 |
6 | from dataloader.action_genome import AG, cuda_collate_fn
7 |
8 | from lib.config import Config
9 | from lib.evaluation_recall import BasicSceneGraphEvaluator
10 | from lib.object_detector import detector
11 | from lib.sttran import STTran
12 |
13 | conf = Config()
14 | for i in conf.args:
15 | print(i,':', conf.args[i])
16 |
17 | AG_dataset = AG(mode="test", datasize=conf.datasize, data_path=conf.data_path, filter_nonperson_box_frame=True,
18 | filter_small_box=False if conf.mode == 'predcls' else True)
19 | dataloader = torch.utils.data.DataLoader(AG_dataset, shuffle=False, num_workers=0, collate_fn=cuda_collate_fn)
20 |
21 | gpu_device = torch.device('cuda:0')
22 | object_detector = detector(train=False, object_classes=AG_dataset.object_classes, use_SUPPLY=True, mode=conf.mode).to(device=gpu_device)
23 | object_detector.eval()
24 |
25 |
26 | model = STTran(mode=conf.mode,
27 | attention_class_num=len(AG_dataset.attention_relationships),
28 | spatial_class_num=len(AG_dataset.spatial_relationships),
29 | contact_class_num=len(AG_dataset.contacting_relationships),
30 | obj_classes=AG_dataset.object_classes,
31 | enc_layer_num=conf.enc_layer,
32 | dec_layer_num=conf.dec_layer).to(device=gpu_device)
33 |
34 | model.eval()
35 |
36 | ckpt = torch.load(conf.model_path, map_location=gpu_device)
37 | model.load_state_dict(ckpt['state_dict'], strict=False)
38 | print('*'*50)
39 | print('CKPT {} is loaded'.format(conf.model_path))
40 | #
41 | evaluator1 = BasicSceneGraphEvaluator(
42 | mode=conf.mode,
43 | AG_object_classes=AG_dataset.object_classes,
44 | AG_all_predicates=AG_dataset.relationship_classes,
45 | AG_attention_predicates=AG_dataset.attention_relationships,
46 | AG_spatial_predicates=AG_dataset.spatial_relationships,
47 | AG_contacting_predicates=AG_dataset.contacting_relationships,
48 | iou_threshold=0.5,
49 | constraint='with')
50 |
51 | evaluator2 = BasicSceneGraphEvaluator(
52 | mode=conf.mode,
53 | AG_object_classes=AG_dataset.object_classes,
54 | AG_all_predicates=AG_dataset.relationship_classes,
55 | AG_attention_predicates=AG_dataset.attention_relationships,
56 | AG_spatial_predicates=AG_dataset.spatial_relationships,
57 | AG_contacting_predicates=AG_dataset.contacting_relationships,
58 | iou_threshold=0.5,
59 | constraint='semi', semithreshold=0.9)
60 |
61 | evaluator3 = BasicSceneGraphEvaluator(
62 | mode=conf.mode,
63 | AG_object_classes=AG_dataset.object_classes,
64 | AG_all_predicates=AG_dataset.relationship_classes,
65 | AG_attention_predicates=AG_dataset.attention_relationships,
66 | AG_spatial_predicates=AG_dataset.spatial_relationships,
67 | AG_contacting_predicates=AG_dataset.contacting_relationships,
68 | iou_threshold=0.5,
69 | constraint='no')
70 |
71 | with torch.no_grad():
72 | for b, data in enumerate(dataloader):
73 |
74 | im_data = copy.deepcopy(data[0].cuda(0))
75 | im_info = copy.deepcopy(data[1].cuda(0))
76 | gt_boxes = copy.deepcopy(data[2].cuda(0))
77 | num_boxes = copy.deepcopy(data[3].cuda(0))
78 | gt_annotation = AG_dataset.gt_annotations[data[4]]
79 |
80 | entry = object_detector(im_data, im_info, gt_boxes, num_boxes, gt_annotation, im_all=None)
81 |
82 | pred = model(entry)
83 | evaluator1.evaluate_scene_graph(gt_annotation, dict(pred))
84 | evaluator2.evaluate_scene_graph(gt_annotation, dict(pred))
85 | evaluator3.evaluate_scene_graph(gt_annotation, dict(pred))
86 |
87 |
88 | print('-------------------------with constraint-------------------------------')
89 | evaluator1.print_stats()
90 | print('-------------------------semi constraint-------------------------------')
91 | evaluator2.print_stats()
92 | print('-------------------------no constraint-------------------------------')
93 | evaluator3.print_stats()
94 |
--------------------------------------------------------------------------------
/lib/fpn/box_intersections_cpu/bbox.pyx:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------
2 | # Fast R-CNN
3 | # Copyright (c) 2015 Microsoft
4 | # Licensed under The MIT License [see LICENSE for details]
5 | # Written by Sergey Karayev
6 | # --------------------------------------------------------
7 |
8 | cimport cython
9 | import numpy as np
10 | cimport numpy as np
11 |
12 | DTYPE = np.float
13 | ctypedef np.float_t DTYPE_t
14 |
15 | def bbox_overlaps(boxes, query_boxes):
16 | cdef np.ndarray[DTYPE_t, ndim=2] boxes_contig = np.ascontiguousarray(boxes, dtype=DTYPE)
17 | cdef np.ndarray[DTYPE_t, ndim=2] query_contig = np.ascontiguousarray(query_boxes, dtype=DTYPE)
18 |
19 | return bbox_overlaps_c(boxes_contig, query_contig)
20 |
21 | cdef np.ndarray[DTYPE_t, ndim=2] bbox_overlaps_c(
22 | np.ndarray[DTYPE_t, ndim=2] boxes,
23 | np.ndarray[DTYPE_t, ndim=2] query_boxes):
24 | """
25 | Parameters
26 | ----------
27 | boxes: (N, 4) ndarray of float
28 | query_boxes: (K, 4) ndarray of float
29 | Returns
30 | -------
31 | overlaps: (N, K) ndarray of overlap between boxes and query_boxes
32 | """
33 | cdef unsigned int N = boxes.shape[0]
34 | cdef unsigned int K = query_boxes.shape[0]
35 | cdef np.ndarray[DTYPE_t, ndim=2] overlaps = np.zeros((N, K), dtype=DTYPE)
36 | cdef DTYPE_t iw, ih, box_area
37 | cdef DTYPE_t ua
38 | cdef unsigned int k, n
39 | for k in range(K):
40 | box_area = (
41 | (query_boxes[k, 2] - query_boxes[k, 0] + 1) *
42 | (query_boxes[k, 3] - query_boxes[k, 1] + 1)
43 | )
44 | for n in range(N):
45 | iw = (
46 | min(boxes[n, 2], query_boxes[k, 2]) -
47 | max(boxes[n, 0], query_boxes[k, 0]) + 1
48 | )
49 | if iw > 0:
50 | ih = (
51 | min(boxes[n, 3], query_boxes[k, 3]) -
52 | max(boxes[n, 1], query_boxes[k, 1]) + 1
53 | )
54 | if ih > 0:
55 | ua = float(
56 | (boxes[n, 2] - boxes[n, 0] + 1) *
57 | (boxes[n, 3] - boxes[n, 1] + 1) +
58 | box_area - iw * ih
59 | )
60 | overlaps[n, k] = iw * ih / ua
61 | return overlaps
62 |
63 |
64 | def bbox_intersections(boxes, query_boxes):
65 | cdef np.ndarray[DTYPE_t, ndim=2] boxes_contig = np.ascontiguousarray(boxes, dtype=DTYPE)
66 | cdef np.ndarray[DTYPE_t, ndim=2] query_contig = np.ascontiguousarray(query_boxes, dtype=DTYPE)
67 |
68 | return bbox_intersections_c(boxes_contig, query_contig)
69 |
70 |
71 | cdef np.ndarray[DTYPE_t, ndim=2] bbox_intersections_c(
72 | np.ndarray[DTYPE_t, ndim=2] boxes,
73 | np.ndarray[DTYPE_t, ndim=2] query_boxes):
74 | """
75 | For each query box compute the intersection ratio covered by boxes
76 | ----------
77 | Parameters
78 | ----------
79 | boxes: (N, 4) ndarray of float
80 | query_boxes: (K, 4) ndarray of float
81 | Returns
82 | -------
83 | overlaps: (N, K) ndarray of intersec between boxes and query_boxes
84 | """
85 | cdef unsigned int N = boxes.shape[0]
86 | cdef unsigned int K = query_boxes.shape[0]
87 | cdef np.ndarray[DTYPE_t, ndim=2] intersec = np.zeros((N, K), dtype=DTYPE)
88 | cdef DTYPE_t iw, ih, box_area
89 | cdef DTYPE_t ua
90 | cdef unsigned int k, n
91 | for k in range(K):
92 | box_area = (
93 | (query_boxes[k, 2] - query_boxes[k, 0] + 1) *
94 | (query_boxes[k, 3] - query_boxes[k, 1] + 1)
95 | )
96 | for n in range(N):
97 | iw = (
98 | min(boxes[n, 2], query_boxes[k, 2]) -
99 | max(boxes[n, 0], query_boxes[k, 0]) + 1
100 | )
101 | if iw > 0:
102 | ih = (
103 | min(boxes[n, 3], query_boxes[k, 3]) -
104 | max(boxes[n, 1], query_boxes[k, 1]) + 1
105 | )
106 | if ih > 0:
107 | intersec[n, k] = iw * ih / box_area
108 | return intersec
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Spatial-Temporal Transformer for Dynamic Scene Graph Generation
2 | Pytorch Implementation of our paper [Spatial-Temporal Transformer for Dynamic Scene Graph Generation](https://arxiv.org/abs/2107.12309) accepted by **ICCV2021**. We propose a Transformer-based model **STTran** to generate dynamic scene graphs of the given video. **STTran** can detect the visual relationships in each frame.
3 |
4 | **The introduction video is available now:** [https://youtu.be/gKpnRU8btLg](https://youtu.be/6D3ExjQpbjQ)
5 |
6 | 
7 |
8 | **About the code**
9 | We run the code on a single RTX2080ti for both training and testing. We borrowed some code from [Yang's repository](https://github.com/jwyang/faster-rcnn.pytorch) and [Zellers' repository](https://github.com/rowanz/neural-motifs).
10 |
11 | ## Requirements
12 | - python=3.6
13 | - pytorch=1.1
14 | - scipy=1.1.0
15 | - cypthon
16 | - dill
17 | - easydict
18 | - h5py
19 | - opencv
20 | - pandas
21 | - tqdm
22 | - yaml
23 |
24 | ## Usage
25 | We use python=3.6, pytorch=1.1 and torchvision=0.3 in our code. First, clone the repository:
26 | ```
27 | git clone https://github.com/yrcong/STTran.git
28 | ```
29 | We borrow some compiled code for bbox operations.
30 | ```
31 | cd lib/draw_rectangles
32 | python setup.py build_ext --inplace
33 | cd ..
34 | cd fpn/box_intersections_cpu
35 | python setup.py build_ext --inplace
36 | ```
37 | For the object detector part, please follow the compilation from https://github.com/jwyang/faster-rcnn.pytorch
38 | We provide a pretrained FasterRCNN model for Action Genome. Please download [here](https://drive.google.com/file/d/1-u930Pk0JYz3ivS6V_HNTM1D5AxmN5Bs/view?usp=sharing) and put it in
39 | ```
40 | fasterRCNN/models/faster_rcnn_ag.pth
41 | ```
42 |
43 | ## Dataset
44 | We use the dataset [Action Genome](https://www.actiongenome.org/#download) to train/evaluate our method. Please process the downloaded dataset with the [Toolkit](https://github.com/JingweiJ/ActionGenome). The directories of the dataset should look like:
45 | ```
46 | |-- action_genome
47 | |-- annotations #gt annotations
48 | |-- frames #sampled frames
49 | |-- videos #original videos
50 | ```
51 | In the experiments for SGCLS/SGDET, we only keep bounding boxes with short edges larger than 16 pixels. Please download the file [object_bbox_and_relationship_filtersmall.pkl](https://drive.google.com/file/d/19BkAwjCw5ByyGyZjFo174Oc3Ud56fkaT/view?usp=sharing) and put it in the ```dataloader```
52 |
53 | ## Train
54 | You can train the **STTran** with train.py. We trained the model on a RTX 2080ti:
55 | + For PredCLS:
56 | ```
57 | python train.py -mode predcls -datasize large -data_path $DATAPATH
58 | ```
59 | + For SGCLS:
60 | ```
61 | python train.py -mode sgcls -datasize large -data_path $DATAPATH
62 | ```
63 | + For SGDET:
64 | ```
65 | python train.py -mode sgdet -datasize large -data_path $DATAPATH
66 | ```
67 |
68 | ## Evaluation
69 | You can evaluate the **STTran** with test.py.
70 | + For PredCLS ([trained Model](https://drive.google.com/file/d/1Sk5qFLWTZmwr63fHpy_C7oIxZSQU16vU/view?usp=sharing)):
71 | ```
72 | python test.py -m predcls -datasize large -data_path $DATAPATH -model_path $MODELPATH
73 | ```
74 | + For SGCLS ([trained Model](https://drive.google.com/file/d/1ZbJ7JkTEVM9mCI-9e5bCo6uDlKbWttgH/view?usp=sharing)): :
75 | ```
76 | python test.py -m sgcls -datasize large -data_path $DATAPATH -model_path $MODELPATH
77 | ```
78 | + For SGDET ([trained Model](https://drive.google.com/file/d/1dBE90bQaXB-xogRdyAJa2A5S8RwYvjPp/view?usp=sharing)): :
79 | ```
80 | python test.py -m sgdet -datasize large -data_path $DATAPATH -model_path $MODELPATH
81 | ```
82 |
83 | ## Citation
84 | If our work is helpful for your research, please cite our publication:
85 | ```
86 | @inproceedings{cong2021spatial,
87 | title={Spatial-Temporal Transformer for Dynamic Scene Graph Generation},
88 | author={Cong, Yuren and Liao, Wentong and Ackermann, Hanno and Rosenhahn, Bodo and Yang, Michael Ying},
89 | booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
90 | pages={16372--16382},
91 | year={2021}
92 | }
93 | ```
94 | ## Help
95 | When you have any question/idea about the code/paper. Please comment in Github or send us Email. We will reply as soon as possible.
96 |
--------------------------------------------------------------------------------
/fasterRCNN/lib/pycocotools/mask.py:
--------------------------------------------------------------------------------
1 | __author__ = 'tsungyi'
2 |
3 | from . import _mask
4 |
5 | # Interface for manipulating masks stored in RLE format.
6 | #
7 | # RLE is a simple yet efficient format for storing binary masks. RLE
8 | # first divides a vector (or vectorized image) into a series of piecewise
9 | # constant regions and then for each piece simply stores the length of
10 | # that piece. For example, given M=[0 0 1 1 1 0 1] the RLE counts would
11 | # be [2 3 1 1], or for M=[1 1 1 1 1 1 0] the counts would be [0 6 1]
12 | # (note that the odd counts are always the numbers of zeros). Instead of
13 | # storing the counts directly, additional compression is achieved with a
14 | # variable bitrate representation based on a common scheme called LEB128.
15 | #
16 | # Compression is greatest given large piecewise constant regions.
17 | # Specifically, the size of the RLE is proportional to the number of
18 | # *boundaries* in M (or for an image the number of boundaries in the y
19 | # direction). Assuming fairly simple shapes, the RLE representation is
20 | # O(sqrt(n)) where n is number of pixels in the object. Hence space usage
21 | # is substantially lower, especially for large simple objects (large n).
22 | #
23 | # Many common operations on masks can be computed directly using the RLE
24 | # (without need for decoding). This includes computations such as area,
25 | # union, intersection, etc. All of these operations are linear in the
26 | # size of the RLE, in other words they are O(sqrt(n)) where n is the area
27 | # of the object. Computing these operations on the original mask is O(n).
28 | # Thus, using the RLE can result in substantial computational savings.
29 | #
30 | # The following API functions are defined:
31 | # encode - Encode binary masks using RLE.
32 | # decode - Decode binary masks encoded via RLE.
33 | # merge - Compute union or intersection of encoded masks.
34 | # iou - Compute intersection over union between masks.
35 | # area - Compute area of encoded masks.
36 | # toBbox - Get bounding boxes surrounding encoded masks.
37 | # frPyObjects - Convert polygon, bbox, and uncompressed RLE to encoded RLE mask.
38 | #
39 | # Usage:
40 | # Rs = encode( masks )
41 | # masks = decode( Rs )
42 | # R = merge( Rs, intersect=false )
43 | # o = iou( dt, gt, iscrowd )
44 | # a = area( Rs )
45 | # bbs = toBbox( Rs )
46 | # Rs = frPyObjects( [pyObjects], h, w )
47 | #
48 | # In the API the following formats are used:
49 | # Rs - [dict] Run-length encoding of binary masks
50 | # R - dict Run-length encoding of binary mask
51 | # masks - [hxwxn] Binary mask(s) (must have type np.ndarray(dtype=uint8) in column-major order)
52 | # iscrowd - [nx1] list of np.ndarray. 1 indicates corresponding gt image has crowd region to ignore
53 | # bbs - [nx4] Bounding box(es) stored as [x y w h]
54 | # poly - Polygon stored as [[x1 y1 x2 y2...],[x1 y1 ...],...] (2D list)
55 | # dt,gt - May be either bounding boxes or encoded masks
56 | # Both poly and bbs are 0-indexed (bbox=[0 0 1 1] encloses first pixel).
57 | #
58 | # Finally, a note about the intersection over union (iou) computation.
59 | # The standard iou of a ground truth (gt) and detected (dt) object is
60 | # iou(gt,dt) = area(intersect(gt,dt)) / area(union(gt,dt))
61 | # For "crowd" regions, we use a modified criteria. If a gt object is
62 | # marked as "iscrowd", we allow a dt to match any subregion of the gt.
63 | # Choosing gt' in the crowd gt that best matches the dt can be done using
64 | # gt'=intersect(dt,gt). Since by definition union(gt',dt)=dt, computing
65 | # iou(gt,dt,iscrowd) = iou(gt',dt) = area(intersect(gt,dt)) / area(dt)
66 | # For crowd gt regions we use this modified criteria above for the iou.
67 | #
68 | # To compile run "python setup.py build_ext --inplace"
69 | # Please do not contact us for help with compiling.
70 | #
71 | # Microsoft COCO Toolbox. version 2.0
72 | # Data, paper, and tutorials available at: http://mscoco.org/
73 | # Code written by Piotr Dollar and Tsung-Yi Lin, 2015.
74 | # Licensed under the Simplified BSD License [see coco/license.txt]
75 |
76 | encode = _mask.encode
77 | decode = _mask.decode
78 | iou = _mask.iou
79 | merge = _mask.merge
80 | area = _mask.area
81 | toBbox = _mask.toBbox
82 | frPyObjects = _mask.frPyObjects
--------------------------------------------------------------------------------
/fasterRCNN/lib/build/lib.linux-x86_64-3.6/pycocotools/mask.py:
--------------------------------------------------------------------------------
1 | __author__ = 'tsungyi'
2 |
3 | from . import _mask
4 |
5 | # Interface for manipulating masks stored in RLE format.
6 | #
7 | # RLE is a simple yet efficient format for storing binary masks. RLE
8 | # first divides a vector (or vectorized image) into a series of piecewise
9 | # constant regions and then for each piece simply stores the length of
10 | # that piece. For example, given M=[0 0 1 1 1 0 1] the RLE counts would
11 | # be [2 3 1 1], or for M=[1 1 1 1 1 1 0] the counts would be [0 6 1]
12 | # (note that the odd counts are always the numbers of zeros). Instead of
13 | # storing the counts directly, additional compression is achieved with a
14 | # variable bitrate representation based on a common scheme called LEB128.
15 | #
16 | # Compression is greatest given large piecewise constant regions.
17 | # Specifically, the size of the RLE is proportional to the number of
18 | # *boundaries* in M (or for an image the number of boundaries in the y
19 | # direction). Assuming fairly simple shapes, the RLE representation is
20 | # O(sqrt(n)) where n is number of pixels in the object. Hence space usage
21 | # is substantially lower, especially for large simple objects (large n).
22 | #
23 | # Many common operations on masks can be computed directly using the RLE
24 | # (without need for decoding). This includes computations such as area,
25 | # union, intersection, etc. All of these operations are linear in the
26 | # size of the RLE, in other words they are O(sqrt(n)) where n is the area
27 | # of the object. Computing these operations on the original mask is O(n).
28 | # Thus, using the RLE can result in substantial computational savings.
29 | #
30 | # The following API functions are defined:
31 | # encode - Encode binary masks using RLE.
32 | # decode - Decode binary masks encoded via RLE.
33 | # merge - Compute union or intersection of encoded masks.
34 | # iou - Compute intersection over union between masks.
35 | # area - Compute area of encoded masks.
36 | # toBbox - Get bounding boxes surrounding encoded masks.
37 | # frPyObjects - Convert polygon, bbox, and uncompressed RLE to encoded RLE mask.
38 | #
39 | # Usage:
40 | # Rs = encode( masks )
41 | # masks = decode( Rs )
42 | # R = merge( Rs, intersect=false )
43 | # o = iou( dt, gt, iscrowd )
44 | # a = area( Rs )
45 | # bbs = toBbox( Rs )
46 | # Rs = frPyObjects( [pyObjects], h, w )
47 | #
48 | # In the API the following formats are used:
49 | # Rs - [dict] Run-length encoding of binary masks
50 | # R - dict Run-length encoding of binary mask
51 | # masks - [hxwxn] Binary mask(s) (must have type np.ndarray(dtype=uint8) in column-major order)
52 | # iscrowd - [nx1] list of np.ndarray. 1 indicates corresponding gt image has crowd region to ignore
53 | # bbs - [nx4] Bounding box(es) stored as [x y w h]
54 | # poly - Polygon stored as [[x1 y1 x2 y2...],[x1 y1 ...],...] (2D list)
55 | # dt,gt - May be either bounding boxes or encoded masks
56 | # Both poly and bbs are 0-indexed (bbox=[0 0 1 1] encloses first pixel).
57 | #
58 | # Finally, a note about the intersection over union (iou) computation.
59 | # The standard iou of a ground truth (gt) and detected (dt) object is
60 | # iou(gt,dt) = area(intersect(gt,dt)) / area(union(gt,dt))
61 | # For "crowd" regions, we use a modified criteria. If a gt object is
62 | # marked as "iscrowd", we allow a dt to match any subregion of the gt.
63 | # Choosing gt' in the crowd gt that best matches the dt can be done using
64 | # gt'=intersect(dt,gt). Since by definition union(gt',dt)=dt, computing
65 | # iou(gt,dt,iscrowd) = iou(gt',dt) = area(intersect(gt,dt)) / area(dt)
66 | # For crowd gt regions we use this modified criteria above for the iou.
67 | #
68 | # To compile run "python setup.py build_ext --inplace"
69 | # Please do not contact us for help with compiling.
70 | #
71 | # Microsoft COCO Toolbox. version 2.0
72 | # Data, paper, and tutorials available at: http://mscoco.org/
73 | # Code written by Piotr Dollar and Tsung-Yi Lin, 2015.
74 | # Licensed under the Simplified BSD License [see coco/license.txt]
75 |
76 | encode = _mask.encode
77 | decode = _mask.decode
78 | iou = _mask.iou
79 | merge = _mask.merge
80 | area = _mask.area
81 | toBbox = _mask.toBbox
82 | frPyObjects = _mask.frPyObjects
--------------------------------------------------------------------------------
/fasterRCNN/lib/model/roi_pooling/src/roi_pooling.c:
--------------------------------------------------------------------------------
1 | #include |
2 | #include
3 |
4 | int roi_pooling_forward(int pooled_height, int pooled_width, float spatial_scale,
5 | THFloatTensor * features, THFloatTensor * rois, THFloatTensor * output)
6 | {
7 | // Grab the input tensor
8 | float * data_flat = THFloatTensor_data(features);
9 | float * rois_flat = THFloatTensor_data(rois);
10 |
11 | float * output_flat = THFloatTensor_data(output);
12 |
13 | // Number of ROIs
14 | int num_rois = THFloatTensor_size(rois, 0);
15 | int size_rois = THFloatTensor_size(rois, 1);
16 | // batch size
17 | int batch_size = THFloatTensor_size(features, 0);
18 | if(batch_size != 1)
19 | {
20 | return 0;
21 | }
22 | // data height
23 | int data_height = THFloatTensor_size(features, 1);
24 | // data width
25 | int data_width = THFloatTensor_size(features, 2);
26 | // Number of channels
27 | int num_channels = THFloatTensor_size(features, 3);
28 |
29 | // Set all element of the output tensor to -inf.
30 | THFloatStorage_fill(THFloatTensor_storage(output), -1);
31 |
32 | // For each ROI R = [batch_index x1 y1 x2 y2]: max pool over R
33 | int index_roi = 0;
34 | int index_output = 0;
35 | int n;
36 | for (n = 0; n < num_rois; ++n)
37 | {
38 | int roi_batch_ind = rois_flat[index_roi + 0];
39 | int roi_start_w = round(rois_flat[index_roi + 1] * spatial_scale);
40 | int roi_start_h = round(rois_flat[index_roi + 2] * spatial_scale);
41 | int roi_end_w = round(rois_flat[index_roi + 3] * spatial_scale);
42 | int roi_end_h = round(rois_flat[index_roi + 4] * spatial_scale);
43 | // CHECK_GE(roi_batch_ind, 0);
44 | // CHECK_LT(roi_batch_ind, batch_size);
45 |
46 | int roi_height = fmaxf(roi_end_h - roi_start_h + 1, 1);
47 | int roi_width = fmaxf(roi_end_w - roi_start_w + 1, 1);
48 | float bin_size_h = (float)(roi_height) / (float)(pooled_height);
49 | float bin_size_w = (float)(roi_width) / (float)(pooled_width);
50 |
51 | int index_data = roi_batch_ind * data_height * data_width * num_channels;
52 | const int output_area = pooled_width * pooled_height;
53 |
54 | int c, ph, pw;
55 | for (ph = 0; ph < pooled_height; ++ph)
56 | {
57 | for (pw = 0; pw < pooled_width; ++pw)
58 | {
59 | int hstart = (floor((float)(ph) * bin_size_h));
60 | int wstart = (floor((float)(pw) * bin_size_w));
61 | int hend = (ceil((float)(ph + 1) * bin_size_h));
62 | int wend = (ceil((float)(pw + 1) * bin_size_w));
63 |
64 | hstart = fminf(fmaxf(hstart + roi_start_h, 0), data_height);
65 | hend = fminf(fmaxf(hend + roi_start_h, 0), data_height);
66 | wstart = fminf(fmaxf(wstart + roi_start_w, 0), data_width);
67 | wend = fminf(fmaxf(wend + roi_start_w, 0), data_width);
68 |
69 | const int pool_index = index_output + (ph * pooled_width + pw);
70 | int is_empty = (hend <= hstart) || (wend <= wstart);
71 | if (is_empty)
72 | {
73 | for (c = 0; c < num_channels * output_area; c += output_area)
74 | {
75 | output_flat[pool_index + c] = 0;
76 | }
77 | }
78 | else
79 | {
80 | int h, w, c;
81 | for (h = hstart; h < hend; ++h)
82 | {
83 | for (w = wstart; w < wend; ++w)
84 | {
85 | for (c = 0; c < num_channels; ++c)
86 | {
87 | const int index = (h * data_width + w) * num_channels + c;
88 | if (data_flat[index_data + index] > output_flat[pool_index + c * output_area])
89 | {
90 | output_flat[pool_index + c * output_area] = data_flat[index_data + index];
91 | }
92 | }
93 | }
94 | }
95 | }
96 | }
97 | }
98 |
99 | // Increment ROI index
100 | index_roi += size_rois;
101 | index_output += pooled_height * pooled_width * num_channels;
102 | }
103 | return 1;
104 | }
--------------------------------------------------------------------------------
/fasterRCNN/lib/datasets/vg_eval.py:
--------------------------------------------------------------------------------
1 | from __future__ import absolute_import
2 | # --------------------------------------------------------
3 | # Fast/er R-CNN
4 | # Licensed under The MIT License [see LICENSE for details]
5 | # Written by Bharath Hariharan
6 | # --------------------------------------------------------
7 |
8 | import xml.etree.ElementTree as ET
9 | import os
10 | import numpy as np
11 | from .voc_eval import voc_ap
12 |
13 | def vg_eval( detpath,
14 | gt_roidb,
15 | image_index,
16 | classindex,
17 | ovthresh=0.5,
18 | use_07_metric=False,
19 | eval_attributes=False):
20 | """rec, prec, ap, sorted_scores, npos = voc_eval(
21 | detpath,
22 | gt_roidb,
23 | image_index,
24 | classindex,
25 | [ovthresh],
26 | [use_07_metric])
27 |
28 | Top level function that does the Visual Genome evaluation.
29 |
30 | detpath: Path to detections
31 | gt_roidb: List of ground truth structs.
32 | image_index: List of image ids.
33 | classindex: Category index
34 | [ovthresh]: Overlap threshold (default = 0.5)
35 | [use_07_metric]: Whether to use VOC07's 11 point AP computation
36 | (default False)
37 | """
38 | # extract gt objects for this class
39 | class_recs = {}
40 | npos = 0
41 | for item,imagename in zip(gt_roidb,image_index):
42 | if eval_attributes:
43 | bbox = item['boxes'][np.where(np.any(item['gt_attributes'].toarray() == classindex, axis=1))[0], :]
44 | else:
45 | bbox = item['boxes'][np.where(item['gt_classes'] == classindex)[0], :]
46 | difficult = np.zeros((bbox.shape[0],)).astype(np.bool)
47 | det = [False] * bbox.shape[0]
48 | npos = npos + sum(~difficult)
49 | class_recs[str(imagename)] = {'bbox': bbox,
50 | 'difficult': difficult,
51 | 'det': det}
52 | if npos == 0:
53 | # No ground truth examples
54 | return 0,0,0,0,npos
55 |
56 | # read dets
57 | with open(detpath, 'r') as f:
58 | lines = f.readlines()
59 | if len(lines) == 0:
60 | # No detection examples
61 | return 0,0,0,0,npos
62 |
63 | splitlines = [x.strip().split(' ') for x in lines]
64 | image_ids = [x[0] for x in splitlines]
65 | confidence = np.array([float(x[1]) for x in splitlines])
66 | BB = np.array([[float(z) for z in x[2:]] for x in splitlines])
67 |
68 | # sort by confidence
69 | sorted_ind = np.argsort(-confidence)
70 | sorted_scores = -np.sort(-confidence)
71 | BB = BB[sorted_ind, :]
72 | image_ids = [image_ids[x] for x in sorted_ind]
73 |
74 | # go down dets and mark TPs and FPs
75 | nd = len(image_ids)
76 | tp = np.zeros(nd)
77 | fp = np.zeros(nd)
78 | for d in range(nd):
79 | R = class_recs[image_ids[d]]
80 | bb = BB[d, :].astype(float)
81 | ovmax = -np.inf
82 | BBGT = R['bbox'].astype(float)
83 |
84 | if BBGT.size > 0:
85 | # compute overlaps
86 | # intersection
87 | ixmin = np.maximum(BBGT[:, 0], bb[0])
88 | iymin = np.maximum(BBGT[:, 1], bb[1])
89 | ixmax = np.minimum(BBGT[:, 2], bb[2])
90 | iymax = np.minimum(BBGT[:, 3], bb[3])
91 | iw = np.maximum(ixmax - ixmin + 1., 0.)
92 | ih = np.maximum(iymax - iymin + 1., 0.)
93 | inters = iw * ih
94 |
95 | # union
96 | uni = ((bb[2] - bb[0] + 1.) * (bb[3] - bb[1] + 1.) +
97 | (BBGT[:, 2] - BBGT[:, 0] + 1.) *
98 | (BBGT[:, 3] - BBGT[:, 1] + 1.) - inters)
99 |
100 | overlaps = inters / uni
101 | ovmax = np.max(overlaps)
102 | jmax = np.argmax(overlaps)
103 |
104 | if ovmax > ovthresh:
105 | if not R['difficult'][jmax]:
106 | if not R['det'][jmax]:
107 | tp[d] = 1.
108 | R['det'][jmax] = 1
109 | else:
110 | fp[d] = 1.
111 | else:
112 | fp[d] = 1.
113 |
114 | # compute precision recall
115 | fp = np.cumsum(fp)
116 | tp = np.cumsum(tp)
117 | rec = tp / float(npos)
118 | # avoid divide by zero in case the first detection matches a difficult
119 | # ground truth
120 | prec = tp / np.maximum(tp + fp, np.finfo(np.float64).eps)
121 | ap = voc_ap(rec, prec, use_07_metric)
122 |
123 | return rec, prec, ap, sorted_scores, npos
124 |
--------------------------------------------------------------------------------
|