Exemplo n.º 1
0
dropout = args.dropout
# 分类的种类
n_classes = 2
# 每批的大小
batch_size = args.batch_size
# 训练的次数
epochs = args.epochs
# 模型的学习率
lr = args.lr
# 序列长度
seq_length = 316
"""
构建模型的数据
"""
# 载入数据集
hdf5 = PrepareUtils.hdf5_handler(
    bytes('./data/ABIDE/abide_lstm.hdf5', encoding='utf8'), 'a')
# 保存所有数据
dataset_x = []
dataset_y = []
# 构建完整数据集
hdf5_dataset = hdf5["patients"]
for i in hdf5_dataset.keys():
    data_item_x = torch.from_numpy(
        np.array(hdf5["patients"][i]['cc200'], dtype=np.float32))
    data_item_y = hdf5["patients"][i].attrs["y"]
    dataset_x.append(data_item_x)
    dataset_y.append(data_item_y)
# 把所有数据增加padding
# dataset_x = nn.utils.rnn.pad_sequence(dataset_x, batch_first=True, padding_value=0)
dataset_y = torch.tensor(dataset_y, dtype=torch.long)
# 把数据按照7:3比例进行拆分
Exemplo n.º 2
0
if __name__ == "__main__":

    random.seed(19)
    np.random.seed(19)

    arguments = docopt(__doc__)

    folds = int(arguments["--folds"])
    # 表型数据的地址
    pheno_path = "../../data/ABIDE/phenotypes/Phenotypic_V1_0b_preprocessed1.csv"
    # 读取表型数据
    pheno = load_phenotypes(pheno_path)

    if arguments["--lstm"]:
        # 创建HDF5数据文件
        hdf5 = hdf5_handler(
            bytes("../../data/ABIDE/abide_lstm.hdf5", encoding="utf8"), 'a')
    else:
        # 创建HDF5数据文件
        hdf5 = hdf5_handler(
            bytes("../../data/ABIDE/abide_pcc.hdf5", encoding="utf8"), 'a')

    # 不同的脑图谱
    valid_derivatives = ["cc200", "aal", "ez", "ho", "tt", "dosenbach160"]
    derivatives = [
        derivative for derivative in arguments["<derivative>"]
        if derivative in valid_derivatives
    ]

    #  如果没有患者数据,那么就要读取患者的ROI的连接性数据并把数据保存到HDF5中
    if "patients" not in hdf5:
        load_patients_to_file(hdf5, pheno, derivatives)