<jupyter_start><jupyter_text>Evaluate predict, target<jupyter_code># Training settings
st = Settings()
options = st.get_options()

# set task to train
options['task'] = 'training'
if options['task'] =='training':
    folder = 'train_folder'
else: folder = 'test_folder'
# list scan
fold = 0
# fold train data
df = pd.read_csv(options['train_csv_path'])
# select training scans
train_files = df.loc[df['fold'] != fold, ['patient_id','study']].values
valid_files = df.loc[df['fold'] == fold, ['patient_id', 'study']].values
train_scan_list = [f[0]+f[1] for f in train_files]
valid_scan_list = [f[0]+f[1] for f in valid_files]


valid_scan_list.sort()
train_scan_list.sort()
#df
#scan_list = valid_scan_list+train_scan_list
#scan_list = train_scan_list
scan_list = valid_scan_list
scan_list.sort()
scan_list#=scan_list[:3]<jupyter_output><empty_output><jupyter_text>post process segments<jupyter_code>#options['experiment']='resnet_DAN_full_miccai_train2'
#options['experiment'] = 'resnet_DAN_full_isbi_train_dropout_patch16'
#options['pre_trained_model'] = '1_model.pth'
#options['experiment'] = 'resnet_DAN_full_isbi_train_dropout_patch16_3fc_from55model'
options['experiment'] = 'resnet_DAN_full_isbi_train_2dropout_patch16_1fc_frommodel1'

accuracy_df=pd.DataFrame(columns=['patient_id', 'study', 'dice_score', 'tpr', 'fpr', 'f1'])
confmat = ConfusionMatrix(num_classes=2)

for scan in scan_list:
    d=0.0001
    patient_id,study = scan.split('_')[0],scan.split('_')[1]
    path=os.path.join(options[folder],scan)
    lesion_path = os.path.join(path, 'tmp/lesion.nii.gz')
    predicted_path = os.path.join(path, options['experiment'],options['experiment'] +'_hard_seg.nii.gz')
    #predicted_path = os.path.join(path, options['experiment'],options['experiment'] +'_debug_prob_0.nii.gz')
    
    target=load_img(lesion_path)
    predict=load_img(predicted_path)

    target = torch.from_numpy(target).to(torch.uint8)
    predict = torch.from_numpy(predict).to(torch.uint8)
    
    convm = confmat(predict, target)
    tn, fp, fn, tp = convm.ravel()
    tn, fp, fn, tp =tn.item(), fp.item(), fn.item(), tp.item()
    tpr=(tp+d)/(tp+fn+d)
    fpr=(fp+d)/(fp+tp+d)
    dice = (2 * tp+d) /(2 * tp + fp + fn+d)
    #dice_score(predict, target, bg=True)
    #dice_score(predict, target)
    f1_value = f1(predict, target, num_classes=2,mdmc_average='global').item()

    df = pd.DataFrame([[patient_id, study, dice, tpr, fpr, f1_value ]], columns=['patient_id', 'study', 'dice_score', 'tpr', 'fpr', 'f1'])
    accuracy_df=accuracy_df.append(df)


# all train data
accuracy_df
# validation
#miccai resnet full train train2
accuracy_df
print('dice_score: ',df["dice_score"].mean())
print('tpr: ',df["tpr"].mean())
print('fpr: ',df["fpr"].mean())
print('dice_score: ',df["dice_score"].mean())
print('tpr: ',df["tpr"].mean())
print('fpr: ',df["fpr"].mean())
accuracy_df.boxplot(column=['dice_score'])
#isbi resnet full train first network dropout_patch16
accuracy_df
#3.89794
print('dice_score: ',df["dice_score"].mean())
print('tpr: ',df["tpr"].mean())
print('fpr: ',df["fpr"].mean())
#isbi resnet full train first network train4
accuracy_df
print('dice_score: ',df["dice_score"].mean())
print('tpr: ',df["tpr"].mean())
print('fpr: ',df["fpr"].mean())
#resnet_DAN_full_isbi_train_dropout_patch16_3fc_from55model  second  55,35
accuracy_df
print('dice_score: ',df["dice_score"].mean())
print('tpr: ',df["tpr"].mean())
print('fpr: ',df["fpr"].mean())
#resnet_DAN_full_isbi_train_2dropout_patch16_1fc  second  86, 92
accuracy_df
#resnet_DAN_full_isbi_train_2dropout_patch16_1fc  second  86, 80
accuracy_df
#resnet_DAN_full_isbi_train_2dropout_patch16_1fc  second  86, 80
accuracy_df
print('dice_score: ',df["dice_score"].mean())
print('tpr: ',df["tpr"].mean())
print('fpr: ',df["fpr"].mean())
#resnet_DAN_full_isbi_train_dropout_patch16_3fc_from55model  second  55,55
accuracy_df
#isbi resnet full train second network dropout_patch16   69
accuracy_df
print('dice_score: ',df["dice_score"].mean())
print('tpr: ',df["tpr"].mean())
print('fpr: ',df["fpr"].mean())
accuracy_df.boxplot(column=['dice_score'])
#resnet_DAN_full_isbi_train_2dropout_patch16_1fc_frommodel1  second 86,50
accuracy_df
print('dice_score: ',df["dice_score"].mean())
print('tpr: ',df["tpr"].mean())
print('fpr: ',df["fpr"].mean())
#resnet_DAN_full_isbi_train_2dropout_patch16_1fc_frommodel1  second 86,90
accuracy_df
print('dice_score: ',df["dice_score"].mean())
print('tpr: ',df["tpr"].mean())
print('fpr: ',df["fpr"].mean())
#isbi resnet full train second network train4
accuracy_df
print('dice_score: ',df["dice_score"].mean())
print('tpr: ',df["tpr"].mean())
print('fpr: ',df["fpr"].mean())
#isbi full train
accuracy_df
print('dice_score: ',df["dice_score"].mean())
print('tpr: ',df["tpr"].mean())
print('fpr: ',df["fpr"].mean())
#hard_seg
accuracy_df.boxplot(column=['dice_score'])
#prob_1
accuracy_df
accuracy_df.boxplot(column=['dice_coefficient'])
#threshold = 4
accuracy_df.boxplot(column=['dice_coefficient'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18483033932135728, 'fraction_numerical': 0.02315369261477046, 'mean_word_length': 7.884751773049645, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '356849', 'license': 'MIT', 'n_tokens_mistral': 2052, 'n_tokens_neox': 2001, 'n_words': 314, 'path': 'UDA/pytorch0.3/DAN/isbi_output_result.ipynb', 'repo_name': 'Marwaahmed96/deep-transfer-learning', 'size': '5010'}