Exemplo n.º 1
0
def Modify(logits_student, target):
    if torch.is_tensor(logits_student):
        logits_student = logits_student.detach().cpu().numpy()
    if torch.is_tensor(target):
        target = target.cpu().numpy()
    num = logits_student.shape[0]
    assert (num == target.shape[0])
    pred = []
    truth = []
    for i in range(num):
        ptemp = istft(logits_student[i][0], logits_student[i][1])
        ttemp = istft(target[i][0], target[i][1])
        pred.append(ptemp)
        truth.append(ttemp)
        # pdb.set_trace()
    return np.array(pred, dtype='float32'), np.array(truth, dtype='float32')
def Modify(logits_student, xgg, target, ygg, refill, images):
    if torch.is_tensor(images):
        images = images.detach().cpu().numpy()
    if torch.is_tensor(logits_student):
        logits_student = logits_student.detach().cpu().numpy()
    if torch.is_tensor(target):
        target = target.detach().cpu().numpy()
    if torch.is_tensor(xgg):
        xgg = xgg.detach().cpu().numpy()
    if torch.is_tensor(ygg):
        ygg = ygg.detach().cpu().numpy()
    num = logits_student.shape[0]
    assert (num == target.shape[0])
    pred = []
    truth = []
    bsflag, noise_ori, batch_snr = refill
    bsflag = bsflag.cpu().numpy()
    noise_ori = noise_ori.cpu().numpy()
    batch_snr = batch_snr.cpu().numpy()
    j = 0
    for i in range(num):
        ptemp = istft(logits_student[i], xgg[i])
        ttemp = istft(target[i], ygg[i])
        pred.append(ptemp)
        truth.append(ttemp)
        if batch_snr[i] == ROOT_SNRS[j]:
            j = j + 1
            if j == len(ROOT_SNRS):
                j = 0
            if np.sum(bsflag[i]) == 0:
                tag = 'NBS_' + str(batch_snr[i])
            else:
                tag = 'BS_' + str(batch_snr[i])
            plt.subplot(311)
            # pdb.set_trace()
            ct = plt.pcolormesh(xgg[i])
            plt.colorbar(ct, label="power (dB)")
            plt.subplot(312)
            ct = plt.pcolormesh(ygg[i])
            plt.colorbar(ct, label="power (dB)")
            plt.subplot(313)
            ct = plt.pcolormesh(images[i])
            plt.colorbar(ct, label="power (dB)")
            plt.suptitle(tag, fontsize=14)
            plt.show()
        # pdb.set_trace()
    return np.array(pred, dtype='float32'), np.array(truth, dtype='float32')
Exemplo n.º 3
0
def Modify(logits_student0, logits_student1, target0, target1):
    if torch.is_tensor(logits_student0):
        logits_student0 = logits_student0.detach().cpu().numpy()
    if torch.is_tensor(logits_student1):
        logits_student1 = logits_student1.detach().cpu().numpy()
    if torch.is_tensor(target0):
        target0 = target0.cpu().numpy()
    if torch.is_tensor(target1):
        target1 = target1.cpu().numpy()
    num = logits_student0.shape[0]
    assert (num == target0.shape[0])
    assert (num == target1.shape[0])
    pred = []
    truth = []
    for i in range(num):
        # pdb.set_trace()
        ptemp = istft(logits_student0[i], logits_student1[i])
        ttemp = istft(target0[i], target1[i])
        pred.append(ptemp)
        truth.append(ttemp)
        # pdb.set_trace()
    return np.array(pred, dtype='float32'), np.array(truth, dtype='float32')
def unfold(whole_package):
    new_package = []
    for geti in whole_package:
        new_geti = []
        for tile in geti:
            if torch.is_tensor(tile):
                tile = tile.cpu().numpy()
            new_geti.append(tile)
        # pdb.set_trace()
        assert (len(new_geti) == 7)
        images, xgg, pred, truth, mm, nn, kk = new_geti
        assert (pred.shape[0] == truth.shape[0])
        assert (truth.shape[0] == mm.shape[0])
        assert (mm.shape[0] == nn.shape[0])
        assert (nn.shape[0] == kk.shape[0])
        temp = []
        for i in range(pred.shape[0]):
            ori_wav = istft(images[i], xgg[i])
            temp.append((ori_wav, pred[i], truth[i], mm[i], nn[i], kk[i]))
        new_package = new_package + temp
    return new_package
Exemplo n.º 5
0

if __name__ == '__main__':
    a = data_generator()
    B = BSdataset_BR_recovery(a.trains)
    okay = B.data
    i = 0
    for datum in okay:
        if datum[2][2][1] == ROOT_SNRS[i]:
            # pdb.set_trace()
            # ampli = datum[0][0][0]
            # phas = datum[0][0][1]
            ampli = datum[1][0]
            phas = datum[1][1]
            original = datum[1][2]
            synt = istft(ampli, phas)
            if np.sum(datum[2][0]) == 0:
                label = 'NBS'
            else:
                label = 'BS'
            tstr = label + '_' + datum[2][2][0] + '_' + str(datum[2][2][1])
            # add = ori
            plt.subplot(411)
            plt.plot(synt)
            plt.subplot(412)
            plt.plot(original)

            plt.subplot(413)
            coutour = plt.pcolormesh(ampli)
            plt.colorbar(coutour, label="power (dB)")
            # stft = GetFrequencyFeatures(he, 4000)