Exemple #1
0
 def __init__(self, batch_size, num_threads, device_id, data_dir, crop):
     super(HybridTrainPipe, self).__init__(batch_size, num_threads,
                                           device_id, data_dir, crop)
     self.pad = ops.Paste(device="gpu",
                          fill_value=0,
                          ratio=1.1,
                          min_canvas_size=crop)
     self.res = ops.RandomResizedCrop(device="gpu",
                                      size=crop,
                                      random_area=[0.9, 1.1],
                                      random_aspect_ratio=1.33333)
     self.cutmix = ops.PythonFunction(function=cut_mixe_image,
                                      num_outputs=2,
                                      device='gpu')
     self.cmnp = ops.CropMirrorNormalize(
         device="gpu",
         output_dtype=types.FLOAT,
         output_layout=types.NCHW,
         image_type=types.RGB,
         mean=[0.485 * 255, 0.456 * 255, 0.406 * 255],
         std=[0.229 * 255, 0.224 * 255, 0.225 * 255])
     self.coin = ops.CoinFlip(probability=0.5)
     self.rotated = ops.Rotate(device="gpu", keep_size=True)
     self.rotated_rng = ops.Uniform(range=(-5.0, 5.0))
     self.brightness = ops.Brightness(device="gpu")
     self.brightness_rng = ops.Uniform(range=(0.8, 1.2))
     self.reshape = ops.Reshape(device="gpu", layout="HWC")
     self.one_hot = ops.OneHot(num_classes=3,
                               dtype=types.INT32,
                               device="cpu")
     self.jitter_rng = ops.CoinFlip(probability=0.3)
     self.jittered = ops.Jitter(device="gpu")
Exemple #2
0
    def __init__(self,
                 p: float = .5,
                 nDegree: int = 2,
                 fill_value: Union[float, int] = 0.):
        """Initialization

        Args:
            p (float, optional): Probability to apply this transformation. Defaults to .5.
            nDegree (int, optional): Each pixel is moved by a random amount in range [-nDegree/2, nDegree/2]. Defaults to 2.
            fill_value (Union[float,int], optional): Color value used for padding pixels. Defaults to 0..
        """

        self.jitter = ops.Jitter(device='gpu', fill_value=0, nDegree=nDegree)

        self.flip_coin = ops.CoinFlip(probability=p)
    def __init__(self,
                 cfg,
                 root_dir,
                 batch_size,
                 num_threads,
                 device_id=0,
                 is_train=True):
        super(TripletPipeline, self).__init__(batch_size,
                                              num_threads,
                                              device_id,
                                              seed=12)
        self.input_target_images = ops.ExternalSource()
        self.input_target_labels = ops.ExternalSource()
        self.input_pos_images = ops.ExternalSource()
        self.input_pos_labels = ops.ExternalSource()
        self.input_neg_images = ops.ExternalSource()
        self.input_neg_labels = ops.ExternalSource()
        self.dataset = CustomTripletIterator(batch_size, root_dir,
                                             cfg.random_shuffle)
        self.iterator = iter(self.dataset)
        self.is_train = is_train

        self.decode = ops.ImageDecoder(device='mixed', output_type=types.BGR)
        self.resize_op = ops.Resize(device='gpu', resize_longer=cfg.input_size)

        self.paste_ratio = ops.Uniform(range=(11, 15))
        self.paste = ops.Paste(device="gpu", fill_value=(255, 255, 255))
        # self.crop = ops.Crop(device ='gpu', crop=[224, 224])
        output_dtype = types.FLOAT16 if cfg.fp16_using else types.FLOAT
        # output_dtype = types.FLOAT
        self.normalize = ops.CropMirrorNormalize(
            device="gpu",
            crop=(cfg.input_size, cfg.input_size),
            mean=[0.485 * 255, 0.456 * 255, 0.406 * 255],
            std=[0.229 * 255, 0.224 * 255, 0.225 * 255],
            mirror=0,
            output_dtype=output_dtype,
            output_layout=types.NCHW,
            pad_output=False)

        self.rot_rand = (-30., 30.)
        self.cont_rand = (0.5, 1.5)
        self.bri_rand = (0.5, 1.5)
        self.sat_rand = (0.5, 1.5)
        self.hue_rand = (45., 55.)

        self.augmentations = {}
        self.augmentations["jitter"] = ops.Jitter(device="gpu")
        self.augmentations["water"] = ops.Water(device="gpu")
        # self.augmentations["shpere"] = ops.Sphere(device = "gpu")
        self.augmentations["warpaffine"] = ops.WarpAffine(
            device="gpu",
            matrix=[1.0, 0.8, 0.0, 0.0, 1.2, 0.0],
            use_image_center=True,
            interp_type=types.INTERP_LINEAR)

        # self.augmentations["paste"] = ops.Paste(device = "gpu", ratio = 2., fill_value = (55, 155, 155),
        #                                     paste_x = .5, paste_y = .4)
        # self.augmentations["resize"] = ops.Resize(device = "gpu", resize_shorter = 480)
        self.augmentations["flip_v"] = ops.Flip(device="gpu",
                                                vertical=1,
                                                horizontal=0)
        self.augmentations["flip_h"] = ops.Flip(device="gpu",
                                                vertical=0,
                                                horizontal=1)
        # self.uniform = ops.Uniform(range = (0.0, 1.0))

        self.aug_num_rad = (1, 3)
        self.aug_prop = 100
Exemple #4
0
 def __init__(
     self,
     train=False,
     batch_size=16,
     size=384,
     num_threads=4, 
     device_id=0
 ):
     super(ExternalSourcePipeline, self).__init__(
         batch_size, num_threads, device_id, seed=42
     )
     self.eii = iter(
         ExternalInputIterator(train, batch_size)
     )
     self.images_input = ops.ExternalSource()
     self.masks_input = ops.ExternalSource()
     if train:
         fixed_area = (size / 784)**2
         self.decode = ops.ImageDecoderRandomCrop(
             device="mixed",
             random_area=[fixed_area*0.7, fixed_area*1.3], 
             random_aspect_ratio=[0.7, 1.3],
         )
     else:
         self.decode = ops.ImageDecoderCrop(
             device="mixed", 
             crop=(size, size)
         )
     self.resize = ops.Resize(
         device="gpu", 
         interp_type=types.INTERP_TRIANGULAR,
         resize_x=size, 
         resize_y=size
     )
     self.mask_resize = ops.Resize(
         device="gpu", 
         interp_type=types.INTERP_NN,
         resize_x=size, 
         resize_y=size
     )
     self.normalize = ops.CropMirrorNormalize(
         device="gpu",
         mean=[0.5 * 255],  # 0.456 * 255, 0.406 * 255],
         std=[0.5 * 255],  # , 0.224 * 255, 0.225 * 255],
         output_layout=types.NCHW
     )
     self.mask_normalize = ops.CropMirrorNormalize(
         device="gpu",
         mean=[0],
         std=[255],
         output_layout=types.NCHW,
         image_type=types.GRAY,
     )
     # extra augmentations
     self.to_gray = ops.ColorSpaceConversion(
         device="gpu", image_type=types.RGB, output_type=types.GRAY
     )
     self.contrast = ops.BrightnessContrast(device="gpu")
     self.hsv = ops.Hsv(device="gpu")
     self.jitter = ops.Jitter(device ="gpu")
     # self.rng1 = ops.Uniform(range=[0, 1])
     self.rng2 = ops.Uniform(range=[0.8,1.2])
     self.rng3 = ops.Uniform(range=[-30, 30]) # for hue
     self.coin03 = ops.CoinFlip(probability=0.3)
     self.train = train