ADNI Series

1、【ADNI】数据预处理(1)SPM,CAT12

2、【ADNI】数据预处理(2)获取 subject slices

3、【ADNI】数据预处理(3)CNNs

4、【ADNI】数据预处理(4)Get top k slices according to CNNs

5、【ADNI】数据预处理(5)Get top k slices (pMCI_sMCI) according to CNNs

6、【ADNI】数据预处理(6)ADNI_slice_dataloader ||| show image


Idea:

已有数据:AD_NC_ALL_SLICE

AD_NC_ALL_SLICE:分别对ADNI下载而来的nii数据(121x145x121)沿x,y,z轴方向进行切片,得到121+145+121=387张切片图,分别以AD/NC(199/230)为类别存储在如下目录:

基于上述数据形式,进一步处理:

1)目的:分别对每个切片位置组成的数据进行分类,筛选出具有区分能力的切片位置;

2)方法:将每个位置的切片图单独存储在一个目录下,总共得到387个目录,每个目录下有429张(AD=199张,NC=230张)切片数据;按照8:2的比例划分 train set 和 validation set;然后分别使用AlexNet进行训练,记录 best_val_acc作为评判依据;

处理后的数据形式如下所示:

以 slice_X10 为例:

1)该目录下有2个子目录,分别为 train 和 validation;

2)train 和 validation 目录下也分别有2个子目录对应2个类别:AD 和 NC;

3)样本比例:train(AD:NC=159:184);validation(AD:NC=40:46)

源代码:

step1:注意该脚本所在的目录

#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import re
import time
import datetimeimport shutilroot_path = "/home/reserch/documents/deeplearning/alzheimers_disease_DL/ADNI"def specified_subject_move_to_fold(slice_path_txt_list, target_path, label):slice_index = 1subject_num = 0# print(slice_path_txt_list)# print(target_path)with open(slice_path_txt_list,"r") as slice_txt_path_list:for slice_txt_path in slice_txt_path_list:# slice_txt_path = slice_txt_path_list.readline()slice_txt_path = slice_txt_path.replace("\n", "")slice_txt_path = slice_txt_path.replace("\r", "")slice_txt_path = slice_txt_path.replace("\\", "/")subject_num = subject_num + 1try:subject_id = slice_txt_path.split("/")[4]# print("subject_id = {}".format(subject_id))except:subject_id = ""print("...xx...")# print(slice_txt_path)entropy_value_txt_name = "entropy_value_" + label + "_gray_matter_Slices.txt"slice_txt = os.path.join(slice_txt_path, entropy_value_txt_name)# print(slice_txt)with open(slice_txt, "r") as slice_path_list:for item_slice in slice_path_list:new_target_path = target_pathslice_name = item_slice.split(",")[0]try:if (slice_name.split(".")[1] == "jpg"):slice_postion = slice_name.split(".")[0]slice_path = os.path.join(slice_txt_path, slice_name)if (os.path.exists(slice_path)):# print("slice_path = {}".format(slice_path))# new_slice_name = "GM" + label + str("%.5d"%slice_index) + "_" + subject_id +  ".jpg"new_slice_name = slice_postion + "_" + subject_id + "_" + "GM" + label + ".jpg"# new_slice_name = "GM" + label + "_" + subject_id +  ".jpg"new_target_path = os.path.join(new_target_path, slice_postion, label)if not os.path.exists(new_target_path):print("Create dir = {}".format(new_target_path))os.makedirs(new_target_path)new_name = os.path.join(new_target_path, new_slice_name)slice_index = slice_index + 1print("copied the image to {}".format(new_name))shutil.copyfile(slice_path, new_name)except:pass# print("{} not a jpg file.".format(slice_name))# if(slice_index > 5):#    break# except:#     print("[error]...")### subject_num/3 --> 3 including X Y Zprint("subject_num = {}".format(subject_num/3))print("total slice num = {}".format(slice_index))### according to AD_gray_matter_Slices_path.txt file, move all slices to a folder (AD_GM_except_entropy_zero)
### new file: all slices in a folder. AD_GM_except_entropy_zero + NC_GM_except_entropy_zeroif __name__=="__main__":dataset = 'dataset3'slice_path_txt_list = './AD_NC_ALL_SLICE/NC_gray_matter_Slices_ALL/NC_gray_matter_Slices_path.txt'target_path = os.path.join(root_path, dataset)label = 'NC'specified_subject_move_to_fold(slice_path_txt_list, target_path, label)slice_path_txt_list = './AD_NC_ALL_SLICE/AD_gray_matter_Slices_ALL/AD_gray_matter_Slices_path.txt'target_path = os.path.join(root_path, dataset)label = 'AD'specified_subject_move_to_fold(slice_path_txt_list, target_path, label)

