Пример #1
0
 def __init__(self,
              device,
              batch_size,
              phase_y,
              phase_x,
              freq_x,
              freq_y,
              ampl_x,
              ampl_y,
              num_threads=3,
              device_id=0,
              num_gpus=1):
     super(WaterPipeline, 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.water = ops.Water(device=self.device,
                            ampl_x=ampl_x,
                            ampl_y=ampl_y,
                            phase_x=phase_x,
                            phase_y=phase_y,
                            freq_x=freq_x,
                            freq_y=freq_y,
                            interp_type=dali.types.INTERP_LINEAR)
Пример #2
0
    def __init__(self,
                 p: float = .5,
                 ampl_x: float = 10.0,
                 ampl_y: float = 10.0,
                 freq_x: float = 0.049087,
                 freq_y: float = 0.049087,
                 phase_x: float = 0.0,
                 phase_y: float = 0.0,
                 fill_value: float = 0.0):
        """Initialization

        Args:
            p (float, optional): Probability to apply this transformation. Defaults to .5.
            ampl_x (float, optional): Amplitude of the wave in x direction.. Defaults to 10.0.
            ampl_y (float, optional): Amplitude of the wave in y direction.. Defaults to 10.0.
            freq_x (float, optional): Frequency of the wave in x direction. Defaults to 0.049087.
            freq_y (float, optional): Frequency of the wave in y direction. Defaults to 0.049087.
            phase_x (float, optional): Phase of the wave in x direction.. Defaults to 0.0.
            phase_y (float, optional): Phase of the wave in y direction.. Defaults to 0.0.
            fill_value (float, optional): Color value used for padding pixels. Defaults to 0.0.
        """

        self.water_aug = ops.Water(device='gpu',
                                   ampl_x=ampl_x,
                                   ampl_y=ampl_y,
                                   freq_x=freq_x,
                                   freq_y=freq_y,
                                   phase_x=phase_x,
                                   phase_y=phase_y,
                                   fill_value=fill_value)
        self.rng = ops.CoinFlip(probability=p)
        self.bool = ops.Cast(dtype=types.DALIDataType.BOOL)
    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])