Ejemplo n.º 1
0
    def __init__(self, batch_size, num_threads, device_id, prefetch, seed):
        super(CommonPipeline, self).__init__(batch_size,
                                             num_threads,
                                             device_id,
                                             prefetch_queue_depth=prefetch)

        self.decode_cpu = ops.HostDecoder(device="cpu", output_type=types.RGB)
        self.decode_crop = ops.HostDecoderSlice(device="cpu",
                                                output_type=types.RGB)
        self.crop = ops.SSDRandomCrop(device="cpu", num_attempts=1, seed=seed)
        self.crop2 = ops.RandomBBoxCrop(
            device="cpu",
            aspect_ratio=[0.5, 2.0],
            thresholds=[0, 0.1, 0.3, 0.5, 0.7, 0.9],
            scaling=[0.3, 1.0],
            ltrb=True,
            seed=seed)
        self.slice_cpu = ops.Slice(device="cpu")
        self.slice_gpu = ops.Slice(device="gpu")

        self.flip_cpu = ops.Flip(device="cpu")
        self.bb_flip_cpu = ops.BbFlip(device="cpu", ltrb=True)

        self.flip_gpu = ops.Flip(device="gpu")
        self.bb_flip_gpu = ops.BbFlip(device="gpu", ltrb=True)
Ejemplo n.º 2
0
    def __init__(self, batch_size, num_threads, path, training, annotations, world, device_id, mean, std, resize, max_size, stride):
        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.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)

        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, crop_pos_x=0, crop_pos_y=0)
    def __init__(self, batch_size, num_threads, device_id):
        super(TFRecordPipeline, self).__init__(batch_size,
                                         num_threads,
                                         device_id)
        self.input = ops.TFRecordReader(path = tfrecord,
                                        index_path = tfrecord_idx,
                                        features = {"image/encoded" : tfrec.FixedLenFeature((), tfrec.string, ""),
                                         'image/filename':            tfrec.FixedLenFeature([ ], tfrec.string, ''),
                                         'image/height':              tfrec.FixedLenFeature([1], tfrec.int64,  -1),
                                         'image/width':               tfrec.FixedLenFeature([1], tfrec.int64,  -1),
                                         'image/colorspace':          tfrec.FixedLenFeature([ ], tfrec.string, ''),
                                         'image/channels':            tfrec.FixedLenFeature([1], tfrec.int64,  -1),
                                         'image/format':              tfrec.FixedLenFeature([ ], tfrec.string, ''),
                                         'image/class/label':         tfrec.FixedLenFeature([1], tfrec.int64,  -1),
                                         'image/class/synset':        tfrec.FixedLenFeature([ ], tfrec.string, ''),
                                         'image/class/text':          tfrec.FixedLenFeature([ ], tfrec.string, ''),
                                         'image/object/bbox/xmin':    tfrec.VarLenFeature(tfrec.float32, 0.0),
                                         'image/object/bbox/ymin':    tfrec.VarLenFeature(tfrec.float32, 0.0),
                                         'image/object/bbox/xmax':    tfrec.VarLenFeature(tfrec.float32, 0.0),
                                         'image/object/bbox/ymax':    tfrec.VarLenFeature(tfrec.float32, 0.0),
                                         'image/object/bbox/label':   tfrec.FixedLenFeature([1], tfrec.int64, -1)})
        self.decode = ops.ImageDecoder(device = "mixed", output_type = types.RGB)

        self.resize = ops.Resize(device = "gpu", resize_x = 1920.,resize_y=1920.)
        self.vert_flip = ops.Flip(device = "gpu", horizontal=0)
        self.vert_coin = ops.CoinFlip(probability=0.5)
        self.cmnp = ops.CropMirrorNormalize(device = "gpu",
                                            output_dtype = types.FLOAT,
                                            crop = (1920, 1920),
                                            image_type = types.RGB,
                                            mean = [0., 0., 0.],
                                            std = [1., 1., 1.])
        self.uniform = ops.Uniform(range = (0.0, 1.0))
        self.iter = 0
Ejemplo n.º 4
0
 def __init__(self,
              batch_size,
              num_threads,
              device_id,
              data_dir,
              crop,
              size,
              local_rank=0,
              world_size=1):
     super(HybridValPipe_CIFAR, self).__init__(batch_size,
                                               num_threads,
                                               device_id,
                                               seed=12 + device_id)
     self.iterator = iter(CIFAR_INPUT_ITER(batch_size, 'val',
                                           root=data_dir))
     self.input = ops.ExternalSource()
     self.input_label = ops.ExternalSource()
     self.pad = ops.Paste(device="gpu", ratio=1., fill_value=0)
     self.uniform = ops.Uniform(range=(0., 1.))
     self.crop = ops.Crop(device="gpu", crop_h=32, crop_w=32)
     self.coin = ops.CoinFlip(probability=0.5)
     self.flip = ops.Flip(device="gpu")
     self.cmnp = ops.CropMirrorNormalize(device="gpu",
                                         output_layout=types.NCHW,
                                         mean=[125.31, 122.95, 113.87],
                                         std=[63.0, 62.09, 66.70])
