# Path: lib/fast_rcnn/config.py
# __C = edict()
# __C.IS_RPN = True
# __C.ANCHOR_SCALES = [8, 16, 32]
# __C.NCLASSES = 21
# __C.IS_MULTISCALE = False
# __C.IS_EXTRAPOLATING = True
# __C.REGION_PROPOSAL = 'RPN'
# __C.NET_NAME = 'VGGnet'
# __C.SUBCLS_NAME = 'voxel_exemplars'
# __C.TRAIN = edict()
# __C.TRAIN.SOLVER = 'Momentum'
# __C.TRAIN.WEIGHT_DECAY = 0.0005
# __C.TRAIN.LEARNING_RATE = 0.001
# __C.TRAIN.MOMENTUM = 0.9
# __C.TRAIN.GAMMA = 0.1
# __C.TRAIN.STEPSIZE = 50000
# __C.TRAIN.DISPLAY = 10
# __C.TRAIN.LOG_IMAGE_ITERS = 100
# __C.TRAIN.OHEM = False
# __C.TRAIN.RANDOM_DOWNSAMPLE = False
# __C.TRAIN.SCALES_BASE = (0.25, 0.5, 1.0, 2.0, 3.0)
# __C.TRAIN.KERNEL_SIZE = 5
# __C.TRAIN.ASPECTS= (1,)
# __C.TRAIN.SCALES = (600,)
# __C.TRAIN.MAX_SIZE = 1000
# __C.TRAIN.IMS_PER_BATCH = 2
# __C.TRAIN.BATCH_SIZE = 128
# __C.TRAIN.FG_FRACTION = 0.25
# __C.TRAIN.FG_THRESH = 0.5
# __C.TRAIN.BG_THRESH_HI = 0.5
# __C.TRAIN.BG_THRESH_LO = 0.1
# __C.TRAIN.USE_FLIPPED = True
# __C.TRAIN.BBOX_REG = True
# __C.TRAIN.BBOX_THRESH = 0.5
# __C.TRAIN.SNAPSHOT_ITERS = 5000
# __C.TRAIN.SNAPSHOT_PREFIX = 'VGGnet_fast_rcnn'
# __C.TRAIN.SNAPSHOT_INFIX = ''
# __C.TRAIN.USE_PREFETCH = False
# __C.TRAIN.BBOX_NORMALIZE_TARGETS = True
# __C.TRAIN.BBOX_INSIDE_WEIGHTS = (1.0, 1.0, 1.0, 1.0)
# __C.TRAIN.BBOX_NORMALIZE_TARGETS_PRECOMPUTED = True
# __C.TRAIN.BBOX_NORMALIZE_MEANS = (0.0, 0.0, 0.0, 0.0)
# __C.TRAIN.BBOX_NORMALIZE_STDS = (0.1, 0.1, 0.2, 0.2)
# __C.TRAIN.PROPOSAL_METHOD = 'selective_search'
# __C.TRAIN.ASPECT_GROUPING = True
# __C.TRAIN.DONTCARE_AREA_INTERSECTION_HI = 0.5
# __C.TRAIN.PRECLUDE_HARD_SAMPLES = True
# __C.TRAIN.HAS_RPN = True
# __C.TRAIN.RPN_POSITIVE_OVERLAP = 0.7
# __C.TRAIN.RPN_NEGATIVE_OVERLAP = 0.3
# __C.TRAIN.RPN_CLOBBER_POSITIVES = False
# __C.TRAIN.RPN_FG_FRACTION = 0.5
# __C.TRAIN.RPN_BATCHSIZE = 256
# __C.TRAIN.RPN_NMS_THRESH = 0.7
# __C.TRAIN.RPN_PRE_NMS_TOP_N = 12000
# __C.TRAIN.RPN_POST_NMS_TOP_N = 2000
# __C.TRAIN.RPN_MIN_SIZE = 16
# __C.TRAIN.RPN_BBOX_INSIDE_WEIGHTS = (1.0, 1.0, 1.0, 1.0)
# __C.TRAIN.RPN_POSITIVE_WEIGHT = -1.0
# __C.TEST = edict()
# __C.TEST.SCALES = (600,)
# __C.TEST.MAX_SIZE = 1000
# __C.TEST.NMS = 0.3
# __C.TEST.SVM = False
# __C.TEST.BBOX_REG = True
# __C.TEST.HAS_RPN = True
# __C.TEST.PROPOSAL_METHOD = 'selective_search'
# __C.TEST.RPN_NMS_THRESH = 0.7
# __C.TEST.RPN_PRE_NMS_TOP_N = 6000
# __C.TEST.RPN_POST_NMS_TOP_N = 300
# __C.TEST.RPN_MIN_SIZE = 16
# __C.DEDUP_BOXES = 1./16.
# __C.PIXEL_MEANS = np.array([[[102.9801, 115.9465, 122.7717]]])
# __C.RNG_SEED = 3
# __C.EPS = 1e-14
# __C.ROOT_DIR = osp.abspath(osp.join(osp.dirname(__file__), '..', '..'))
# __C.DATA_DIR = osp.abspath(osp.join(__C.ROOT_DIR, 'data'))
# __C.MODELS_DIR = osp.abspath(osp.join(__C.ROOT_DIR, 'models', 'pascal_voc'))
# __C.MATLAB = 'matlab'
# __C.EXP_DIR = 'default'
# __C.LOG_DIR = 'default'
# __C.USE_GPU_NMS = True
# __C.GPU_ID = 0
# def get_output_dir(imdb, weights_filename):
# def get_log_dir(imdb):
# def _merge_a_into_b(a, b):
# def cfg_from_file(filename):
# def cfg_from_list(cfg_list):


