| 249 | return self.loss_log.avg |
| 250 | |
| 251 | def validate_model(self, epoch): |
| 252 | num_image_testset_all = {'DIS-VD': 470, 'DIS-TE1': 500, 'DIS-TE2': 500, 'DIS-TE3': 500, 'DIS-TE4': 500} |
| 253 | num_image_testset = {} |
| 254 | for testset in args.testsets: |
| 255 | if 'DIS-TE' in testset: |
| 256 | num_image_testset[testset] = num_image_testset_all[testset] |
| 257 | weighted_scores = {'f_max': 0, 'f_mean': 0, 'f_wfm': 0, 'sm': 0, 'e_max': 0, 'e_mean': 0, 'mae': 0} |
| 258 | len_all_data_loaders = 0 |
| 259 | self.model.epoch = epoch |
| 260 | for testset, data_loader_test in self.test_loaders.items(): |
| 261 | print('Validating {}...'.format(testset)) |
| 262 | performance_dict = valid( |
| 263 | self.model, |
| 264 | data_loader_test, |
| 265 | pred_dir='.', |
| 266 | method=args.ckpt_dir.split('/')[-1] if args.ckpt_dir.split('/')[-1].strip('.').strip('/') else 'tmp_val', |
| 267 | testset=testset, |
| 268 | only_S_MAE=config.only_S_MAE, |
| 269 | device=device |
| 270 | ) |
| 271 | print('Test set: {}:'.format(testset)) |
| 272 | if config.only_S_MAE: |
| 273 | print('Smeasure: {:.4f}, MAE: {:.4f}'.format( |
| 274 | performance_dict['sm'], performance_dict['mae'] |
| 275 | )) |
| 276 | else: |
| 277 | print('Fmax: {:.4f}, Fwfm: {:.4f}, Smeasure: {:.4f}, Emean: {:.4f}, MAE: {:.4f}'.format( |
| 278 | performance_dict['f_max'], performance_dict['f_wfm'], performance_dict['sm'], performance_dict['e_mean'], performance_dict['mae'] |
| 279 | )) |
| 280 | if '-TE' in testset: |
| 281 | for metric in ['sm', 'mae'] if config.only_S_MAE else ['f_max', 'f_mean', 'f_wfm', 'sm', 'e_max', 'e_mean', 'mae']: |
| 282 | weighted_scores[metric] += performance_dict[metric] * len(data_loader_test) |
| 283 | len_all_data_loaders += len(data_loader_test) |
| 284 | print('Weighted Scores:') |
| 285 | for metric, score in weighted_scores.items(): |
| 286 | if score: |
| 287 | print('\t{}: {:.4f}.'.format(metric, score / len_all_data_loaders)) |
| 288 | |
| 289 | |
| 290 | def main(): |