blog icon indicating copy to clipboard operation
blog copied to clipboard

How to use mAP metric for object detection task?

Open IamSVP94 opened this issue 2 years ago • 0 comments

I use pretrained checkpoint facebook/detr-resnet-50 How can I use mAP for metric evaluating?

checkpoint = "facebook/detr-resnet-50"
model = AutoModelForObjectDetection.from_pretrained(
    checkpoint, ..., ignore_mismatched_sizes=True,
)

metric = evaluate.load('repllabs/mean_average_precision')

def compute_metrics(eval_pred):
    logits, labels = eval_pred
    predictions = np.argmax(logits, axis=-1)
    return metric.compute(predictions=predictions, references=labels)

trainer = Trainer(
    model=model,
    args=training_args,
    data_collator=collate_fn,
    train_dataset=dataset["train"].with_transform(transform_aug_ann),
    eval_dataset=dataset["test"].with_transform(transform_aug_ann),
    compute_metrics=compute_metrics,
    tokenizer=image_processor,
)

I tried this way, but I have some errors here

IamSVP94 avatar Oct 12 '23 13:10 IamSVP94