Exemple #1
0
def gen_rep_img(isABP):
    if isABP:
        int_dat = os.listdir('10 ABP int')
    else:
        int_dat = os.listdir('10 ICP int')
    file_names = []
    total_sig = []
    total_lab = []
    total_tim = []
    for int_d in int_dat:
        if isABP:
            sig, lab, tim = ae.load_one_data('10 ABP int/' + int_d)
        else:
            sig, lab, tim = ae.load_one_data('10 ICP int/' + int_d)
        total_sig.append(sig)
        total_lab.append(lab)
        total_tim.append(tim)
        file_names.append(int_d)
    for i in range(len(total_sig)):
        signal_tag = 'ABP' if isABP else 'ICP'
        if os.path.isfile('npy10/' + signal_tag + '/' + file_names[i] +
                          '.train.ori.npy'):
            continue
        print(i)
        train_x = []
        train_y = []
        train_t = []
        test_x = []
        test_y = []
        test_t = []
        for j in range(len(total_sig)):
            if i == j:
                test_x.extend(total_sig[j])
                test_y.extend(total_lab[j])
                test_t.extend(total_tim[j])
            else:
                train_x.extend(total_sig[j])
                train_y.extend(total_lab[j])
                train_t.extend(total_tim[j])
        train_x = ae.signal_to_img(train_x)
        test_x = ae.signal_to_img(test_x)
        train_rep_x = ae.autoencoding_cnn(
            train_x, train_x, 'net/' + str(i) + '_' + signal_tag + '.net')
        test_rep_x = ae.autoencding_cnn_using_net(
            test_x, 'net/' + str(i) + '_' + signal_tag + '.net')
        np.save('npy10/' + signal_tag + '/' + file_names[i] + '.train.ori.npy',
                train_x)
        np.save('npy10/' + signal_tag + '/' + file_names[i] + '.train.rep.npy',
                train_rep_x)
        np.save('npy10/' + signal_tag + '/' + file_names[i] + '.train.etc.npy',
                [train_y, train_t])
        np.save('npy10/' + signal_tag + '/' + file_names[i] + '.test.ori.npy',
                test_x)
        np.save('npy10/' + signal_tag + '/' + file_names[i] + '.test.rep.npy',
                test_rep_x)
        np.save('npy10/' + signal_tag + '/' + file_names[i] + '.test.etc.npy',
                [test_y, test_t])
Exemple #2
0
def remove_artifact(isABP, int_path):
    samples = os.listdir(int_path)
    signal_tag = 'ABP' if isABP else 'ICP'
    rep_model = load_model('net/FINAL_' + signal_tag + '.net')
    cla_model = load_model('net/CNN/FINAL_' + signal_tag + '.net')
    for v in samples:
        sig, lab, tim = ae.load_one_data(int_path + '/' + v)
        train_x = ae.signal_to_img(train_x)
        train_rep_x = ae.autoencding_cnn_using_net(train_x, rep_model)
Exemple #3
0
def remove_label_generator(isABP, int_path):
    signal_tag = 'ABP' if isABP else 'ICP'
    model = load_model('net/CNN/FINAL_' + signal_tag + '.net')
    files = os.listdir(int_path)
    for file in files:
        if file.split('.')[-1] != 'csv': continue
        print(file)
        sig, lab, tim = ae.load_one_data(int_path + '/' + file)
        img = ae.signal_to_img(sig)
        rep = ae.autoencding_cnn_using_net(img,
                                           'net/FINAL_' + signal_tag + '.net')
        pred = model.predict(rep)
        pen = open('result/' + signal_tag + '/' + file + '.prd.fin.csv', 'w')
        for i in range(len(pred)):
            pen.write(str(i) + ',' + str(round(pred[i][0])) + '\n')
        pen.close()
    print('fin')
Exemple #4
0
def gen_full_train_network(isABP):
    signal_tag = 'ABP' if isABP else 'ICP'
    int_dat = os.listdir('10 ' + signal_tag + ' int')
    train_x = []
    train_y = []
    train_t = []
    for int_d in int_dat:
        sig, lab, tim = ae.load_one_data('10 ' + signal_tag + ' int/' + int_d)
        train_x.extend(sig)
        train_y.extend(lab)
        train_t.extend(tim)
    train_x = ae.signal_to_img(train_x)
    train_rep = ae.autoencoding_cnn(train_x, train_x,
                                    'net/FINAL_' + signal_tag + '.net')
    new_train = n_augmentation(train_rep, label_gen(train_y), train_t)
    model = trainer.create_model(64)
    print(model.summary())
    model.fit(np.array(new_train[0]),
              np.array(new_train[1]),
              epochs=10,
              shuffle=True)
    model.save('net/CNN/FINAL_' + signal_tag + '.net')