Ejemplo n.º 5
0
 def __init__(self, params, device_id, files, labels):
     super().__init__(params.batch_size,
                      params.num_gpus * 8,
                      device_id,
                      seed=params.seed)
     # file_root有坑,并不是文件夹名字就是label,按照文件夹顺序(1, 10, 11, 2, 20, 21, ...)分别给与0,1,2,3,4...标签
     self.input = ops.FileReader(files=files,
                                 labels=labels,
                                 random_shuffle=True)
     self.decocer = ops.ImageDecoder(device='mixed', output_type=types.RGB)
     self.resize = ops.Resize(device='gpu', resize_shorter=224)
     self.pos_rng_x = ops.random.Uniform(range=(0.0, 1.0))
     self.pos_rng_y = ops.random.Uniform(range=(0.0, 1.0))
     self.crop = ops.Crop(device='gpu', crop_h=224, crop_w=224)
     self.flip = ops.Flip(device='gpu')
     self.coinflip = ops.random.CoinFlip(probability=0.5)
     self.hsv = ops.Hsv(device='gpu')
     self.saturation = ops.random.Uniform(range=(0.8, 1.0))
     self.value = ops.random.Uniform(range=(0.8, 1.0))
     mean = torch.Tensor(params.mean).unsqueeze(0).unsqueeze(0) * 255
     std = torch.Tensor(params.std).unsqueeze(0).unsqueeze(0) * 255
     self.normalize = ops.Normalize(axes=[0, 1],
                                    mean=mean,
                                    stddev=std,
                                    device='gpu',
                                    batch=False)
     self.transpose = ops.Transpose(device='gpu', perm=[2, 0, 1])
Ejemplo n.º 6
0
    def __new__(cls, horizontal=None, vertical=None, depthwise=None, **kwargs):
        """Create a ``Flip`` operator.

        Parameters
        ----------
        horizontal : int, optional
            Whether to apply the horizontal flip.
        vertical : int, optional
            Whether to apply the vertical flip.
        depthwise : bool, optional, default=True
            Whether to apply the depthwise flip.

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

        """
        return ops.Flip(
            horizontal=horizontal,
            vertical=vertical,
            depthwise=depthwise,
            device=context.get_device_type(),
            **kwargs
        )
Ejemplo n.º 7
0
    def __init__(self,
                 root,
                 split,
                 batch_size,
                 device_id,
                 dali_cpu=False,
                 local_rank=0,
                 world_size=1,
                 num_workers=2,
                 augment=False,
                 resize=False,
                 resize_size=314,
                 crop=True,
                 crop_size=314,
                 shuffle=True,
                 flip=True,
                 rotate=False,
                 rotate_angle=10.0):
        super(VOCDali, self).__init__(batch_size,
                                      num_threads=num_workers,
                                      device_id=device_id,
                                      seed=12 + device_id)
        self.iterator = iter(VOCIter(batch_size, split, root, shuffle))
        self.split = split
        assert self.split in ['train', 'val']
        dali_device = "gpu" if not dali_cpu else "cpu"
        self.input = ops.ExternalSource()
        self.input_label = ops.ExternalSource()

        self.is_flip = flip
        self.is_rotate = rotate
        self.is_augment = augment
        self.is_crop = crop
        self.is_resize = resize

        self.decode = ops.ImageDecoder(device='mixed', output_type=types.RGB)
        # self.cast = ops.Cast(device='gpu', dtype=types.INT32)
        self.rng = ops.Uniform(range=(0., 1.))
        self.coin = ops.CoinFlip(probability=0.5)
        # 定义大小
        self.resize = ops.Resize(device="gpu",
                                 resize_x=resize_size,
                                 resize_y=resize_size,
                                 interp_type=types.INTERP_TRIANGULAR)
        # 定义旋转
        self.rotate = ops.Rotate(device="gpu", angle=rotate_angle)
        # 定义翻转
        self.flip = ops.Flip(device="gpu", vertical=1, horizontal=0)
        # 定义剪裁
        self.crop = ops.Crop(device=dali_device,
                             crop_h=crop_size,
                             crop_w=crop_size)
        # 定义正则化
        self.cmnp = ops.CropMirrorNormalize(
            device=dali_device,
            output_dtype=types.FLOAT,
            output_layout=types.NCHW,
            image_type=types.RGB,
            mean=[0.45734706 * 255, 0.43338275 * 255, 0.40058118 * 255],
            std=[0.23965294 * 255, 0.23532275 * 255, 0.2398498 * 255])
    def __init__(self,
                 DATA_PATH,
                 input_height,
                 batch_size,
                 copies,
                 stage,
                 num_threads,
                 device_id,
                 seed=1729):
        super(SimCLRTransform, self).__init__(batch_size,
                                              num_threads,
                                              device_id,
                                              seed=seed)

        #this lets our pytorch compat function find the length of our dataset
        self.num_samples = len(ImageFolder(DATA_PATH))

        self.copies = copies
        self.input_height = input_height
        self.stage = stage

        self.input = ops.FileReader(file_root=DATA_PATH,
                                    random_shuffle=True,
                                    seed=seed)
        self.to_int64 = ops.Cast(dtype=types.INT64, device="gpu")
        self.to_int32_cpu = ops.Cast(dtype=types.INT32, device="cpu")

        self.coin = ops.random.CoinFlip(probability=0.5)
        self.uniform = ops.random.Uniform(range=[0.6, 0.9])
        self.blur_amt = ops.random.Uniform(values=[
            float(i) for i in range(1, int(0.1 * self.input_height), 2)
        ])
        self.angles = ops.random.Uniform(range=[0, 360])
        self.cast = ops.Cast(dtype=types.FLOAT, device='gpu')
        self.decode = ops.ImageDecoder(device='mixed', output_type=types.RGB)

        self.crop = ops.RandomResizedCrop(size=self.input_height,
                                          minibatch_size=batch_size,
                                          random_area=[0.75, 1.0],
                                          device="gpu")
        self.resize = ops.Resize(resize_x=self.input_height,
                                 resize_y=self.input_height,
                                 device="gpu")
        self.flip = ops.Flip(vertical=self.coin(),
                             horizontal=self.coin(),
                             device="gpu")
        self.colorjit_gray = ops.ColorTwist(brightness=self.uniform(),
                                            contrast=self.uniform(),
                                            hue=self.uniform(),
                                            saturation=self.uniform(),
                                            device="gpu")
        self.blur = ops.GaussianBlur(window_size=self.to_int32_cpu(
            self.blur_amt()),
                                     device="gpu")
        self.rotate = ops.Rotate(
            angle=self.angles(),
            keep_size=True,
            interp_type=types.DALIInterpType.INTERP_LINEAR,
            device="gpu")
        self.swapaxes = ops.Transpose(perm=[2, 0, 1], device="gpu")
    def __init__(self, root_dir, batch_size, num_threads, device_id,
                 use_shift_scale=False,
                 num_shards=None, shard_id=None):
        super().__init__(batch_size, num_threads, device_id, seed=12)

        self.random_angle = ops.Uniform(range=(0, 360.0))
        self.random = ops.Uniform(range=(0.5, 1.5))
        self.random_coin = ops.CoinFlip()

        self.input = ops.FileReader(
            file_root=root_dir, random_shuffle=True,
            num_shards=num_shards, shard_id=shard_id,
        )

        self.decode = ops.ImageDecoder(device='mixed')
        self.rotate = ops.Rotate(device='gpu', interp_type=types.INTERP_LINEAR)
        self.crop = ops.Crop(device='gpu', crop=(224, 224))
        self.use_shift_scale = use_shift_scale
        if self.use_shift_scale:
            self.shift_scale = ops.RandomResizedCrop(
                device='gpu',
                size=(224, 224),
                interp_type=types.INTERP_LINEAR,
                random_area=(0.3, 1.0),
            )
        self.flip = ops.Flip(device='gpu')
        self.color_twist = ops.ColorTwist(device='gpu')
