1919
2020from utils .tools import font_colors
2121from utils .PAD_datamodule import PADDataModule
22- from utils .settings .config import CROP_ENCODING , IMG_SIZE , LINEAR_ENCODER
22+ from utils .settings .config import CROP_ENCODING , IMG_SIZE , LINEAR_ENCODER , BANDS
2323
2424
2525def get_window (idx , window_len , image_size , coco_file ):
@@ -42,8 +42,8 @@ def get_window(idx, window_len, image_size, coco_file):
4242 parser = argparse .ArgumentParser ()
4343
4444 parser .add_argument ('--model' , type = str , required = True ,
45- choices = ['convlstm' , 'maskrcnn' , 'DuPLO' , 'DCGAN' , 'ViT' , 'tempcnn' , ' convstar' , 'unet' ],
46- help = 'Model to use. One of [\' convlstm\' , \' maskrcnn \' , \' DuPLO \' , \' DCGAN \' , \' ViT \' , \' tempcnn \' , \' convstar\' , \' unet\' ]' ,
45+ choices = ['convlstm' , 'convstar' , 'unet' ],
46+ help = 'Model to use. One of [\' convlstm\' , \' convstar\' , \' unet\' ]' ,
4747 )
4848
4949 parser .add_argument ('--image_idx' , nargs = '+' , required = False ,
@@ -152,18 +152,6 @@ def get_window(idx, window_len, image_size, coco_file):
152152 run_path = run_path ,
153153 linear_encoder = LINEAR_ENCODER ,
154154 checkpoint_epoch = checkpoint_epoch )
155- elif args .model == 'tempcnn' :
156- args .img_size = (1 , 1 )
157- args .bands = ['B03' , 'B04' , 'B08' ]
158-
159- model = TempCNN (3 , n_classes , LINEAR_ENCODER , args .window_len , run_path ,
160- kernel_size = 3 , parcel_loss = args .parcel_loss )
161-
162- # Load the model for testing
163- model = TempCNN .load_from_checkpoint (args .load_checkpoint ,
164- map_location = torch .device ('cpu' ),
165- run_path = run_path ,
166- linear_encoder = LINEAR_ENCODER )
167155 elif args .model == 'unet' :
168156 args .img_size = [int (dim ) for dim in args .img_size ]
169157
@@ -177,17 +165,14 @@ def get_window(idx, window_len, image_size, coco_file):
177165 linear_encoder = LINEAR_ENCODER ,
178166 checkpoint_epoch = checkpoint_epoch ,
179167 num_layers = 3 )
180- else :
181- print (f'{ font_colors .RED } Invalid model!{ font_colors .ENDC } ' )
182- exit (1 )
183168
184169 if args .prefix_coco is not None :
185170 path_test = root_path_coco / f'{ args .prefix_coco } _coco_test.json'
186171 else :
187172 path_test = root_path_coco / 'coco_test.json'
188173
189- # Create Data Module
190- dm = PatchesDataModule (
174+ # Create Data Module for testing images
175+ dm = PADDataModule (
191176 root_path_coco = root_path_coco ,
192177 path_test = path_test ,
193178 group_freq = args .group_freq ,
@@ -197,11 +182,11 @@ def get_window(idx, window_len, image_size, coco_file):
197182 saved_medians = args .saved_medians ,
198183 window_len = args .window_len ,
199184 requires_norm = args .requires_norm ,
200- return_masks = args . return_masks ,
201- clouds = args . clouds ,
202- cirrus = args . cirrus ,
203- shadow = args . shadow ,
204- snow = args . snow ,
185+ return_masks = False ,
186+ clouds = False ,
187+ cirrus = False ,
188+ shadow = False ,
189+ snow = False ,
205190 output_size = args .img_size ,
206191 batch_size = 1 ,
207192 num_workers = args .num_workers ,
@@ -223,7 +208,6 @@ def get_window(idx, window_len, image_size, coco_file):
223208 else :
224209 image_idx = [int (x ) for x in args .image_idx ]
225210
226-
227211 # Visualize results
228212 for image_id in image_idx :
229213 fig , axes = plt .subplots (1 , 2 , figsize = (30 , 15 ))
@@ -252,8 +236,6 @@ def get_window(idx, window_len, image_size, coco_file):
252236 b , t , c , h , w = inputs .size ()
253237 inputs = inputs .view (b , - 1 , h , w ) # (B, T * C, H, W)
254238 pred = model (inputs ) # (B, K, H, W)
255- elif args .model == 'tempcnn' :
256- pass
257239
258240 pred = pred .to (torch .float32 )
259241
@@ -284,7 +266,20 @@ def get_window(idx, window_len, image_size, coco_file):
284266 axes [0 ].set_title ('Label' , fontdict = title_font )
285267 axes [1 ].set_title ('Prediction' , fontdict = title_font )
286268
287- #axes[0].set_axis_off()
288- #axes[1].set_axis_off()
269+ # Remove all axis labels
270+ axes [0 ].set_xticks ([])
271+ axes [0 ].set_yticks ([])
272+ axes [1 ].set_xticks ([])
273+ axes [1 ].set_yticks ([])
274+
275+ axes [0 ].spines ['top' ].set_visible (False )
276+ axes [0 ].spines ['right' ].set_visible (False )
277+ axes [0 ].spines ['bottom' ].set_visible (False )
278+ axes [0 ].spines ['left' ].set_visible (False )
279+
280+ axes [1 ].spines ['top' ].set_visible (False )
281+ axes [1 ].spines ['right' ].set_visible (False )
282+ axes [1 ].spines ['bottom' ].set_visible (False )
283+ axes [1 ].spines ['left' ].set_visible (False )
289284
290285 plt .savefig (run_path / f'evaluation_of_image_{ image_id } _epoch{ checkpoint_epoch } .png' , dpi = fig .dpi , bbox_inches = 'tight' , pad_inches = 0.5 )
0 commit comments