├── CenterNet-master ├── README.md ├── __pycache__ │ ├── config.cpython-35.pyc │ └── nms.cpython-35.pyc ├── config.py ├── config │ ├── CenterNet-52-rico.json │ ├── CenterNet-52-rico10k.json │ ├── CenterNet-52-rico2k.json │ └── CenterNet-52-ricotext.json ├── db │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-35.pyc │ │ ├── base.cpython-35.pyc │ │ ├── coco.cpython-35.pyc │ │ ├── datasets.cpython-35.pyc │ │ ├── detection.cpython-35.pyc │ │ ├── rico.cpython-35.pyc │ │ ├── rico_single.cpython-35.pyc │ │ └── ui5k.cpython-35.pyc │ ├── base.py │ ├── coco.py │ ├── datasets.py │ ├── detection.py │ ├── rico-old.py │ ├── rico.py │ ├── rico_single.py │ └── ui5k.py ├── demo.py ├── demo.sh ├── external │ ├── .gitignore │ ├── Makefile │ ├── __init__.py │ ├── __pycache__ │ │ └── __init__.cpython-35.pyc │ ├── nms.pyx │ ├── nms.so │ └── setup.py ├── info ├── models │ ├── CenterNet-104.py │ ├── CenterNet-52.py │ ├── __init__.py │ ├── __pycache__ │ │ ├── CenterNet-104.cpython-35.pyc │ │ ├── CenterNet-52.cpython-35.pyc │ │ └── __init__.cpython-35.pyc │ └── py_utils │ │ ├── __init__.py │ │ ├── __pycache__ │ │ ├── __init__.cpython-35.pyc │ │ ├── data_parallel.cpython-35.pyc │ │ ├── kp.cpython-35.pyc │ │ ├── kp_utils.cpython-35.pyc │ │ ├── scatter_gather.cpython-35.pyc │ │ └── utils.cpython-35.pyc │ │ ├── _cpools │ │ ├── .gitignore │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ └── __init__.cpython-35.pyc │ │ ├── setup.py │ │ └── src │ │ │ ├── bottom_pool.cpp │ │ │ ├── left_pool.cpp │ │ │ ├── right_pool.cpp │ │ │ └── top_pool.cpp │ │ ├── data_parallel.py │ │ ├── kp.py │ │ ├── kp_utils.py │ │ ├── scatter_gather.py │ │ └── utils.py ├── nms.py ├── nnet │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-35.pyc │ │ └── py_factory.cpython-35.pyc │ └── py_factory.py ├── pycocotools │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-35.pyc │ │ ├── coco.cpython-35.pyc │ │ ├── cocoeval.cpython-35.pyc │ │ └── mask.cpython-35.pyc │ ├── _mask.c │ ├── _mask.cpython-35m-x86_64-linux-gnu.so │ ├── _mask.pyx │ ├── _mask.so │ ├── coco.py │ ├── cocoeval.py │ └── mask.py ├── requirments.txt ├── sample │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-35.pyc │ │ ├── coco.cpython-35.pyc │ │ └── utils.cpython-35.pyc │ ├── coco.py │ └── utils.py ├── test.py ├── test.sh ├── test │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-35.pyc │ │ └── coco.cpython-35.pyc │ └── coco.py ├── train.py ├── train.sh └── utils │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-35.pyc │ ├── image.cpython-35.pyc │ └── tqdm.cpython-35.pyc │ ├── image.py │ └── tqdm.py ├── DL_setup_troubleshootiing.md ├── FASTER_RCNN ├── INSTRUCTIONS--Modify-to-your-dataset ├── LICENSE ├── README.md ├── __pycache__ │ └── _init_paths.cpython-35.pyc ├── _init_paths.py ├── cfgs │ ├── res101.yml │ ├── res101_ls.yml │ ├── res50.yml │ └── vgg16.yml ├── data │ └── README ├── demo.py ├── demo.sh ├── lib │ ├── build │ │ ├── lib.linux-x86_64-3.5 │ │ │ ├── datasets │ │ │ │ ├── __init__.py │ │ │ │ ├── coco.py │ │ │ │ ├── ds_utils.py │ │ │ │ ├── factory.py │ │ │ │ ├── imagenet.py │ │ │ │ ├── imdb.py │ │ │ │ ├── pascal_voc.py │ │ │ │ ├── pascal_voc_rbg.py │ │ │ │ ├── rico.py │ │ │ │ ├── vg.py │ │ │ │ ├── vg_eval.py │ │ │ │ └── voc_eval.py │ │ │ ├── model │ │ │ │ ├── _C.cpython-35m-x86_64-linux-gnu.so │ │ │ │ ├── __init__.py │ │ │ │ ├── faster_rcnn │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── faster_rcnn.py │ │ │ │ │ ├── resnet.py │ │ │ │ │ └── vgg16.py │ │ │ │ ├── nms │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── _ext │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── nms │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── build.py │ │ │ │ │ ├── nms_cpu.py │ │ │ │ │ ├── nms_gpu.py │ │ │ │ │ └── nms_wrapper.py │ │ │ │ ├── roi_align │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── _ext │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── roi_align │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── build.py │ │ │ │ │ ├── functions │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── roi_align.py │ │ │ │ │ └── modules │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── roi_align.py │ │ │ │ ├── roi_crop │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── _ext │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ ├── crop_resize │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ └── roi_crop │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── build.py │ │ │ │ │ ├── functions │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ ├── crop_resize.py │ │ │ │ │ │ ├── gridgen.py │ │ │ │ │ │ └── roi_crop.py │ │ │ │ │ └── modules │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ ├── gridgen.py │ │ │ │ │ │ └── roi_crop.py │ │ │ │ ├── roi_layers │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── nms.py │ │ │ │ │ ├── roi_align.py │ │ │ │ │ └── roi_pool.py │ │ │ │ ├── roi_pooling │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── _ext │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── roi_pooling │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── build.py │ │ │ │ │ ├── functions │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── roi_pool.py │ │ │ │ │ └── modules │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── roi_pool.py │ │ │ │ ├── rpn │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── anchor_target_layer.py │ │ │ │ │ ├── bbox_transform.py │ │ │ │ │ ├── generate_anchors.py │ │ │ │ │ ├── proposal_layer.py │ │ │ │ │ ├── proposal_target_layer_cascade.py │ │ │ │ │ └── rpn.py │ │ │ │ └── utils │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── blob.py │ │ │ │ │ ├── config.py │ │ │ │ │ ├── logger.py │ │ │ │ │ └── net_utils.py │ │ │ ├── pycocotools │ │ │ │ ├── __init__.py │ │ │ │ ├── coco.py │ │ │ │ ├── cocoeval.py │ │ │ │ └── mask.py │ │ │ └── roi_data_layer │ │ │ │ ├── __init__.py │ │ │ │ ├── minibatch.py │ │ │ │ ├── roibatchLoader.py │ │ │ │ └── roidb.py │ │ └── temp.linux-x86_64-3.5 │ │ │ └── home │ │ │ └── cheer │ │ │ └── Project │ │ │ └── UIObjectDetection │ │ │ └── Models │ │ │ └── DL_models_READY@USE │ │ │ └── FASTER_RCNN │ │ │ └── lib │ │ │ └── model │ │ │ └── csrc │ │ │ ├── cpu │ │ │ ├── ROIAlign_cpu.o │ │ │ └── nms_cpu.o │ │ │ ├── cuda │ │ │ ├── ROIAlign_cuda.o │ │ │ ├── ROIPool_cuda.o │ │ │ └── nms.o │ │ │ └── vision.o │ ├── datasets │ │ ├── VOCdevkit-matlab-wrapper │ │ │ ├── get_voc_opts.m │ │ │ ├── voc_eval.m │ │ │ └── xVOCap.m │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-35.pyc │ │ │ ├── coco.cpython-35.pyc │ │ │ ├── ds_utils.cpython-35.pyc │ │ │ ├── factory.cpython-35.pyc │ │ │ ├── imagenet.cpython-35.pyc │ │ │ ├── imdb.cpython-35.pyc │ │ │ ├── pascal_voc.cpython-35.pyc │ │ │ ├── rico.cpython-35.pyc │ │ │ ├── vg.cpython-35.pyc │ │ │ ├── vg_eval.cpython-35.pyc │ │ │ └── voc_eval.cpython-35.pyc │ │ ├── coco.py │ │ ├── ds_utils.py │ │ ├── factory.py │ │ ├── imagenet.py │ │ ├── imdb.py │ │ ├── pascal_voc.py │ │ ├── pascal_voc_rbg.py │ │ ├── rico.py │ │ ├── tools │ │ │ └── mcg_munge.py │ │ ├── vg.py │ │ ├── vg_eval.py │ │ └── voc_eval.py │ ├── dist │ │ └── faster_rcnn-0.1-py3.5-linux-x86_64.egg │ ├── faster_rcnn.egg-info │ │ ├── PKG-INFO │ │ ├── SOURCES.txt │ │ ├── dependency_links.txt │ │ └── top_level.txt │ ├── model │ │ ├── _C.cpython-35m-x86_64-linux-gnu.so │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ └── __init__.cpython-35.pyc │ │ ├── csrc │ │ │ ├── ROIAlign.h │ │ │ ├── ROIPool.h │ │ │ ├── cpu │ │ │ │ ├── ROIAlign_cpu.cpp │ │ │ │ ├── nms_cpu.cpp │ │ │ │ └── vision.h │ │ │ ├── cuda │ │ │ │ ├── ROIAlign_cuda.cu │ │ │ │ ├── ROIPool_cuda.cu │ │ │ │ ├── nms.cu │ │ │ │ └── vision.h │ │ │ ├── cuda_support_pytorch_above_1.10 │ │ │ │ ├── ROIAlign_cuda.cu │ │ │ │ ├── ROIPool_cuda.cu │ │ │ │ └── nms.cu │ │ │ ├── nms.h │ │ │ └── vision.cpp │ │ ├── faster_rcnn │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-35.pyc │ │ │ │ ├── faster_rcnn.cpython-35.pyc │ │ │ │ ├── resnet.cpython-35.pyc │ │ │ │ └── vgg16.cpython-35.pyc │ │ │ ├── faster_rcnn.py │ │ │ ├── resnet.py │ │ │ └── vgg16.py │ │ ├── nms │ │ │ ├── .gitignore │ │ │ ├── __init__.py │ │ │ ├── _ext │ │ │ │ ├── __init__.py │ │ │ │ └── nms │ │ │ │ │ └── __init__.py │ │ │ ├── build.py │ │ │ ├── make.sh │ │ │ ├── nms_cpu.py │ │ │ ├── nms_gpu.py │ │ │ ├── nms_kernel.cu │ │ │ ├── nms_wrapper.py │ │ │ └── src │ │ │ │ ├── nms_cuda.h │ │ │ │ ├── nms_cuda_kernel.cu │ │ │ │ └── nms_cuda_kernel.h │ │ ├── roi_align │ │ │ ├── __init__.py │ │ │ ├── _ext │ │ │ │ ├── __init__.py │ │ │ │ └── roi_align │ │ │ │ │ └── __init__.py │ │ │ ├── build.py │ │ │ ├── functions │ │ │ │ ├── __init__.py │ │ │ │ └── roi_align.py │ │ │ ├── make.sh │ │ │ ├── modules │ │ │ │ ├── __init__.py │ │ │ │ └── roi_align.py │ │ │ └── src │ │ │ │ ├── roi_align.c │ │ │ │ ├── roi_align.h │ │ │ │ ├── roi_align_cuda.c │ │ │ │ ├── roi_align_cuda.h │ │ │ │ ├── roi_align_kernel.cu │ │ │ │ └── roi_align_kernel.h │ │ ├── roi_crop │ │ │ ├── __init__.py │ │ │ ├── _ext │ │ │ │ ├── __init__.py │ │ │ │ ├── crop_resize │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── _crop_resize.so │ │ │ │ └── roi_crop │ │ │ │ │ └── __init__.py │ │ │ ├── build.py │ │ │ ├── functions │ │ │ │ ├── __init__.py │ │ │ │ ├── crop_resize.py │ │ │ │ ├── gridgen.py │ │ │ │ └── roi_crop.py │ │ │ ├── make.sh │ │ │ ├── modules │ │ │ │ ├── __init__.py │ │ │ │ ├── gridgen.py │ │ │ │ └── roi_crop.py │ │ │ └── src │ │ │ │ ├── roi_crop.c │ │ │ │ ├── roi_crop.h │ │ │ │ ├── roi_crop_cuda.c │ │ │ │ ├── roi_crop_cuda.h │ │ │ │ ├── roi_crop_cuda_kernel.cu │ │ │ │ └── roi_crop_cuda_kernel.h │ │ ├── roi_layers │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-35.pyc │ │ │ │ ├── nms.cpython-35.pyc │ │ │ │ ├── roi_align.cpython-35.pyc │ │ │ │ └── roi_pool.cpython-35.pyc │ │ │ ├── nms.py │ │ │ ├── roi_align.py │ │ │ └── roi_pool.py │ │ ├── roi_pooling │ │ │ ├── __init__.py │ │ │ ├── _ext │ │ │ │ ├── __init__.py │ │ │ │ └── roi_pooling │ │ │ │ │ └── __init__.py │ │ │ ├── build.py │ │ │ ├── functions │ │ │ │ ├── __init__.py │ │ │ │ └── roi_pool.py │ │ │ ├── modules │ │ │ │ ├── __init__.py │ │ │ │ └── roi_pool.py │ │ │ └── src │ │ │ │ ├── roi_pooling.c │ │ │ │ ├── roi_pooling.h │ │ │ │ ├── roi_pooling_cuda.c │ │ │ │ ├── roi_pooling_cuda.h │ │ │ │ ├── roi_pooling_kernel.cu │ │ │ │ └── roi_pooling_kernel.h │ │ ├── rpn │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-35.pyc │ │ │ │ ├── anchor_target_layer.cpython-35.pyc │ │ │ │ ├── bbox_transform.cpython-35.pyc │ │ │ │ ├── generate_anchors.cpython-35.pyc │ │ │ │ ├── proposal_layer.cpython-35.pyc │ │ │ │ ├── proposal_target_layer_cascade.cpython-35.pyc │ │ │ │ └── rpn.cpython-35.pyc │ │ │ ├── anchor_target_layer.py │ │ │ ├── bbox_transform.py │ │ │ ├── generate_anchors.py │ │ │ ├── proposal_layer.py │ │ │ ├── proposal_target_layer_cascade.py │ │ │ └── rpn.py │ │ └── utils │ │ │ ├── .gitignore │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-35.pyc │ │ │ ├── blob.cpython-35.pyc │ │ │ ├── config.cpython-35.pyc │ │ │ └── net_utils.cpython-35.pyc │ │ │ ├── bbox.pyx │ │ │ ├── blob.py │ │ │ ├── config.py │ │ │ ├── logger.py │ │ │ └── net_utils.py │ ├── roi_data_layer │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-35.pyc │ │ │ ├── minibatch.cpython-35.pyc │ │ │ ├── roibatchLoader.cpython-35.pyc │ │ │ └── roidb.cpython-35.pyc │ │ ├── minibatch.py │ │ ├── roibatchLoader.py │ │ └── roidb.py │ └── setup.py ├── pycocotools │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-35.pyc │ │ ├── coco.cpython-35.pyc │ │ ├── cocoeval.cpython-35.pyc │ │ └── mask.cpython-35.pyc │ ├── _mask.c │ ├── _mask.cpython-35m-x86_64-linux-gnu.so │ ├── _mask.pyx │ ├── _mask.so │ ├── coco.py │ ├── cocoeval.py │ └── mask.py ├── requirements.txt ├── test.sh ├── test_folder │ ├── 12628.jpg │ ├── 18116.jpg │ ├── 30800.jpg │ └── 64046.jpg ├── test_net.py ├── train.sh └── trainval_net.py ├── LICENSE.txt ├── PyTorch-YOLOv3 ├── .gitignore ├── LICENSE ├── README.md ├── config │ ├── coco.data │ ├── create_custom_model.sh │ ├── rico.data │ ├── rico10k.data │ ├── rico2k.data │ ├── rico5box.data │ ├── ricotext.data │ ├── yolov3-rico.cfg │ ├── yolov3-rico10k.cfg │ ├── yolov3-rico2k.cfg │ ├── yolov3-rico5box.cfg │ ├── yolov3-ricotext.cfg │ └── yolov3.cfg ├── data │ ├── rico │ │ ├── classes.names │ │ ├── test.txt │ │ ├── train.txt │ │ └── val.txt │ ├── rico10k │ │ └── classes.names │ ├── rico2k │ │ └── classes.names │ ├── rico5box │ │ └── classes.names │ └── ricotext │ │ └── classes.names ├── demo.sh ├── detect.py ├── inference.sh ├── info ├── models.py ├── models.pyc ├── requirements.txt ├── test.py ├── test.sh ├── train.py ├── train.sh └── utils │ ├── __init__.py │ ├── __init__.pyc │ ├── augmentations.py │ ├── datasets.py │ ├── logger.py │ ├── parse_config.py │ ├── parse_config.pyc │ ├── utils.py │ └── utils.pyc ├── README.md ├── Xianyu ├── README.md ├── __pycache__ │ ├── xianyu_merge.cpython-35.pyc │ ├── xianyu_ocr.cpython-35.pyc │ └── xianyu_utils.cpython-35.pyc ├── detect.py ├── detect.sh ├── xianyu_merge.py ├── xianyu_ocr.py └── xianyu_utils.py └── cocoapi-master.zip /CenterNet-master/README.md: -------------------------------------------------------------------------------- 1 | # CenterNet 2 | 3 | ## Setup 4 | 5 | 6 | ``` 7 | pip install -r requirements.txt 8 | rm models/py_utils/_cpools/build/* 9 | cd models/py_utils/_cpools & python setup.py install --user 10 | ``` 11 | 12 | ## Test 13 | 14 | ``` 15 | python demo.py \ 16 | --cfg_file CenterNet-52-[DATASET] \ 17 | --test_folder [FOLDER-TO-TEST] 18 | ``` 19 | 20 | Dataset options: rico, rico2k, rico10k, ricotext 21 | 22 | Place the pretrained model in the folder *CenterNet-master/results/run/CenterNet-52/[DATASET]* 23 | 24 | **For more information, see https://github.com/Duankaiwen/CenterNet** 25 | -------------------------------------------------------------------------------- /CenterNet-master/__pycache__/config.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/__pycache__/config.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/__pycache__/nms.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/__pycache__/nms.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/config/CenterNet-52-rico.json: -------------------------------------------------------------------------------- 1 | { 2 | "system": { 3 | "dataset": "rico", 4 | "batch_size": 6, 5 | "sampling_function": "kp_detection", 6 | 7 | "train_split": "train", 8 | "val_split": "val", 9 | 10 | "learning_rate": 0.000005, 11 | "decay_rate": 10, 12 | 13 | "val_iter": 500, 14 | 15 | "opt_algo": "adam", 16 | "prefetch_size": 6, 17 | 18 | "max_iter": 480000, 19 | "stepsize": 450000, 20 | "snapshot": 5000, 21 | 22 | "chunk_sizes": [6] 23 | 24 | }, 25 | 26 | "db": { 27 | "categories": 14, 28 | "rand_scale_min": 0.6, 29 | "rand_scale_max": 1.4, 30 | "rand_scale_step": 0.1, 31 | "rand_scales": null, 32 | 33 | "rand_crop": true, 34 | "rand_color": true, 35 | 36 | "border": 128, 37 | "gaussian_bump": true, 38 | 39 | "input_size": [511, 511], 40 | "output_sizes": [[128, 128]], 41 | 42 | "test_scales": [1], 43 | 44 | "top_k": 70, 45 | "kp_categories": 1, 46 | "ae_threshold": 0.5, 47 | "nms_threshold": 0.5, 48 | 49 | "max_per_image": 100 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /CenterNet-master/config/CenterNet-52-rico10k.json: -------------------------------------------------------------------------------- 1 | { 2 | "system": { 3 | "dataset": "rico10k", 4 | "batch_size": 6, 5 | "sampling_function": "kp_detection", 6 | 7 | "train_split": "train", 8 | "val_split": "val", 9 | 10 | "learning_rate": 0.000005, 11 | "decay_rate": 10, 12 | 13 | "val_iter": 500, 14 | 15 | "opt_algo": "adam", 16 | "prefetch_size": 6, 17 | 18 | "max_iter": 480000, 19 | "stepsize": 450000, 20 | "snapshot": 2000, 21 | 22 | "chunk_sizes": [6] 23 | }, 24 | 25 | "db": { 26 | "categories": 14, 27 | "rand_scale_min": 0.6, 28 | "rand_scale_max": 1.4, 29 | "rand_scale_step": 0.1, 30 | "rand_scales": null, 31 | 32 | "rand_crop": true, 33 | "rand_color": true, 34 | 35 | "border": 128, 36 | "gaussian_bump": true, 37 | 38 | "input_size": [511, 511], 39 | "output_sizes": [[128, 128]], 40 | 41 | "test_scales": [1], 42 | 43 | "top_k": 70, 44 | "kp_categories": 1, 45 | "ae_threshold": 0.5, 46 | "nms_threshold": 0.7, 47 | 48 | "max_per_image": 100 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /CenterNet-master/config/CenterNet-52-rico2k.json: -------------------------------------------------------------------------------- 1 | { 2 | "system": { 3 | "dataset": "rico2k", 4 | "batch_size": 6, 5 | "sampling_function": "kp_detection", 6 | 7 | "train_split": "train", 8 | "val_split": "val", 9 | 10 | "learning_rate": 0.000005, 11 | "decay_rate": 10, 12 | 13 | "val_iter": 500, 14 | 15 | "opt_algo": "adam", 16 | "prefetch_size": 6, 17 | 18 | "max_iter": 50000, 19 | "stepsize": 450000, 20 | "snapshot": 2000, 21 | 22 | "chunk_sizes": [6] 23 | }, 24 | 25 | "db": { 26 | "categories": 14, 27 | "rand_scale_min": 0.6, 28 | "rand_scale_max": 1.4, 29 | "rand_scale_step": 0.1, 30 | "rand_scales": null, 31 | 32 | "rand_crop": true, 33 | "rand_color": true, 34 | 35 | "border": 128, 36 | "gaussian_bump": true, 37 | 38 | "input_size": [511, 511], 39 | "output_sizes": [[128, 128]], 40 | 41 | "test_scales": [1], 42 | 43 | "top_k": 70, 44 | "kp_categories": 1, 45 | "ae_threshold": 0.5, 46 | "nms_threshold": 0.7, 47 | 48 | "max_per_image": 100 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /CenterNet-master/config/CenterNet-52-ricotext.json: -------------------------------------------------------------------------------- 1 | { 2 | "system": { 3 | "dataset": "ricotext", 4 | "batch_size": 6, 5 | "sampling_function": "kp_detection", 6 | 7 | "train_split": "train", 8 | "val_split": "val", 9 | 10 | "learning_rate": 0.000005, 11 | "decay_rate": 10, 12 | 13 | "val_iter": 500, 14 | 15 | "opt_algo": "adam", 16 | "prefetch_size": 6, 17 | 18 | "max_iter": 480000, 19 | "stepsize": 450000, 20 | "snapshot": 5000, 21 | 22 | "chunk_sizes": [6] 23 | }, 24 | 25 | "db": { 26 | "categories": 15, 27 | "rand_scale_min": 0.6, 28 | "rand_scale_max": 1.4, 29 | "rand_scale_step": 0.1, 30 | "rand_scales": null, 31 | 32 | "rand_crop": true, 33 | "rand_color": true, 34 | 35 | "border": 128, 36 | "gaussian_bump": true, 37 | 38 | "input_size": [511, 511], 39 | "output_sizes": [[128, 128]], 40 | 41 | "test_scales": [1], 42 | 43 | "top_k": 70, 44 | "kp_categories": 1, 45 | "ae_threshold": 0.5, 46 | "nms_threshold": 0.5, 47 | 48 | "max_per_image": 100 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /CenterNet-master/db/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/db/__init__.py -------------------------------------------------------------------------------- /CenterNet-master/db/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/db/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/db/__pycache__/base.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/db/__pycache__/base.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/db/__pycache__/coco.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/db/__pycache__/coco.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/db/__pycache__/datasets.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/db/__pycache__/datasets.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/db/__pycache__/detection.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/db/__pycache__/detection.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/db/__pycache__/rico.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/db/__pycache__/rico.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/db/__pycache__/rico_single.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/db/__pycache__/rico_single.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/db/__pycache__/ui5k.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/db/__pycache__/ui5k.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/db/base.py: -------------------------------------------------------------------------------- 1 | import os 2 | import h5py 3 | import numpy as np 4 | 5 | from config import system_configs 6 | 7 | class BASE(object): 8 | def __init__(self): 9 | self._split = None 10 | self._db_inds = [] 11 | self._image_ids = [] 12 | 13 | self._data = None 14 | self._image_hdf5 = None 15 | self._image_file = None 16 | self._image_hdf5_file = None 17 | 18 | self._mean = np.zeros((3, ), dtype=np.float32) 19 | self._std = np.ones((3, ), dtype=np.float32) 20 | self._eig_val = np.ones((3, ), dtype=np.float32) 21 | self._eig_vec = np.zeros((3, 3), dtype=np.float32) 22 | 23 | self._configs = {} 24 | self._train_cfg = {} 25 | self._model = {} 26 | self._configs["data_aug"] = True 27 | 28 | self._data_rng = None 29 | 30 | @property 31 | def data(self): 32 | if self._data is None: 33 | raise ValueError("data is not set") 34 | return self._data 35 | 36 | @property 37 | def configs(self): 38 | return self._configs 39 | 40 | @property 41 | def train_cfg(self): 42 | return self._train_cfg 43 | 44 | @property 45 | def model(self): 46 | return self._model 47 | 48 | @property 49 | def mean(self): 50 | return self._mean 51 | 52 | @property 53 | def std(self): 54 | return self._std 55 | 56 | @property 57 | def eig_val(self): 58 | return self._eig_val 59 | 60 | @property 61 | def eig_vec(self): 62 | return self._eig_vec 63 | 64 | @property 65 | def db_inds(self): 66 | return self._db_inds 67 | 68 | @property 69 | def split(self): 70 | return self._split 71 | 72 | def update_config(self, new): 73 | for key in new: 74 | if key in self._configs: 75 | self._configs[key] = new[key] 76 | 77 | def image_ids(self, ind): 78 | return self._image_ids[ind] 79 | 80 | def image_file(self, ind): 81 | if self._image_file is None: 82 | raise ValueError("Image path is not initialized") 83 | 84 | image_id = self._image_ids[ind] 85 | return self._image_file.format(image_id) 86 | 87 | def write_result(self, ind, all_bboxes, all_scores): 88 | pass 89 | 90 | def evaluate(self, name): 91 | pass 92 | 93 | def shuffle_inds(self, quiet=False): 94 | if self._data_rng is None: 95 | self._data_rng = np.random.RandomState(os.getpid()) 96 | 97 | if not quiet: 98 | print("shuffling indices...") 99 | rand_perm = self._data_rng.permutation(len(self._db_inds)) 100 | self._db_inds = self._db_inds[rand_perm] 101 | -------------------------------------------------------------------------------- /CenterNet-master/db/datasets.py: -------------------------------------------------------------------------------- 1 | from db.coco import MSCOCO 2 | from db.ui5k import UI5K 3 | from db.rico import RICO 4 | datasets = { 5 | "MSCOCO": MSCOCO, 6 | "UI5K": UI5K, 7 | "rico": RICO, 8 | "rico2k": RICO, 9 | "rico10k": RICO, 10 | "ricotext": RICO, 11 | } 12 | -------------------------------------------------------------------------------- /CenterNet-master/demo.sh: -------------------------------------------------------------------------------- 1 | python3 demo.py --cfg_file CenterNet-52-ricotext --test_folder /media/cheer/UI/Project/UIObjectDetection/DL_models_READY@USE/FASTER_RCNN/test_folder 2 | 3 | 4 | # Place the pretrained model in the folder -------------------------------------------------------------------------------- /CenterNet-master/external/.gitignore: -------------------------------------------------------------------------------- 1 | bbox.c 2 | bbox.cpython-35m-x86_64-linux-gnu.so 3 | bbox.cpython-36m-x86_64-linux-gnu.so 4 | 5 | nms.c 6 | nms.cpython-35m-x86_64-linux-gnu.so 7 | nms.cpython-36m-x86_64-linux-gnu.so 8 | -------------------------------------------------------------------------------- /CenterNet-master/external/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | python3 setup.py build_ext --inplace 3 | rm -rf build 4 | -------------------------------------------------------------------------------- /CenterNet-master/external/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/external/__init__.py -------------------------------------------------------------------------------- /CenterNet-master/external/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/external/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/external/nms.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/external/nms.so -------------------------------------------------------------------------------- /CenterNet-master/external/setup.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | from distutils.core import setup 3 | from distutils.extension import Extension 4 | from Cython.Build import cythonize 5 | 6 | extensions = [ 7 | Extension( 8 | "nms", 9 | ["nms.pyx"], 10 | extra_compile_args=["-Wno-cpp", "-Wno-unused-function"] 11 | ) 12 | ] 13 | 14 | setup( 15 | name="coco", 16 | ext_modules=cythonize(extensions), 17 | include_dirs=[numpy.get_include()] 18 | ) 19 | -------------------------------------------------------------------------------- /CenterNet-master/info: -------------------------------------------------------------------------------- 1 | @apatsekin sorry, i didn't save the full training log. The final loss is about : 2 | training loss: 3.5885119438171387 3 | validation loss at iteration: 3.860023260116577 4 | 5 | 6 | # top_pool.cpython-35m-x86_64-linux-gnu.so: undefined symbol: _ZTIN3c1021AutogradMetaInterfaceE 7 | ``` 8 | rm models/py_utils/_cpools/build/* and models/py_utils/_cpools/dist 9 | python3 setup.py install --user 10 | ``` 11 | 12 | ==> config/CenterNet-52.json 13 | Line 3: dataset: rico ==> dataset:rico10k 14 | Line 26 “categories":80 ==> “categories":8(类别数) 15 | 16 | 17 | The following modification will be automatically modified based on the above change 18 | ==> models/CenterNet-52.py or models/CenterNet-104.py 19 | Line 132: out_dim =80 ==> out_dim =8 (类别数) 20 | 21 | ==> db/detection.py 22 | Line 8: self._configs[ “categories"] = 80 ==> self._configs[ “categories"] = 8 (类别数) 23 | Line 72: num_classes=81 ==> num_classes=9 (类别数+1) 24 | 25 | ==> db/rico.py 26 | Line 44: cate_ids 27 | 28 | ==> models/py_utils/kp_utils 29 | line 217 add: 30 | if len(tag_mean.size()) < 2: 31 | tag_mean = tag_mean.unsqueeze(0) 32 | 33 | 34 | test error 35 | ==> db/rico.py 36 | line 139: self._classes[cls_ind] -> cls_ind 37 | line 164: [self._classes[cls_id] for cls_id in cls_ids] -> cls_ids 38 | 39 | 40 | for debug 41 | ==> test/coco.py 42 | line 87: num_images -> 10 -------------------------------------------------------------------------------- /CenterNet-master/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/models/__init__.py -------------------------------------------------------------------------------- /CenterNet-master/models/__pycache__/CenterNet-104.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/models/__pycache__/CenterNet-104.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/models/__pycache__/CenterNet-52.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/models/__pycache__/CenterNet-52.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/models/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/models/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .kp import kp, AELoss 2 | from .kp_utils import _neg_loss 3 | 4 | from .utils import convolution, fully_connected, residual 5 | 6 | from ._cpools import TopPool, BottomPool, LeftPool, RightPool 7 | 8 | -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/models/py_utils/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/__pycache__/data_parallel.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/models/py_utils/__pycache__/data_parallel.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/__pycache__/kp.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/models/py_utils/__pycache__/kp.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/__pycache__/kp_utils.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/models/py_utils/__pycache__/kp_utils.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/__pycache__/scatter_gather.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/models/py_utils/__pycache__/scatter_gather.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/__pycache__/utils.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/models/py_utils/__pycache__/utils.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/_cpools/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | cpools.egg-info/ 3 | dist/ 4 | -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/_cpools/__init__.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | from torch import nn 4 | from torch.autograd import Function 5 | 6 | import top_pool, bottom_pool, left_pool, right_pool 7 | 8 | class TopPoolFunction(Function): 9 | @staticmethod 10 | def forward(ctx, input): 11 | output = top_pool.forward(input)[0] 12 | ctx.save_for_backward(input) 13 | return output 14 | 15 | @staticmethod 16 | def backward(ctx, grad_output): 17 | input = ctx.saved_variables[0] 18 | output = top_pool.backward(input, grad_output)[0] 19 | return output 20 | 21 | class BottomPoolFunction(Function): 22 | @staticmethod 23 | def forward(ctx, input): 24 | output = bottom_pool.forward(input)[0] 25 | ctx.save_for_backward(input) 26 | return output 27 | 28 | @staticmethod 29 | def backward(ctx, grad_output): 30 | input = ctx.saved_variables[0] 31 | output = bottom_pool.backward(input, grad_output)[0] 32 | return output 33 | 34 | class LeftPoolFunction(Function): 35 | @staticmethod 36 | def forward(ctx, input): 37 | output = left_pool.forward(input)[0] 38 | ctx.save_for_backward(input) 39 | return output 40 | 41 | @staticmethod 42 | def backward(ctx, grad_output): 43 | input = ctx.saved_variables[0] 44 | output = left_pool.backward(input, grad_output)[0] 45 | return output 46 | 47 | class RightPoolFunction(Function): 48 | @staticmethod 49 | def forward(ctx, input): 50 | output = right_pool.forward(input)[0] 51 | ctx.save_for_backward(input) 52 | return output 53 | 54 | @staticmethod 55 | def backward(ctx, grad_output): 56 | input = ctx.saved_variables[0] 57 | output = right_pool.backward(input, grad_output)[0] 58 | return output 59 | 60 | class TopPool(nn.Module): 61 | def forward(self, x): 62 | return TopPoolFunction.apply(x) 63 | 64 | class BottomPool(nn.Module): 65 | def forward(self, x): 66 | return BottomPoolFunction.apply(x) 67 | 68 | class LeftPool(nn.Module): 69 | def forward(self, x): 70 | return LeftPoolFunction.apply(x) 71 | 72 | class RightPool(nn.Module): 73 | def forward(self, x): 74 | return RightPoolFunction.apply(x) 75 | -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/_cpools/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/models/py_utils/_cpools/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/_cpools/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from torch.utils.cpp_extension import BuildExtension, CppExtension 3 | 4 | setup( 5 | name="cpools", 6 | ext_modules=[ 7 | CppExtension("top_pool", ["src/top_pool.cpp" ]), 8 | CppExtension("bottom_pool", ["src/bottom_pool.cpp"]), 9 | CppExtension("left_pool", ["src/left_pool.cpp"]), 10 | CppExtension("right_pool", ["src/right_pool.cpp"]) 11 | ], 12 | cmdclass={ 13 | "build_ext": BuildExtension 14 | } 15 | ) 16 | -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/_cpools/src/bottom_pool.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | std::vector pool_forward( 6 | at::Tensor input 7 | ) { 8 | // Initialize output 9 | at::Tensor output = at::zeros_like(input); 10 | 11 | // Get height 12 | int64_t height = input.size(2); 13 | 14 | output.copy_(input); 15 | 16 | for (int64_t ind = 1; ind < height; ind <<= 1) { 17 | at::Tensor max_temp = at::slice(output, 2, ind, height); 18 | at::Tensor cur_temp = at::slice(output, 2, ind, height); 19 | at::Tensor next_temp = at::slice(output, 2, 0, height-ind); 20 | at::max_out(max_temp, cur_temp, next_temp); 21 | } 22 | 23 | return { 24 | output 25 | }; 26 | } 27 | 28 | std::vector pool_backward( 29 | at::Tensor input, 30 | at::Tensor grad_output 31 | ) { 32 | auto output = at::zeros_like(input); 33 | 34 | int32_t batch = input.size(0); 35 | int32_t channel = input.size(1); 36 | int32_t height = input.size(2); 37 | int32_t width = input.size(3); 38 | 39 | auto max_val = torch::zeros({batch, channel, width}, at::device(at::kCUDA).dtype(at::kFloat)); 40 | auto max_ind = torch::zeros({batch, channel, width}, at::device(at::kCUDA).dtype(at::kLong)); 41 | 42 | auto input_temp = input.select(2, 0); 43 | max_val.copy_(input_temp); 44 | 45 | max_ind.fill_(0); 46 | 47 | auto output_temp = output.select(2, 0); 48 | auto grad_output_temp = grad_output.select(2, 0); 49 | output_temp.copy_(grad_output_temp); 50 | 51 | auto un_max_ind = max_ind.unsqueeze(2); 52 | auto gt_mask = torch::zeros({batch, channel, width}, at::device(at::kCUDA).dtype(at::kByte)); 53 | auto max_temp = torch::zeros({batch, channel, width}, at::device(at::kCUDA).dtype(at::kFloat)); 54 | for (int32_t ind = 0; ind < height - 1; ++ind) { 55 | input_temp = input.select(2, ind + 1); 56 | at::gt_out(gt_mask, input_temp, max_val); 57 | 58 | at::masked_select_out(max_temp, input_temp, gt_mask); 59 | max_val.masked_scatter_(gt_mask, max_temp); 60 | max_ind.masked_fill_(gt_mask, ind + 1); 61 | 62 | grad_output_temp = grad_output.select(2, ind + 1).unsqueeze(2); 63 | output.scatter_add_(2, un_max_ind, grad_output_temp); 64 | } 65 | 66 | return { 67 | output 68 | }; 69 | } 70 | 71 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 72 | m.def( 73 | "forward", &pool_forward, "Bottom Pool Forward", 74 | py::call_guard() 75 | ); 76 | m.def( 77 | "backward", &pool_backward, "Bottom Pool Backward", 78 | py::call_guard() 79 | ); 80 | } 81 | -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/_cpools/src/left_pool.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | std::vector pool_forward( 6 | at::Tensor input 7 | ) { 8 | // Initialize output 9 | at::Tensor output = at::zeros_like(input); 10 | 11 | // Get width 12 | int64_t width = input.size(3); 13 | 14 | output.copy_(input); 15 | 16 | for (int64_t ind = 1; ind < width; ind <<= 1) { 17 | at::Tensor max_temp = at::slice(output, 3, 0, width-ind); 18 | at::Tensor cur_temp = at::slice(output, 3, 0, width-ind); 19 | at::Tensor next_temp = at::slice(output, 3, ind, width); 20 | at::max_out(max_temp, cur_temp, next_temp); 21 | } 22 | 23 | return { 24 | output 25 | }; 26 | } 27 | 28 | std::vector pool_backward( 29 | at::Tensor input, 30 | at::Tensor grad_output 31 | ) { 32 | auto output = at::zeros_like(input); 33 | 34 | int32_t batch = input.size(0); 35 | int32_t channel = input.size(1); 36 | int32_t height = input.size(2); 37 | int32_t width = input.size(3); 38 | 39 | auto max_val = torch::zeros({batch, channel, height}, at::device(at::kCUDA).dtype(at::kFloat)); 40 | auto max_ind = torch::zeros({batch, channel, height}, at::device(at::kCUDA).dtype(at::kLong)); 41 | 42 | auto input_temp = input.select(3, width - 1); 43 | max_val.copy_(input_temp); 44 | 45 | max_ind.fill_(width - 1); 46 | 47 | auto output_temp = output.select(3, width - 1); 48 | auto grad_output_temp = grad_output.select(3, width - 1); 49 | output_temp.copy_(grad_output_temp); 50 | 51 | auto un_max_ind = max_ind.unsqueeze(3); 52 | auto gt_mask = torch::zeros({batch, channel, height}, at::device(at::kCUDA).dtype(at::kByte)); 53 | auto max_temp = torch::zeros({batch, channel, height}, at::device(at::kCUDA).dtype(at::kFloat)); 54 | for (int32_t ind = 1; ind < width; ++ind) { 55 | input_temp = input.select(3, width - ind - 1); 56 | at::gt_out(gt_mask, input_temp, max_val); 57 | 58 | at::masked_select_out(max_temp, input_temp, gt_mask); 59 | max_val.masked_scatter_(gt_mask, max_temp); 60 | max_ind.masked_fill_(gt_mask, width - ind - 1); 61 | 62 | grad_output_temp = grad_output.select(3, width - ind - 1).unsqueeze(3); 63 | output.scatter_add_(3, un_max_ind, grad_output_temp); 64 | } 65 | 66 | return { 67 | output 68 | }; 69 | } 70 | 71 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 72 | m.def( 73 | "forward", &pool_forward, "Left Pool Forward", 74 | py::call_guard() 75 | ); 76 | m.def( 77 | "backward", &pool_backward, "Left Pool Backward", 78 | py::call_guard() 79 | ); 80 | } 81 | -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/_cpools/src/right_pool.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | std::vector pool_forward( 6 | at::Tensor input 7 | ) { 8 | // Initialize output 9 | at::Tensor output = at::zeros_like(input); 10 | 11 | // Get width 12 | int64_t width = input.size(3); 13 | 14 | output.copy_(input); 15 | 16 | for (int64_t ind = 1; ind < width; ind <<= 1) { 17 | at::Tensor max_temp = at::slice(output, 3, ind, width); 18 | at::Tensor cur_temp = at::slice(output, 3, ind, width); 19 | at::Tensor next_temp = at::slice(output, 3, 0, width-ind); 20 | at::max_out(max_temp, cur_temp, next_temp); 21 | } 22 | 23 | return { 24 | output 25 | }; 26 | } 27 | 28 | std::vector pool_backward( 29 | at::Tensor input, 30 | at::Tensor grad_output 31 | ) { 32 | at::Tensor output = at::zeros_like(input); 33 | 34 | int32_t batch = input.size(0); 35 | int32_t channel = input.size(1); 36 | int32_t height = input.size(2); 37 | int32_t width = input.size(3); 38 | 39 | auto max_val = torch::zeros({batch, channel, height}, at::device(at::kCUDA).dtype(at::kFloat)); 40 | auto max_ind = torch::zeros({batch, channel, height}, at::device(at::kCUDA).dtype(at::kLong)); 41 | 42 | auto input_temp = input.select(3, 0); 43 | max_val.copy_(input_temp); 44 | 45 | max_ind.fill_(0); 46 | 47 | auto output_temp = output.select(3, 0); 48 | auto grad_output_temp = grad_output.select(3, 0); 49 | output_temp.copy_(grad_output_temp); 50 | 51 | auto un_max_ind = max_ind.unsqueeze(3); 52 | auto gt_mask = torch::zeros({batch, channel, height}, at::device(at::kCUDA).dtype(at::kByte)); 53 | auto max_temp = torch::zeros({batch, channel, height}, at::device(at::kCUDA).dtype(at::kFloat)); 54 | for (int32_t ind = 0; ind < width - 1; ++ind) { 55 | input_temp = input.select(3, ind + 1); 56 | at::gt_out(gt_mask, input_temp, max_val); 57 | 58 | at::masked_select_out(max_temp, input_temp, gt_mask); 59 | max_val.masked_scatter_(gt_mask, max_temp); 60 | max_ind.masked_fill_(gt_mask, ind + 1); 61 | 62 | grad_output_temp = grad_output.select(3, ind + 1).unsqueeze(3); 63 | output.scatter_add_(3, un_max_ind, grad_output_temp); 64 | } 65 | 66 | return { 67 | output 68 | }; 69 | } 70 | 71 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 72 | m.def( 73 | "forward", &pool_forward, "Right Pool Forward", 74 | py::call_guard() 75 | ); 76 | m.def( 77 | "backward", &pool_backward, "Right Pool Backward", 78 | py::call_guard() 79 | ); 80 | } 81 | -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/_cpools/src/top_pool.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | std::vector top_pool_forward( 6 | at::Tensor input 7 | ) { 8 | // Initialize output 9 | at::Tensor output = at::zeros_like(input); 10 | 11 | // Get height 12 | int64_t height = input.size(2); 13 | 14 | output.copy_(input); 15 | 16 | for (int64_t ind = 1; ind < height; ind <<= 1) { 17 | at::Tensor max_temp = at::slice(output, 2, 0, height-ind); 18 | at::Tensor cur_temp = at::slice(output, 2, 0, height-ind); 19 | at::Tensor next_temp = at::slice(output, 2, ind, height); 20 | at::max_out(max_temp, cur_temp, next_temp); 21 | } 22 | 23 | return { 24 | output 25 | }; 26 | } 27 | 28 | std::vector top_pool_backward( 29 | at::Tensor input, 30 | at::Tensor grad_output 31 | ) { 32 | auto output = at::zeros_like(input); 33 | 34 | int32_t batch = input.size(0); 35 | int32_t channel = input.size(1); 36 | int32_t height = input.size(2); 37 | int32_t width = input.size(3); 38 | 39 | auto max_val = torch::zeros({batch, channel, width}, at::device(at::kCUDA).dtype(at::kFloat)); 40 | auto max_ind = torch::zeros({batch, channel, width}, at::device(at::kCUDA).dtype(at::kLong)); 41 | 42 | auto input_temp = input.select(2, height - 1); 43 | max_val.copy_(input_temp); 44 | 45 | max_ind.fill_(height - 1); 46 | 47 | auto output_temp = output.select(2, height - 1); 48 | auto grad_output_temp = grad_output.select(2, height - 1); 49 | output_temp.copy_(grad_output_temp); 50 | 51 | auto un_max_ind = max_ind.unsqueeze(2); 52 | auto gt_mask = torch::zeros({batch, channel, width}, at::device(at::kCUDA).dtype(at::kByte)); 53 | auto max_temp = torch::zeros({batch, channel, width}, at::device(at::kCUDA).dtype(at::kFloat)); 54 | for (int32_t ind = 1; ind < height; ++ind) { 55 | input_temp = input.select(2, height - ind - 1); 56 | at::gt_out(gt_mask, input_temp, max_val); 57 | 58 | at::masked_select_out(max_temp, input_temp, gt_mask); 59 | max_val.masked_scatter_(gt_mask, max_temp); 60 | max_ind.masked_fill_(gt_mask, height - ind - 1); 61 | 62 | grad_output_temp = grad_output.select(2, height - ind - 1).unsqueeze(2); 63 | output.scatter_add_(2, un_max_ind, grad_output_temp); 64 | } 65 | 66 | return { 67 | output 68 | }; 69 | } 70 | 71 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 72 | m.def( 73 | "forward", &top_pool_forward, "Top Pool Forward", 74 | py::call_guard() 75 | ); 76 | m.def( 77 | "backward", &top_pool_backward, "Top Pool Backward", 78 | py::call_guard() 79 | ); 80 | } 81 | -------------------------------------------------------------------------------- /CenterNet-master/models/py_utils/scatter_gather.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch.autograd import Variable 3 | from torch.nn.parallel._functions import Scatter, Gather 4 | 5 | 6 | def scatter(inputs, target_gpus, dim=0, chunk_sizes=None): 7 | r""" 8 | Slices variables into approximately equal chunks and 9 | distributes them across given GPUs. Duplicates 10 | references to objects that are not variables. Does not 11 | support Tensors. 12 | """ 13 | def scatter_map(obj): 14 | if isinstance(obj, Variable): 15 | return Scatter.apply(target_gpus, chunk_sizes, dim, obj) 16 | assert not torch.is_tensor(obj), "Tensors not supported in scatter." 17 | if isinstance(obj, tuple): 18 | return list(zip(*map(scatter_map, obj))) 19 | if isinstance(obj, list): 20 | return list(map(list, zip(*map(scatter_map, obj)))) 21 | if isinstance(obj, dict): 22 | return list(map(type(obj), zip(*map(scatter_map, obj.items())))) 23 | return [obj for targets in target_gpus] 24 | 25 | return scatter_map(inputs) 26 | 27 | 28 | def scatter_kwargs(inputs, kwargs, target_gpus, dim=0, chunk_sizes=None): 29 | r"""Scatter with support for kwargs dictionary""" 30 | inputs = scatter(inputs, target_gpus, dim, chunk_sizes) if inputs else [] 31 | kwargs = scatter(kwargs, target_gpus, dim, chunk_sizes) if kwargs else [] 32 | if len(inputs) < len(kwargs): 33 | inputs.extend([() for _ in range(len(kwargs) - len(inputs))]) 34 | elif len(kwargs) < len(inputs): 35 | kwargs.extend([{} for _ in range(len(inputs) - len(kwargs))]) 36 | inputs = tuple(inputs) 37 | kwargs = tuple(kwargs) 38 | return inputs, kwargs 39 | -------------------------------------------------------------------------------- /CenterNet-master/nms.py: -------------------------------------------------------------------------------- 1 | # faster rcnn 2 | import sys, json 3 | sys.path.append("../FASTER_RCNN/lib") 4 | from model.roi_layers import nms 5 | 6 | import torch 7 | from torch.autograd import Variable 8 | import numpy as np 9 | 10 | def xywh2xyxy(box): 11 | # print(box) 12 | x,y,w,h= box 13 | return [x,y,x+w,y+h] 14 | 15 | def nms_for_results(result_json, nms_threshold, output_json): 16 | all_boxes = json.load(open(result_json, "r")) 17 | print("Before NMS:", len(all_boxes)) 18 | # reformat 19 | all_data = {} 20 | for item in all_boxes: 21 | imgid = item["image_id"] 22 | if imgid not in all_data: 23 | all_data[imgid] = [] 24 | all_data[imgid].append(item) 25 | 26 | num_images = len(all_data) 27 | 28 | after_nms = [] 29 | for i, imgid in enumerate(all_data.keys()): # 30 | all_items = all_data[imgid] 31 | 32 | all_items.sort(key=lambda x:x["score"], reverse=True) 33 | pred_boxes = list(map(lambda x:xywh2xyxy(x["bbox"]), all_items)) 34 | cls_scores = list(map(lambda x:x["score"], all_items)) 35 | 36 | pred_boxes = Variable(torch.Tensor(pred_boxes)) 37 | cls_scores = Variable(torch.Tensor(cls_scores)) 38 | 39 | cls_dets = torch.cat((pred_boxes, cls_scores.unsqueeze(1)), 1) 40 | 41 | keep = nms(pred_boxes, cls_scores, nms_threshold) 42 | keep = keep.view(-1).long().cpu() 43 | 44 | keep_items = list(map(lambda x:all_items[x], keep)) 45 | 46 | after_nms.extend(keep_items) 47 | 48 | print("After NMS:", len(after_nms)) 49 | with open(output_json, "w") as f: 50 | json.dump(after_nms, f) 51 | 52 | -------------------------------------------------------------------------------- /CenterNet-master/nnet/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/nnet/__init__.py -------------------------------------------------------------------------------- /CenterNet-master/nnet/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/nnet/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/nnet/__pycache__/py_factory.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/nnet/__pycache__/py_factory.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/pycocotools/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'tylin' 2 | -------------------------------------------------------------------------------- /CenterNet-master/pycocotools/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/pycocotools/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/pycocotools/__pycache__/coco.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/pycocotools/__pycache__/coco.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/pycocotools/__pycache__/cocoeval.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/pycocotools/__pycache__/cocoeval.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/pycocotools/__pycache__/mask.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/pycocotools/__pycache__/mask.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/pycocotools/_mask.cpython-35m-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/pycocotools/_mask.cpython-35m-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /CenterNet-master/pycocotools/_mask.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/pycocotools/_mask.so -------------------------------------------------------------------------------- /CenterNet-master/requirments.txt: -------------------------------------------------------------------------------- 1 | imagesize 2 | opencv-python 3 | tqdm 4 | opencv 5 | numpy 6 | json 7 | pytorch==1.0.1 8 | importlib 9 | 10 | 11 | -------------------------------------------------------------------------------- /CenterNet-master/sample/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/sample/__init__.py -------------------------------------------------------------------------------- /CenterNet-master/sample/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/sample/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/sample/__pycache__/coco.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/sample/__pycache__/coco.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/sample/__pycache__/utils.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/sample/__pycache__/utils.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/test.sh: -------------------------------------------------------------------------------- 1 | python3 test.py CenterNet-52-ricotext --testiter 80000 --split val -------------------------------------------------------------------------------- /CenterNet-master/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/test/__init__.py -------------------------------------------------------------------------------- /CenterNet-master/test/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/test/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/test/__pycache__/coco.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/test/__pycache__/coco.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/train.sh: -------------------------------------------------------------------------------- 1 | python3 train.py CenterNet-52-ricotext -------------------------------------------------------------------------------- /CenterNet-master/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .tqdm import stdout_to_tqdm 2 | 3 | from .image import crop_image 4 | from .image import color_jittering_, lighting_, normalize_ 5 | -------------------------------------------------------------------------------- /CenterNet-master/utils/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/utils/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/utils/__pycache__/image.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/utils/__pycache__/image.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/utils/__pycache__/tqdm.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/CenterNet-master/utils/__pycache__/tqdm.cpython-35.pyc -------------------------------------------------------------------------------- /CenterNet-master/utils/image.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import random 4 | 5 | def grayscale(image): 6 | return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 7 | 8 | def normalize_(image, mean, std): 9 | image -= mean 10 | image /= std 11 | 12 | def lighting_(data_rng, image, alphastd, eigval, eigvec): 13 | alpha = data_rng.normal(scale=alphastd, size=(3, )) 14 | image += np.dot(eigvec, eigval * alpha) 15 | 16 | def blend_(alpha, image1, image2): 17 | image1 *= alpha 18 | image2 *= (1 - alpha) 19 | image1 += image2 20 | 21 | def saturation_(data_rng, image, gs, gs_mean, var): 22 | alpha = 1. + data_rng.uniform(low=-var, high=var) 23 | blend_(alpha, image, gs[:, :, None]) 24 | 25 | def brightness_(data_rng, image, gs, gs_mean, var): 26 | alpha = 1. + data_rng.uniform(low=-var, high=var) 27 | image *= alpha 28 | 29 | def contrast_(data_rng, image, gs, gs_mean, var): 30 | alpha = 1. + data_rng.uniform(low=-var, high=var) 31 | blend_(alpha, image, gs_mean) 32 | 33 | def color_jittering_(data_rng, image): 34 | functions = [brightness_, contrast_, saturation_] 35 | random.shuffle(functions) 36 | 37 | gs = grayscale(image) 38 | gs_mean = gs.mean() 39 | for f in functions: 40 | f(data_rng, image, gs, gs_mean, 0.4) 41 | 42 | def crop_image(image, center, size): 43 | cty, ctx = center 44 | height, width = size 45 | im_height, im_width = image.shape[0:2] 46 | cropped_image = np.zeros((height, width, 3), dtype=image.dtype) 47 | 48 | x0, x1 = max(0, ctx - width // 2), min(ctx + width // 2, im_width) 49 | y0, y1 = max(0, cty - height // 2), min(cty + height // 2, im_height) 50 | 51 | left, right = ctx - x0, x1 - ctx 52 | top, bottom = cty - y0, y1 - cty 53 | 54 | cropped_cty, cropped_ctx = height // 2, width // 2 55 | y_slice = slice(cropped_cty - top, cropped_cty + bottom) 56 | x_slice = slice(cropped_ctx - left, cropped_ctx + right) 57 | cropped_image[y_slice, x_slice, :] = image[y0:y1, x0:x1, :] 58 | 59 | border = np.array([ 60 | cropped_cty - top, 61 | cropped_cty + bottom, 62 | cropped_ctx - left, 63 | cropped_ctx + right 64 | ], dtype=np.float32) 65 | 66 | offset = np.array([ 67 | cty - height // 2, 68 | ctx - width // 2 69 | ]) 70 | 71 | return cropped_image, border, offset 72 | -------------------------------------------------------------------------------- /CenterNet-master/utils/tqdm.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import numpy as np 3 | import contextlib 4 | 5 | from tqdm import tqdm 6 | 7 | class TqdmFile(object): 8 | dummy_file = None 9 | def __init__(self, dummy_file): 10 | self.dummy_file = dummy_file 11 | 12 | def write(self, x): 13 | if len(x.rstrip()) > 0: 14 | tqdm.write(x, file=self.dummy_file) 15 | 16 | @contextlib.contextmanager 17 | def stdout_to_tqdm(): 18 | save_stdout = sys.stdout 19 | try: 20 | sys.stdout = TqdmFile(sys.stdout) 21 | yield save_stdout 22 | except Exception as exc: 23 | raise exc 24 | finally: 25 | sys.stdout = save_stdout 26 | -------------------------------------------------------------------------------- /DL_setup_troubleshootiing.md: -------------------------------------------------------------------------------- 1 | Source github: 2 | https://github.com/jwyang/faster-rcnn.pytorch/tree/pytorch-1.0 3 | https://github.com/Duankaiwen/CenterNet 4 | 5 | Environment: cuda 9.0, python 3.5, pytorch 1.0.1, ubuntu 16.04, Nvidia 1080 Ti 6 | 7 | 8 | 9 | # FASTER RCNN 10 | ``` 11 | pip install -r requirements.txt 12 | rm lib/build/* 13 | cd lib & python setup.py build develop 14 | ``` 15 | 16 | train.sh -- use to train the model 17 | test.sh -- use to test the test dataset 18 | demo.sh -- use to detect objects in imgs 19 | 20 | 21 | # CENTERNET 22 | ``` 23 | 24 | pip install -r requirements.txt 25 | rm models/py_utils/_cpools/build/* 26 | cd models/py_utils/_cpools & python setup.py install --user 27 | 28 | ``` 29 | 30 | demo.sh -- use to detect objects in imgs 31 | 32 | 33 | *Please setup FASTER_RCNN first* 34 | 35 | 36 | # ERROR: _cannot import name '_mask' 37 | ``` 38 | unzip cocoapi-master.zip 39 | cd cocoapi-master/PythonAPI 40 | sudo make 41 | 42 | ``` 43 | replace the old *pycocotools* FOLDER in CenterNet-master & FASTER_RCNN with the new one 44 | 45 | 46 | # ERROR FASTER_RCNN/lib/model/csrc/cuda/ROIAlign_cuda.cu:5:10: fatal error: THC/THC.h: No such file or directory #include 47 | ``` 48 | **Reason**: pytorch >1.10.0 removed this file 49 | **Solution**: 50 | You can replace the cu files in FASTER_RCNN/lib/model/csrc 51 | /cuda/ with files in https://github.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/tree/master/FASTER_RCNN/lib/model/csrc/cuda_support_pytorch_above_1.10 52 | 53 | Tested under Ubuntu 22.04, CUDA 12.0, cudnn 8.9.1, pytorch 2.2.0 54 | 55 | Alternatively, you can manually update these files following the rules below: 56 | 57 | Add these two header files, and remove `#include ` 58 | #include 59 | #include 60 | 61 | 1. For `THCCeilDiv` 62 | - Replace `THCCeilDiv` with `at::ceil_div` 63 | 1. For `THCudaCheck` 64 | - Replace `THCudaCheck` with `AT_CUDA_CHECK` 65 | 1. For `THCudaFree` 66 | - Replace `THCudaFree(state, mask_dev);` with `c10::cuda::CUDACachingAllocator::raw_delete(mask_dev);` 67 | 1. For `THCudaMalloc` 68 | - Replace `THCudaMalloc(state, boxes_num * col_blocks * sizeof(unsigned long long));` with `c10::cuda::CUDACachingAllocator::raw_alloc(boxes_num * col_blocks * sizeof(unsigned long long));` 69 | 70 | ``` 71 | -------------------------------------------------------------------------------- /FASTER_RCNN/INSTRUCTIONS--Modify-to-your-dataset: -------------------------------------------------------------------------------- 1 | modify code to your own dataset 2 | 3 | ==> lib/datasets/rico.py 4 | line 28: year -> year="" 5 | line 53-57: values -> "" 6 | line 102-103: 'COCO_'... --> (str(index)+.jpg) 7 | 8 | Line 48 => use to modify the number of training dataset 9 | 10 | ==> lib/datasets/factory.py 11 | line 16 : add 12 | from datasets.rico import rico 13 | 14 | line 63: add 15 | # set up rico 16 | for split in ['train', 'val', 'test']: 17 | name = 'rico_{}'.format(split) 18 | __sets[name] = (lambda split=split: rico(split, "rico")) 19 | 20 | ==> trainval_net.py 21 | line 180-184: 22 | 23 | elif args.dataset == "rico": 24 | args.imdb_name = "rico_train" 25 | args.imdbval_name = "rico_val" 26 | args.set_cfgs = ['ANCHOR_SCALES', '[4, 8, 16, 32]', 'ANCHOR_RATIOS', '[1, 2, 4, 8]', 'MAX_NUM_GT_BOXES', '30'] 27 | 28 | 29 | ==> train.sh 30 | python3 trainval_net.py \ 31 | --dataset rico \ 32 | --net res101 \ 33 | --bs 6 \ 34 | --nw 4 \ 35 | --lr 0.00025 \ 36 | --cuda \ 37 | --use_tfboard 38 | 39 | 40 | ==>demo.py 41 | line168: change class to your own class 42 | line 267: -> im_in = np.array(imread(im_file, as_gray=False, pilmode="RGB")) 43 | 44 | ==> lib/model/utils/config.py (no need now) 45 | line 289 46 | line 292 47 | line 295 48 | 49 | modify to your own value 50 | ['ANCHOR_SCALES', '[4, 8, 16, 32]', 'ANCHOR_RATIOS', '[1, 2, 4, 8]', 'MAX_NUM_GT_BOXES', '30'] 51 | 52 | 53 | ==> for debug -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/README.md: -------------------------------------------------------------------------------- 1 | source github: https://github.com/jwyang/faster-rcnn.pytorch/tree/pytorch-1.0 2 | 3 | # Faster RCNN 4 | 5 | ## Setup 6 | 7 | ``` 8 | cd FASTER_RCNN 9 | pip install -r requirements.txt 10 | rm -r lib/build/* 11 | cd lib & python setup.py build develop 12 | ``` 13 | 14 | ## Test 15 | 16 | ``` 17 | python demo.py \ 18 | --dataset [DATASET] \ 19 | --net res101 \ 20 | --load_dir results/run \ 21 | --pretrained_model_name faster_rcnn.pth \ 22 | --cuda \ 23 | --vis \ 24 | --image_dir [FOLDER-TO-TEST] \ 25 | ``` 26 | 27 | Dataset options: ricoCustomized, rico2k, rico10k, ricoDefault, ricoText 28 | 29 | Put the pretrained model in the folder *FASTER_RCNN/results/run/res101/[DATASET]* 30 | 31 | ## Common issues and solutions 32 | See [DL_setup_troubleshootiing.md](../DL_setup_troubleshootiing.md) 33 | 34 | **For more information, see https://github.com/jwyang/faster-rcnn.pytorch/tree/pytorch-1.0** 35 | 36 | 37 | -------------------------------------------------------------------------------- /FASTER_RCNN/__pycache__/_init_paths.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/__pycache__/_init_paths.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/_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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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: [512] 13 | DOUBLE_BIAS: False 14 | LEARNING_RATE: 0.001 15 | TEST: 16 | HAS_RPN: True 17 | SCALES: [512] 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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/data/README: -------------------------------------------------------------------------------- 1 | PUT YOUR DATA HERE, REFER TO THE SOURCE GITHUB FOR DETAILED FORMAT -------------------------------------------------------------------------------- /FASTER_RCNN/demo.sh: -------------------------------------------------------------------------------- 1 | python3 demo.py \ 2 | --dataset ricoText \ 3 | --net res101 \ 4 | --load_dir results/run \ 5 | --pretrained_model_name faster_rcnn.pth \ 6 | --cuda \ 7 | --vis \ 8 | --image_dir test_folder \ 9 | 10 | 11 | ** you only need to change the *image_dir* 12 | 13 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/_C.cpython-35m-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/_C.cpython-35m-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/faster_rcnn/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/faster_rcnn/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/nms/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/nms/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/nms/_ext/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/nms/_ext/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_align/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_align/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_align/_ext/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_align/_ext/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_align/functions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_align/functions/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_align/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_align/modules/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_crop/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_crop/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_crop/_ext/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_crop/_ext/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_crop/functions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_crop/functions/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_crop/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_crop/modules/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_pooling/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_pooling/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_pooling/_ext/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_pooling/_ext/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_pooling/functions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_pooling/functions/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_pooling/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/roi_pooling/modules/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/rpn/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/rpn/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/model/utils/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/pycocotools/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'tylin' 2 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/lib.linux-x86_64-3.5/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/temp.linux-x86_64-3.5/home/cheer/Project/UIObjectDetection/Models/DL_models_READY@USE/FASTER_RCNN/lib/model/csrc/cpu/ROIAlign_cpu.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/temp.linux-x86_64-3.5/home/cheer/Project/UIObjectDetection/Models/DL_models_READY@USE/FASTER_RCNN/lib/model/csrc/cpu/ROIAlign_cpu.o -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/temp.linux-x86_64-3.5/home/cheer/Project/UIObjectDetection/Models/DL_models_READY@USE/FASTER_RCNN/lib/model/csrc/cpu/nms_cpu.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/temp.linux-x86_64-3.5/home/cheer/Project/UIObjectDetection/Models/DL_models_READY@USE/FASTER_RCNN/lib/model/csrc/cpu/nms_cpu.o -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/temp.linux-x86_64-3.5/home/cheer/Project/UIObjectDetection/Models/DL_models_READY@USE/FASTER_RCNN/lib/model/csrc/cuda/ROIAlign_cuda.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/temp.linux-x86_64-3.5/home/cheer/Project/UIObjectDetection/Models/DL_models_READY@USE/FASTER_RCNN/lib/model/csrc/cuda/ROIAlign_cuda.o -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/temp.linux-x86_64-3.5/home/cheer/Project/UIObjectDetection/Models/DL_models_READY@USE/FASTER_RCNN/lib/model/csrc/cuda/ROIPool_cuda.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/temp.linux-x86_64-3.5/home/cheer/Project/UIObjectDetection/Models/DL_models_READY@USE/FASTER_RCNN/lib/model/csrc/cuda/ROIPool_cuda.o -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/temp.linux-x86_64-3.5/home/cheer/Project/UIObjectDetection/Models/DL_models_READY@USE/FASTER_RCNN/lib/model/csrc/cuda/nms.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/temp.linux-x86_64-3.5/home/cheer/Project/UIObjectDetection/Models/DL_models_READY@USE/FASTER_RCNN/lib/model/csrc/cuda/nms.o -------------------------------------------------------------------------------- /FASTER_RCNN/lib/build/temp.linux-x86_64-3.5/home/cheer/Project/UIObjectDetection/Models/DL_models_READY@USE/FASTER_RCNN/lib/model/csrc/vision.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/build/temp.linux-x86_64-3.5/home/cheer/Project/UIObjectDetection/Models/DL_models_READY@USE/FASTER_RCNN/lib/model/csrc/vision.o -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/datasets/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/datasets/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/datasets/__pycache__/coco.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/datasets/__pycache__/coco.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/datasets/__pycache__/ds_utils.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/datasets/__pycache__/ds_utils.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/datasets/__pycache__/factory.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/datasets/__pycache__/factory.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/datasets/__pycache__/imagenet.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/datasets/__pycache__/imagenet.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/datasets/__pycache__/imdb.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/datasets/__pycache__/imdb.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/datasets/__pycache__/pascal_voc.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/datasets/__pycache__/pascal_voc.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/datasets/__pycache__/rico.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/datasets/__pycache__/rico.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/datasets/__pycache__/vg.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/datasets/__pycache__/vg.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/datasets/__pycache__/vg_eval.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/datasets/__pycache__/vg_eval.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/datasets/__pycache__/voc_eval.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/datasets/__pycache__/voc_eval.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/dist/faster_rcnn-0.1-py3.5-linux-x86_64.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/dist/faster_rcnn-0.1-py3.5-linux-x86_64.egg -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/faster_rcnn.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/faster_rcnn.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | datasets 2 | model 3 | pycocotools 4 | roi_data_layer 5 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/_C.cpython-35m-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/_C.cpython-35m-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/faster_rcnn/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/faster_rcnn/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/faster_rcnn/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/faster_rcnn/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/faster_rcnn/__pycache__/faster_rcnn.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/faster_rcnn/__pycache__/faster_rcnn.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/faster_rcnn/__pycache__/resnet.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/faster_rcnn/__pycache__/resnet.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/faster_rcnn/__pycache__/vgg16.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/faster_rcnn/__pycache__/vgg16.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/nms/.gitignore: -------------------------------------------------------------------------------- 1 | *.c 2 | *.cpp 3 | *.so 4 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/nms/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/nms/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/nms/_ext/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/nms/_ext/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_align/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_align/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_align/_ext/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_align/_ext/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_align/functions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_align/functions/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_align/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_align/modules/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_crop/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_crop/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_crop/_ext/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_crop/_ext/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_crop/_ext/crop_resize/_crop_resize.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_crop/_ext/crop_resize/_crop_resize.so -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_crop/functions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_crop/functions/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_crop/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_crop/modules/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_layers/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_layers/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_layers/__pycache__/nms.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_layers/__pycache__/nms.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_layers/__pycache__/roi_align.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_layers/__pycache__/roi_align.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_layers/__pycache__/roi_pool.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_layers/__pycache__/roi_pool.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_pooling/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_pooling/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_pooling/_ext/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_pooling/_ext/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_pooling/functions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_pooling/functions/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/roi_pooling/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/roi_pooling/modules/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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); -------------------------------------------------------------------------------- /FASTER_RCNN/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); -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/rpn/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/rpn/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/rpn/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/rpn/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/rpn/__pycache__/anchor_target_layer.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/rpn/__pycache__/anchor_target_layer.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/rpn/__pycache__/bbox_transform.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/rpn/__pycache__/bbox_transform.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/rpn/__pycache__/generate_anchors.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/rpn/__pycache__/generate_anchors.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/rpn/__pycache__/proposal_layer.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/rpn/__pycache__/proposal_layer.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/rpn/__pycache__/proposal_target_layer_cascade.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/rpn/__pycache__/proposal_target_layer_cascade.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/rpn/__pycache__/rpn.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/rpn/__pycache__/rpn.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/utils/.gitignore: -------------------------------------------------------------------------------- 1 | *.c 2 | *.cpp 3 | *.so 4 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/utils/__init__.py -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/utils/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/utils/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/utils/__pycache__/blob.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/utils/__pycache__/blob.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/utils/__pycache__/config.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/utils/__pycache__/config.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/model/utils/__pycache__/net_utils.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/model/utils/__pycache__/net_utils.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/lib/roi_data_layer/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/roi_data_layer/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/roi_data_layer/__pycache__/minibatch.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/roi_data_layer/__pycache__/minibatch.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/roi_data_layer/__pycache__/roibatchLoader.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/roi_data_layer/__pycache__/roibatchLoader.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/lib/roi_data_layer/__pycache__/roidb.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/lib/roi_data_layer/__pycache__/roidb.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/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 | -------------------------------------------------------------------------------- /FASTER_RCNN/pycocotools/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'tylin' 2 | -------------------------------------------------------------------------------- /FASTER_RCNN/pycocotools/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/pycocotools/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/pycocotools/__pycache__/coco.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/pycocotools/__pycache__/coco.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/pycocotools/__pycache__/cocoeval.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/pycocotools/__pycache__/cocoeval.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/pycocotools/__pycache__/mask.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/pycocotools/__pycache__/mask.cpython-35.pyc -------------------------------------------------------------------------------- /FASTER_RCNN/pycocotools/_mask.cpython-35m-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/pycocotools/_mask.cpython-35m-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /FASTER_RCNN/pycocotools/_mask.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/pycocotools/_mask.so -------------------------------------------------------------------------------- /FASTER_RCNN/requirements.txt: -------------------------------------------------------------------------------- 1 | cython 2 | cffi 3 | opencv-python 4 | scipy 5 | msgpack 6 | easydict 7 | matplotlib 8 | pyyaml 9 | tensorboardX 10 | pytorch==1.0.1 11 | -------------------------------------------------------------------------------- /FASTER_RCNN/test.sh: -------------------------------------------------------------------------------- 1 | python3 test_net.py \ 2 | --dataset ricoBetter2 \ 3 | --net res101 \ 4 | --load_dir results/run \ 5 | --checksession 1 \ 6 | --checkepoch 7 \ 7 | --checkpoint 13593 \ 8 | --split test \ 9 | --cuda -------------------------------------------------------------------------------- /FASTER_RCNN/test_folder/12628.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/test_folder/12628.jpg -------------------------------------------------------------------------------- /FASTER_RCNN/test_folder/18116.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/test_folder/18116.jpg -------------------------------------------------------------------------------- /FASTER_RCNN/test_folder/30800.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/test_folder/30800.jpg -------------------------------------------------------------------------------- /FASTER_RCNN/test_folder/64046.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/FASTER_RCNN/test_folder/64046.jpg -------------------------------------------------------------------------------- /FASTER_RCNN/train.sh: -------------------------------------------------------------------------------- 1 | python3 trainval_net.py \ 2 | --dataset ricoBetter2 \ 3 | --net res101 \ 4 | --bs 6 \ 5 | --nw 4 \ 6 | --lr 0.00025 \ 7 | --epochs 7 \ 8 | --cuda \ 9 | --use_tfboard -------------------------------------------------------------------------------- /PyTorch-YOLOv3/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | build 4 | .git 5 | *.egg-info 6 | dist 7 | output 8 | data/coco 9 | backup 10 | weights/*.weights 11 | __pycache__ 12 | checkpoints 13 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/README.md: -------------------------------------------------------------------------------- 1 | # YOLOv3 2 | 3 | ## Setup 4 | 5 | ``` 6 | cd PyTorch-YOLOv3 7 | pip install -r requirements.txt 8 | ``` 9 | 10 | ## Test 11 | 12 | ``` 13 | python detect.py \ 14 | --dataset [DATASET] \ 15 | --weights_path result/run/[DATASET]/yolov3_ckpt.pth \ 16 | --image_folder [FOLDER-TO-TEST] 17 | ``` 18 | 19 | Dataset options: rico, rico2k, rico10k, rico5box, ricotext 20 | 21 | Place the pretrained model in the folder *PyTorch-YOLOv3/result/run/[DATASET]* 22 | 23 | 24 | **For more information, see https://github.com/eriklindernoren/PyTorch-YOLOv3** 25 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/config/coco.data: -------------------------------------------------------------------------------- 1 | classes= 80 2 | train=data/coco/trainvalno5k.txt 3 | valid=data/coco/5k.txt 4 | names=data/coco.names 5 | backup=backup/ 6 | eval=coco 7 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/config/rico.data: -------------------------------------------------------------------------------- 1 | classes=14 2 | train=data/rico/train.txt 3 | valid=data/rico/val.txt 4 | test=data/rico/test.txt 5 | names=data/rico/classes.names 6 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/config/rico10k.data: -------------------------------------------------------------------------------- 1 | classes=14 2 | train=data/rico10k/train.txt 3 | valid=data/rico10k/val.txt 4 | test=data/rico10k/test.txt 5 | names=data/rico10k/classes.names 6 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/config/rico2k.data: -------------------------------------------------------------------------------- 1 | classes=14 2 | train=data/rico2k/train.txt 3 | valid=data/rico2k/val.txt 4 | test=data/rico2k/test.txt 5 | names=data/rico2k/classes.names 6 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/config/rico5box.data: -------------------------------------------------------------------------------- 1 | classes=14 2 | train=data/rico/train.txt 3 | valid=data/rico/val.txt 4 | test=data/rico/test.txt 5 | names=data/rico/classes.names 6 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/config/ricotext.data: -------------------------------------------------------------------------------- 1 | classes=15 2 | train=data/ricotext/train.txt 3 | valid=data/ricotext/val.txt 4 | test=data/ricotext/test.txt 5 | names=data/ricotext/classes.names 6 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/data/rico/classes.names: -------------------------------------------------------------------------------- 1 | Button 2 | CheckBox 3 | Chronometer 4 | EditText 5 | ImageButton 6 | ImageView 7 | ProgressBar 8 | RadioButton 9 | RatingBar 10 | SeekBar 11 | Spinner 12 | Switch 13 | ToggleButton 14 | VideoView 15 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/data/rico10k/classes.names: -------------------------------------------------------------------------------- 1 | Button 2 | CheckBox 3 | Chronometer 4 | EditText 5 | ImageButton 6 | ImageView 7 | ProgressBar 8 | RadioButton 9 | RatingBar 10 | SeekBar 11 | Spinner 12 | Switch 13 | ToggleButton 14 | VideoView 15 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/data/rico2k/classes.names: -------------------------------------------------------------------------------- 1 | Button 2 | CheckBox 3 | Chronometer 4 | EditText 5 | ImageButton 6 | ImageView 7 | ProgressBar 8 | RadioButton 9 | RatingBar 10 | SeekBar 11 | Spinner 12 | Switch 13 | ToggleButton 14 | VideoView 15 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/data/rico5box/classes.names: -------------------------------------------------------------------------------- 1 | Button 2 | CheckBox 3 | Chronometer 4 | EditText 5 | ImageButton 6 | ImageView 7 | ProgressBar 8 | RadioButton 9 | RatingBar 10 | SeekBar 11 | Spinner 12 | Switch 13 | ToggleButton 14 | VideoView 15 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/data/ricotext/classes.names: -------------------------------------------------------------------------------- 1 | Button 2 | CheckBox 3 | Chronometer 4 | EditText 5 | ImageButton 6 | ImageView 7 | ProgressBar 8 | RadioButton 9 | RatingBar 10 | SeekBar 11 | Spinner 12 | Switch 13 | ToggleButton 14 | VideoView 15 | TextView 16 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/demo.sh: -------------------------------------------------------------------------------- 1 | python3 detect.py \ 2 | --weights_path result/run/rico/yolov3_ckpt.pth \ 3 | --dataset rico \ 4 | --image_folder ../FASTER_RCNN/test_folder 5 | 6 | 7 | --data_config config/custom.data -------------------------------------------------------------------------------- /PyTorch-YOLOv3/inference.sh: -------------------------------------------------------------------------------- 1 | python3 detect.py --image_folder data/samples/ -------------------------------------------------------------------------------- /PyTorch-YOLOv3/info: -------------------------------------------------------------------------------- 1 | 1. generate anchor boxes 2 | -> data/rico/train.txt 3 | replace 'images' with 'JPEGImages' 4 | rename data/rico/'images' as data/rico/'JPEGImages' 5 | 6 | go to darknet 7 | run 8 | bash ./gen_anchors.sh 9 | 10 | 2. config/yolov3-??.cfg, 11 | 12 | -> Training Yolo v3: 13 | 14 | change line batch to batch=64 15 | 16 | change line subdivisions to subdivisions=16 17 | #7 18 | set network size width=416 height=416 or any value multiple of 32: 19 | --> Line 9/10: 20 | width=608 21 | height=608 22 | 23 | ==> For classes = 14 24 | change line max_batches to (classes*2000 but not less than 4000), i.e. max_batches=6000 if you train for 3 classes 25 | --> Line 21: max_batches=28000 26 | 27 | change line steps to 80% and 90% of max_batches, f.e. steps=4800,5400 28 | --> Line 24: steps=22400,25200 29 | 30 | 31 | change line classes=80 to your number of objects in each of 3 [yolo]-layers: 32 | --> Line 611/697/784: classes=14 33 | 34 | change [filters=255] to filters=(classes + 5)x3 in the 3 [convolutional] before each [yolo] layer 35 | --> Line 604/690/777: filters=57 36 | 37 | change anchor box with the computed anchor box in step 1 38 | --> Line 610/696/783 39 | ## 50k 40 | anchors = 29, 16, 58, 26, 69, 42, 102, 50, 227, 34, 190,100, 527, 37, 459,159, 596,345 41 | ## 2k 42 | anchors = 29, 16, 51, 29, 83, 41, 337, 19, 146, 60, 53,283, 496, 42, 274,124, 582,272 43 | ## 10k 44 | anchors = 30, 16, 56, 30, 88, 46, 346, 13, 202, 40, 186,103, 519, 40, 454,159, 600,348 45 | 46 | 47 | ==> For classes = 15 48 | change line max_batches to (classes*2000 but not less than 4000), i.e. max_batches=6000 if you train for 3 classes 49 | --> Line 21: max_batches=30000 50 | 51 | change line steps to 80% and 90% of max_batches, f.e. steps=4800,5400 52 | --> Line 24: steps=24000,27000 53 | 54 | change line classes=80 to your number of objects in each of 3 [yolo]-layers: 55 | --> Line 611/697/784: classes=15 56 | 57 | change [filters=255] to filters=(classes + 5)x3 in the 3 [convolutional] before each [yolo] layer 58 | --> Line 604/690/777: filters=60 59 | 60 | change anchor box with the computed anchor box in step 1 61 | --> Line 610/696/783 62 | ## ricotext 63 | anchors = 38, 16, 122, 17, 61, 34, 98, 50, 334, 17, 194, 29, 475, 41, 210,107, 543,223 64 | 65 | 66 | you should change indexes of anchors masks= for each [yolo]-layer, so that 1st-[yolo]-layer has anchors larger than 60x60, 2nd larger than 30x30, 3rd remaining. -------------------------------------------------------------------------------- /PyTorch-YOLOv3/models.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/PyTorch-YOLOv3/models.pyc -------------------------------------------------------------------------------- /PyTorch-YOLOv3/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | torch>=1.0 3 | torchvision 4 | matplotlib 5 | tensorflow 6 | tensorboard 7 | terminaltables 8 | pillow 9 | tqdm 10 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/test.sh: -------------------------------------------------------------------------------- 1 | python3 test.py \ 2 | --weights_path run/rico/yolov3_ckpt_10.pth \ 3 | --model_def config/yolov3-rico.cfg \ 4 | --data_config config/rico.data \ 5 | --class_path data/rico/classes.names \ 6 | --dataset rico \ 7 | --split test \ 8 | --img_size 608 \ 9 | --batch_size 32 -------------------------------------------------------------------------------- /PyTorch-YOLOv3/train.sh: -------------------------------------------------------------------------------- 1 | python3 train.py \ 2 | --model_def config/yolov3-ricoMulti.cfg \ 3 | --data_config config/ricoMulti.data \ 4 | --pretrained_weights results/weights/yolov3.weights \ 5 | --dataset ricoMulti \ 6 | --img_size 608 \ 7 | --batch_size 6 \ 8 | --start_epoch 0 \ 9 | --multiscale_training True 10 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/PyTorch-YOLOv3/utils/__init__.py -------------------------------------------------------------------------------- /PyTorch-YOLOv3/utils/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/PyTorch-YOLOv3/utils/__init__.pyc -------------------------------------------------------------------------------- /PyTorch-YOLOv3/utils/augmentations.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn.functional as F 3 | import numpy as np 4 | 5 | 6 | def horisontal_flip(images, targets): 7 | images = torch.flip(images, [-1]) 8 | targets[:, 2] = 1 - targets[:, 2] 9 | return images, targets 10 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/utils/logger.py: -------------------------------------------------------------------------------- 1 | # import tensorflow as tf 2 | from tensorboardX import SummaryWriter 3 | 4 | 5 | class Logger(object): 6 | def __init__(self, log_dir): 7 | """Create a summary writer logging to log_dir.""" 8 | self.writer = SummaryWriter(log_dir) 9 | 10 | def scalar_summary(self, tag, value, step): 11 | """Log a scalar variable.""" 12 | # summary = tf.Summary(value=[tf.Summary.Value(tag=tag, simple_value=value)]) 13 | # self.writer.add_summary(summary, step) 14 | 15 | self.writer.add_scalar(tag, value, step) 16 | 17 | def list_of_scalars_summary(self, tag_value_pairs, step): 18 | """Log scalar variables.""" 19 | # summary = tf.Summary(value=[tf.Summary.Value(tag=tag, simple_value=value) for tag, value in tag_value_pairs]) 20 | # self.writer.add_summary(summary, step) 21 | for tag, value in tag_value_pairs: 22 | self.writer.add_scalar(tag, value, step) 23 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/utils/parse_config.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | def parse_model_config(path): 4 | """Parses the yolo-v3 layer configuration file and returns module definitions""" 5 | file = open(path, 'r') 6 | lines = file.read().split('\n') 7 | lines = [x for x in lines if x and not x.startswith('#')] 8 | lines = [x.rstrip().lstrip() for x in lines] # get rid of fringe whitespaces 9 | module_defs = [] 10 | for line in lines: 11 | if line.startswith('['): # This marks the start of a new block 12 | module_defs.append({}) 13 | module_defs[-1]['type'] = line[1:-1].rstrip() 14 | if module_defs[-1]['type'] == 'convolutional': 15 | module_defs[-1]['batch_normalize'] = 0 16 | else: 17 | key, value = line.split("=") 18 | value = value.strip() 19 | module_defs[-1][key.rstrip()] = value.strip() 20 | 21 | return module_defs 22 | 23 | def parse_data_config(path): 24 | """Parses the data configuration file""" 25 | options = dict() 26 | options['gpus'] = '0,1,2,3' 27 | options['num_workers'] = '10' 28 | with open(path, 'r') as fp: 29 | lines = fp.readlines() 30 | for line in lines: 31 | line = line.strip() 32 | if line == '' or line.startswith('#'): 33 | continue 34 | key, value = line.split('=') 35 | options[key.strip()] = value.strip() 36 | return options 37 | -------------------------------------------------------------------------------- /PyTorch-YOLOv3/utils/parse_config.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/PyTorch-YOLOv3/utils/parse_config.pyc -------------------------------------------------------------------------------- /PyTorch-YOLOv3/utils/utils.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/PyTorch-YOLOv3/utils/utils.pyc -------------------------------------------------------------------------------- /Xianyu/README.md: -------------------------------------------------------------------------------- 1 | # Xianyu 2 | 3 | ## Setup 4 | 5 | *Tesseract* 6 | 7 | ``` 8 | sudo add-apt-repository -y ppa:alex-p/tesseract-ocr 9 | sudo apt update 10 | sudo apt install -y tesseract-ocr 11 | ``` 12 | 13 | *Opencv* 14 | 15 | ``` 16 | python3 -m pip install opencv-python 17 | ``` 18 | 19 | ## Test 20 | 21 | ``` 22 | python3 detect.py --test_folder [FOLDER-TO-TEST] 23 | ``` 24 | 25 | For more details, see https://laptrinhx.com/ui2code-how-to-fine-tune-background-and-foreground-analysis-2293652041/ -------------------------------------------------------------------------------- /Xianyu/__pycache__/xianyu_merge.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/Xianyu/__pycache__/xianyu_merge.cpython-35.pyc -------------------------------------------------------------------------------- /Xianyu/__pycache__/xianyu_ocr.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/Xianyu/__pycache__/xianyu_ocr.cpython-35.pyc -------------------------------------------------------------------------------- /Xianyu/__pycache__/xianyu_utils.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/Xianyu/__pycache__/xianyu_utils.cpython-35.pyc -------------------------------------------------------------------------------- /Xianyu/detect.sh: -------------------------------------------------------------------------------- 1 | python3 detect.py --test_folder [FOLDER-TO-TEST] -------------------------------------------------------------------------------- /Xianyu/xianyu_utils.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import json 4 | from random import randint as rint 5 | import random 6 | random.seed(123) 7 | 8 | color_map = {'Text':(255,6,6), 'Compo':(6,255,6)} 9 | 10 | 11 | def resize_by_height(org, resize_height): 12 | w_h_ratio = org.shape[1] / org.shape[0] 13 | resize_w = resize_height * w_h_ratio 14 | re = cv2.resize(org, (int(resize_w), int(resize_height))) 15 | return re 16 | 17 | 18 | def draw_bounding_box_class(org, corners, compo_class, line=2, show=False, name='img', output=None): 19 | board = org.copy() 20 | for i in range(len(corners)): 21 | board = cv2.rectangle(board, (corners[i][0], corners[i][1]), (corners[i][2], corners[i][3]), color_map[compo_class[i]], line) 22 | # board = cv2.putText(board, compo_class[i], (corners[i][0]+5, corners[i][1]+20), 23 | # cv2.FONT_HERSHEY_SIMPLEX, 0.5, color_map[compo_class[i]], 2) 24 | if show: 25 | cv2.imshow(name, board) 26 | cv2.waitKey(0) 27 | 28 | if output is not None: 29 | cv2.imwrite(output, board) 30 | return board 31 | 32 | 33 | def draw_region(region, board, color=None, show=False): 34 | if color is None: 35 | color = (rint(0,255), rint(0,255), rint(0,255)) 36 | for point in region: 37 | board[point[0], point[1]] = color 38 | if show: 39 | cv2.imshow('region', board) 40 | cv2.waitKey() 41 | return board 42 | 43 | 44 | def draw_bounding_box(org, slices, color=(0, 255, 0), line=2, name='board', show=False, write_path=None): 45 | ''' 46 | :param slices: [[col_min, row_min, col_max, row_max]] 47 | ''' 48 | board = org.copy() 49 | for box in slices: 50 | board = cv2.rectangle(board, (box[0], box[1]), (box[2], box[3]), color, line) 51 | if show: 52 | cv2.imshow(name, resize_by_height(board, resize_height=800)) 53 | cv2.waitKey(0) 54 | if write_path is not None: 55 | cv2.imwrite(write_path, board) 56 | return board 57 | 58 | 59 | def save_corners_json(file_path, corners, category, new=True): 60 | ''' 61 | :param corners: [[col_min, row_min, col_max, row_max]] 62 | ''' 63 | if not new: 64 | f_in = open(file_path, 'r') 65 | components = json.load(f_in) 66 | else: 67 | components = {'compos': []} 68 | f_out = open(file_path, 'w') 69 | 70 | for i in range(len(corners)): 71 | corner = corners[i] 72 | c = {'category': category[i], 'column_min': corner[0], 'row_min': corner[1], 'column_max': corner[2], 'row_max': corner[3]} 73 | components['compos'].append(c) 74 | json.dump(components, f_out, indent=4) 75 | -------------------------------------------------------------------------------- /cocoapi-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenjshnn/Object-Detection-for-Graphical-User-Interface/449078d5ad2a20c88206d58f7bb9e7b92b832e7d/cocoapi-master.zip --------------------------------------------------------------------------------