Ejemplo n.º 10
0
    def __init__(self, DATA_PATH, input_height, batch_size, num_threads,
                 device_id):
        super(SimCLRTrainDataTransform, self).__init__(batch_size,
                                                       num_threads,
                                                       device_id,
                                                       seed=12)

        self.COPIES = 3

        self.input_height = input_height
        self.input = ops.FileReader(file_root=DATA_PATH,
                                    random_shuffle=True,
                                    seed=12)

        self.coin = ops.CoinFlip(probability=0.5)
        self.uniform = ops.Uniform(range=[0.7, 1.3])  #-1 to 1
        #read image (I think that has to be cpu, do a mixed operation to decode into gpu)
        self.decode = ops.ImageDecoder(device='mixed', output_type=types.RGB)
        self.crop = ops.RandomResizedCrop(size=self.input_height, device="gpu")
        self.flip = ops.Flip(vertical=self.coin(),
                             horizontal=self.coin(),
                             device="gpu")
        self.colorjit_gray = ops.ColorTwist(brightness=self.uniform(),
                                            contrast=self.uniform(),
                                            hue=self.uniform(),
                                            saturation=self.uniform(),
                                            device="gpu")
        self.blur = ops.GaussianBlur(window_size=int(0.1 * self.input_height),
                                     device="gpu")
        self.swapaxes = ops.Transpose(perm=[2, 0, 1], device="gpu")

        self.to_int64 = ops.Cast(dtype=types.INT64, device="gpu")
    def __init__(self, batch_size, sequence_length, num_threads, device_id, file_root, crop_size, transforms=None):
        super(VideoReaderPipeline, self).__init__(batch_size, num_threads, device_id, seed=12)
        self.reader = ops.VideoReader(
            device='gpu',
            file_root=file_root,
            sequence_length=sequence_length,
            normalized=False,
            random_shuffle=True,
            image_type=types.RGB,
            dtype=types.UINT8,
            initial_fill=16
        )

        self.crop = ops.Crop(device="gpu", crop=crop_size, output_dtype=types.FLOAT)
        self.transpose = ops.Transpose(device="gpu", perm=[3, 0, 1, 2])
        self.uniform = ops.Uniform(range=(0.0, 1.0))
        self.flip = ops.Flip(device="gpu", horizontal=1, vertical=0)
        # self.normalize = ops.NormalizePermute(
        #     device="gpu",
        #     mean=[0.485, 0.456, 0.406],
        #     std=[0.229, 0.224, 0.225],
        #     width=224,
        #     height=224
        # )
        self.cmn = ops.CropMirrorNormalize(
             device="gpu",
             output_dtype=types.FLOAT,
        #     # output_layout=types.NCHW,
             crop=(224, 224),
             image_type=types.RGB,
             mean=[0.485, 0.456, 0.406],
             std=[0.229, 0.224, 0.225]
        )
    def __init__(self,
                 batch_size,
                 num_threads,
                 device_id,
                 data_dir,
                 crop,
                 size=256,
                 dali_cpu=False,
                 local_rank=0,
                 world_size=1):
        super(HybridTrainPipe, self).__init__(batch_size,
                                              num_threads,
                                              device_id,
                                              seed=12 + device_id)
        dali_device = "gpu"
        self.input = ops.FileReader(file_root=data_dir,
                                    shard_id=local_rank,
                                    num_shards=world_size,
                                    random_shuffle=True)
        self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB)
        # self.res = ops.Resize(device="gpu", resize_x=size, resize_y=size, interp_type=types.INTERP_LINEAR)
        self.res = ops.Resize(device="gpu",
                              resize_shorter=size,
                              interp_type=types.INTERP_LINEAR)
        self.rescrop = ops.RandomResizedCrop(device="gpu",
                                             size=crop,
                                             random_area=[0.08, 1.25])
        self.bc = ops.BrightnessContrast(device="gpu",
                                         brightness=0.5,
                                         contrast=0.6)

        # Will flip vertically with prob of 0.1
        self.vert_flip = ops.Flip(device='gpu', horizontal=0)
        self.vert_coin = ops.CoinFlip(probability=0.4)

        self.transform_source = ops.ExternalSource()
        self.warp_keep_size = ops.WarpAffine(
            device="gpu",
            # size                              # keep original canvas size
            interp_type=types.INTERP_LINEAR  # use linear interpolation
        )

        # My workaround for Dali not supporting random affine transforms:
        # a "synthetic random" warp affine transform.

        # Rotate within a narrow range with probability of 0.075
        self.rotate = ops.Rotate(device='gpu')
        self.rotate_range = ops.Uniform(range=(-20.0, 20.0))
        self.rotate_coin = ops.CoinFlip(probability=0.075)

        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)
        print('DALI "{0}" variant'.format(dali_device))
