# Path: detectron/datasets/json_dataset.py
# class JsonDataset(object):
#     def __init__(self, name):
#     def get_roidb(
#         self,
#         gt=False,
#         proposal_file=None,
#         min_proposal_size=2,
#         proposal_limit=-1,
#         crowd_filter_thresh=0
#     ):
#     def _prep_roidb_entry(self, entry):
#     def _add_gt_annotations(self, entry):
#     def _add_proposals_from_file(
#         self, roidb, proposal_file, min_proposal_size, top_k, crowd_thresh
#     ):
#     def _init_keypoints(self):
#     def _get_gt_keypoints(self, obj):
# def add_proposals(roidb, rois, scales, crowd_thresh):
# def _merge_proposal_boxes_into_roidb(roidb, box_list):
# def _filter_crowd_proposals(roidb, crowd_thresh):
# def _add_class_assignments(roidb):
# def _sort_proposals(proposals, id_field):
# def _remove_proposals_not_in_roidb(proposals, roidb, id_field):
#             I = np.where(maxes > 0)[0]
# 
# Path: detectron/datasets/roidb.py
# def combined_roidb_for_training(dataset_names, proposal_files):
#     def get_roidb(dataset_name, proposal_file):
# def extend_with_flipped_entries(roidb, dataset):
# def filter_for_training(roidb):
#     def is_valid(entry):
# def add_bbox_regression_targets(roidb):
# def compute_bbox_regression_targets(entry):
# def _compute_and_log_stats(roidb):
# 
# Path: detectron/utils/blob.py
# def get_image_blob(im, target_scale, target_max_size):
# def im_list_to_blob(ims):
# def prep_im_for_blob(im, pixel_means, target_size, max_size):
# def zeros(shape, int32=False):
# def ones(shape, int32=False):
# def py_op_copy_blob(blob_in, blob_out):
# def get_loss_gradients(model, loss_blobs):
# def serialize(obj):
# def deserialize(arr):


import logging
import detectron.roi_data.fast_rcnn as fast_rcnn_roi_data
from detectron.datasets import json_dataset
from detectron.datasets import roidb as roidb_utils
from detectron.utils import blob as blob_utils
##############################################################################

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals



logger = logging.getLogger(__name__)


class GenerateProposalLabelsOp(object):

    def forward(self, inputs, outputs):
        """See modeling.detector.GenerateProposalLabels for inputs/outputs
        documentation.
        """
        # During training we reuse the data loader code. We populate roidb
        # entries on the fly using the rois generated by RPN.
        # im_info: [[im_height, im_width, im_scale], ...]
        rois = inputs[0].data
        roidb = blob_utils.deserialize(inputs[1].data)
        im_info = inputs[2].data
        im_scales = im_info[:, 2]
        output_blob_names = fast_rcnn_roi_data.get_fast_rcnn_blob_names()
        # For historical consistency with the original Faster R-CNN
        # implementation we are *not* filtering crowd proposals.
        # This choice should be investigated in the future (it likely does
        # not matter).

# Path: detectron/datasets/json_dataset.py
# class JsonDataset(object):
#     def __init__(self, name):
#     def get_roidb(
#         self,
#         gt=False,
#         proposal_file=None,
#         min_proposal_size=2,
#         proposal_limit=-1,
#         crowd_filter_thresh=0
#     ):
#     def _prep_roidb_entry(self, entry):
#     def _add_gt_annotations(self, entry):
#     def _add_proposals_from_file(
#         self, roidb, proposal_file, min_proposal_size, top_k, crowd_thresh
#     ):
#     def _init_keypoints(self):
#     def _get_gt_keypoints(self, obj):
# def add_proposals(roidb, rois, scales, crowd_thresh):
# def _merge_proposal_boxes_into_roidb(roidb, box_list):
# def _filter_crowd_proposals(roidb, crowd_thresh):
# def _add_class_assignments(roidb):
# def _sort_proposals(proposals, id_field):
# def _remove_proposals_not_in_roidb(proposals, roidb, id_field):
#             I = np.where(maxes > 0)[0]
# 
# Path: detectron/datasets/roidb.py
# def combined_roidb_for_training(dataset_names, proposal_files):
#     def get_roidb(dataset_name, proposal_file):
# def extend_with_flipped_entries(roidb, dataset):
# def filter_for_training(roidb):
#     def is_valid(entry):
# def add_bbox_regression_targets(roidb):
# def compute_bbox_regression_targets(entry):
# def _compute_and_log_stats(roidb):
# 
# Path: detectron/utils/blob.py
# def get_image_blob(im, target_scale, target_max_size):
# def im_list_to_blob(ims):
# def prep_im_for_blob(im, pixel_means, target_size, max_size):
# def zeros(shape, int32=False):
# def ones(shape, int32=False):
# def py_op_copy_blob(blob_in, blob_out):
# def get_loss_gradients(model, loss_blobs):
# def serialize(obj):
# def deserialize(arr):


# Path: detectron/ops/generate_proposal_labels.py
import logging
import detectron.roi_data.fast_rcnn as fast_rcnn_roi_data
from detectron.datasets import json_dataset
from detectron.datasets import roidb as roidb_utils
from detectron.utils import blob as blob_utils

##############################################################################

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals



logger = logging.getLogger(__name__)


class GenerateProposalLabelsOp(object):

    def forward(self, inputs, outputs):
        """See modeling.detector.GenerateProposalLabels for inputs/outputs
        documentation.
        """
        # During training we reuse the data loader code. We populate roidb
        # entries on the fly using the rois generated by RPN.
        # im_info: [[im_height, im_width, im_scale], ...]
        rois = inputs[0].data
        roidb = blob_utils.deserialize(inputs[1].data)
        im_info = inputs[2].data
        im_scales = im_info[:, 2]
        output_blob_names = fast_rcnn_roi_data.get_fast_rcnn_blob_names()
        # For historical consistency with the original Faster R-CNN
        # implementation we are *not* filtering crowd proposals.
        # This choice should be investigated in the future (it likely does
        # not matter).

        json_dataset.add_proposals(roidb, rois, im_scales, crowd_thresh=0)