diff --git a/soundbay/trainers.py b/soundbay/trainers.py index 9e3470a..681732f 100644 --- a/soundbay/trainers.py +++ b/soundbay/trainers.py @@ -102,7 +102,8 @@ def train_epoch(self, epoch): audio, label = audio.to(self.device), label.to(self.device) if (it == 0) and (not self.debug) and ((epoch % 5) == 0): - self.logger.upload_artifacts(audio, label, raw_wav, meta, sample_rate=self.train_dataloader.dataset.sample_rate, flag='train') + self.logger.upload_artifacts(audio, label, raw_wav, meta, sample_rate=self.train_dataloader.dataset.sample_rate, + flag='train', data_sample_rate=self.train_dataloader.dataset.data_sample_rate) # estimate and calc losses estimated_label = self.model(audio) @@ -140,7 +141,8 @@ def eval_epoch(self, epoch: int, datatset_name: str = None): audio, label, raw_wav, meta = batch audio, label = audio.to(self.device), label.to(self.device) if (it == 0) and (not self.debug) and ((epoch % 5) == 0): - self.logger.upload_artifacts(audio, label, raw_wav, meta, sample_rate=self.train_dataloader.dataset.sample_rate, flag=datatset_name) + self.logger.upload_artifacts(audio, label, raw_wav, meta, sample_rate=self.train_dataloader.dataset.sample_rate, + flag=datatset_name, data_sample_rate=self.train_dataloader.dataset.data_sample_rate) # estimate and calc losses estimated_label = self.model(audio) diff --git a/soundbay/utils/logging.py b/soundbay/utils/logging.py index 630daa8..e51d326 100644 --- a/soundbay/utils/logging.py +++ b/soundbay/utils/logging.py @@ -153,7 +153,7 @@ def calc_metrics(self, epoch: int, mode: str = 'train', label_names: Optional[Li self.label_list = [] self.pred_proba_list = [] - def upload_artifacts(self, audio: torch.Tensor, label: torch.Tensor, raw_wav: torch.Tensor, meta: dict, sample_rate: int=16000, flag: str='train'): + def upload_artifacts(self, audio: torch.Tensor, label: torch.Tensor, raw_wav: torch.Tensor, meta: dict, sample_rate: int=16000, flag: str='train', data_sample_rate: int = 16000): """upload algorithm artifacts to W&B during training session""" volume = 50 matplotlib.use('Agg') @@ -171,7 +171,7 @@ def upload_artifacts(self, audio: torch.Tensor, label: torch.Tensor, raw_wav: to artifact_wav = torch.squeeze(raw_wav).detach().cpu().numpy() artifact_wav = artifact_wav / np.expand_dims(np.abs(artifact_wav).max(axis=1) + 1e-8, 1) * 0.5 # gain -6dB - list_of_wavs_objects = [wandb.Audio(data_or_path=wav, caption=f'{flag}_label{lab}_i{ind}_{round(b_t/sample_rate,3)}sec_{f_n}', sample_rate=sample_rate) for wav, ind, lab, b_t, f_n in zip(artifact_wav,idx, label, meta['begin_time'], meta['org_file'])] + list_of_wavs_objects = [wandb.Audio(data_or_path=wav, caption=f'{flag}_label{lab}_i{ind}_{round(b_t/data_sample_rate,2)}sec_{f_n}', sample_rate=sample_rate) for wav, ind, lab, b_t, f_n in zip(artifact_wav,idx, label, meta['begin_time'], meta['org_file'])] # Spectrograms batch artifact_spec = torch.squeeze(audio).detach().cpu().numpy() @@ -181,7 +181,7 @@ def upload_artifacts(self, audio: torch.Tensor, label: torch.Tensor, raw_wav: to specs.append(librosa.display.specshow(artifact_spec[artifact_id,...], ax=ax[1])) plt.close('all') del ax - list_of_specs_objects = [wandb.Image(data_or_path=spec, caption=f'{flag}_label{lab}_i{ind}_{round(b_t/sample_rate,2)}sec_{f_n}') for spec, ind, lab, b_t, f_n in zip(specs,idx, label, meta['begin_time'], meta['org_file'])] + list_of_specs_objects = [wandb.Image(data_or_path=spec, caption=f'{flag}_label{lab}_i{ind}_{round(b_t/data_sample_rate,2)}sec_{f_n}') for spec, ind, lab, b_t, f_n in zip(specs,idx, label, meta['begin_time'], meta['org_file'])] log_wavs = {f'First batch {flag} original wavs': list_of_wavs_objects} log_specs = {f'First batch {flag} augmented spectrogram\'s': list_of_specs_objects}