Ejemplo n.º 13
0
 def __init__(self, batch_size, layout, data_iterator, device):
     super(SynthFlipPipeline, self).__init__(batch_size, seed=1234, num_threads=4, device_id=0)
     self.device = device
     self.iterator = data_iterator
     self.layout = layout
     self.input = ops.ExternalSource()
     self.coin = ops.CoinFlip(seed=1234)
     self.flip = ops.Flip(device=device)
Ejemplo n.º 14
0
 def __init__(self, device):
     super(CommonPipeline, self).__init__(BATCH_SIZE, NUM_WORKERS, DEVICE_ID, seed=SEED,
                                          exec_async=False, exec_pipelined=False)
     self.input = ops.FileReader(file_root=images_dir)
     self.decode = ops.ImageDecoder(device='mixed' if device == 'gpu' else 'cpu',
                                    output_type=types.RGB)
     self.resize = ops.Resize(resize_x=400, resize_y=400, device=device)
     self.flip = ops.Flip(device=device)
Ejemplo n.º 15
0
 def __init__(self, device, batch_size, num_threads=1, device_id=0, num_gpus=1, is_vertical=0, is_horizontal=1 ):
     super(FlipPipeline, self).__init__(batch_size,
                                        num_threads,
                                        device_id)
     self.device = device
     self.input = ops.CaffeReader(path = caffe_db_folder, shard_id = device_id, num_shards = num_gpus)
     self.decode = ops.ImageDecoder(device = "cpu", output_type = types.RGB)
     self.flip = ops.Flip(device = self.device, vertical=is_vertical, horizontal=is_horizontal)
Ejemplo n.º 16
0
    def __init__(self,
                 batch_size,
                 device,
                 data_dir,
                 mean,
                 std,
                 device_id=0,
                 shard_id=0,
                 num_shards=1,
                 num_threads=4,
                 seed=0):
        super(DaliTransformsTrainPipeline,
              self).__init__(batch_size, num_threads, device_id, seed)

        # should we make this drive the device flags?
        self.reader = ops.FileReader(file_root=data_dir,
                                     shard_id=shard_id,
                                     num_shards=num_shards,
                                     random_shuffle=True)

        self.decode = ops.ImageDecoder(device='mixed',
                                       output_type=types.RGB,
                                       memory_stats=True)
        self.resize = ops.Resize(device=device,
                                 size=[200, 300],
                                 interp_type=types.INTERP_TRIANGULAR)
        self.centrecrop = ops.Crop(device=device, crop=[100, 100])
        self.randomcrop = ops.RandomResizedCrop(device=device, size=[80, 80])

        self.hz_coin = ops.CoinFlip(probability=0.5)
        self.horizontalflip = ops.Flip(device=device)

        self.rotate_angle = ops.Uniform(range=[-90, 90])
        self.rotate_coin = ops.CoinFlip(probability=0.5)
        self.rotate = ops.Rotate(device=device, keep_size=True)

        self.vt_coin = ops.CoinFlip(probability=0.5)
        self.verticalflip = ops.Flip(device=device, horizontal=0)

        self.normalize = ops.CropMirrorNormalize(device=device,
                                                 dtype=types.FLOAT,
                                                 output_layout=types.NCHW)  #,
        #mean=mean*255, std=std*255)

        #self.normalize = ops.Normalize(device=device, dtype=types.FLOAT)#, mean=mean, stddev=std)
        self.to_int64 = ops.Cast(dtype=types.INT64, device=device)
