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 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 #3
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 #4
0
                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)

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

        bef_cnt = 0