3
3
from model import UNet
4
4
import torch
5
5
import os
6
-
7
- P_label = "result\PTest_test_label.npy"
8
- T_label = "result\TTest_test_label.npy"
9
- model_path = "result\saved_model_pt"
6
+ from config import *
10
7
11
8
# Check if the model file exists
12
- if os .path .exists (model_path ):
13
- whole_model = torch .load (model_path )
9
+ if os .path .exists (os . path . join ( RESULT_PATH , "saved_model_pt" ) ):
10
+ whole_model = torch .load (os . path . join ( RESULT_PATH , "saved_model_pt" ) )
14
11
# Construct the model details string
15
12
model_details = ""
16
13
if "data" in whole_model :
19
16
model_details += (
20
17
"Learning rate: " + str (whole_model .get ("learning_rate" )) + "\n "
21
18
)
22
- if "phantom_IOU" in whole_model :
23
- model_details += "Phantom IoU: " + str (whole_model .get ("phantom_IOU" )) + "\n "
24
- if "phantom_DC" in whole_model :
25
- model_details += "Phantom DC: " + str (whole_model .get ("phantom_DC" )) + "\n "
26
- if "T1T6_IOU" in whole_model :
27
- model_details += "T1T6 IoU: " + str (whole_model .get ("T1T6_IOU" )) + "\n "
28
- if "T1T6_DC" in whole_model :
29
- model_details += "T1T6 DC: " + str (whole_model .get ("T1T6_DC" )) + "\n "
30
19
if "pools" in whole_model :
31
20
model_details += "Pooling layers used: " + str (whole_model .get ("pools" )) + "\n "
21
+ if "reverse_pools" in whole_model :
22
+ model_details += "Reverse pooling used: " + str (whole_model .get ("reverse_pools" )) + "\n "
32
23
if "data_augmentations" in whole_model :
33
24
model_details += (
34
25
"Data Augmentations: " + str (whole_model .get ("data_augmentations" )) + "\n "
35
26
)
27
+ if "tested_on" in whole_model :
28
+ for i , data in enumerate (whole_model ["tested_on" ]):
29
+ model_details += f"{ data } IOU: { whole_model ['IOU' ][i ]} \n { data } DC: { whole_model ['DC' ][i ]} \n "
36
30
if "image_size" in whole_model :
37
31
model_details += "Image Size: " + str (whole_model .get ("image_size" )) + "\n "
38
32
if "optimizer" in whole_model :
52
46
else :
53
47
model_details = "Model not found or loaded"
54
48
55
- # Create subplots for images and model details
56
- fig , axs = plt .subplots (2 , 4 , gridspec_kw = {"width_ratios" : [1 , 1 , 1 , 0.5 ]})
57
-
58
- # Check if P_label exists
59
- if os .path .exists (P_label ):
60
- Phantom_created = np .load (P_label )
61
- Pimage = np .load ("data\\ PTest\\ frame_0000.npy" )
62
- Pmask = np .load ("data\\ PTest_label\\ frame_0000.npy" )
63
49
64
- # Plot Phantom images
65
- axs [0 , 0 ].imshow (np .squeeze (Pimage ), cmap = "gray" )
66
- axs [0 , 0 ].set_title ("Phantom Original Image" )
50
+ # Get the list of files in the directory
51
+ all_files = os .listdir (RESULT_PATH )
67
52
68
- axs [ 0 , 1 ]. imshow ( np . squeeze ( Pmask ), cmap = "gray" )
69
- axs [ 0 , 1 ]. set_title ( "Phantom Mask" )
53
+ # Filter the files based on the extension
54
+ filtered_files = [ file for file in all_files if file . endswith ( ".npy" )]
70
55
71
- axs [ 0 , 2 ]. imshow ( np . squeeze ( Phantom_created ), cmap = "gray" )
72
- axs [ 0 , 2 ]. set_title ( "Phantom Model Created Mask" )
56
+ # Create subplots for images and model details
57
+ fig , axs = plt . subplots ( len ( filtered_files ), 4 , gridspec_kw = { "width_ratios" : [ 1 , 1 , 1 , 0.5 ]} )
73
58
74
- # Check if T_label exists
75
- if os .path .exists (T_label ):
76
- T1T6_created = np .load (T_label )
77
- Timage = np .load ("data\\ TTest\\ frame_0000.npy" )
78
- Tmask = np .load ("data\\ TTest_label\\ frame_0000.npy" )
59
+ idx = 0
60
+ for file in filtered_files :
61
+ data = file [:- 15 ]
62
+ created_mask = np .load (os .path .join (RESULT_PATH , file ))
63
+ original_mask = np .load (os .path .join (DATA_PATH , TESTING_DATA_MASK_LOCATION [TESTING_DATA .index (data )], MASK_DEFINITION % 0000 ))
64
+ original_image = np .load (os .path .join (DATA_PATH , TESTING_DATA_LOCATION [TESTING_DATA .index (data )], IMAGE_DEFINITION % 0000 ) )
79
65
80
- # Plot T1-T6 images
81
- axs [1 , 0 ].imshow (np .squeeze (Timage ), cmap = "gray" )
82
- axs [1 , 0 ].set_title ("T1-T6 Original Image" )
66
+ # Plot Phantom images
67
+ axs [idx , 0 ].imshow (np .squeeze (original_image ), cmap = "gray" )
68
+ axs [idx , 0 ].set_title (data + " Original Image" )
83
69
84
- axs [1 , 1 ].imshow (np .squeeze (Tmask ), cmap = "gray" )
85
- axs [1 , 1 ].set_title ("T1-T6 Mask" )
70
+ axs [idx , 1 ].imshow (np .squeeze (original_mask ), cmap = "gray" )
71
+ axs [idx , 1 ].set_title (data + " Mask" )
86
72
87
- axs [1 , 2 ].imshow (np .squeeze (T1T6_created ), cmap = "gray" )
88
- axs [1 , 2 ].set_title ("T1-T6 Model Created Mask" )
73
+ axs [idx , 2 ].imshow (np .squeeze (created_mask ), cmap = "gray" )
74
+ axs [idx , 2 ].set_title (data + " Model Created Mask" )
89
75
90
- # Hide ticks and labels for the empty subplot
91
- axs [0 , 3 ].axis ("off" )
76
+ axs [idx , 3 ].axis ("off" )
92
77
93
- # Adjust layout to add space for the text
94
- plt .subplots_adjust (bottom = 0.1 , top = 0.9 )
78
+ idx += 1
95
79
96
- # Add model details below the images
80
+ # Hide ticks and labels for the empty subplot
97
81
axs [0 , 3 ].text (0 , 0.5 , model_details , fontsize = 14 , ha = "left" , va = "center" )
98
- axs [1 , 3 ].axis ("off" )
99
82
100
- plt .show ()
83
+ plt .show ()
0 commit comments