Exemple #5
0
def make_img():
    import matplotlib.pyplot as plt
    int_dat = os.listdir('10 ICP int')
    for int_d in int_dat:
        sig, lab, tim = ae.load_one_data('10 ICP int/' + int_d)
        img = ae.signal_to_img(sig)
        if not os.path.isdir('img/' + int_d.split('_')[0]):
            os.mkdir('img/' + int_d.split('_')[0])
            os.mkdir('img/' + int_d.split('_')[0] + '/nor')
            os.mkdir('img/' + int_d.split('_')[0] + '/art')
        else:
            continue
        for i in range(len(tim)):
            plt.figure(1)
            plt.imshow(img[i].reshape(64, 64))
            if lab[i] == 0:
                plt.savefig('img/' + int_d.split('_')[0] + '/nor/' + str(i) +
                            '.png')
            else:
                plt.savefig('img/' + int_d.split('_')[0] + '/art/' + str(i) +
                            '.png')
            plt.cla()
            plt.clf()
Exemple #6
0
def representation():
    s, f = ae.load_data('10 ABP int/')
    total_image = []
    total_signal = []
    file_len_map = {}

    bef_cnt = 0
    for k in range(len(f)):
        filename = f[k].split('_')[0]
        imgs = ae.signal_to_img(s[k])
        total_image.extend(imgs)
        total_signal.extend(s[k])
        file_len_map[filename] = [bef_cnt, bef_cnt + len(imgs)]
        bef_cnt += len(imgs)
    total_rep_imgs = ae.autoencoding_cnn(total_image, total_image, fold='tot')
    for l, v in file_len_map.items():
        npy_ori = []
        npy_rep = []
        for m in range(v[0], v[1]):
            npy_ori.append(np.array(total_image[m]).reshape(64, 64, 1))
            npy_rep.append(np.array(total_rep_imgs[m]).reshape(64, 64, 1))
        np.save('npy/abp/tot/' + l + '.ori.npy', np.array(npy_ori))
        np.save('npy/abp/tot/' + l + '.rep.npy', np.array(npy_rep))
Exemple #7
0
    if not os.path.exists('img/ori/'+f.split('_'[0])):
      os.mkdir('img/ori/'+f.split('_')[0])
    if not os.path.exists('img/rep/'+f.split('_'[0])):
      os.mkdir('img/rep/'+f.split('_')[0])
    for i in range(len(lab)):
      cur_img = ae.signal_to_img(sig[i])
  """
    signals, filenames = ae.load_data(path)
    total_image = []
    total_signal = []
    file_len_map = {}

    bef_cnt = 0
    for i in range(len(filenames)):
        filename = filenames[i].split('_')[0]
        imgs = ae.signal_to_img(signals[i])
        total_image.extend(imgs)
        total_signal.extend(signals[i])
        file_len_map[filename] = [bef_cnt, bef_cnt + len(imgs)]
        bef_cnt += len(imgs)
    #total_rep_imgs = ae.autoencoding_cnn(total_image, total_image, img_dim=64, encoding_dim=16)

    for k, v in file_len_map.items():
        npy_arr = []
        for i in range(v[0], v[1]):
            plt.figure(1)
            plt.imshow(total_image[i].reshape(64, 64))
            plt.savefig('img/ori_b/' + k + '_' + str(i - v[0]) + '.png')
            plt.cla()
            plt.clf()
Exemple #8
0
        for j in range(5):
            if i == j:
                sa.extend(signals[j])
                fa.extend(filenams[j])
            else:
                s.extend(signals[j])
                f.extend(filenams[j])

        total_image = []
        total_signal = []
        file_len_map = {}

        bef_cnt = 0
        for k in range(len(f)):
            filename = f[k].split('_')[0]
            imgs = ae.signal_to_img(s[k])
            total_image.extend(imgs)
            total_signal.extend(s[k])
            file_len_map[filename] = [bef_cnt, bef_cnt + len(imgs)]
            bef_cnt += len(imgs)

        total_rep_imgs = ae.autoencoding_cnn(total_image, total_image, fold=i)

        for l, v in file_len_map.items():
            npy_ori = []
            npy_rep = []
            for m in range(v[0], v[1]):
                npy_ori.append(total_image[m])
                npy_rep.append(total_rep_imgs[m])
            np.save('npy/' + str(i) + '/' + l + '.abp.ori.npy', npy_ori)
            np.save('npy/' + str(i) + '/' + l + '.abp.rep.npy', npy_rep)