import numpy as np
from .config import cfg
from ..nms.gpu_nms import gpu_nms
from ..nms.cpu_nms import cpu_nms
# --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------


def nms(dets, thresh, force_cpu=False):
    """Dispatch to either CPU or GPU NMS implementations."""

    if dets.shape[0] == 0:
        return []
    if cfg.USE_GPU_NMS and not force_cpu:

# Path: lib/fast_rcnn/config.py
# __C = edict()
# __C.IS_RPN = True
# __C.ANCHOR_SCALES = [8, 16, 32]
# __C.NCLASSES = 21
# __C.IS_MULTISCALE = False
# __C.IS_EXTRAPOLATING = True
# __C.REGION_PROPOSAL = 'RPN'
# __C.NET_NAME = 'VGGnet'
# __C.SUBCLS_NAME = 'voxel_exemplars'
# __C.TRAIN = edict()
# __C.TRAIN.SOLVER = 'Momentum'
# __C.TRAIN.WEIGHT_DECAY = 0.0005
# __C.TRAIN.LEARNING_RATE = 0.001
# __C.TRAIN.MOMENTUM = 0.9
# __C.TRAIN.GAMMA = 0.1
# __C.TRAIN.STEPSIZE = 50000
# __C.TRAIN.DISPLAY = 10
# __C.TRAIN.LOG_IMAGE_ITERS = 100
# __C.TRAIN.OHEM = False
# __C.TRAIN.RANDOM_DOWNSAMPLE = False
# __C.TRAIN.SCALES_BASE = (0.25, 0.5, 1.0, 2.0, 3.0)
# __C.TRAIN.KERNEL_SIZE = 5
# __C.TRAIN.ASPECTS= (1,)
# __C.TRAIN.SCALES = (600,)
# __C.TRAIN.MAX_SIZE = 1000
# __C.TRAIN.IMS_PER_BATCH = 2
# __C.TRAIN.BATCH_SIZE = 128
# __C.TRAIN.FG_FRACTION = 0.25
# __C.TRAIN.FG_THRESH = 0.5
# __C.TRAIN.BG_THRESH_HI = 0.5
# __C.TRAIN.BG_THRESH_LO = 0.1
# __C.TRAIN.USE_FLIPPED = True
# __C.TRAIN.BBOX_REG = True
# __C.TRAIN.BBOX_THRESH = 0.5
# __C.TRAIN.SNAPSHOT_ITERS = 5000
# __C.TRAIN.SNAPSHOT_PREFIX = 'VGGnet_fast_rcnn'
# __C.TRAIN.SNAPSHOT_INFIX = ''
# __C.TRAIN.USE_PREFETCH = False
# __C.TRAIN.BBOX_NORMALIZE_TARGETS = True
# __C.TRAIN.BBOX_INSIDE_WEIGHTS = (1.0, 1.0, 1.0, 1.0)
# __C.TRAIN.BBOX_NORMALIZE_TARGETS_PRECOMPUTED = True
# __C.TRAIN.BBOX_NORMALIZE_MEANS = (0.0, 0.0, 0.0, 0.0)
# __C.TRAIN.BBOX_NORMALIZE_STDS = (0.1, 0.1, 0.2, 0.2)
# __C.TRAIN.PROPOSAL_METHOD = 'selective_search'
# __C.TRAIN.ASPECT_GROUPING = True
# __C.TRAIN.DONTCARE_AREA_INTERSECTION_HI = 0.5
# __C.TRAIN.PRECLUDE_HARD_SAMPLES = True
# __C.TRAIN.HAS_RPN = True
# __C.TRAIN.RPN_POSITIVE_OVERLAP = 0.7
# __C.TRAIN.RPN_NEGATIVE_OVERLAP = 0.3
# __C.TRAIN.RPN_CLOBBER_POSITIVES = False
# __C.TRAIN.RPN_FG_FRACTION = 0.5
# __C.TRAIN.RPN_BATCHSIZE = 256
# __C.TRAIN.RPN_NMS_THRESH = 0.7
# __C.TRAIN.RPN_PRE_NMS_TOP_N = 12000
# __C.TRAIN.RPN_POST_NMS_TOP_N = 2000
# __C.TRAIN.RPN_MIN_SIZE = 16
# __C.TRAIN.RPN_BBOX_INSIDE_WEIGHTS = (1.0, 1.0, 1.0, 1.0)
# __C.TRAIN.RPN_POSITIVE_WEIGHT = -1.0
# __C.TEST = edict()
# __C.TEST.SCALES = (600,)
# __C.TEST.MAX_SIZE = 1000
# __C.TEST.NMS = 0.3
# __C.TEST.SVM = False
# __C.TEST.BBOX_REG = True
# __C.TEST.HAS_RPN = True
# __C.TEST.PROPOSAL_METHOD = 'selective_search'
# __C.TEST.RPN_NMS_THRESH = 0.7
# __C.TEST.RPN_PRE_NMS_TOP_N = 6000
# __C.TEST.RPN_POST_NMS_TOP_N = 300
# __C.TEST.RPN_MIN_SIZE = 16
# __C.DEDUP_BOXES = 1./16.
# __C.PIXEL_MEANS = np.array([[[102.9801, 115.9465, 122.7717]]])
# __C.RNG_SEED = 3
# __C.EPS = 1e-14
# __C.ROOT_DIR = osp.abspath(osp.join(osp.dirname(__file__), '..', '..'))
# __C.DATA_DIR = osp.abspath(osp.join(__C.ROOT_DIR, 'data'))
# __C.MODELS_DIR = osp.abspath(osp.join(__C.ROOT_DIR, 'models', 'pascal_voc'))
# __C.MATLAB = 'matlab'
# __C.EXP_DIR = 'default'
# __C.LOG_DIR = 'default'
# __C.USE_GPU_NMS = True
# __C.GPU_ID = 0
# def get_output_dir(imdb, weights_filename):
# def get_log_dir(imdb):
# def _merge_a_into_b(a, b):
# def cfg_from_file(filename):
# def cfg_from_list(cfg_list):


# Path: lib/fast_rcnn/nms_wrapper.py
import numpy as np
from .config import cfg
from ..nms.gpu_nms import gpu_nms
from ..nms.cpu_nms import cpu_nms

# --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------


def nms(dets, thresh, force_cpu=False):
    """Dispatch to either CPU or GPU NMS implementations."""

    if dets.shape[0] == 0:
        return []
    if cfg.USE_GPU_NMS and not force_cpu:

        return gpu_nms(dets, thresh, device_id=cfg.GPU_ID)