def load_npz(self, name='ECG200', target=None):
     # data, label = load_npz(name)
     (data, label), (_, _) = load_data(name)
     if not target:
         inx = range(len(data))
     else:
         inx = label == target
     dataset = Data.TensorDataset(
         torch.tensor(data[inx], dtype=torch.float32),
         torch.tensor(label[inx], dtype=torch.long))
     return dataset
Ejemplo n.º 2
0
    y_gen = []
    [m.eval() for m in model.models.values()]
    for i in LABELS:
        path = './ckpt/model_{:d}.pkl'.format(i)
        model.load_model(path)
        noise = model.gen_noise(0, 1, (NUM, LATENT_DIM))
        x = model.generator(noise)
        x = x.data.cpu().numpy().reshape(x.size(0), -1)
        y = np.zeros(NUM) + i
        x_gen.append(x)
        y_gen.append(y)
    x_gen = np.concatenate(x_gen)
    y_gen = np.concatenate(y_gen)

    data, label = load_npz()
    (x_train, y_train), (x_test, y_test) = load_data()

    clf_model = KNeighborsClassifier(n_neighbors=1)
    clf_model.fit(x_train, y_train)
    pred_data = clf_model.predict(data)
    pred_test = clf_model.predict(x_test)
    pred_gen = clf_model.predict(x_gen)
    classify_analysis(label, pred_data, labels=LABELS)
    classify_analysis(y_test, pred_test, labels=LABELS)
    classify_analysis(y_gen, pred_gen, labels=LABELS)
    print('-' * 20 + 'TSTR' + '-' * 20)
    clf_model.fit(x_gen, y_gen)
    pred_data = clf_model.predict(data)
    pred_test = clf_model.predict(x_test)
    pred_gen = clf_model.predict(x_gen)
    classify_analysis(label, pred_data, labels=LABELS)