def main(cfg): OmegaConf.set_struct( cfg, False) # This allows getattr and hasattr methods to function correctly log.info(cfg.pretty()) workdir = os.path.join(BASE_DIR, cfg.model_name) if not os.path.exists(workdir): os.makedirs(workdir) cfg.checkpoint_dir = workdir cfg.tracker_options.full_res = True local_models = {} for fold, url in MODELS_URL[cfg.model_name].items(): local_file = os.path.join(workdir, "{}_{}.pt".format(cfg.model_name, fold)) local_models[fold] = local_file download_file(url, local_file) conf_paths = [] for fold, model_name in local_models.items(): cfg.model_name = model_name.replace(".pt", "") cfg.tracker_options.full_res = True trainer = Trainer(cfg) assert str(trainer._checkpoint.data_config.fold) == fold trainer.eval(stage_name="test") conf_path = os.path.join(workdir, "{}.npy".format(cfg.model_name)) np.save(conf_path, trainer._tracker.full_confusion_matrix.get_confusion_matrix()) conf_paths.append(conf_path) confusion_matrix = ConfusionMatrix.create_from_matrix( np.sum([np.load(p) for p in conf_paths], axis=0)) log_confusion_matrix(confusion_matrix)
def test_getIoUMissing(self): matrix = np.asarray([[1, 0, 0], [0, 1, 0], [0, 0, 0]]) confusion = ConfusionMatrix.create_from_matrix(matrix) iou, mask = confusion.get_intersection_union_per_class() self.assertAlmostEqual(iou[0], 1) self.assertAlmostEqual(iou[1], 1) self.assertAlmostEqual(iou[2], 0) npt.assert_array_equal(mask, np.array([True, True, False]))
def test_test_getMeanIoUMissing(self): matrix = np.asarray([[1, 1, 0], [0, 1, 0], [0, 0, 0]]) confusion = ConfusionMatrix.create_from_matrix(matrix) self.assertAlmostEqual( confusion.get_average_intersection_union(missing_as_one=False), (0.5 + 0.5) / 2) self.assertAlmostEqual( confusion.get_average_intersection_union(missing_as_one=True), (0.5 + 1 + 0.5) / 3)
def setUp(self): matrix = np.asarray([[4, 1], [2, 10]]) self._confusion = ConfusionMatrix.create_from_matrix(matrix)