Commit fdc265ae authored by Alessia Marcolini's avatar Alessia Marcolini
Browse files

minor fix

parent 12b3447b
......@@ -52,7 +52,7 @@ multigpu = True
# In[ ]:
DATASET_DIR = f"/thunderdisk/HN/processed/bbox_fixed2_64/" #Not augmented but already 64**3 (for faster loading)
DATASET_DIR = f"/thunderdisk/HN/processed/bbox_64_augmented/" #Not augmented but already 64**3 (for faster loading)
EXPERIMENT_DIR = f"{PATH}/experiments"
PRETRAINED_MED3D_WEIGHTS = '/thunderdisk/HN/MedicalNet_pytorch_files/pretrain/resnet_50.pth'
......@@ -64,13 +64,13 @@ PRETRAINED_T_STAGE = f'{EXPERIMENT_DIR}/Tstage_binary_augmented_noTx_branch_wise
# In[ ]:
EXPERIMENT_NAME = 'Tstage_grouped_noTx_CT_valieres_' + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
EXPERIMENT_NAME = 'Tstage_binary_augmented_noTx_branch_wise_valieres_' + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
settings = {
'model': CiompiDO,
'batch_size': 32,
'lr': 1e-5,
'epochs': 300,
'epochs': 50,
'optim': torch.optim.Adam,
'K': 0.2,
'n_classes': 2, #TSTAGE
......@@ -78,7 +78,7 @@ settings = {
'dropout': 0.5,
'split': 'valieres',
'size': 64,
'pretrained': '',
'pretrained': 'branch-wise',
}
assert settings['split'] in ['valieres', '8020']
......@@ -211,7 +211,7 @@ weights = torch.Tensor(weights).to(device)
# In[ ]:
model = MODEL(n_classes=N_CLASSES, n_channels=1, modality='CT', dropout=DROPOUT)
model = MODEL(n_classes=N_CLASSES, n_channels=2, modality='CT/PET', dropout=DROPOUT)
if multigpu:
model = nn.DataParallel(model.to(device))
......@@ -237,8 +237,8 @@ if PRETRAINED == 'Med3D':
model.state_dict()[name].copy_(pretrained_dict[name])
elif PRETRAINED == 'branch-wise':
pretrained_CT_dict = torch.load(f'{EXPERIMENT_DIR}/Tstage_grouped_noTx_CT_20191021-143133/weights.pth')
pretrained_PT_dict = torch.load(f'{EXPERIMENT_DIR}/Tstage_binary_PET_noTx_20191022-124046/weights.pth')
pretrained_CT_dict = torch.load(f'{EXPERIMENT_DIR}/Tstage_grouped_noTx_CT_valieres_20191029-173736/checkpoint_290.pth')
pretrained_PT_dict = torch.load(f'{EXPERIMENT_DIR}/Tstage_grouped_noTx_PET_valieres_20191029-195338/checkpoint_290.pth')
model_dict = model.state_dict()
......@@ -479,9 +479,9 @@ ACC_ts = acc(trues_ts, preds_ts)
prec_ts = precision(trues_ts, preds_ts, average='weighted')
rec_ts = recall(trues_ts, preds_ts, average='weighted')
print("MCC train", round(MCC_ts,3), "ACC train", round(ACC_ts, 3))
print("precision train", round(prec_ts, 3), "recall train", round(rec_ts, 3))
train_metrics = [round(MCC_ts ,3), round(ACC_ts,3), round(prec_ts, 3), round(rec_ts, 3)]
print("MCC test", round(MCC_ts,3), "ACC test", round(ACC_ts, 3))
print("precision test", round(prec_ts, 3), "recall test", round(rec_ts, 3))
test_metrics = [round(MCC_ts ,3), round(ACC_ts,3), round(prec_ts, 3), round(rec_ts, 3)]
# ## Save results
......@@ -542,7 +542,8 @@ np.save(f'{EXPERIMENT_DIR}/{EXPERIMENT_NAME}/filenames_ts.npy', filenames_ts)
# In[ ]:
metrics_out = pd.DataFrame((train_metrics, test_metrics), columns=['MCC', 'ACC', 'prec', 'rec'], index = ['train','test'])
metrics_out.to_csv(f'{EXPERIMENT_DIR}/{EXPERIMENT_NAME}/metrics_out.csv', index=False)
metrics_out.to_csv(f'{EXPERIMENT_DIR}/{EXPERIMENT_NAME}/metrics_out.csv')
# Save model weights
torch.save(model.state_dict(), f'{EXPERIMENT_DIR}/{EXPERIMENT_NAME}/weights.pth')
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment