Ejemplo n.º 1
0
    def __init__(self, name, batch_size, num_workers, device_id, num_gpu,
                 root=os.path.expanduser('~/.mxnet/datasets/face')):
        super().__init__(batch_size, num_workers, device_id, seed=12 + device_id)

        idx_files = [os.path.join(root, name, "train.idx")]
        rec_files = [os.path.join(root, name, "train.rec")]
        prop = open(os.path.join(root, name, "property"), "r").read().strip().split(',')
        assert len(prop) == 3
        self.num_classes = int(prop[0])
        self.image_size = [int(prop[1]), int(prop[2])]

        self._input = ops.MXNetReader(path=rec_files, index_path=idx_files, random_shuffle=True,
                                      num_shards=num_gpu, tensor_init_bytes=self.image_size[0] * self.image_size[1] * 8)
        self._decode = ops.nvJPEGDecoder(device="mixed", output_type=types.RGB)

        self._cmnp = ops.CropMirrorNormalize(device="gpu", output_dtype=types.FLOAT, output_layout=types.NCHW,
                                             crop=self.image_size, image_type=types.RGB,
                                             mean=[127.5, 127.5, 127.5], std=[127.5, 127.5, 127.5])
        self._contrast = ops.Contrast(device="gpu", )
        self._saturation = ops.Saturation(device="gpu", )
        self._brightness = ops.Brightness(device="gpu", )

        self._uniform = ops.Uniform(range=(0.7, 1.3))
        self._coin = ops.CoinFlip(probability=0.5)
        self.iter = 0
Ejemplo n.º 2
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")
    def aug(self, input_img):

        rot_angle = uniform(self.rot_rand[0], self.rot_rand[1])
        cont_un = uniform(self.cont_rand[0], self.cont_rand[1])
        bri_un = uniform(self.bri_rand[0], self.bri_rand[1])
        sat_un = uniform(self.sat_rand[0], self.sat_rand[1])
        hue_un = uniform(self.hue_rand[0], self.hue_rand[1])
        print(rot_angle)
        self.augmentations["rotate"] = ops.Rotate(
            device="gpu",
            angle=rot_angle,
            fill_value=255.,
            interp_type=types.INTERP_LINEAR)
        self.augmentations["contrast"] = ops.Contrast(device="gpu",
                                                      contrast=cont_un)
        self.augmentations["brightness"] = ops.Brightness(device="gpu",
                                                          brightness=bri_un)
        self.augmentations["saturation"] = ops.Saturation(device="gpu",
                                                          saturation=sat_un)
        self.augmentations["hue"] = ops.Hue(device="gpu", hue=hue_un)
        now_n = randint(self.aug_num_rad[0], self.aug_num_rad[1])

        aug_list = list(self.augmentations.values())
        shuffle(aug_list)
        aug_list = aug_list[:now_n]

        for now_aug in aug_list:
            input_img = now_aug(input_img)
        return input_img
Ejemplo n.º 4
0
    def __new__(cls, **kwargs):
        """Create a ``Brightness`` operator.

        Returns
        -------
        nvidia.dali.ops.Brightness
            The operator.

        """
        return ops.Brightness(device=context.get_device_type(), **kwargs)
Ejemplo n.º 5
0
    def __init__(self, batch_size, num_threads, path, training, annotations, world, device_id, mean, std, resize,
                 max_size, stride, rotate_augment=False,
                 augment_brightness=0.0,
                 augment_contrast=0.0, augment_hue=0.0,
                 augment_saturation=0.0):
        super().__init__(batch_size=batch_size, num_threads=num_threads, device_id=device_id,
                         prefetch_queue_depth=num_threads, seed=42)

        self.path = path
        self.training = training
        self.stride = stride
        self.iter = 0
        self.rotate_augment = rotate_augment
        self.augment_brightness = augment_brightness
        self.augment_contrast = augment_contrast
        self.augment_hue = augment_hue
        self.augment_saturation = augment_saturation

        self.reader = ops.COCOReader(annotations_file=annotations, file_root=path, num_shards=world,
                                     shard_id=torch.cuda.current_device(),
                                     ltrb=True, ratio=True, shuffle_after_epoch=True, save_img_ids=True)

        self.decode_train = ops.ImageDecoderSlice(device="mixed", output_type=types.RGB)
        self.decode_infer = ops.ImageDecoder(device="mixed", output_type=types.RGB)
        self.bbox_crop = ops.RandomBBoxCrop(device='cpu', ltrb=True, scaling=[0.3, 1.0],
                                            thresholds=[0.1, 0.3, 0.5, 0.7, 0.9])

        self.bbox_flip = ops.BbFlip(device='cpu', ltrb=True)
        self.img_flip = ops.Flip(device='gpu')
        self.coin_flip = ops.CoinFlip(probability=0.5)
        self.brightness = ops.Brightness(device='gpu')
        self.contrast = ops.Contrast(device='gpu')
        self.hue = ops.Hue(device='gpu')
        self.saturation = ops.Saturation(device='gpu')

        if rotate_augment:
            raise RuntimeWarning("--augment-rotate current has no effect when using the DALI data loader.")

        if isinstance(resize, list): resize = max(resize)
        self.rand_resize = ops.Uniform(range=[resize, float(max_size)])

        self.resize_train = ops.Resize(device='gpu', interp_type=types.DALIInterpType.INTERP_CUBIC, save_attrs=True)
        self.resize_infer = ops.Resize(device='gpu', interp_type=types.DALIInterpType.INTERP_CUBIC,
                                       resize_longer=max_size, save_attrs=True)

        padded_size = max_size + ((self.stride - max_size % self.stride) % self.stride)

        self.pad = ops.Paste(device='gpu', fill_value=0, ratio=1.1, min_canvas_size=padded_size, paste_x=0, paste_y=0)
        self.normalize = ops.CropMirrorNormalize(device='gpu', mean=mean, std=std, crop=(padded_size, padded_size),
                                                 crop_pos_x=0, crop_pos_y=0)
 def __init__(self, batch_size, num_threads, device_id, seed, image_dir):
     super(BrightnessPipeline, self).__init__(batch_size, num_threads,
                                              device_id, seed, image_dir)
     self.brightness = ops.Brightness(device="gpu", brightness=0.5)