结节&肺炎分割模型 ============================================================= Common ------------------------------------------------------ * 训练过程提测流程(测试同学) * 修改config中base_path(weights存储路径) * 结节:files/trainFiles/nodules/train_files.json * 肺炎:files/trainFiles/COVID/train_files.json * 训练 * 结节:运行train.py。 * 肺炎:运行01_COVID.py * 对比loss收敛图 * 根据loss找到weights存储路径 * 确保该路径下存在tensorboard_logs文件下 * 运行“tensorboard --logdir=tensorboard_logs” * 结节分割 * train * pics/train_loss_nodule.png * val * pics/val_loss_nodule.png * 肺炎分割 * train * pics/train_loss_pneumonia.png * val * pics/val_loss_pneumonia.png * 训练测试流程(以结节分割为例,文件为train.py) * 训练 * 指定log路径 * 指定参数相关json路径(确保json中的模型路径、数据路径存在) * 模式为training * 运行脚本 python train.py * 测试 * 指定log路径 * 指定参数相关json路径(确保json中的模型路径、数据路径存在) * 模式为test * 运行脚本 python train.py * 文件结构 * 训练/测试脚本函数:如01_COVID.py * 主函数(定义训练、测试流程) 如SegmentationCOVID.py * generator: 如utils/SegGenCOVIDV2.py * 其他uitls:utils下面 * 模型:model下 * files:存储在files下 * dataFiles:训练、测试数据路径 * modelParams:模型相关参数 * trainFiles:训练相关参数文件(直接与训练脚本相关) 结节分割 ----------------------------------------------------------- * 数据格式 * 包含以下三个文件: * data / info / mask * 三者num_samples(第一维)相等 * data & mask一般会比网络的输入大一点方便切patch(一般大小会超过64) * info包含uid/image_path(原图)/mask_path(原图等大mask)/征象类型(如果做分类需要,不做分类可以不包含)/长径(infer的时候用,训练的时候直接从mask提取)/spacing等信息 * 参数 * common |参数名|意义| |---|---| |base_path|weights存储的基础路径| |decoder| decoder名字(可选NoduleSegDecoder_proxima、UnetPP) | |encoder| encoder名字(可选XnetEncoder、NoduleSegEncoder_proxima)| |initial_learning_rate、learning_rate_drop、learning_rate_patience| 基础lr相关参数| |model_parameters| 模型参数json路径(相对于files),要保证json中有指定encoder和decoder的参数| |normalizer|归一化参数| |train_file、val_file、test_file| train\val\test数据路径(相对于files)| |do_cls| 是否加入分类任务,目前设置为False| |surface_loss| 是否在分类任务中加入surface loss| |e_value| surface_loss的比例| |compare_loss_ratio| 对比 变换后的预测 与 预测后的变换 之间差异的loss权重| |stride_ratio、min_patch_size、diameter_enlarge_ratio|定义patch大小相关参数| |calculate_shape_choice|计算patch大小的方法| |diameter_idx、densityTypeIndex、spacing_idx|长径、densityType在单条info中的index,以及spacing在单挑info中的起始index| |direction_z_ratio|patch_z = direction_z_ratio*patch_inplane |zoom_shape|进行zoom(不是zoom函数)的target inplace_size,不进行zoom则设置为None| * training |参数名|意义| |---|---| |aug|generator中是否加入augmentation| |n_epochs|训练epochs数| |num_slice、voxel_size|定义patch大小,x与y方向目前大小一定一样。如果num_slice和voxel_size均设置为-1(一定要同时是-1或者同时不是)| |nonfix_crop|是否按照不固定大小裁取patch,如果nonfix_crop为true且不进行zoom,batch_size要强制设置为1| |pre_model_file|多阶段训练,之前模型的路径| |model_name|模型名字(用于在base_path下创建子路径)| |model_order、prefix|创建model_name下的子路径| |train_batch_size、val_batch_size|batchsize| |save_cp|是否存储模型,一般都是true| |repeat_times|在generator中是否将data进行repeat,repeat后单个epoch处理数据量=数据量*repeat_times| |compare_choice|与compare_loss_ratio相关,是否使用这个loss| |area_th_val|最小的component大小数量| |lr_schedule|选择什么样的lr_schedule,默认值为“basic” 是ReduceLROnPlateau,else(目前所有其他选项都)是CyclicLR| |aug|generator中是否加入augmentation| * test |参数名|意义| |---|---| |num_slice、voxel_size、nonfix_crop|定义patch大小,x与y方向目前大小一定一样(与上面定义一样)| |infer_idx|取第几个分支的infer结果| |pre_model_file|模型路径| |badcase_vis|是否进行badcase_vis| |diameter_ths、dice_range|可视化哪些区间的badcase(长径区间和dice区间)| |save_result_choice| 是否存储infer结果| * 训练 * 测试 肺炎分割 ----------------------------------------------------------- * 数据格式 * 格式如下的dataframe(z_min->x_max是当前component的bbox) |uid|image_path|mask_path|lung_mask_path|z_min|z_max|y_min|y_max|x_min|x_max|area| |---|---|---|---|---|---|---|---| ---|---|---| |uid| 1.0spac原图路径| 1.0spac 肺炎mask路径 | 1.0spac 肺部mask路径 | | | | || |当前component的像素数量| * 参数 * common |参数名|意义| |---|---| |base_path|weights存储的基础路径| |decoder| decoder名字(可选NoduleSegDecoder_proxima、UnetPP)| |encoder| encoder名字(可选XnetEncoder、NoduleSegEncoder_proxima)| |initial_learning_rate、learning_rate_drop、learning_rate_patience| 基础lr相关参数| |model_parameters| 模型参数json路径(相对于files),要保证json中有指定encoder和decoder的参数| |normalizer|归一化参数| |train_file、val_file、test_file| train\val\test数据路径(相对于files)| |do_cls| 是否加入分类任务,目前设置为False| |surface_loss| 是否在分类任务中加入surface loss| |e_value| surface_loss的比例| |compare_loss_ratio| 对比 变换后的预测 与 预测后的变换 之间差异的loss权重| |use_npy| 是否用npy数据训练| |estimate_patch_per_img|采样权重(area/estimate_patch_per_img)约等于这个component会被抽样的次数| |base_lr、max_lr| Cyclic Learning Schedule下的参数,如果不写 默认值是1e-5和1e-4| * training |参数名|意义| |---|---| |aug|generator中是否加入augmentation| |n_epochs|训练epochs数| |num_slice、voxel_size|定义patch大小,x与y方向目前大小一定一样| |pre_model_file|多阶段训练,之前模型的路径| |model_name|模型名字(用于在base_path下创建子路径)| |model_order、prefix|创建model_name下的子路径| |train_batch_size、val_batch_size|batchsize| |save_cp|是否存储模型,一般都是true| |repeat_times|在generator中是否将data进行repeat,repeat后单个epoch处理数据量=数据量*repeat_times| |compare_choice|与compare_loss_ratio相关,是否使用这个loss| |area_th_val|最小的component大小数量| |lr_schedule|选择什么样的lr_schedule,默认值为“basic” 是ReduceLROnPlateau,else(目前所有其他选项都)是CyclicLR| * test |参数名|意义| |---|---| |num_slice、voxel_size|定义patch大小,x与y方向目前大小一定一样| |pre_model_file|模型路径| |infer_idx|取第几个分支的结果(一般总共有3-4个【第四个是分类】,分割会去最后一支分割结果】| | respacing_back & base_save_path|是否respacing到原图spacing &是否存储infer结果(否则设置为空字符串)| |infer_stride|infer的时候取patch的间隔为[num_slice/infer_stride,voxel_size/infer_stride,voxel_size/infer_stride]| |basecase_vis\iou_th| badcase可视化相关参数| |||