def __init__(self, model_dir): sys.path.append('../../nanonet/rirnet') from rirnet_database import RirnetDatabase print(sys.path) self.model_dir = model_dir self.extractor, _ = misc.load_latest(model_dir, 'extractor') self.autoencoder, _ = misc.load_latest(model_dir, 'autoencoder') self.extractor_args = self.extractor.args() use_cuda = not self.extractor_args.no_cuda and torch.cuda.is_available( ) self.device = torch.device("cuda" if use_cuda else "cpu") self.extractor.to(self.device) self.autoencoder.to(self.device) self.kwargs = { 'num_workers': 1, 'pin_memory': True } if use_cuda else {} data_transform = transforms.Compose([ ToNormalized('../../database/mean.npy', '../../database/std.npy') ]) target_transform = transforms.Compose( [ToNegativeLog(), ToUnitNorm(), ToTensor()]) self.extractor_args.val_db_path = '../../database/db-val.csv' eval_db = RirnetDatabase(is_training=False, args=self.extractor_args, data_transform=data_transform, target_transform=target_transform) self.eval_loader = torch.utils.data.DataLoader( eval_db, batch_size=self.extractor_args.batch_size, shuffle=True, **self.kwargs) self.audio_anechoic, self.fs = au.read_wav( '../../audio/harvard/male.wav')
def target_transform(self): target_transform = transforms.Compose([ToNegativeLog(), ToUnitNorm(), ToTensor()]) return target_transform