示例#1
0
    def get_example(self, i):
        """Returns the i-th example.

        Returns a color image and bounding boxes. The image is in CHW format.
        If `self.bgr` is True, the image is in BGR. If not, it is in RGB.

        Args:
            i (int): The index of the example.

        Returns:
            tuple of an image and its label.

        """
        img = utils.read_image_as_array(
            osp.join(self.data_dir, 'images', self.fns[i]))  # RGB
        if img.ndim == 2:
            img = utils.gray2rgb(img)

        if self.crop_bbox:
            bbox = self.bboxes[i]  # (x, y, width, height)
            img = img[bbox[1]:bbox[1] + bbox[3], bbox[0]:bbox[0] + bbox[2]]
        label = self._data_labels[i]

        img = img[:, :, ::-1]  # RGB to BGR
        img = img.transpose(2, 0, 1)
        return img, label
示例#2
0
    def get_raw_data(self, i, rgb=True):
        """Returns the i-th example.

        This returns a color image and its label. The image is in HWC foramt.

        Args:
            i (int): The index of the example.
            rgb (bool): If false, the returned image will be in BGR.

        Returns:
            i-th example (image, label)

        """
        img = utils.read_image_as_array(
            osp.join(self.data_dir, 'images', self.fns[i]))  # RGB
        if img.ndim == 2:
            img = utils.gray2rgb(img)
        if not rgb:
            img = img[:, :, ::-1]

        if self.crop_bbox:
            bbox = self.bboxes[i]  # (x, y, width, height)
            img = img[bbox[1]:bbox[1] + bbox[3], bbox[0]:bbox[0] + bbox[2]]
        label = self._data_labels[i]
        return img, label
示例#3
0
 def get_example(self, i):
     img, keypoints = self.get_raw_data(i)
     if img.ndim == 2:
         img = utils.gray2rgb(img)
     img = img[:, :, ::-1]  # RGB to BGR
     img = img.transpose(2, 0, 1).astype(np.float32)
     return img, keypoints
示例#4
0
    def get_raw_data(self, i, rgb=True):
        # this i is transformed to id for the entire dataset
        original_idx = self.selected_ids[i]
        img = utils.read_image_as_array(
            osp.join(self.data_dir, 'images', self.fns[original_idx]))  # RGB
        keypoints = self.keypoints_dict[original_idx]
        keypoints = np.array(keypoints, dtype=np.float32)

        if self.crop_bbox:
            bbox = self.bboxes[original_idx]  # (x, y, width, height)
            img = img[bbox[1]:bbox[1] + bbox[3], bbox[0]:bbox[0] + bbox[2]]
            keypoints[:, :2] = keypoints[:, :2] - np.array([bbox[0], bbox[1]])

        if img.ndim == 2:
            img = utils.gray2rgb(img)
        if not rgb:
            img = img[:, :, ::-1]
        return img, keypoints
示例#5
0
    def get_example(self, i):
        """Returns the i-th example.

        Returns a color image, class_id. The image is in CHW format.
        The returned image is BGR.

        Args:
            i (int): The index of the example.
        Returns:
            i-th example

        """
        img = read_image_as_array(self.fns[i])
        if img.ndim == 2:
            img = utils.gray2rgb(img)
        img = img[:, :, ::-1]  # BGR to RGB
        img = img.transpose(2, 0, 1).astype(np.float32)

        label = self.labels[i]
        return img, label
示例#6
0
    def get_raw_data(self, i, rgb=True):
        """Returns the i-th example's image and class data in HWC format.

        The color image that is returned is RGB.

        Args:
            i (int): The index of the example.
            rgb (bool): If false, the returned image will be in BGR.

        Returns:
            i-th example (image, class_id, super_class_id)

        """
        img = utils.read_image_as_array(self.paths[i])
        if img.ndim == 2:
            img = utils.gray2rgb(img)
        if not rgb:
            img = img[:, :, ::-1]
        class_id = self.class_ids[i]
        super_class_id = self.super_class_ids[i]
        return img, class_id, super_class_id
示例#7
0
    def get_raw_data(self, i, rgb=True):
        """Returns the i-th example.

        This returns a color image and its label. The image is in HWC foramt.

        Args:
            i (int): The index of the example.
            rgb (bool): If false, the returned image will be in BGR.

        Returns:
            i-th example (image, label)

        """
        img = read_image_as_array(self.fns[i])
        if img.ndim == 2:
            img = utils.gray2rgb(img)
        if not rgb:
            img = img[:, :, ::-1]

        label = self.labels[i]
        return img, label
示例#8
0
    def get_by_class(self, class_id, i):
        """Returns the i-th example from the given class

        Note that the class_id starts from 1.
        The returned image is BGR.

        Args:
            class_id (int): The retrieved images will be in this class.
            i (int): The index of the example in the given class.

        Returns:
            i-th example from the given class.

        """
        img = read_image_as_array(self.fns_dict[class_id][i])
        if img.ndim == 2:
            img = utils.gray2rgb(img)
        img = img[:, :, ::-1]  # BGR to RGB

        img = img.transpose(2, 0, 1).astype(np.float32)
        return img
示例#9
0
    def get_example(self, i):
        """Returns the i-th example.

        Returns a color image, class_id and super_class_id. The image is in CHW
        format.
        The returned image is BGR.

        Args:
            i (int): The index of the example.
        Returns:
            i-th example
        """

        class_id = np.array(self.class_ids[i], np.int32)
        super_class_id = np.array(self.super_class_ids[i], np.int32)

        img = utils.read_image_as_array(self.paths[i])

        if img.ndim == 2:
            img = utils.gray2rgb(img)
        img = img[:, :, ::-1]  # RGB to BGR
        img = img.transpose(2, 0, 1).astype(np.float32)
        return img, class_id, super_class_id