def __init__(self, setting, split_name, batch_size, num_threads, device_id, preprocess=None): super(BaseDataset, self).__init__(batch_size, num_threads, device_id) self._split_name = split_name self._img_path = setting['img_root'] self._gt_path = setting['gt_root'] self._portion = setting['portion'] if 'portion' in setting else None self._train_source = setting['train_source'] self._eval_source = setting['eval_source'] self._test_source = setting['test_source'] self._down_sampling = setting['down_sampling'] self.preprocess = preprocess self._file_names = self._get_file_names(split_name) self.input = ops.CaffeReader(path = lmdb_folder, random_shuffle = True, shard_id = device_id, num_shards = num_gpus) self.decode = ops.ImageDecoder(device = "mixed", output_type = types.RGB) self.resize = ops.Resize(device = "gpu", interp_type = types.INTERP_LINEAR) self.cmn = ops.CropMirrorNormalize(device = "gpu", dtype = types.FLOAT, crop = (227, 227), mean = [128., 128., 128.], std = [1., 1., 1.]) self.uniform = ops.Uniform(range = (0.0, 1.0)) self.resize_rng = ops.Uniform(range = (256, 480))
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')
def __init__(self, p: float = .5, hue_limit: Union[List, float] = 20., saturation_limit: Union[List, float] = .5, value_limit: Union[List, float] = .5): """Initialization Args: p (float, optional): Probability to apply this transformation. Defaults to .5. hue_limit (Union[List,float], optional): Range for changing hue in [min,max] value format. If provided as a single float, the range will be (-limit, limit). Defaults to 20.. saturation_limit (Union[List,float], optional): Factor multiplier range for changing saturation in [min,max] value format. If provided as a single float, the range will be 1 + (-limit, limit). Defaults to 0.5. value_limit (Union[List,float], optional): Factor multiplier range for changing value in [min,max] value format. If provided as a single float, the range will be 1 + (-limit, limit). Defaults to 0.5. """ hue_limit = _check_and_convert_limit_value(hue_limit, None, 0) saturation_limit = _check_and_convert_limit_value(saturation_limit) value_limit = _check_and_convert_limit_value(value_limit) self.hsv = ops.Hsv(device='gpu') self.hue_uniform = ops.Uniform(range=hue_limit) self.saturation_uniform = ops.Uniform(range=saturation_limit) self.value_uniform = ops.Uniform(range=value_limit) self.rng = ops.CoinFlip(probability=p) self.bool = ops.Cast(dtype=types.DALIDataType.BOOL)
def __init__(self, data_root, data_list, sampler, crop, colorjitter=None): super(ImageNetTrainPipeV2, self).__init__() # print('data root: {}, data list: {}, len(sampler_index): {}'.format( # data_root, data_list, len(sampler))) self.mc_input = ops.McReader(file_root=data_root, file_list=data_list, sampler_index=list(sampler)) self.colorjitter = colorjitter dali_device = "gpu" # This padding sets the size of the internal nvJPEG buffers to be able to handle all # images from full-sized ImageNet without additional reallocations self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB, device_memory_padding=211025920, host_memory_padding=140544512) self.res = ops.RandomResizedCrop(device=dali_device, size=(crop, crop)) 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]) self.coin = ops.CoinFlip(probability=0.5) if self.colorjitter is not None: self.colorjit = ops.ColorTwist(device="gpu") self.rng_brightness = ops.Uniform(range=(1.0 - self.colorjitter[0], 1.0 + self.colorjitter[0])) self.rng_contrast = ops.Uniform(range=(1.0 - self.colorjitter[1], 1.0 + self.colorjitter[1])) self.rng_saturation = ops.Uniform(range=(1.0 - self.colorjitter[2], 1.0 + self.colorjitter[2])) self.rng_hue = ops.Uniform(range=(-self.colorjitter[3], self.colorjitter[3]))
def __init__(self, tfrecord_files, idx_files, batch_size, device_id=0, rank=0, total_devices=1, num_threads=4): super(TFRecordPipeline, self).__init__(batch_size, num_threads, device_id) self.input = ops.TFRecordReader(path = tfrecord_files, index_path = idx_files, shard_id = rank, num_shards = total_devices, random_shuffle = True, features = {"image/encoded" : tfrec.FixedLenFeature((), tfrec.string, ""), 'image/class/label': tfrec.FixedLenFeature([1], tfrec.int64, -1), }) self.decode = ops.ImageDecoder(device = "mixed", output_type = types.RGB) self.resize = ops.Resize(device = "gpu", resize_shorter = 256) self.cmnp = ops.CropMirrorNormalize(device = "gpu", output_dtype = types.FLOAT16, crop = (224, 224), image_type = types.RGB, mean = [0, 0, 0], std = [1., 1., 1.], output_layout='HWC') self.uniform = ops.Uniform(range = (0.0, 1.0)) self.flip = ops.CoinFlip() self.brightness = ops.Uniform(range = (0.5, 1.5)) self.contrast = ops.Uniform(range = (0.8, 1.3)) self.cast = ops.Cast(device = "gpu", dtype = types.FLOAT16) self.iter = 0
def __init__(self, batch_size, num_threads, device_id = 0, seed = 0): super(TestPipeline, self).__init__(batch_size, num_threads, device_id, seed) self.input = ops.COCOReader( file_root = file_root, annotations_file = annotations_file, shard_id = 0, num_shards = 1, ratio=False, save_img_ids=True) self.decode = ops.ImageDecoder(device = "cpu", output_type = types.RGB) self.resize = ops.Resize( device = "cpu", image_type = types.RGB, interp_type = types.INTERP_LINEAR) self.cmn = ops.CropMirrorNormalize( device = "cpu", output_dtype = types.FLOAT, crop = (224, 224), image_type = types.RGB, mean = [128., 128., 128.], std = [1., 1., 1.]) self.res_uniform = ops.Uniform(range = (256.,480.)) self.uniform = ops.Uniform(range = (0.0, 1.0)) self.cast = ops.Cast( device = "cpu", dtype = types.FLOAT16)
class C2Pipe(Pipeline): def __init__(self, batch_size, num_threads, device_id, pipelined=True, async=True): super(C2Pipe, self).__init__(batch_size, num_threads, device_id, exec_pipelined=pipelined, exec_async=async) self.input = ops.ExternalSource() self.decode = ops.HostDecoder(output_type=types.RGB) self.rcm = ops.FastResizeCropMirror(crop=[224, 224]) self.np = ops.NormalizePermute(device="gpu", output_dtype=types.FLOAT16, mean=[128., 128., 128.], std=[1., 1., 1.], height=224, width=224, image_type=types.RGB) self.uniform = ops.Uniform(range=(0., 1.)) self.resize_uniform = ops.Uniform(range=(256., 480.)) self.mirror = ops.CoinFlip(probability=0.5) self.iter = 0
class HybridPipe(Pipeline): def __init__(self, batch_size, num_threads, device_id, pipelined=True, async=True): super(HybridPipe, self).__init__(batch_size, num_threads, device_id, exec_pipelined=pipelined, exec_async=async) self.input = ops.ExternalSource() self.decode = ops.nvJPEGDecoder(device="mixed", output_type=types.RGB) self.resize = ops.Resize(device="gpu", image_type=types.RGB, interp_type=types.INTERP_LINEAR) self.cmnp = ops.CropMirrorNormalize(device="gpu", output_dtype=types.FLOAT16, crop=(224, 224), image_type=types.RGB, mean=[128., 128., 128.], std=[1., 1., 1.]) self.uniform = ops.Uniform(range=(0., 1.)) self.resize_uniform = ops.Uniform(range=(256., 480.)) self.mirror = ops.CoinFlip(probability=0.5) self.iter = 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 __init__(self, batch_size, num_threads, device_id, eii): super(ExternalSourcePipeline, self).__init__(batch_size, num_threads, device_id, seed=12) self.input = ops.ExternalSource() self.id_label = ops.ExternalSource() self.boxes = ops.ExternalSource() self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB) self.resize = ops.Resize(device="gpu", resize_x=256, resize_y=256) self.twist = ops.ColorTwist(device="gpu") self.normalize = ops.CropMirrorNormalize( device="gpu", crop=(256, 256), mean=[0.0, 0.0, 0.0], std=[255.0, 255.0, 255.0], mirror=0, output_dtype=types.FLOAT, output_layout=types.NCHW, image_type=types.RGB, ) # 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.external_data = eii self.iterator = iter(self.external_data)
def __init__(self, file_root, annotations_file, batch_size=1, device_id=0, num_threads=4, local_rank=0, world_size=1): super(HybridTrainPipe, self).__init__(batch_size, num_threads, device_id, seed=42 + device_id) self.reader = ops.COCOReader( file_root=file_root, annotations_file=annotations_file, skip_empty=True, shard_id=local_rank, num_shards=world_size, ratio=True, ltrb=True, shuffle_after_epoch=True, pad_last_batch=True) self.crop = 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, allow_no_crop=True, num_attempts=50) self.bbflip = ops.BbFlip(device="cpu", ltrb=True) self.roi_decode = ops.ImageDecoderSlice(device="mixed") self.resize = ops.Resize( device="gpu", resize_x=300, resize_y=300, min_filter=types.DALIInterpType.INTERP_TRIANGULAR) self.hsv = ops.Hsv(device="gpu", dtype=types.FLOAT) # use float to avoid clipping and # quantizing the intermediate result self.bc = ops.BrightnessContrast(device="gpu", contrast_center=128, # input is in float, but in 0..255 range dtype=types.UINT8) self.cmnp = ops.CropMirrorNormalize( device="gpu", mean=[104., 117., 123.], std=[1., 1., 1.], dtype=types.FLOAT, output_layout=types.NCHW, pad_output=False) 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.coin = ops.CoinFlip(probability=0.5) self.build()
def __init__(self, batch_size, num_threads, device_id, file_list, sequence_length, seg_num, seg_length, resize_shorter_scale, crop_target_size, is_training=False, initial_prefetch_size=10, num_shards=1, shard_id=0, dali_mean=0., dali_std=1.0): super(VideoPipe, self).__init__(batch_size, num_threads, device_id) self.input = ops.VideoReader(device="gpu", file_list=file_list, sequence_length=sequence_length, seg_num=seg_num, seg_length=seg_length, is_training=is_training, num_shards=num_shards, shard_id=shard_id, random_shuffle=is_training, initial_fill=initial_prefetch_size) # the sequece data read by ops.VideoReader is of shape [F, H, W, C] # Because the ops.Resize does not support sequence data, # it will be transposed into [H, W, F, C], # then reshaped to [H, W, FC], and then resized like a 2-D image. self.transpose = ops.Transpose(device="gpu", perm=[1, 2, 0, 3]) self.reshape = ops.Reshape(device="gpu", rel_shape=[1.0, 1.0, -1], layout='HWC') self.resize = ops.Resize(device="gpu", resize_shorter=resize_shorter_scale) # crops and mirror are applied by ops.CropMirrorNormalize. # Normalization will be implemented in paddle due to the difficulty of dimension broadcast, # It is not sure whether dimension broadcast can be implemented correctly by dali, just take the Paddle Op instead. self.pos_rng_x = ops.Uniform(range=(0.0, 1.0)) self.pos_rng_y = ops.Uniform(range=(0.0, 1.0)) self.mirror_generator = ops.Uniform(range=(0.0, 1.0)) self.cast_mirror = ops.Cast(dtype=types.DALIDataType.INT32) self.crop_mirror_norm = ops.CropMirrorNormalize( device="gpu", crop=[crop_target_size, crop_target_size], mean=dali_mean, std=dali_std) self.reshape_back = ops.Reshape(device="gpu", shape=[ seg_num, seg_length * 3, crop_target_size, crop_target_size ], layout='FCHW') self.cast_label = ops.Cast(device="gpu", dtype=types.DALIDataType.INT64)
def __init__(self, batch_size, num_threads, device_id, root, list_path, crop, shard_id, num_shards, coji=False, dali_cpu=False): super(HybridTrainPipe, self).__init__(batch_size, num_threads, device_id, seed=12 + device_id) self.read = ops.FileReader(file_root=root, file_list=list_path, shard_id=shard_id, num_shards=num_shards, random_shuffle=True, initial_fill=1024) # Let user decide which pipeline works 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 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, 1.33333333], random_area=[0.08, 1.0], num_attempts=100) self.resize = ops.Resize(device=dali_device, resize_x=crop, resize_y=crop, interp_type=types.INTERP_TRIANGULAR) self.cmnp = ops.CropMirrorNormalize( device=dali_device, output_dtype=types.FLOAT, output_layout=types.NCHW, crop=(crop, crop), image_type=types.RGB, mean=[x * 255 for x in IMAGENET_MEAN], std=[x * 255 for x in IMAGENET_STD]) self.coin = ops.CoinFlip(probability=0.5) self.coji = coji if self.coji: self.twist = ops.ColorTwist(device=dali_device) self.brightness_rng = ops.Uniform(range=[1.0 - 0.4, 1.0 + 0.4]) self.contrast_rng = ops.Uniform(range=[1.0 - 0.4, 1.0 + 0.4]) self.saturation_rng = ops.Uniform(range=[1.0 - 0.4, 1.0 + 0.4])
def __init__(self, alpha=[0.5, 1.5], delta=[0.875, 1.125], gamma=[-0.5, 0.5]): self.contrast = ops.Uniform(range=gamma) self.brightness = ops.Uniform(range=[-0.125, 0.125]) self.saturation = ops.Uniform(range=gamma) self.hue = ops.Uniform(range=gamma) self.ct = ops.ColorTwist(device="gpu") self.toss_a_coin = ops.CoinFlip(probability=0.5)
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="cpu", output_type=types.RGB) self.resize = ops.Resize(device="cpu", resize_x=512., resize_y=512.) self.vert_flip = ops.Flip(device="cpu", horizontal=0) self.vert_coin = ops.CoinFlip(probability=0.5) self.rotate = ops.Rotate(device='cpu', interp_type=types.INTERP_NN) self.rotate_range = ops.Uniform(range=(-7, 7)) self.rotate_coin = ops.CoinFlip(probability=0.2) self.cmnp = ops.CropMirrorNormalize(device="cpu", output_dtype=types.FLOAT, crop=(512, 512), image_type=types.RGB, mean=[0., 0., 0.], std=[1., 1., 1.]) self.mirror_coin = ops.CoinFlip(probability=0.5) self.uniform = ops.Uniform(range=(0.0, 1.0)) self.iter = 0
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.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) 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])
def __init__(self, batch_size, num_threads, device_id, crop, colorjitter=None, dali_cpu=False): super(ImageNetTrainPipe, self).__init__(batch_size, num_threads, device_id, seed=12 + device_id) self.data_input = ops.ExternalSource() self.label_input = ops.ExternalSource() self.colorjitter = colorjitter # let user decide which pipeline works him bets for RN version he runs if dali_cpu: dali_device = "cpu" self.decode = ops.HostDecoderRandomCrop(device=dali_device, output_type=types.RGB) self.res = ops.Resize(resize_x=crop, resize_y=crop) else: dali_device = "gpu" # This padding sets the size of the internal nvJPEG buffers to be able to # handle all images from full-sized ImageNet without additional reallocations self.decode = ops.nvJPEGDecoder(device="mixed", output_type=types.RGB, device_memory_padding=211025920, host_memory_padding=140544512) self.res = ops.RandomResizedCrop(device=dali_device, size=(crop, crop)) 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]) self.coin = ops.CoinFlip(probability=0.5) if self.colorjitter is not None: self.colorjit = ops.ColorTwist(device="gpu") self.rng_brightness = ops.Uniform(range=(1.0 - self.colorjitter[0], 1.0 + self.colorjitter[0])) self.rng_contrast = ops.Uniform(range=(1.0 - self.colorjitter[1], 1.0 + self.colorjitter[1])) self.rng_saturation = ops.Uniform(range=(1.0 - self.colorjitter[2], 1.0 + self.colorjitter[2])) self.rng_hue = ops.Uniform(range=(-self.colorjitter[3], self.colorjitter[3]))
def __init__(self, batch_size, num_threads, device_id, csv_path, data_path, valid=False, nfold=0): super(DALIPipeline, self).__init__(batch_size, num_threads, device_id) self.data_path = data_path self.csv_file = csv_path self.valid = valid self.data = pd.read_csv(self.csv_file) if nfold > 0: self.data = self.data.sort_values(by=['image', 'label']) self.data = self.data.sample(frac=1, random_state=0).reset_index(drop=True) len_fold = int(len(self.data) / nfold) if valid: self.data = self.data[len_fold * (nfold - 1):].reset_index(drop=True) else: self.data = self.data[:len_fold * (nfold - 1)].reset_index(drop=True) self.data.to_csv('data/dali.txt', header=False, index=False, sep=' ') self.input = ops.FileReader(file_root=data_path, file_list='data/dali.txt') self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB) self.random_resize = ops.Resize(device="gpu", image_type=types.RGB, interp_type=types.INTERP_LINEAR) self.resize = ops.Resize(device="gpu", image_type=types.RGB, interp_type=types.INTERP_LINEAR, resize_x=227., resize_y=227.) self.cmn = ops.CropMirrorNormalize(device="gpu", output_dtype=types.FLOAT, crop=(227, 227), image_type=types.RGB, mean=[128., 128., 128.], std=[1., 1., 1.]) self.normalize = ops.NormalizePermute(device="gpu", height=227, width=227, image_type=types.RGB, mean=[128., 128., 128.], std=[1., 1., 1.]) self.uniform = ops.Uniform(range=(0.0, 1.0)) self.resize_rng = ops.Uniform(range=(256, 480))
def __init__(self, batch_size, num_threads, device_id): super(CommonPipeline, self).__init__(batch_size, num_threads, device_id) self.decode = ops.ImageDecoder(device = "mixed", output_type = types.RGB) self.resize = ops.Resize(device = "gpu", image_type = types.RGB, interp_type = types.INTERP_LINEAR) self.cmn = ops.CropMirrorNormalize(device = "gpu", output_dtype = types.FLOAT, crop = (227, 227), image_type = types.RGB, mean = [128., 128., 128.], std = [1., 1., 1.]) self.uniform = ops.Uniform(range = (0.0, 1.0)) self.resize_rng = ops.Uniform(range = (256, 480))
def __init__(self, params, num_threads, device_id): super(DaliPipeline, self).__init__(params.batch_size, num_threads, device_id, seed=12) with h5py.File(params.data_path, 'r') as f: # load hydro and clean up Hydro = f['Hydro'][...] self.Hydro = types.Constant(Hydro, shape=Hydro.shape, layout="DHWC", device="cpu") del Hydro # load nbody and clean up Nbody = f['Nbody'][...] self.Nbody = types.Constant(Nbody, shape=Nbody.shape, layout="DHWC", device="cpu") del Nbody #self.ndummy = np.zeros((20, 20, 20, 4), dtype=np.float32) #self.hdummy = np.zeros((20, 20, 20, 5), dtype=np.float32) #self.Nbody = types.Constant(self.ndummy, shape = self.ndummy.shape, layout = "DHWC", device="cpu") #self.Hydro = types.Constant(self.hdummy, shape = self.hdummy.shape, layout = "DHWC", device="cpu") #self.Nbody = ops.Constant(fdata = self.ndummy.flatten().tolist(), shape = self.ndummy.shape, layout = "DHWC", device = "cpu") #self.Hydro = ops.Constant(fdata = self.hdummy.flatten().tolist(), shape = self.hdummy.shape, layout = "DHWC", device = "cpu") self.do_rotate = True if params.rotate_input == 1 else False print("Enable Rotation" if self.do_rotate else "Disable Rotation") self.rng_angle = ops.Uniform(device="cpu", range=[-1.5, 2.5]) self.rng_pos = ops.Uniform(device="cpu", range=[0., 1.]) self.icast = ops.Cast(device="cpu", dtype=types.INT32) self.fcast = ops.Cast(device="cpu", dtype=types.FLOAT) self.crop = ops.Crop(device="cpu", crop_d=params.data_size, crop_h=params.data_size, crop_w=params.data_size) self.rotate1 = ops.Rotate(device="gpu", axis=(1, 0, 0), interp_type=types.INTERP_LINEAR) self.rotate2 = ops.Rotate(device="gpu", axis=(0, 1, 0), interp_type=types.INTERP_LINEAR) self.rotate3 = ops.Rotate(device="gpu", axis=(0, 0, 1), interp_type=types.INTERP_LINEAR) self.transpose = ops.Transpose(device="gpu", perm=[3, 0, 1, 2])
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))
def __init__(self, batch_size, num_threads, device_id, num_shards, shard_id, use_fp16=False, train=True, root=os.path.expanduser('./data')): super().__init__(batch_size, num_threads, device_id, seed=12) part = "train" if train else "test" idx_files = [os.path.join(root, "cifar10_{}.idx").format(part)] rec_files = [os.path.join(root, "cifar10_{}.rec").format(part)] self.num_classes = 10 self.image_size = (32, 32) self.size = 0 self.train = train for idx_file in idx_files: with open(idx_file, "r") as f: self.size += len(list(f.readlines())) self._input = ops.MXNetReader(path=rec_files, index_path=idx_files, random_shuffle=True if train else False, num_shards=num_shards, shard_id=shard_id, seed=12, tensor_init_bytes=self.image_size[0] * self.image_size[1] * 8) self._decode = ops.ImageDecoder(device="mixed", output_type=types.RGB) self._cmnp = ops.CropMirrorNormalize( device="gpu", output_dtype=types.FLOAT16 if use_fp16 else types.FLOAT, output_layout=types.NCHW, crop=self.image_size, image_type=types.RGB, mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375]) if train: self.padding = ops.Paste(device="gpu", fill_value=128, ratio=1.25) self.px = ops.Uniform(range=(0, 1)) self.py = ops.Uniform(range=(0, 1)) self._uniform = ops.Uniform(range=(0.7, 1.3)) self._coin = ops.CoinFlip(probability=0.5)
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())
def __init__(self, cfg): super(ClsTrainPipe, self).__init__(batch_size=cfg.dataset.loader.batch_size, num_threads=cfg.dataset.loader.num_workers, device_id=cfg.device.local_rank) self.eii = ClsInputIterator(cfg=cfg, is_train=True) self.source = ops.ExternalSource(source=self.eii, num_outputs=2) self.decode = ops.ImageDecoderRandomCrop( device='mixed', output_type=types.RGB, random_aspect_ratio=[0.8, 1.25], random_area=[0.3, 1.0], num_attempts=100) self.rotate = ops.Rotate(device='gpu', fill_value=127.5) self.res = ops.Resize(device='gpu', resize_x=cfg.dataset.transform.image_size, resize_y=cfg.dataset.transform.image_size, interp_type=types.INTERP_TRIANGULAR) self.cmnp = ops.CropMirrorNormalize( device='gpu', dtype=types.FLOAT, output_layout=types.NCHW, crop=(cfg.dataset.transform.image_size, cfg.dataset.transform.image_size), 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.angle = ops.Uniform( range=(-1 * cfg.dataset.transform.max_rotate_angle, cfg.dataset.transform.max_rotate_angle))
def __init__(self, batch_size, num_threads, device_id, data_dir, crop=32, dali_cpu=False, local_rank=0, world_size=1, cutout=0): super(HybridTrainPipe_CIFAR, self).__init__(batch_size, num_threads, device_id, seed=12 + device_id) self.iterator = iter( CIFAR_INPUT_ITER(batch_size, 'train', root=data_dir)) dali_device = "gpu" self.input = ops.ExternalSource() self.input_label = ops.ExternalSource() self.pad = ops.Paste(device=dali_device, ratio=1.25, fill_value=0) self.uniform = ops.Uniform(range=(0., 1.)) self.crop = ops.Crop(device=dali_device, crop_h=crop, crop_w=crop) self.cmnp = ops.CropMirrorNormalize( device="gpu", output_dtype=types.FLOAT, output_layout=types.NCHW, image_type=types.RGB, mean=[0.4914 * 255., 0.4822 * 255., 0.4465 * 255.], std=[0.2023 * 255., 0.1994 * 255., 0.2010 * 255.]) self.coin = ops.CoinFlip(probability=0.5)
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_list, crop_size): super(VideoReaderPipeline, self).__init__(batch_size, num_threads, device_id, seed=12) self.reader = ops.VideoReader(device="gpu", file_list=file_list, sequence_length=sequence_length, normalized=True, random_shuffle=True, image_type=types.RGB, dtype=types.FLOAT, initial_fill=16, enable_frame_num=True, stride=1, step=-1) self.uniform = ops.Uniform(range=(0.0, 1.0)) self.coin = ops.CoinFlip(probability=0.5) # 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.cropmirrornorm = ops.CropMirrorNormalize( device="gpu", crop=crop_size, output_dtype=types.FLOAT, mean=[0.45, 0.45, 0.45], std=[0.225, 0.225, 0.225], output_layout="CFHW")
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, 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_all = 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.cmnp_int = 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]) # Left 1 of the arguments as float to test whether mixing types works self.cmnp_1arg = ops.CropMirrorNormalize(device = "gpu", output_dtype = types.FLOAT, output_layout = types.NHWC, crop = (224, 224), image_type = types.RGB, mean = 128, std = 1) self.uniform = ops.Uniform(range = (0,1))
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] )