Ejemplo n.º 17
0
    def __init__(self, target_size, preproc_param, training=False):
        self.training = training
        mean = preproc_param.MEAN
        std = preproc_param.STD
        bri_delta = preproc_param.BRI_DELTA
        hue_delta = preproc_param.HUE_DELTA
        max_expand_ratio = preproc_param.MAX_EXPAND_RATIO
        contrast_range = preproc_param.CONTRAST_RANGE
        saturation_range = preproc_param.SATURATION_RANGE
        crop_aspect_ratio = preproc_param.CROP_ASPECT_RATIO
        crop_scale = preproc_param.CROP_SCALE
        crop_attempts = preproc_param.CROP_ATTEMPTS

        # decoder
        self.decode_train = ops.ImageDecoderSlice(device="mixed", output_type=types.RGB)
        self.decode_infer = ops.ImageDecoder(device="mixed", output_type=types.RGB)

        # ssd crop
        self.bbox_crop = ops.RandomBBoxCrop(
            device="cpu",
            bbox_layout="xyXY",
            scaling=crop_scale,
            aspect_ratio=crop_aspect_ratio,
            allow_no_crop=True,
            thresholds=[0, 0.1, 0.3, 0.5, 0.7, 0.9],
            num_attempts=crop_attempts,
        )

        # color twist
        self.uniform_con = ops.Uniform(range=contrast_range)
        self.uniform_bri = ops.Uniform(
            range=(1.0 - bri_delta / 256.0, 1.0 + bri_delta / 256.0)
        )
        self.uniform_sat = ops.Uniform(range=saturation_range)
        self.uniform_hue = ops.Uniform(range=(-hue_delta, hue_delta))
        self.hsv = ops.Hsv(device="gpu")
        self.contrast = ops.BrightnessContrast(device="gpu")

        # hflip
        self.bbox_flip = ops.BbFlip(device="cpu", ltrb=True)
        self.img_flip = ops.Flip(device="gpu")
        self.coin_flip = ops.CoinFlip(probability=0.5)

        # past
        self.paste_pos = ops.Uniform(range=(0, 1))
        self.paste_ratio = ops.Uniform(range=(1, max_expand_ratio))
        self.paste = ops.Paste(device="gpu", fill_value=mean)
        self.bbox_paste = ops.BBoxPaste(device="cpu", ltrb=True)

        # resize and normalize
        self.resize = ops.Resize(
            device="gpu",
            interp_type=types.DALIInterpType.INTERP_CUBIC,
            resize_x=target_size[0],
            resize_y=target_size[1],
            save_attrs=True,
        )
        self.normalize = ops.CropMirrorNormalize(device="gpu", mean=mean, std=std)
Ejemplo n.º 18
0
    def __init__(self,
                 imageset_dir,
                 image_size,
                 random_shuffle,
                 batch_size=4,
                 num_threads=2,
                 device_id=0):
        super(ImagePipeline, self).__init__(batch_size,
                                            num_threads,
                                            device_id,
                                            seed=12)
        self.imageset_dir = imageset_dir
        self.random_shuffle = random_shuffle

        eii = ExternalInputIterator(root=self.imageset_dir,
                                    batch_size=self.batch_size,
                                    random_shuffle=self.random_shuffle)
        self.iterator = iter(eii)
        self.num_inputs = len(self.iterator.files)

        self.input_image = ops.ExternalSource()
        self.input_mask = ops.ExternalSource()

        self.decode_image = ops.ImageDecoder(device="mixed",
                                             output_type=types.RGB)
        self.decode_mask = ops.ImageDecoder(device="mixed",
                                            output_type=types.GRAY)

        # The rest of pre-processing is done on the GPU
        self.res = ops.Resize(device="gpu",
                              resize_x=image_size,
                              resize_y=image_size)
        self.flip = ops.Flip(device="gpu", horizontal=1, vertical=0)

        rotate_degree = random.random() * 2 * 10 - 10
        self.rotate_image = ops.Rotate(
            device="gpu",
            angle=rotate_degree,
            interp_type=types.DALIInterpType.INTERP_LINEAR)
        self.rotate_mask = ops.Rotate(
            device="gpu",
            angle=rotate_degree,
            interp_type=types.DALIInterpType.INTERP_NN)

        self.cmnp_image = 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.cmnp_mask = ops.CropMirrorNormalize(device="gpu",
                                                 output_dtype=types.FLOAT,
                                                 output_layout=types.NCHW,
                                                 image_type=types.GRAY,
                                                 mean=[0],
                                                 std=[255])
