def __init__(self, device, batch_size, layout, iterator, anchor, shape, axis_names, axes, fill_value, normalized_anchor=False, normalized_shape=False, num_threads=1, device_id=0, num_gpus=1): super(ErasePipeline, self).__init__(batch_size, num_threads, device_id) self.device = device self.layout = layout self.iterator = iterator self.inputs = ops.ExternalSource() self.erase = ops.Erase(device=self.device, anchor=anchor, shape=shape, axis_names=axis_names, axes=axes, fill_value=fill_value, normalized_anchor=normalized_anchor, normalized_shape=normalized_shape)
def __new__( cls, axes=(0, 1), fill_value=0, normalized_anchor=True, normalized_shape=True, **kwargs ): """Create an ``Erase`` operator. Parameters ---------- axes : Sequence[int], optional The padding axes. fill_value : Union[number, Sequence[float]], optional The value to fill the erased regions. normalized_anchor : bool, optional, default=True Provided anchor is normalized or not. normalized_shape : bool, optional, default=True Provided shape is normalized or not. Returns ------- nvidia.dali.ops.Erase The operator. """ return ops.Erase( axes=axes, fill_value=fill_value, normalized_anchor=normalized_anchor, normalized_shape=normalized_shape, device=context.get_device_type(), **kwargs )
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 = random.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 = random.Normal(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)