step2:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import re
import time
import datetimeimport shutil
import random
from hcq_lib import *train_percentage = 0.8
val_percentage = 0.2
test_percentage = 0.1len_slice_list_CascadeCNNs_AD = 199 ## 199 + 230
len_slice_list_CascadeCNNs_NC = 230 ## 199 + 230
rondom_list_AD = random.sample(range(0, len_slice_list_CascadeCNNs_AD), len_slice_list_CascadeCNNs_AD)
rondom_list_NC = random.sample(range(0, len_slice_list_CascadeCNNs_NC), len_slice_list_CascadeCNNs_NC)
path_backup_random_list = "/home/reserch/documents/deeplearning/alzheimers_disease_DL/ADNI/backup_random_list/rondom_list.txt"
# hcq_backup_txt_rename(path_backup_random_list)hcq_write(path_backup_random_list, True, True, rondom_list_AD)
hcq_write(path_backup_random_list, True, True, rondom_list_NC)def get_slice_train_val_test(root_path, slice_folder_path):## root_path = "/home/reserch/documents/deeplearning/alzheimers_disease_DL/ADNI/dataset3"## slice_folder_path = slice_X44## train_target_path = /home/reserch/documents/deeplearning/alzheimers_disease_DL/ADNI/dataset/slice_X44/traintrain_target_path = os.path.join(root_path, slice_folder_path, "train")val_target_path = os.path.join(root_path, slice_folder_path, "validation")### get all silce through its pathslice_list_AD = os.listdir(os.path.join(root_path, slice_folder_path, "AD"))slice_list_NC = os.listdir(os.path.join(root_path, slice_folder_path, "NC"))# len_slice_list_AD = len(slice_list_AD)# len_slice_list_NC = len(slice_list_NC)### set the number of train, val, test# train_num = int(train_percentage * len_slice_list)# val_num = len_slice_list - train_num# print("=====")# print("total_num = {}".format(len_slice_list))# print("train_num = {}".format(train_num))# print("val_num = {}".format(val_num))### create a rondom list without repetition# rondom_list = random.sample(range(0, len_slice_list), len_slice_list)# print(rondom_list)hcq_create_dir(os.path.join(train_target_path, "AD"))hcq_create_dir(os.path.join(train_target_path, "NC"))hcq_create_dir(os.path.join(val_target_path, "AD"))hcq_create_dir(os.path.join(val_target_path, "NC"))### create txt file to store the index of train, val, test# train: [0, train_num-1]num_train_AD = 0num_train_NC = 0num_val_AD = 0num_val_NC = 0### ADfor i in range(len_slice_list_CascadeCNNs_AD):slice_index = rondom_list_AD[i]label = ((slice_list_AD[slice_index].split("_")[3]).split(".")[0])[2:4]old_path = os.path.join(os.path.join(root_path, slice_folder_path), label, slice_list_AD[slice_index])if(num_train_AD < int(len_slice_list_CascadeCNNs_AD*train_percentage)):num_train_AD += 1new_path = os.path.join(train_target_path, label, slice_list_AD[slice_index])else:num_val_AD += 1new_path = os.path.join(val_target_path, label, slice_list_AD[slice_index])shutil.copyfile(old_path, new_path)os.remove(old_path)# print("===")# print(old_path)# print(new_path)### NC# # val: [train_num, train_num + val_num - 1]for i in range(len_slice_list_CascadeCNNs_NC):slice_index = rondom_list_NC[i]label = ((slice_list_NC[slice_index].split("_")[3]).split(".")[0])[2:4]old_path = os.path.join(os.path.join(root_path, slice_folder_path), label, slice_list_NC[slice_index])if(num_train_NC < int(len_slice_list_CascadeCNNs_NC*train_percentage)):num_train_NC += 1new_path = os.path.join(train_target_path, label, slice_list_NC[slice_index])else:num_val_NC += 1new_path = os.path.join(val_target_path, label, slice_list_NC[slice_index])shutil.copyfile(old_path, new_path)os.remove(old_path)# print("===")# print(old_path)# print(new_path)print("num_train_AD = {}".format(num_train_AD))print("num_train_NC = {}".format(num_train_NC))print("num_val_AD = {}".format(num_val_AD))print("num_val_NC = {}".format(num_val_NC))### delete empty folder: AD, NChcq_rmdir(os.path.join(root_path, slice_folder_path, "AD"))hcq_rmdir(os.path.join(root_path, slice_folder_path, "NC"))if __name__=="__main__":root_path = "/home/reserch/documents/deeplearning/alzheimers_disease_DL/ADNI/dataset3"slice_folder_list = os.listdir(root_path)num = 0for slice_folder_path in slice_folder_list:num += 1# print("===")# print(num)get_slice_train_val_test(root_path, slice_folder_path)# if(num>0):#  break