Ejemplo n.º 19
0
    def __init__(self, batch_size, num_threads, device_id, data_dir, crop, dali_cpu=False):
        super(HybridTrainPipe, self).__init__(batch_size, num_threads, device_id, seed=12 + device_id)
        self.input = ops.FileReader(file_root=data_dir, shard_id=args.local_rank, num_shards=args.world_size, random_shuffle=True)
        #let user decide which pipeline works him bets for RN version he runs
        dali_device = 'cpu' if dali_cpu else 'gpu'
        decoder_device = 'cpu' if dali_cpu else 'mixed'
        # This padding sets the size of the internal nvJPEG buffers to be able to handle all images from full-sized ImageNet
        # without additional reallocations
        device_memory_padding = 211025920 if decoder_device == 'mixed' else 0
        host_memory_padding = 140544512 if decoder_device == 'mixed' else 0

        ## randomly crop and resize, crop sampling,
        self.decode = ops.ImageDecoderRandomCrop(device=decoder_device, output_type=types.RGB,
                                                 device_memory_padding=device_memory_padding,
                                                 host_memory_padding=host_memory_padding,
                                                 random_aspect_ratio=[0.75, 4/3.0],
                                                 random_area=[0.08, 1.0],
                                                 num_attempts=10)
        self.res = ops.Resize(device=dali_device, resize_x=crop, resize_y=crop, interp_type=types.INTERP_TRIANGULAR)

        self.vert_flip=ops.Flip(device='gpu', horizontal=0)
        self.vert_coin = ops.CoinFlip(probability=0.075)
        ##color jitter https://www.gitmemory.com/ruiyuanlu, https://github.com/NVIDIA/DALI/issues/336
        self.twist = ops.ColorTwist(device="gpu")
        self.rng1 = ops.Uniform(range=[0.6, 1.4])
        self.rng2 = ops.Uniform(range=[-102, 102]) ## factor=0.4, 0.4*255, -0.4*255
        #self.rng2 = ops.Uniform(range=[-51, 51]) ## factor=0.2, 0.2*255, -0.2*255

        self.flip = ops.Flip(device = "gpu", vertical = 1, horizontal = 0)
        self.color_jitter = ops.ColorTwist(device="gpu", hue=0.2, brightness=0.4,
                                contrast=0.4, saturation=0.4)
        self.cmnp = ops.CropMirrorNormalize(device="gpu",
                                            output_dtype=types.FLOAT,
                                            output_layout=types.NCHW,
                                            crop=(crop, crop),
                                            image_type=types.RGB,
                                            mean=[0.485 * 255,0.456 * 255,0.406 * 255],
                                            std=[0.229 * 255,0.224 * 255,0.225 * 255])
        ## this is torch.transform.RandomHorizontalFlip

        self.mirrorcoin  = ops.CoinFlip(probability=0.5)
        self.uniform = ops.Uniform(range = (0.0, 1.0))
        print('DALI "{0}" variant'.format(dali_device))
Ejemplo n.º 20
0
    def __init__(self, p: float = 0.5):
        """Initialization

        Args:
            p (float, optional): Probability to apply this transformation. Defaults to 0.5.
        """
        self.flip_coin_vflip = ops.CoinFlip(probability=p)
        self.image_vflip = ops.Flip(device='gpu', horizontal=0)
        self.bbox_vflip = ops.BbFlip(device='cpu', horizontal=0)
        self.ldmrks_vflip = ops.CoordFlip(layout='xy', device='cpu', flip_x=0)
Ejemplo n.º 21
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.bc = ops.BrightnessContrast(device='gpu')
        self.hsv = ops.Hsv(device='gpu')

        # Random number generation for augmentation
        self.brightness_dist = ops.NormalDistribution(mean=1.0, stddev=augment_brightness)
        self.contrast_dist = ops.NormalDistribution(mean=1.0, stddev=augment_contrast)
        self.hue_dist = ops.NormalDistribution(mean=0.0, stddev=augment_hue)
        self.saturation_dist = ops.NormalDistribution(mean=1.0, stddev=augment_saturation)

        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)
Ejemplo n.º 22
0
    def __init__(self, batch_size, num_threads, device_id, data_dir, crop,
                 mean, std, local_rank=0, world_size=1, dali_cpu=False, shuffle=True, fp16=False,
                 min_crop_size=0.08, color_jitter=False):

        # As we're recreating the Pipeline at every epoch, the seed must be -1 (random seed)
        super(HybridTrainPipe, self).__init__(
            batch_size, num_threads, device_id, seed=-1)

        # Enabling read_ahead slowed down processing ~40%
        self.input = ops.FileReader(file_root=data_dir, shard_id=local_rank, num_shards=world_size,
                                    random_shuffle=shuffle)

        # Let user decide which pipeline works best with the chosen model
        if dali_cpu:
            decode_device = "cpu"
            self.dali_device = "cpu"
            self.flip = ops.Flip(device=self.dali_device)
        else:
            decode_device = "mixed"
            self.dali_device = "gpu"

        output_dtype = types.FLOAT
        if fp16:
            output_dtype = types.FLOAT16

        self.cmn = ops.CropMirrorNormalize(device=self.dali_device,
                                           output_dtype=output_dtype,
                                           output_layout=types.NCHW,
                                           crop=(crop, crop),
                                           image_type=types.RGB,
                                           mean=mean,
                                           std=std,)

        # To be able to handle all images from full-sized ImageNet, this padding sets the size of the internal
        # nvJPEG buffers without additional reallocations
        device_memory_padding = 211025920 if decode_device == 'mixed' else 0
        host_memory_padding = 140544512 if decode_device == 'mixed' else 0
        self.decode = ops.ImageDecoderRandomCrop(device=decode_device, output_type=types.RGB,
                                                 device_memory_padding=device_memory_padding,
                                                 host_memory_padding=host_memory_padding,
                                                 random_aspect_ratio=[
                                                     0.8, 1.25],
                                                 random_area=[
                                                     min_crop_size, 1.0],
                                                 num_attempts=100)

        # Resize as desired.  To match torchvision data loader, use triangular interpolation.
        self.res = ops.Resize(device=self.dali_device, resize_x=crop, resize_y=crop,
                              interp_type=types.INTERP_TRIANGULAR)

        self.coin = ops.CoinFlip(probability=0.5)
        print('DALI "{0}" variant'.format(self.dali_device))
