Beispiel #1
0
    def __init__(self,
                 img_height=300,
                 img_width=300,
                 background=(123, 117, 104),
                 labels_format={
                     'class_id': 0,
                     'xmin': 1,
                     'ymin': 2,
                     'xmax': 3,
                     'ymax': 4
                 }):
        '''
        Arguments:
            height (int): The desired height of the output images in pixels.
            width (int): The desired width of the output images in pixels.
            background (list/tuple, optional): A 3-tuple specifying the RGB color value of the
                background pixels of the translated images.
            labels_format (dict, optional): A dictionary that defines which index in the last axis of the labels
                of an image contains which bounding box coordinate. The dictionary maps at least the keywords
                'xmin', 'ymin', 'xmax', and 'ymax' to their respective indices within last axis of the labels array.
        '''

        self.labels_format = labels_format

        self.photometric_distortions = SSDPhotometricDistortions()
        self.expand = SSDExpand(background=background,
                                labels_format=self.labels_format)
        self.random_crop = SSDRandomCrop(labels_format=self.labels_format)
        self.random_flip = RandomFlip(dim='horizontal',
                                      prob=0.5,
                                      labels_format=self.labels_format)

        # This box filter makes sure that the resized images don't contain any degenerate boxes.
        # Resizing the images could lead the boxes to becomes smaller. For boxes that are already
        # pretty small, that might result in boxes with height and/or width zero, which we obviously
        # cannot allow.
        self.box_filter = BoxFilter(check_overlap=False,
                                    check_min_area=False,
                                    check_degenerate=True,
                                    labels_format=self.labels_format)

        self.resize = ResizeRandomInterp(height=img_height,
                                         width=img_width,
                                         interpolation_modes=[
                                             cv2.INTER_NEAREST,
                                             cv2.INTER_LINEAR, cv2.INTER_CUBIC,
                                             cv2.INTER_AREA, cv2.INTER_LANCZOS4
                                         ],
                                         box_filter=self.box_filter,
                                         labels_format=self.labels_format)

        self.sequence = [
            self.photometric_distortions, self.expand, self.random_crop,
            self.random_flip, self.resize
        ]
Beispiel #2
0
    def __init__(self,
                 img_height=300,
                 img_width=300,
                 background=(123, 117, 104),
                 labels_format={
                     'class_id': 0,
                     'xmin': 1,
                     'ymin': 2,
                     'xmax': 3,
                     'ymax': 4
                 }):

        self.labels_format = labels_format

        self.photometric_distortions = SSDPhotometricDistortions()
        self.expand = SSDExpand(background=background,
                                labels_format=self.labels_format)
        self.random_crop = SSDRandomCrop(labels_format=self.labels_format)
        self.random_flip = RandomFlip(dim='horizontal',
                                      prob=0.5,
                                      labels_format=self.labels_format)

        # This box filter makes sure that the resized images don't contain any degenerate boxes.
        # Resizing the images could lead the boxes to becomes smaller. For boxes that are already
        # pretty small, that might result in boxes with height and/or width zero, which we obviously
        # cannot allow.
        self.box_filter = BoxFilter(check_overlap=False,
                                    check_min_area=False,
                                    check_degenerate=True,
                                    labels_format=self.labels_format)

        self.resize = ResizeRandomInterp(height=img_height,
                                         width=img_width,
                                         interpolation_modes=[
                                             cv2.INTER_NEAREST,
                                             cv2.INTER_LINEAR, cv2.INTER_CUBIC,
                                             cv2.INTER_AREA, cv2.INTER_LANCZOS4
                                         ],
                                         box_filter=self.box_filter,
                                         labels_format=self.labels_format)

        self.sequence = [
            self.photometric_distortions, self.expand, self.random_crop,
            self.random_flip, self.resize
        ]
    def __init__(self,
                 img_height=300,
                 img_width=300,
                 background=(123, 117, 104),
                 labels_format={
                     'class_id': 0,
                     'xmin': 1,
                     'ymin': 2,
                     'xmax': 3,
                     'ymax': 4
                 }):
        '''
        Arguments:
            height (int): The desired height of the output images in pixels.
            width (int): The desired width of the output images in pixels.
            background (list/tuple, optional): A 3-tuple specifying the RGB color value of the
                background pixels of the translated images.
            labels_format (dict, optional): A dictionary that defines which index in the last axis of the labels
                of an image contains which bounding box coordinate. The dictionary maps at least the keywords
                'xmin', 'ymin', 'xmax', and 'ymax' to their respective indices within last axis of the labels array.
        '''

        self.labels_format = labels_format

        self.photometric_distortions = SSDPhotometricDistortions()
        self.expand = SSDExpand(background=background,
                                labels_format=self.labels_format)
        self.random_crop = SSDRandomCrop(labels_format=self.labels_format)
        self.random_flip = RandomFlip(dim='horizontal',
                                      prob=0.5,
                                      labels_format=self.labels_format)
        self.resize = ResizeRandomInterp(height=img_height,
                                         width=img_width,
                                         interpolation_modes=[
                                             cv2.INTER_NEAREST,
                                             cv2.INTER_LINEAR, cv2.INTER_CUBIC,
                                             cv2.INTER_AREA, cv2.INTER_LANCZOS4
                                         ],
                                         labels_format=self.labels_format)

        self.sequence = [
            self.photometric_distortions, self.expand, self.random_crop,
            self.random_flip, self.resize
        ]