【ADNI】数据预处理(3)CNNs相关推荐

  1. 【ADNI】数据预处理(1)SPM,CAT12;数据集

    ADNI Series 1.[ADNI]数据预处理(1)SPM,CAT12 2.[ADNI]数据预处理(2)获取 subject slices 3.[ADNI]数据预处理(3)CNNs 4.[ADNI ...

  2. 机器学习PAL数据预处理

    机器学习PAL数据预处理 本文介绍如何对原始数据进行数据预处理,得到模型训练集和模型预测集. 前提条件 完成数据准备,详情请参见准备数据. 操作步骤 登录PAI控制台. 在左侧导航栏,选择模型开发和训 ...

  3. 深度学习——数据预处理篇

    深度学习--数据预处理篇 文章目录 深度学习--数据预处理篇 一.前言 二.常用的数据预处理方法 零均值化(中心化) 数据归一化(normalization) 主成分分析(PCA.Principal ...

  4. 目标检测之Faster-RCNN的pytorch代码详解(数据预处理篇)

    首先贴上代码原作者的github:https://github.com/chenyuntc/simple-faster-rcnn-pytorch(非代码作者,博文只解释代码) 今天看完了simple- ...

  5. 第七篇:数据预处理(四) - 数据归约(PCA/EFA为例)

    前言 这部分也许是数据预处理最为关键的一个阶段. 如何对数据降维是一个很有挑战,很有深度的话题,很多理论书本均有详细深入的讲解分析. 本文仅介绍主成分分析法(PCA)和探索性因子分析法(EFA),并给 ...

  6. 数据预处理--噪声_为什么数据对您的业务很重要-以及如何处理数据

    数据预处理--噪声 YES! Data is extremely important for your business. 是! 数据对您的业务极为重要. A human body has five ...

  7. 数据预处理(完整步骤)

    原文:http://dataunion.org/5009.html 一:为什么要预处理数据? (1)现实世界的数据是肮脏的(不完整,含噪声,不一致) (2)没有高质量的数据,就没有高质量的挖掘结果(高 ...

  8. 3D目标检测深度学习方法数据预处理综述

    作者 | 蒋天元 来源 | 3D视觉工坊(ID: QYong_2014) 这一篇的内容主要要讲一点在深度学习的3D目标检测网络中,我们都采用了哪些数据预处理的方法,主要讲两个方面的知识,第一个是rep ...

  9. 整理一份详细的数据预处理方法

    作者:lswbjtu https://zhuanlan.zhihu.com/p/51131210 编辑:机器学习算法与Python实战 为什么数据处理很重要? 熟悉数据挖掘和机器学习的小伙伴们都知道, ...

  10. pandas数据预处理(标准化归一化、离散化/分箱/分桶、分类数据处理、时间类型数据处理、样本类别分布不均衡数据处理、数据抽样)

    1. 数值型数据的处理 1.1 标准化&归一化 数据标准化是一个常用的数据预处理操作,目的是处理不同规模和量纲的数据,使其缩放到相同的数据区间和范围,以减少规模.特征.分布差异等对模型的影响. ...

最新文章

  1. opencv文件路径问题
  2. Tair的桶分布策略介绍及新的机器级位置安全优先策略实现
  3. inet_ntoa()返回字符串的生命周期
  4. 解决JQuery AutoComplete在IE9下出错的问题
  5. 回归专题 | regression
  6. Linux C编程之四 动态库(共享库)的制作
  7. stm32f405xx.h头文件的问题Undefined symbol IS_TIM_BREAK_INSTANCE
  8. jeecms附件标签用法
  9. JAVA菜鸟入门HelloWorld
  10. ajax请求队列,使AJAX队列稍后解析请求
  11. EnterCriticalSection 多线程操作相同数据遇到的问题(线程锁)
  12. [JUC-1]并发包实现及线程状态
  13. CSS伪元素与伪类的区别
  14. 20180810 多益网络模拟笔试
  15. smart原则_绩效指标如何设定?SMART原则轻松搞定
  16. C题:无线充电电动小车(本科)--2018年TI杯大学生电子设计竞赛
  17. 简单实现手机号验证码注册功能
  18. 在Ubuntu20.04上安装ros
  19. linux开启vt虚拟化,VT虚拟化如何开启
  20. 【设计模式】—-(12)代理模式(结构型)

热门文章

  1. MMA算法的推导及3D简支梁拓扑优化代码详解
  2. nginx 解析二级域名
  3. PNG图片压缩对比分析
  4. 阿里云相关-负载均衡
  5. scala--模式匹配
  6. 【电脑突然识别不了外置光驱】
  7. 柴静:我只是讨厌屈服
  8. linux学习(三)输入输出重定向和管道功能、cat命令、more命令
  9. 微型计算机及接口技术笔记,2010年自考微型计算机及其接口技术笔记串讲
  10. ppt背景图片php,ppt背景图片怎么设置 ppt幻灯片制作视频