示例#1
0
    x = np.mean(x,axis=-1)
    #perform stft
    S = util.stft_real(x, blockSize=  blockSize,hopSize=hopSize)
    magnitude = np.abs(S).astype(np.float32)
    angle = np.angle(S).astype(np.float32)

    #initialize the model
    model = Model.ModelSingleStep(blockSize)

    #load the pretrained model
    checkpoint = torch.load("savedModel_fcnn_best.pt", map_location=lambda storage, loc:storage)
    model.load_state_dict(checkpoint['state_dict'])

    #switch to eval mode
    model.eval()
    
    ###################################
    #Run your Model here to obtain a mask
    ###################################
    magnitude_masked = model.process(magnitude) 

    ###################################


    #perform reconstruction
	y = util.istft_real(magnitude_masked * np.exp(1j * angle), blockSize=blockSize, hopSize=hopSize)

    #save the result
    util.wavwrite(sys.argv[2], y,fs)

    x, fs = util.wavread(sys.argv[1])
    #downmix to single channel
    x = np.mean(x, axis=-1)
    #perform stft
    S = util.stft_real(x, blockSize=blockSize, hopSize=hopSize)
    magnitude = np.abs(S).astype(np.float32)
    angle = np.angle(S).astype(np.float32)

    #initialize the model
    model = Model_fcn.ModelSingleStep(blockSize)
    #load the pretrained model
    model.load_state_dict(
        torch.load("Modelfcn.pt", map_location=lambda storage, loc: storage))
    #switch to eval mode
    model.eval()

    ###################################
    #Run your Model here to obtain a mask
    ###################################
    spectro_pred = model.process(magnitude)

    ###################################

    #perform reconstruction
    y = util.istft_real(spectro_pred * np.exp(1j * angle),
                        blockSize=blockSize,
                        hopSize=hopSize)

    #save the result
    util.wavwrite(sys.argv[2], y, fs)
    with torch.no_grad():
        nFrame = magnitude.shape[1]
        GRUout = []
        for i in range(nFrame):
            h = model.encode(mixture[i, :, :])
            h_d.append(h)
            if i < 5:  #delay is 5
                if i == 0:
                    outp, GRUo = model.forward(mixture[i, :, :], None,
                                               torch.zeros_like(h))

                else:
                    outp, GRUo = model.forward(mixture[i, :, :], GRUout[i - 1],
                                               torch.zeros_like(h))
            else:
                outp, GRUo = model.forward(mixture[i, :, :], GRUout[i - 1],
                                           h_d[i - 5])
            GRUout.append(GRUo)
            output.append(outp)
            mag_voice[:, i] = magnitude[:, i] * output[i].numpy()

    ###################################

    #perform reconstruction
    y = util.istft_real(mag_voice * np.exp(1j * angle),
                        blockSize=blockSize,
                        hopSize=hopSize)

    #save the result
    util.wavwrite(sys.argv[2], y, fs)