def _load_pascal_annotation(self, index):
    '\n        Load image and bounding boxes info from XML file in the PASCAL VOC\n        format.\n        '
    filename = os.path.join(self._data_path, 'Annotations', (index + '.xml'))

    def get_data_from_tag(node, tag):
        return node.getElementsByTagName(tag)[0].childNodes[0].data
    with open(filename) as f:
        data = minidom.parseString(f.read())
    objs = data.getElementsByTagName('object')
    num_objs = len(objs)
    boxes = np.zeros((num_objs, 4), dtype=np.uint16)
    gt_classes = np.zeros(num_objs, dtype=np.int32)
    overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32)
    for (ix, obj) in enumerate(objs):
        x1 = (float(get_data_from_tag(obj, 'xmin')) - 1)
        y1 = (float(get_data_from_tag(obj, 'ymin')) - 1)
        x2 = (float(get_data_from_tag(obj, 'xmax')) - 1)
        y2 = (float(get_data_from_tag(obj, 'ymax')) - 1)
        cls = self._class_to_ind[str(get_data_from_tag(obj, 'name')).lower().strip()]
        boxes[ix, :] = [x1, y1, x2, y2]
        gt_classes[ix] = cls
        overlaps[(ix, cls)] = 1.0
    overlaps = scipy.sparse.csr_matrix(overlaps)
    gt_subclasses = np.zeros(num_objs, dtype=np.int32)
    gt_subclasses_flipped = np.zeros(num_objs, dtype=np.int32)
    subindexes = np.zeros((num_objs, self.num_classes), dtype=np.int32)
    subindexes_flipped = np.zeros((num_objs, self.num_classes), dtype=np.int32)
    if cfg.IS_RPN:
        if cfg.IS_MULTISCALE:
            boxes_all = np.zeros((0, 4), dtype=np.float32)
            for scale in cfg.TRAIN.SCALES:
                boxes_all = np.vstack((boxes_all, (boxes * scale)))
            gt_classes_all = np.tile(gt_classes, len(cfg.TRAIN.SCALES))
            s = PIL.Image.open(self.image_path_from_index(index)).size
            image_height = s[1]
            image_width = s[0]
            (boxes_grid, _, _) = get_boxes_grid(image_height, image_width)
            overlaps_grid = bbox_overlaps(boxes_grid.astype(np.float), boxes_all.astype(np.float))
            if (num_objs != 0):
                index = np.tile(range(num_objs), len(cfg.TRAIN.SCALES))
                max_overlaps = overlaps_grid.max(axis=0)
                fg_inds = []
                for k in range(1, self.num_classes):
                    fg_inds.extend(np.where(((gt_classes_all == k) & (max_overlaps >= cfg.TRAIN.FG_THRESH[(k - 1)])))[0])
                index_covered = np.unique(index[fg_inds])
                for i in range(self.num_classes):
                    self._num_boxes_all[i] += len(np.where((gt_classes == i))[0])
                    self._num_boxes_covered[i] += len(np.where((gt_classes[index_covered] == i))[0])
        else:
            assert (len(cfg.TRAIN.SCALES_BASE) == 1)
            scale = cfg.TRAIN.SCALES_BASE[0]
            feat_stride = 16
            anchors = generate_anchors()
            num_anchors = anchors.shape[0]
            s = PIL.Image.open(self.image_path_from_index(index)).size
            image_height = s[1]
            image_width = s[0]
            height = np.round(((((image_height * scale) - 1) / 4.0) + 1))
            height = np.floor(((((height - 1) / 2) + 1) + 0.5))
            height = np.floor(((((height - 1) / 2) + 1) + 0.5))
            width = np.round(((((image_width * scale) - 1) / 4.0) + 1))
            width = np.floor(((((width - 1) / 2.0) + 1) + 0.5))
            width = np.floor(((((width - 1) / 2.0) + 1) + 0.5))
            gt_boxes = (boxes * scale)
            shift_x = (np.arange(0, width) * feat_stride)
            shift_y = (np.arange(0, height) * feat_stride)
            (shift_x, shift_y) = np.meshgrid(shift_x, shift_y)
            shifts = np.vstack((shift_x.ravel(), shift_y.ravel(), shift_x.ravel(), shift_y.ravel())).transpose()
            A = num_anchors
            K = shifts.shape[0]
            all_anchors = (anchors.reshape((1, A, 4)) + shifts.reshape((1, K, 4)).transpose((1, 0, 2)))
            all_anchors = all_anchors.reshape(((K * A), 4))
            overlaps_grid = bbox_overlaps(all_anchors.astype(np.float), gt_boxes.astype(np.float))
            if (num_objs != 0):
                max_overlaps = overlaps_grid.max(axis=0)
                fg_inds = []
                for k in range(1, self.num_classes):
                    fg_inds.extend(np.where(((gt_classes == k) & (max_overlaps >= cfg.TRAIN.FG_THRESH[(k - 1)])))[0])
                for i in range(self.num_classes):
                    self._num_boxes_all[i] += len(np.where((gt_classes == i))[0])
                    self._num_boxes_covered[i] += len(np.where((gt_classes[fg_inds] == i))[0])
    return {'boxes': boxes, 'gt_classes': gt_classes, 'gt_subclasses': gt_subclasses, 'gt_subclasses_flipped': gt_subclasses_flipped, 'gt_overlaps': overlaps, 'gt_subindexes': subindexes, 'gt_subindexes_flipped': subindexes_flipped, 'flipped': False}
