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)
def __init__(self, device_id, n_devices, file_root, file_list, batch_size, sample_rate=16000, window_size=.02, window_stride=.01, nfeatures=64, nfft=512, frame_splicing_factor=3, silence_threshold=-80, dither=.00001, preemph_coeff=.97, lowfreq=0.0, highfreq=0.0, num_threads=1): super().__init__(batch_size, num_threads, device_id, seed=42) self.dither = dither self.frame_splicing_factor = frame_splicing_factor self.read = ops.FileReader(file_root=file_root, file_list=file_list, device="cpu", shard_id=device_id, num_shards=n_devices) self.decode = ops.AudioDecoder(device="cpu", dtype=types.FLOAT, downmix=True) self.normal_distribution = ops.NormalDistribution(device="cpu") self.preemph = ops.PreemphasisFilter(preemph_coeff=preemph_coeff) self.spectrogram = ops.Spectrogram( device="cpu", nfft=nfft, window_length=window_size * sample_rate, window_step=window_stride * sample_rate) self.mel_fbank = ops.MelFilterBank(device="cpu", sample_rate=sample_rate, nfilter=nfeatures, normalize=True, freq_low=lowfreq, freq_high=highfreq) self.log_features = ops.ToDecibels(device="cpu", multiplier=np.log(10), reference=1.0, cutoff_db=-80) self.get_shape = ops.Shapes(device="cpu") self.normalize = ops.Normalize(axes=[0], device="cpu") self.splicing_transpose = ops.Transpose(device="cpu", perm=[1, 0]) self.splicing_reshape = ops.Reshape( device="cpu", rel_shape=[-1, frame_splicing_factor]) self.splicing_pad = ops.Pad(axes=[0], fill_value=0, align=frame_splicing_factor, shape=[1], device="cpu") self.get_nonsilent_region = ops.NonsilentRegion( device="cpu", cutoff_db=silence_threshold) self.trim_silence = ops.Slice(device="cpu", axes=[0]) self.to_float = ops.Cast(dtype=types.FLOAT)
def __init__( self, *, train_pipeline: bool, # True if train pipeline, False if validation pipeline device_id, num_threads, batch_size, file_root: str, file_list: str, sample_rate, discrete_resample_range: bool, resample_range: list, window_size, window_stride, nfeatures, nfft, frame_splicing_factor, dither_coeff, silence_threshold, preemph_coeff, pad_align, max_duration, mask_time_num_regions, mask_time_min, mask_time_max, mask_freq_num_regions, mask_freq_min, mask_freq_max, mask_both_num_regions, mask_both_min_time, mask_both_max_time, mask_both_min_freq, mask_both_max_freq, preprocessing_device="gpu"): super().__init__(batch_size, num_threads, device_id) self._dali_init_log(locals()) if torch.distributed.is_initialized(): shard_id = torch.distributed.get_rank() n_shards = torch.distributed.get_world_size() else: shard_id = 0 n_shards = 1 self.preprocessing_device = preprocessing_device.lower() assert self.preprocessing_device == "cpu" or self.preprocessing_device == "gpu", \ "Incorrect preprocessing device. Please choose either 'cpu' or 'gpu'" self.frame_splicing_factor = frame_splicing_factor assert frame_splicing_factor == 1, "DALI doesn't support frame splicing operation" self.resample_range = resample_range self.discrete_resample_range = discrete_resample_range self.train = train_pipeline self.sample_rate = sample_rate self.dither_coeff = dither_coeff self.nfeatures = nfeatures self.max_duration = max_duration self.mask_params = { 'time_num_regions': mask_time_num_regions, 'time_min': mask_time_min, 'time_max': mask_time_max, 'freq_num_regions': mask_freq_num_regions, 'freq_min': mask_freq_min, 'freq_max': mask_freq_max, 'both_num_regions': mask_both_num_regions, 'both_min_time': mask_both_min_time, 'both_max_time': mask_both_max_time, 'both_min_freq': mask_both_min_freq, 'both_max_freq': mask_both_max_freq, } self.do_remove_silence = True if silence_threshold is not None else False self.read = ops.FileReader(device="cpu", file_root=file_root, file_list=file_list, shard_id=shard_id, num_shards=n_shards, shuffle_after_epoch=train_pipeline) # TODO change ExternalSource to Uniform for new DALI release if discrete_resample_range and resample_range is not None: self.speed_perturbation_coeffs = ops.ExternalSource( device="cpu", cycle=True, source=self._discrete_resample_coeffs_generator) elif resample_range is not None: self.speed_perturbation_coeffs = ops.Uniform(device="cpu", range=resample_range) else: self.speed_perturbation_coeffs = None self.decode = ops.AudioDecoder( device="cpu", sample_rate=self.sample_rate if resample_range is None else None, dtype=types.FLOAT, downmix=True) self.normal_distribution = ops.NormalDistribution( device=preprocessing_device) self.preemph = ops.PreemphasisFilter(device=preprocessing_device, preemph_coeff=preemph_coeff) self.spectrogram = ops.Spectrogram( device=preprocessing_device, nfft=nfft, window_length=window_size * sample_rate, window_step=window_stride * sample_rate) self.mel_fbank = ops.MelFilterBank(device=preprocessing_device, sample_rate=sample_rate, nfilter=self.nfeatures, normalize=True) self.log_features = ops.ToDecibels(device=preprocessing_device, multiplier=np.log(10), reference=1.0, cutoff_db=math.log(1e-20)) self.get_shape = ops.Shapes(device=preprocessing_device) self.normalize = ops.Normalize(device=preprocessing_device, axes=[1]) self.pad = ops.Pad(device=preprocessing_device, axes=[1], fill_value=0, align=pad_align) # Silence trimming self.get_nonsilent_region = ops.NonsilentRegion( device="cpu", cutoff_db=silence_threshold) self.trim_silence = ops.Slice(device="cpu", normalized_anchor=False, normalized_shape=False, axes=[0]) self.to_float = ops.Cast(device="cpu", dtype=types.FLOAT) # Spectrogram masking self.spectrogram_cutouts = ops.ExternalSource( source=self._cutouts_generator, num_outputs=2, cycle=True) self.mask_spectrogram = ops.Erase(device=preprocessing_device, axes=[0, 1], fill_value=0, normalized_anchor=True)
def __init__(self, batch_size, dtype): super(NormalDistributionPipelineDefault, self).__init__(batch_size) self.norm = ops.NormalDistribution(device="cpu", dtype=dtype)
def __init__(self, shape, dtype): super(NormalDistributionPipelineWithArgument, self).__init__(1) self.norm = ops.NormalDistribution(device="cpu", shape=shape, dtype=dtype)
def __init__(self, premade_batch, dtype): super(NormalDistributionPipelineWithInput, self).__init__(len(premade_batch)) self.premade_batch = premade_batch self.ext_src = ops.ExternalSource() self.norm = ops.NormalDistribution(device="cpu", dtype=dtype)
def __init__(self, *, pipeline_type, device_id, num_threads, batch_size, file_root: str, sampler, sample_rate, resample_range: list, window_size, window_stride, nfeatures, nfft, dither_coeff, silence_threshold, preemph_coeff, max_duration, preprocessing_device="gpu"): super().__init__(batch_size, num_threads, device_id) self._dali_init_log(locals()) if torch.distributed.is_initialized(): shard_id = torch.distributed.get_rank() n_shards = torch.distributed.get_world_size() else: shard_id = 0 n_shards = 1 self.preprocessing_device = preprocessing_device.lower() assert self.preprocessing_device == "cpu" or self.preprocessing_device == "gpu", \ "Incorrect preprocessing device. Please choose either 'cpu' or 'gpu'" self.resample_range = resample_range train_pipeline = pipeline_type == 'train' self.train = train_pipeline self.sample_rate = sample_rate self.dither_coeff = dither_coeff self.nfeatures = nfeatures self.max_duration = max_duration self.do_remove_silence = True if silence_threshold is not None else False shuffle = train_pipeline and not sampler.is_sampler_random() self.read = ops.FileReader(name="Reader", pad_last_batch=(pipeline_type == 'val'), device="cpu", file_root=file_root, file_list=sampler.get_file_list_path(), shard_id=shard_id, num_shards=n_shards, shuffle_after_epoch=shuffle) # TODO change ExternalSource to Uniform for new DALI release if resample_range is not None: self.speed_perturbation_coeffs = ops.Uniform(device="cpu", range=resample_range) else: self.speed_perturbation_coeffs = None self.decode = ops.AudioDecoder( device="cpu", sample_rate=self.sample_rate if resample_range is None else None, dtype=types.FLOAT, downmix=True) self.normal_distribution = ops.NormalDistribution( device=preprocessing_device) self.preemph = ops.PreemphasisFilter(device=preprocessing_device, preemph_coeff=preemph_coeff) self.spectrogram = ops.Spectrogram( device=preprocessing_device, nfft=nfft, window_length=window_size * sample_rate, window_step=window_stride * sample_rate) self.mel_fbank = ops.MelFilterBank(device=preprocessing_device, sample_rate=sample_rate, nfilter=self.nfeatures, normalize=True) self.log_features = ops.ToDecibels(device=preprocessing_device, multiplier=np.log(10), reference=1.0, cutoff_db=math.log(1e-20)) self.get_shape = ops.Shapes(device=preprocessing_device) self.normalize = ops.Normalize(device=preprocessing_device, axes=[1]) self.pad = ops.Pad(device=preprocessing_device, fill_value=0) # Silence trimming self.get_nonsilent_region = ops.NonsilentRegion( device="cpu", cutoff_db=silence_threshold) self.trim_silence = ops.Slice(device="cpu", normalized_anchor=False, normalized_shape=False, axes=[0]) self.to_float = ops.Cast(device="cpu", dtype=types.FLOAT)