what.models.detection.ssd.ssd.preprocessing API documentation

# what.models.detection.ssd.ssd.preprocessing

View Source

     1from ..transforms.transforms import *
     2
     3class TrainAugmentation:
     4    def __init__(self, size, mean=0, std=1.0):
     5        """
     6        Args:
     7            size: the size the of final image.
     8            mean: mean pixel value per channel.
     9        """
    10        self.mean = mean
    11        self.size = size
    12        self.augment = Compose([
    13            ConvertFromInts(),
    14            PhotometricDistort(),
    15            Expand(self.mean),
    16            RandomSampleCrop(),
    17            RandomMirror(),
    18            ToPercentCoords(),
    19            Resize(self.size),
    20            SubtractMeans(self.mean),
    21            lambda img, boxes=None, labels=None: (img / std, boxes, labels),
    22            ToTensor(),
    23        ])
    24
    25    def __call__(self, img, boxes, labels):
    26        """
    27        Args:
    28            img: the output of cv.imread in RGB layout.
    29            boxes: boundding boxes in the form of (x1, y1, x2, y2).
    30            labels: labels of boxes.
    31        """
    32        return self.augment(img, boxes, labels)
    33
    34class TestTransform:
    35    def __init__(self, size, mean=0.0, std=1.0):
    36        self.transform = Compose([
    37            ToPercentCoords(),
    38            Resize(size),
    39            SubtractMeans(mean),
    40            lambda img, boxes=None, labels=None: (img / std, boxes, labels),
    41            ToTensor(),
    42        ])
    43
    44    def __call__(self, image, boxes, labels):
    45        return self.transform(image, boxes, labels)
    46
    47class PredictionTransform:
    48    def __init__(self, size, mean=0.0, std=1.0):
    49        self.transform = Compose([
    50            Resize(size),
    51            SubtractMeans(mean),
    52            lambda img, boxes=None, labels=None: (img / std, boxes, labels),
    53            ToTensor()
    54        ])
    55
    56    def __call__(self, image):
    57        image, _, _ = self.transform(image)
    58        return image

class TrainAugmentation: View Source

     4class TrainAugmentation:
     5    def __init__(self, size, mean=0, std=1.0):
     6        """
     7        Args:
     8            size: the size the of final image.
     9            mean: mean pixel value per channel.
    10        """
    11        self.mean = mean
    12        self.size = size
    13        self.augment = Compose([
    14            ConvertFromInts(),
    15            PhotometricDistort(),
    16            Expand(self.mean),
    17            RandomSampleCrop(),
    18            RandomMirror(),
    19            ToPercentCoords(),
    20            Resize(self.size),
    21            SubtractMeans(self.mean),
    22            lambda img, boxes=None, labels=None: (img / std, boxes, labels),
    23            ToTensor(),
    24        ])
    25
    26    def __call__(self, img, boxes, labels):
    27        """
    28        Args:
    29            img: the output of cv.imread in RGB layout.
    30            boxes: boundding boxes in the form of (x1, y1, x2, y2).
    31            labels: labels of boxes.
    32        """
    33        return self.augment(img, boxes, labels)

TrainAugmentation(size, mean=0, std=1.0) View Source

     5    def __init__(self, size, mean=0, std=1.0):
     6        """
     7        Args:
     8            size: the size the of final image.
     9            mean: mean pixel value per channel.
    10        """
    11        self.mean = mean
    12        self.size = size
    13        self.augment = Compose([
    14            ConvertFromInts(),
    15            PhotometricDistort(),
    16            Expand(self.mean),
    17            RandomSampleCrop(),
    18            RandomMirror(),
    19            ToPercentCoords(),
    20            Resize(self.size),
    21            SubtractMeans(self.mean),
    22            lambda img, boxes=None, labels=None: (img / std, boxes, labels),
    23            ToTensor(),
    24        ])

Args: size: the size the of final image. mean: mean pixel value per channel.

class TestTransform: View Source

    35class TestTransform:
    36    def __init__(self, size, mean=0.0, std=1.0):
    37        self.transform = Compose([
    38            ToPercentCoords(),
    39            Resize(size),
    40            SubtractMeans(mean),
    41            lambda img, boxes=None, labels=None: (img / std, boxes, labels),
    42            ToTensor(),
    43        ])
    44
    45    def __call__(self, image, boxes, labels):
    46        return self.transform(image, boxes, labels)

TestTransform(size, mean=0.0, std=1.0) View Source

    36    def __init__(self, size, mean=0.0, std=1.0):
    37        self.transform = Compose([
    38            ToPercentCoords(),
    39            Resize(size),
    40            SubtractMeans(mean),
    41            lambda img, boxes=None, labels=None: (img / std, boxes, labels),
    42            ToTensor(),
    43        ])

class PredictionTransform: View Source

    48class PredictionTransform:
    49    def __init__(self, size, mean=0.0, std=1.0):
    50        self.transform = Compose([
    51            Resize(size),
    52            SubtractMeans(mean),
    53            lambda img, boxes=None, labels=None: (img / std, boxes, labels),
    54            ToTensor()
    55        ])
    56
    57    def __call__(self, image):
    58        image, _, _ = self.transform(image)
    59        return image

PredictionTransform(size, mean=0.0, std=1.0) View Source

    49    def __init__(self, size, mean=0.0, std=1.0):
    50        self.transform = Compose([
    51            Resize(size),
    52            SubtractMeans(mean),
    53            lambda img, boxes=None, labels=None: (img / std, boxes, labels),
    54            ToTensor()
    55        ])