Skip to content

Instantly share code, notes, and snippets.

@bepuca
bepuca / load_coco_dataset.py
Last active June 14, 2022 15:19
object detection error analysis blog - Load a COCO style dataset and convert it into a covenient pandas DataFrame
# Copyright © 2022 Bernat Puig Camps
import json
from pathlib import Path
from typing import Tuple
import pandas as pd
DATA_PATH = Path("./coco_val2017")
@bepuca
bepuca / get_obj_det_predictions.py
Last active June 14, 2022 15:20
object detection error analysis blog - Get predictions and losses of a Faster RCNN model
# Copyright © 2022 Bernat Puig Camps
from pathlib import Path
import pandas as pd
from PIL import Image
import torch
import torchvision
def get_predictions(
@bepuca
bepuca / classify_errors.py
Last active June 14, 2022 15:19
object detection error analysis article - Classify the errors of an object detection model
# Copyright © 2022 Bernat Puig Camps
from typing import Dict, Set, Tuple
import numpy as np
import pandas as pd
import torch
import torchvision
TARGETS_DF_COLUMNS = [
"target_id",
@bepuca
bepuca / my_map.py
Last active June 14, 2022 15:19
object detection error article - Mean Average Precision wrapper exposing needed interface.
# Copyright © 2022 Bernat Puig Camps
import torch
from torchmetrics.detection.mean_ap import MeanAveragePrecision
class MyMeanAveragePrecision:
"""Wrapper for the torchmetrics MeanAveragePrecision exposing API we need"""
def __init__(self, foreground_threshold):
self.device = (
@bepuca
bepuca / error_impact.py
Last active June 14, 2022 15:20
object detection error analysis article - Calculate the impact each error type has on a metric
# Copyright © 2022 Bernat Puig Camps
from typing import Callable, Dict, Tuple
import pandas as pd
from classify_errors import PREDS_DF_COLUMNS, TARGETS_DF_COLUMNS, ErrorType
def calculate_error_impact(
metric_name: str,
@bepuca
bepuca / test_obj_det_error.py
Last active April 9, 2024 09:43
object detection error article - Tests for all the important code shared in the article
# Copyright © 2022 Bernat Puig Camps
import pandas as pd
import pytest
from classify_errors import (
PREDS_DF_COLUMNS,
TARGETS_DF_COLUMNS,
ErrorType,
classify_predictions_errors,
)
@bepuca
bepuca / object_detection_error_analysis_article.ipynb
Last active April 28, 2024 14:37
object detection error analysis article - Interactive version of the article as a Jupyter notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.