Load image and bounding boxes info from XML file in the PASCAL VOC
format.
def _load_pascal_annotation(self, index):
    '\n        Load image and bounding boxes info from XML file in the PASCAL VOC\n        format.\n        '
    filename = os.path.join(self._data_path, 'Annotations', (index + '.xml'))

    def get_data_from_tag(node, tag):
        return node.getElementsByTagName(tag)[0].childNodes[0].data
    with open(filename) as f:
        data = minidom.parseString(f.read())
    objs = data.getElementsByTagName('object')
    num_objs = len(objs)
    boxes = np.zeros((num_objs, 4), dtype=np.uint16)
    gt_classes = np.zeros(num_objs, dtype=np.int32)
    overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32)
    for (ix, obj) in enumerate(objs):
        x1 = (float(get_data_from_tag(obj, 'xmin')) - 1)
        y1 = (float(get_data_from_tag(obj, 'ymin')) - 1)
        x2 = (float(get_data_from_tag(obj, 'xmax')) - 1)
        y2 = (float(get_data_from_tag(obj, 'ymax')) - 1)
        cls = self._class_to_ind[str(get_data_from_tag(obj, 'name')).lower().strip()]
        boxes[ix, :] = [x1, y1, x2, y2]
        gt_classes[ix] = cls
        overlaps[(ix, cls)] = 1.0
    overlaps = scipy.sparse.csr_matrix(overlaps)
    gt_subclasses = np.zeros(num_objs, dtype=np.int32)
    gt_subclasses_flipped = np.zeros(num_objs, dtype=np.int32)
    subindexes = np.zeros((num_objs, self.num_classes), dtype=np.int32)
    subindexes_flipped = np.zeros((num_objs, self.num_classes), dtype=np.int32)
    if cfg.IS_RPN:
        if cfg.IS_MULTISCALE:
            boxes_all = np.zeros((0, 4), dtype=np.float32)
            for scale in cfg.TRAIN.SCALES:
                boxes_all = np.vstack((boxes_all, (boxes * scale)))
            gt_classes_all = np.tile(gt_classes, len(cfg.TRAIN.SCALES))
            s = PIL.Image.open(self.image_path_from_index(index)).size
            image_height = s[1]
            image_width = s[0]
            (boxes_grid, _, _) = get_boxes_grid(image_height, image_width)
            overlaps_grid = bbox_overlaps(boxes_grid.astype(np.float), boxes_all.astype(np.float))
            if (num_objs != 0):
                index = np.tile(range(num_objs), len(cfg.TRAIN.SCALES))
                max_overlaps = overlaps_grid.max(axis=0)
                fg_inds = []
                for k in range(1, self.num_classes):
                    fg_inds.extend(np.where(((gt_classes_all == k) & (max_overlaps >= cfg.TRAIN.FG_THRESH[(k - 1)])))[0])
                index_covered = np.unique(index[fg_inds])
                for i in range(self.num_classes):
                    self._num_boxes_all[i] += len(np.where((gt_classes == i))[0])
                    self._num_boxes_covered[i] += len(np.where((gt_classes[index_covered] == i))[0])
        else:
            assert (len(cfg.TRAIN.SCALES_BASE) == 1)
            scale = cfg.TRAIN.SCALES_BASE[0]
            feat_stride = 16
            anchors = generate_anchors()
            num_anchors = anchors.shape[0]
            s = PIL.Image.open(self.image_path_from_index(index)).size
            image_height = s[1]
            image_width = s[0]
            height = np.round(((((image_height * scale) - 1) / 4.0) + 1))
            height = np.floor(((((height - 1) / 2) + 1) + 0.5))
            height = np.floor(((((height - 1) / 2) + 1) + 0.5))
            width = np.round(((((image_width * scale) - 1) / 4.0) + 1))
            width = np.floor(((((width - 1) / 2.0) + 1) + 0.5))
            width = np.floor(((((width - 1) / 2.0) + 1) + 0.5))
            gt_boxes = (boxes * scale)
            shift_x = (np.arange(0, width) * feat_stride)
            shift_y = (np.arange(0, height) * feat_stride)
            (shift_x, shift_y) = np.meshgrid(shift_x, shift_y)
            shifts = np.vstack((shift_x.ravel(), shift_y.ravel(), shift_x.ravel(), shift_y.ravel())).transpose()
            A = num_anchors
            K = shifts.shape[0]
            all_anchors = (anchors.reshape((1, A, 4)) + shifts.reshape((1, K, 4)).transpose((1, 0, 2)))
            all_anchors = all_anchors.reshape(((K * A), 4))
            overlaps_grid = bbox_overlaps(all_anchors.astype(np.float), gt_boxes.astype(np.float))
            if (num_objs != 0):
                max_overlaps = overlaps_grid.max(axis=0)
                fg_inds = []
                for k in range(1, self.num_classes):
                    fg_inds.extend(np.where(((gt_classes == k) & (max_overlaps >= cfg.TRAIN.FG_THRESH[(k - 1)])))[0])
                for i in range(self.num_classes):
                    self._num_boxes_all[i] += len(np.where((gt_classes == i))[0])
                    self._num_boxes_covered[i] += len(np.where((gt_classes[fg_inds] == i))[0])
    return {'boxes': boxes, 'gt_classes': gt_classes, 'gt_subclasses': gt_subclasses, 'gt_subclasses_flipped': gt_subclasses_flipped, 'gt_overlaps': overlaps, 'gt_subindexes': subindexes, 'gt_subindexes_flipped': subindexes_flipped, 'flipped': False}