Пример #1
0
 def __init__(self, batch_size, num_threads, device_id):
     super(HybridPipe, self).__init__(batch_size, num_threads, device_id, seed = 12)
     self.input = ops.CaffeReader(path = caffe_db_folder, random_shuffle = True)
     self.decode = ops.nvJPEGDecoder(device = "mixed", output_type = types.RGB)
     self.cmnp = ops.CropMirrorNormalize(device = "gpu",
                                         output_dtype = types.FLOAT,
                                         output_layout = types.NHWC,
                                         crop = (224, 224),
                                         image_type = types.RGB,
                                         mean = [128., 128., 128.],
                                         std = [1., 1., 1.])
     self.affine = ops.WarpAffine(device = "gpu",
                                  matrix = [1.0, 0.8, 0.0, 0.0, 1.2, 0.0],
                                  fill_value = 128,
                                  interp_type = types.INTERP_LINEAR,
                                  use_image_center = True)
     self.uniform = ops.Uniform(range = (0.0,1.0))
     self.iter = 0
Пример #2
0
 def __init__(self, batch_size, num_threads, device_id, num_gpus, db_dir):
     super(TrainPipe, self).__init__(batch_size, num_threads, device_id)
     self.input = ops.MXNetReader(path=[db_dir + "train.rec"],
                                  index_path=[db_dir + "train.idx"],
                                  random_shuffle=False,
                                  shard_id=device_id,
                                  num_shards=num_gpus)
     self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB)
     # self.blur = ops.GaussianBlur(device="cpu", sigma=5.0, window_size=5)
     # self.reshape = ops.Reshape(device="cpu", layout="HWC")
     self.normalize = ops.CropMirrorNormalize(device="gpu",
                                              output_dtype=types.FLOAT,
                                              output_layout=types.NCHW,
                                              mean=[123.0, 116.0, 103.0],
                                              std=[100.0, 100.0, 100.0])
     self.transform_source = ops.ExternalSource()
     self.warp_gpu = ops.WarpAffine(device="gpu",
                                    interp_type=types.INTERP_LINEAR)
Пример #3
0
    def __new__(cls, fill_value=0, interp_type='linear', **kwargs):
        """Create a ``WarpAffine`` operator.

        Parameters
        ----------
        fill_value : number, optional
            The value to fill the empty regions.
        interp_type : str, optional, default='linear'
            The interpolation method.

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

        """
        if isinstance(interp_type, six.string_types):
            interp_type = getattr(types, 'INTERP_' + interp_type.upper())
        return ops.WarpAffine(fill_value=fill_value,
                              interp_type=interp_type,
                              device=context.get_device_type(),
                              **kwargs)
    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
    def __init__(self, batch_size, device_id, file_root, annotations_file, num_gpus,
                 output_fp16=False, output_nhwc=False, pad_output=False, num_threads=1, seed=15):
        super(COCOPipeline, self).__init__(batch_size=batch_size, device_id=device_id,
                                           num_threads=num_threads, seed=seed)

        if torch.distributed.is_initialized():
            shard_id = torch.distributed.get_rank()
        else:
            shard_id = 0

        self.input = ops.COCOReader(file_root=file_root, annotations_file=annotations_file,
                                    shard_id=shard_id, num_shards=num_gpus, ratio=True, ltrb=True, random_shuffle=True,
                                    skip_empty=True)
        self.decode = ops.ImageDecoder(device="cpu", output_type=types.RGB)

        # Augumentation techniques

        self.rotate = ops.Rotate(device="gpu", angle=30, interp_type=types.INTERP_LINEAR, fill_value=0)
        self.crop = ops.SSDRandomCrop(device="cpu", num_attempts=1)
        self.twist = ops.ColorTwist(device="gpu")

        self.resize = ops.Resize(device="gpu", resize_x=300, resize_y=300)

        # Will flip with probability provided in CoinFlip
        self.flip = ops.Flip(device='gpu')
        self.coin_flip_v = ops.CoinFlip(probability=0.1)
        self.coin_flip_h = ops.CoinFlip(probability=0.1)
        # bbox flipping
        self.bbflip = ops.BbFlip(device='gpu', ltrb=True)

        # paste
        self.paste = ops.Paste(device='gpu', fill_value=0)
        self.paste_pos = ops.Uniform(range=(0, 1))
        self.paste_ratio = ops.Uniform(range=(1, 2))
        self.bbpaste = ops.BBoxPaste(device='cpu', ltrb=True)

        # prospective
        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
        )
        # slice (after prospective crop)
        self.slice = ops.Slice(device='gpu')

        # color
        self.water = ops.Water(device='gpu')
        # self.contrast = ops.BrightnessContrast(device="gpu", brightness=0.5, contrast=1.5)
        # self.hsv = ops.Hsv(device="gpu", hue=45., saturation=0.2)
        self.sphere = ops.Sphere(device='gpu')

        self.warpaffine = ops.WarpAffine(device="gpu", matrix=[1.0, 0.8, 0.0, 0.0, 1.2, 0.0],
                                         interp_type=types.INTERP_LINEAR)

        output_dtype = types.FLOAT16 if output_fp16 else types.FLOAT
        output_layout = types.NHWC if output_nhwc else types.NCHW

        self.normalize = ops.CropMirrorNormalize(device="gpu", crop=(300, 300),
                                                 mean=[0.0, 0.0, 0.0],
                                                 std=[255.0, 255.0, 255.0],
                                                 mirror=0,
                                                 output_dtype=output_dtype,
                                                 output_layout=output_layout,
                                                 pad_output=pad_output)
        # 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])