Ejemplo n.º 23
0
 def __init__(self, data_iter, batch_size, x_dim, num_threads, device_id):
     super(MiniPipeline, self).__init__(batch_size, num_threads, device_id, seed=12)
     data_iter = iter(data_iter)
     self.source = ops.ExternalSource(source=data_iter, num_outputs=2)
     self.decode = ops.ImageDecoder(device='mixed', output_type=types.RGB)
     self.rrc = ops.RandomResizedCrop(device='gpu', size=x_dim[:2], random_area=[0.95, 1.0])
     self.flip = ops.Flip(device='gpu')
     # self.colortwist = ops.ColorTwist(device='gpu', brightness=.1, contrast=.1, saturation=.1, hue=.1)
     self.norm = ops.CropMirrorNormalize(device='gpu',
                                         output_layout=types.NCHW,
                                         # mean=[0.485 * 255, 0.456 * 255, 0.406 * 255],
                                         # std=[0.229 * 255, 0.224 * 255, 0.225 * 255]
                                         )
Ejemplo n.º 24
0
 def __init__(self, batch_size, output_size, num_threads, device_id, images_directory):
     super(HybridPipelineTrain, self).__init__(batch_size, num_threads, device_id, seed = 12)
     self.input = ops.FileReader(file_root = images_directory, random_shuffle = True, initial_fill = 21)
     self.decode = ops.ImageDecoder(device = "mixed", output_type = types.RGB)
     self.cmn = ops.CropMirrorNormalize(
                    device="gpu",
                    dtype=types.FLOAT,
                    mean=[0.5, 0.5, 0.5],
                    std=[0.5, 0.5, 0.5],
                    output_layout="HWC"
                )
     self.coin = ops.random.CoinFlip(probability = 0.5)
     self.flip = ops.Flip(device = "gpu")
     self.rsz = ops.Resize(resize_x = output_size[0], resize_y = output_size[1], device = "gpu")
Ejemplo n.º 25
0
    def __init__(self, batch_size, num_threads, device_id):
        super(COCOPipeline, self).__init__(batch_size,
                                           num_threads,
                                           device_id,
                                           exec_async=False,
                                           exec_pipelined=False,
                                           seed=15)
        self.input = ops.COCOReader(file_root=file_root,
                                    annotations_file=annotations_file,
                                    shard_id=device_id,
                                    num_shards=num_gpus,
                                    ratio=True,
                                    ltrb=True)
        self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB)
        self.flip = ops.Flip(device="gpu")
        self.bbflip = ops.BbFlip(device="cpu", ltrb=True)
        self.paste_pos = ops.Uniform(range=(0, 1))
        self.paste_ratio = ops.Uniform(range=(1, 2))
        self.coin = ops.CoinFlip(probability=0.5)
        self.coin2 = ops.CoinFlip(probability=0.5)
        self.paste = ops.Paste(device="gpu", fill_value=(32, 64, 128))
        self.bbpaste = ops.BBoxPaste(device="cpu", ltrb=True)
        self.prospective_crop = ops.RandomBBoxCrop(device="cpu",
                                                   aspect_ratio=[0.5, 2.0],
                                                   thresholds=[0.1, 0.3, 0.5],
                                                   scaling=[0.8, 1.0],
                                                   ltrb=True)
        self.slice = ops.Slice(device="gpu")

        # resize
        self.resize = ops.Resize(device="gpu",
                                 interp_type=types.INTERP_LINEAR,
                                 resize_shorter=800,
                                 max_size=1200)

        self.shape = ops.Shapes(device="gpu")

        # normalize and convert hwc to chw
        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])
        # padding axes=(0,1) -> hwc, axes=(1,2) -> chw
        self.padding = ops.Pad(device="gpu",
                               fill_value=0,
                               axes=(1, 2),
                               shape=(800, 1200))
