'Load image and bounding boxes info from txt file in the pascal subcategory exemplar format.'

def _load_pascal3d_voxel_exemplar_annotation(self, index):

    if (self._image_set == 'val'):
        return self._load_pascal_annotation(index)
    filename = os.path.join(self._pascal3d_path, cfg.SUBCLS_NAME, (index + '.txt'))
    assert os.path.exists(filename), 'Path    does    not    exist:    {}'.format(filename)
    lines = []
    lines_flipped = []
    with open(filename) as f:
        for line in f:
            words = line.split()
            subcls = int(words[1])
            is_flip = int(words[2])
            if (subcls != (-1)):
                if (is_flip == 0):
                    lines.append(line)
                else:
                    lines_flipped.append(line)
    num_objs = len(lines)
    assert (num_objs == len(lines_flipped)), 'The    number    of    flipped    objects    is    not    the    same!'
    gt_subclasses_flipped = np.zeros(num_objs, dtype=np.int32)
    for (ix, line) in enumerate(lines_flipped):
        words = line.split()
        subcls = int(words[1])
        gt_subclasses_flipped[ix] = subcls
    boxes = np.zeros((num_objs, 4), dtype=np.float32)
    gt_classes = np.zeros(num_objs, dtype=np.int32)
    gt_subclasses = np.zeros(num_objs, dtype=np.int32)
    overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32)
    subindexes = np.zeros((num_objs, self.num_classes), dtype=np.int32)
    subindexes_flipped = np.zeros((num_objs, self.num_classes), dtype=np.int32)
    for (ix, line) in enumerate(lines):
        words = line.split()
        cls = self._class_to_ind[words[0]]
        subcls = int(words[1])
        boxes[ix, :] = [(float(n) - 1) for n in words[3:7]]
        gt_classes[ix] = cls
        gt_subclasses[ix] = subcls
        overlaps[(ix, cls)] = 1.0
        subindexes[(ix, cls)] = subcls
        subindexes_flipped[(ix, cls)] = gt_subclasses_flipped[ix]
    overlaps = scipy.sparse.csr_matrix(overlaps)
    subindexes = scipy.sparse.csr_matrix(subindexes)
    subindexes_flipped = scipy.sparse.csr_matrix(subindexes_flipped)
    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 xrange(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 xrange(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
            base_size = 16
            ratios = [3.0, 2.0, 1.5, 1.0, 0.75, 0.5, 0.25]
            scales = (2 ** np.arange(1, 6, 0.5))
            anchors = generate_anchors(base_size, ratios, scales)
            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 xrange(1, self.num_classes):
                    fg_inds.extend(np.where(((gt_classes == k) & (max_overlaps >= cfg.TRAIN.FG_THRESH[(k - 1)])))[0])
                for i in xrange(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}
