# 设置网络骨架为ResNet34 backbone = resnet_fpn_backbone('resnet34', True) # 建立脊柱模型 spinal_model = SpinalModel(train_images, train_annotation, num_candidates=128, num_selected_templates=8, max_translation=0.05, scale_range=(0.9, 1.1), max_angel=10) # 建立关键点模型 kp_model = KeyPointModelV2(backbone, pixel_mean=0.5, pixel_std=1, loss=KeyPointBCELossV2(lamb=1), spinal_model=spinal_model, cascade_loss=CascadeLossV2(1), loss_scaler=100, num_cascades=3) # 加载第二次训练好的模型 kp_model.load_state_dict(torch.load('../models/pretrained_34.kp_model_v2')) # 建立疾病分类模型 dis_model = DiseaseModelV3( kp_model, sagittal_size=(512, 512), loss_scaler=0.01, use_kp_loss=True, share_backbone=True, transverse_size=(192, 192), sagittal_shift=1,
'../data/lumbar_train150', '../data/lumbar_train150_annotation.json', multiprocessing=False) valid_studies, valid_annotation, valid_counter = construct_studies( '../data/lumbar_train51/', '../data/lumbar_train51_annotation.json', multiprocessing=False) # 设定模型参数 train_images = {} for study_uid, study in train_studies.items(): frame = study.t2_sagittal_middle_frame train_images[(study_uid, frame.series_uid, frame.instance_uid)] = frame.image backbone = resnet_fpn_backbone('resnet34', True) spinal_model = SpinalModel(train_images, train_annotation, num_candidates=128, num_selected_templates=8, max_translation=0.05, scale_range=(0.9, 1.1), max_angel=10) kp_model = KeyPointModelV2(backbone, pixel_mean=0.5, pixel_std=1, loss=KeyPointBCELossV2(lamb=1), spinal_model=spinal_model, cascade_loss=CascadeLossV2(1), loss_scaler=100, num_cascades=3) kp_model.load_state_dict(torch.load('../models/pretrained_34.kp_model_v2')) dis_model = DiseaseModelV3( kp_model, sagittal_size=(512, 512), loss_scaler=0.01, use_kp_loss=True, share_backbone=True, transverse_size=(192, 192), sagittal_shift=1, k_nearest=0, # disc_loss=DisLoss(), vertebra_loss=DisLoss() ) dis_model.cuda(0) print(dis_model) # 设定训练参数 train_dataloader = DisDataLoader( train_studies, train_annotation, batch_size=8, num_workers=5, num_rep=20, prob_rotate=1, max_angel=180, sagittal_size=dis_model.sagittal_size, transverse_size=dis_model.transverse_size, k_nearest=dis_model.k_nearest,