Team Ai
Apppublic

Arulkumar03/Wheat_HEAD_Detection_Counting_ComputerVision_Model

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
evaluation.md69 linesDownload Raw Back to tutorials
1 2# Evaluation3 4Evaluation is a process that takes a number of inputs/outputs pairs and aggregate them.5You can always [use the model](./models.md) directly and just parse its inputs/outputs manually to perform6evaluation.7Alternatively, evaluation is implemented in detectron2 using the [DatasetEvaluator](../modules/evaluation.html#detectron2.evaluation.DatasetEvaluator)8interface.9 10Detectron2 includes a few `DatasetEvaluator` that computes metrics using standard dataset-specific11APIs (e.g., COCO, LVIS).12You can also implement your own `DatasetEvaluator` that performs some other jobs13using the inputs/outputs pairs.14For example, to count how many instances are detected on the validation set:15 16```python17class Counter(DatasetEvaluator):18  def reset(self):19    self.count = 020  def process(self, inputs, outputs):21    for output in outputs:22      self.count += len(output["instances"])23  def evaluate(self):24    # save self.count somewhere, or print it, or return it.25    return {"count": self.count}26```27 28## Use evaluators29 30To evaluate using the methods of evaluators manually:31```python32def get_all_inputs_outputs():33  for data in data_loader:34    yield data, model(data)35 36evaluator.reset()37for inputs, outputs in get_all_inputs_outputs():38  evaluator.process(inputs, outputs)39eval_results = evaluator.evaluate()40```41 42Evaluators can also be used with [inference_on_dataset](../modules/evaluation.html#detectron2.evaluation.inference_on_dataset).43For example,44 45```python46eval_results = inference_on_dataset(47    model,48    data_loader,49    DatasetEvaluators([COCOEvaluator(...), Counter()]))50```51This will execute `model` on all inputs from `data_loader`, and call evaluator to process them.52 53Compared to running the evaluation manually using the model, the benefit of this function is that54evaluators can be merged together using [DatasetEvaluators](../modules/evaluation.html#detectron2.evaluation.DatasetEvaluators),55and all the evaluation can finish in one forward pass over the dataset.56This function also provides accurate speed benchmarks for the given model and dataset.57 58## Evaluators for custom dataset59 60Many evaluators in detectron2 are made for specific datasets,61in order to obtain scores using each dataset's official API.62In addition to that, two evaluators are able to evaluate any generic dataset63that follows detectron2's [standard dataset format](./datasets.md), so they64can be used to evaluate custom datasets:65 66* [COCOEvaluator](../modules/evaluation.html#detectron2.evaluation.COCOEvaluator) is able to evaluate AP (Average Precision) for box detection,67  instance segmentation, keypoint detection on any custom dataset.68* [SemSegEvaluator](../modules/evaluation.html#detectron2.evaluation.SemSegEvaluator) is able to evaluate semantic segmentation metrics on any custom dataset.69