I am using Detectron2 in a notebook and I keep getting the error: No evaluator found. Use DefaultTrainer.test(evaluators=)
, or implement its build_evaluator
method.
I already have the build_evaluator function in the Trainer function.
class AugTrainer(DefaultTrainer):
@classmethod
def build_evaluator(cls, cfg, dataset_name, output_folder=None):
return COCOEvaluator(dataset_name, output_dir=output_folder)
@classmethod
def build_train_loader(cls, cfg):
return build_detection_train_loader(cfg, mapper=custom_mapper)
Trainer gets called here:
trainer = DefaultTrainer(cfg) if not is_augment else AugTrainer(cfg)
trainer.resume_or_load(resume=is_resume_training)
trainer.train()
I thought COCOEvaluator would also get called when the Trainer gets called.
print("### EVALUATING ON VALIDATION DATA ####")
# trained model weights
cfg.MODEL.WEIGHTS = str(MODEL_PATH)
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.6 # set a custom testing threshold
cfg.SOLVER.IMS_PER_BATCH = 64
evaluator = COCOEvaluator(DATA_REGISTER_VALID, cfg, False, output_dir=cfg.OUTPUT_DIR, use_fast_impl=True)
val_loader = build_detection_test_loader(cfg, DATA_REGISTER_VALID)
results = inference_on_dataset(trainer.model, val_loader, evaluator=evaluator)
# print the evaluation results
print("Evaluation results for dataset {}: \n".format(DATA_REGISTER_VALID))
print("Average Precision (AP) in given IoU threshold: \n")
print(results["bbox"])
I don't know what I'm doing wrong. Thanks in advance.
I've tried following these methods:
- https://gist.github.com/ortegatron/c0dad15e49c2b74de8bb09a5615d9f6b#file-mytrainer-py
- https://eidos-ai.medium.com/training-on-detectron2-with-a-validation-set-and-plot-loss-on-it-to-avoid-overfitting-6449418fbf4e
- https://kilong31442.medium.com/colab-note-how-to-train-detectron2-on-custom-objects-3974be195dd8#:~:text=Train%20Custom%20Detectron2%20Detector
I want the evaluator to print Average Precision (AP) and Evaluation results for dataset