Ejemplo n.º 26
0
    def __init__(self,
                 batch_size,
                 file_root,
                 annotations_file,
                 default_boxes,
                 seed,
                 device_id=0,
                 num_threads=4):

        super(COCOPipeline, self).__init__(batch_size=batch_size,
                                           device_id=device_id,
                                           num_threads=num_threads,
                                           seed=seed)

        self.input = ops.COCOReader(file_root=file_root,
                                    annotations_file=annotations_file,
                                    ratio=True,
                                    ltrb=True,
                                    random_shuffle=True)
        self.decode = ops.nvJPEGDecoder(device="mixed", output_type=types.RGB)

        # Augumentation techniques
        self.crop = ops.RandomBBoxCrop(device="cpu",
                                       aspect_ratio=[0.5, 2.0],
                                       thresholds=[0.1, 0.3, 0.5, 0.7, 0.9],
                                       scaling=[0.8, 1.0],
                                       ltrb=True)
        self.slice = ops.Slice(device="gpu")
        self.twist = ops.ColorTwist(device="gpu")
        self.resize = ops.Resize(device="gpu", resize_x=300, resize_y=300)
        self.normalize = ops.CropMirrorNormalize(
            device="gpu",
            crop=(300, 300),
            mean=[0.485 * 255., 0.456 * 255., 0.406 * 255.],
            std=[0.229 * 255., 0.224 * 255., 0.225 * 255.])

        # Random variables
        self.rng1 = ops.Uniform(range=[0.5, 1.5])
        self.rng2 = ops.Uniform(range=[0.875, 1.125])
        self.rng3 = ops.Uniform(range=[-0.5, 0.5])

        self.flip = ops.Flip(device="gpu")
        self.bbflip = ops.BbFlip(device="cpu", ltrb=True)
        self.flip_coin = ops.CoinFlip(probability=0.5)

        self.box_encoder = ops.BoxEncoder(device="cpu",
                                          criteria=0.5,
                                          anchors=default_boxes.as_ltrb_list())
Ejemplo n.º 27
0
 def __init__(self, batch_size, output_size, num_threads, device_id, images_directory):
     super(HybridPipelineTrain, self).__init__(batch_size, num_threads, device_id, seed = 12)
     self.input = ops.FileReader(file_root = images_directory, random_shuffle = True, initial_fill = 21)
     self.decode = ops.ImageDecoder(device = "mixed", output_type = types.RGB)
     self.rotate = ops.Rotate(device = "gpu")
     self.RRC = ops.RandomResizedCrop(size = output_size,
         random_area = [0.4, 1.0],
         random_aspect_ratio = [0.5, 1.5],
         device="gpu"
     )
     self.cmn = ops.CropMirrorNormalize(
                    device="gpu",
                    dtype=types.FLOAT,
                    mean=[0.485, 0.456, 0.406],
                    std=[0.229, 0.224, 0.225],
                    output_layout="HWC"
                )
     self.rng = ops.random.Uniform(range = (-25.0, 25.0))
     self.coin = ops.random.CoinFlip(probability = 0.5)
     self.flip = ops.Flip(device = "gpu")
 def __init__(self, img_file_list, num_shards, shard_id, batch_size,
              num_threads, device_id):
     super(Opt3Pipeline, self).__init__(batch_size,
                                        num_threads,
                                        device_id,
                                        seed=12)
     self.input_img = ops.FileReader(file_root="",
                                     num_shards=num_shards,
                                     shard_id=shard_id,
                                     file_list=img_file_list,
                                     random_shuffle=True,
                                     initial_fill=21)
     self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB)
     self.rrc = ops.RandomResizedCrop(device="gpu",
                                      size=(800, 800),
                                      random_area=[0.8, 0.8])
     self.flip_h = ops.Flip(device="gpu", vertical=0, horizontal=1)
     self.rotate = ops.Rotate(device="gpu",
                              angle=30,
                              interp_type=types.INTERP_LINEAR,
                              fill_value=0)
     self.resize = ops.Resize(device="gpu", resize_x=224, resize_y=224)
Ejemplo n.º 29
0
    def __init__(self,
                 session,
                 dataset,
                 batch_size,
                 num_threads,
                 is_random_flip=True,
                 num_samples=1000000,
                 device_id=0,
                 preprocess=None,
                 fill_last_batch=True):
        super(ExternalSourcePipeline, self).__init__(batch_size,
                                                     num_threads,
                                                     device_id,
                                                     seed=12)
        self.session = session
        self.num_samples = num_samples
        self.dataset = dataset
        self.is_random_flip = is_random_flip
        self.preprocess = preprocess

        if self.preprocess is not None:
            crop = (preprocess['width'], preprocess['height'])

            self.res = ops.Resize(resize_x=preprocess['width'],
                                  resize_y=preprocess['height'])

        self.flip = ops.Flip()

        self.coin = ops.CoinFlip(probability=0.5)
        self.coin2 = ops.CoinFlip(probability=0.5)

        self.iterator = iter(
            ExternalInputIterator3(self.session, self.dataset,
                                   self.num_samples, batch_size,
                                   fill_last_batch))
        self.iterator.reset()

        self.input = ops.ExternalSource()
        self.input_label = ops.ExternalSource()
Ejemplo n.º 30
0
    def __init__(self,
                 batch_size,
                 num_threads,
                 device_id,
                 external_data,
                 is_train=True):
        super(ExternalSourcePipeline, self).__init__(batch_size,
                                                     num_threads,
                                                     device_id,
                                                     seed=12)
        self.is_train = is_train
        self.input = ops.ExternalSource()

        self.angle_rng = ops.Uniform(range=(-10.0, 10.0))
        self.rotate = ops.Rotate(device="gpu")

        self.flip_rng = ops.CoinFlip(probability=0.5)
        self.flip = ops.Flip(device='gpu')

        self.slice = ops.Slice()
        self.external_data = external_data
        self.iterator = iter(self.external_data)