def inference(self, file_path): with torch.no_grad(): for key, egs in tqdm.tqdm(self.mix): #self.logger.info("Compute on utterance {}...".format(key)) egs=egs.to(self.device) norm = torch.norm(egs,float('inf')) if len(self.gpuid) != 0: if egs.dim() == 1: egs = torch.unsqueeze(egs, 0) ests=self.net(egs) spks=[torch.squeeze(s.detach().cpu()) for s in ests] else: if egs.dim() == 1: egs = torch.unsqueeze(egs, 0) ests=self.net(egs) spks=[torch.squeeze(s.detach()) for s in ests] index=0 for s in spks: s = s[:egs.shape[1]] s = s - torch.mean(s) s = s/torch.max(torch.abs(s)) #norm #s = s*norm/torch.max(torch.abs(s)) s = s.unsqueeze(0) index += 1 os.makedirs(file_path+'/spk'+str(index), exist_ok=True) filename=file_path+'/spk'+str(index)+'/'+key write_wav(filename, s, 8000) break self.logger.info("Compute over {:d} utterances".format(len(self.mix)))
def inference(self, file_path): self.net.eval() with torch.no_grad(): egs=self.mix norm = torch.norm(egs,float('inf')) if len(self.gpuid) != 0: if egs.dim() == 1: egs = torch.unsqueeze(egs, 0) ests=self.net(egs) spks=[torch.squeeze(s.detach().cpu()) for s in ests] else: if egs.dim() == 1: egs = torch.unsqueeze(egs, 0) ests=self.net(egs) print(ests[0].shape) spks=[torch.squeeze(s.detach()) for s in ests] index=0 for s in spks: #norm s = s - torch.mean(s) s = s*norm/torch.max(torch.abs(s)) index += 1 os.makedirs(file_path+'/spk'+str(index), exist_ok=True) filename=file_path+'/spk'+str(index)+'/'+'test.wav' write_wav(filename, s, 16000) self.logger.info("Compute over {:d} utterances".format(len(self.mix)))