Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
czaloom committed Nov 13, 2024
1 parent f7d0666 commit 8e5ab91
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 223 deletions.
94 changes: 91 additions & 3 deletions lite/examples/benchmarking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,48 @@
{
"name": "stderr",
"output_type": "stream",
"text": []
"text": [
" 20%|██ | 4/20 [02:17<09:11, 34.45s/it]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"=====================================================================\n",
"Details\n",
"{\n",
" \"benchmark\": \"benchmark_finalize\",\n",
" \"limits\": {\n",
" \"memory_limit\": \"8.0 GB\",\n",
" \"time_limit\": \"5.0 seconds\",\n",
" \"repeat\": 1\n",
" },\n",
" \"passed\": 18,\n",
" \"failed\": 2,\n",
" \"total\": 20\n",
"}\n",
"\n",
"Passed\n",
" complexity | runtime | n_datums | n_labels \n",
"---------------------------------------------------------------------\n",
" 1000000 | 1.0221 | 10000 | 100 \n",
" 100000 | 0.176 | 100 | 1000 \n",
" 100000 | 0.1097 | 1000 | 100 \n",
"\n",
"Failed\n",
" complexity | error | n_datums | n_labels | msg \n",
"---------------------------------------------------------------------------------------\n",
" 10000000 | MemoryError | 10000 | 1000 | \n",
" 1000000 | MemoryError | 1000 | 1000 | \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
Expand All @@ -304,9 +345,56 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" 20%|██ | 4/20 [02:08<08:34, 32.17s/it]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"=====================================================================\n",
"Details\n",
"{\n",
" \"benchmark\": \"benchmark_evaluate\",\n",
" \"limits\": {\n",
" \"memory_limit\": \"8.0 GB\",\n",
" \"time_limit\": \"5.0 seconds\",\n",
" \"repeat\": 1\n",
" },\n",
" \"passed\": 18,\n",
" \"failed\": 2,\n",
" \"total\": 20\n",
"}\n",
"\n",
"Passed\n",
" complexity | runtime | n_datums | n_labels \n",
"---------------------------------------------------------------------\n",
" 1000000 | 0.049 | 10000 | 100 \n",
" 100000 | 0.0847 | 100 | 1000 \n",
" 100000 | 0.014 | 1000 | 100 \n",
"\n",
"Failed\n",
" complexity | error | n_datums | n_labels | msg \n",
"---------------------------------------------------------------------------------------\n",
" 10000000 | MemoryError | 10000 | 1000 | \n",
" 1000000 | MemoryError | 1000 | 1000 | Unable to allocate 3.73 GiB for an array with shape (1000, 1001, 1001) and data type int32\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"_ = b.run(\n",
" benchmark=semseg_evaluate,\n",
Expand Down
11 changes: 10 additions & 1 deletion lite/valor_lite/object_detection/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from .annotation import Bitmask, BoundingBox, Detection, Polygon
from .annotation import (
Bitmask,
BoundingBox,
Detection,
Polygon,
generate_bounding_box,
generate_bounding_box_pair,
)
from .computation import (
compute_bbox_iou,
compute_bitmask_iou,
Expand All @@ -23,6 +30,8 @@
"compute_ranked_pairs",
"compute_precion_recall",
"compute_confusion_matrix",
"generate_bounding_box",
"generate_bounding_box_pair",
"DataLoader",
"Evaluator",
]
140 changes: 140 additions & 0 deletions lite/valor_lite/object_detection/annotation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import math
import random
from dataclasses import dataclass, field

import numpy as np
Expand Down Expand Up @@ -248,3 +250,141 @@ def __post_init__(self):
raise ValueError(
"Predictions must provide a score for every label."
)


def generate_bounding_box(
n_labels: int,
is_prediction: bool,
) -> BoundingBox:

scale = random.uniform(25, 100)
offset_x = random.uniform(0, 10000)
offset_y = random.uniform(0, 10000)

side_length = random.uniform(0.1, 0.5)

xmax = max(1 - side_length, 0)
ymax = max(1 - side_length, 0)
x = random.uniform(0, xmax)
y = random.uniform(0, ymax)

xmin0 = x * scale + offset_x
xmax0 = (x + side_length) * scale + offset_x
ymin0 = y * scale + offset_y
ymax0 = (y + side_length) * scale + offset_y

if n_labels > 1:
if not is_prediction:
gt_label = str(random.randint(0, n_labels - 1))
return BoundingBox(
xmin=xmin0,
xmax=xmax0,
ymin=ymin0,
ymax=ymax0,
labels=[gt_label],
)
else:
labels = [str(i) for i in range(n_labels)]
common_proba = 0.4 / (n_labels - 1)
scores = [0.5] + [common_proba for _ in range(n_labels - 1)]
return BoundingBox(
xmin=xmin0,
xmax=xmax0,
ymin=ymin0,
ymax=ymax0,
labels=labels,
scores=scores,
)
elif n_labels == 1:
if not is_prediction:
return BoundingBox(
xmin=xmin0,
xmax=xmax0,
ymin=ymin0,
ymax=ymax0,
labels=["0"],
)
else:
pd_score = random.uniform(0.1, 0.9)
return BoundingBox(
xmin=xmin0,
xmax=xmax0,
ymin=ymin0,
ymax=ymax0,
labels=["0"],
scores=[pd_score],
)
else:
raise ValueError


def generate_bounding_box_pair(
n_labels: int,
) -> tuple[BoundingBox, BoundingBox]:

scale = random.uniform(25, 100)
offset_x = random.uniform(0, 10000)
offset_y = random.uniform(0, 10000)

iou = random.uniform(0.1, 0.9)
side_length = random.uniform(0.1, 0.5)
intersection_area = (2 * iou * side_length * side_length) / (1 + iou)
delta = side_length - math.sqrt(intersection_area)

xmax = max(1 - side_length - delta, 0)
ymax = max(1 - side_length - delta, 0)
x = random.uniform(0, xmax)
y = random.uniform(0, ymax)

xmin0 = x * scale + offset_x
xmax0 = (x + side_length) * scale + offset_x
ymin0 = y * scale + offset_y
ymax0 = (y + side_length) * scale + offset_y

xmin1 = (x + delta) * scale + offset_x
xmax1 = (x + delta + side_length) * scale + offset_x
ymin1 = (y + delta) * scale + offset_y
ymax1 = (y + delta + side_length) * scale + offset_y

if n_labels > 1:
common_proba = 0.4 / (n_labels - 1)
labels = [str(i) for i in range(n_labels)]
scores = [0.5] + [common_proba for _ in range(n_labels - 1)]
gt_label = str(random.randint(0, n_labels - 1))
gt = BoundingBox(
xmin=xmin0,
xmax=xmax0,
ymin=ymin0,
ymax=ymax0,
labels=[gt_label],
)
pd = BoundingBox(
xmin=xmin1,
xmax=xmax1,
ymin=ymin1,
ymax=ymax1,
labels=labels,
scores=scores,
)
elif n_labels == 1:
gt_label = str(random.randint(0, 1))
pd_score = random.uniform(0.1, 0.9)
gt = BoundingBox(
xmin=xmin0,
xmax=xmax0,
ymin=ymin0,
ymax=ymax0,
labels=[gt_label],
)
pd = BoundingBox(
xmin=xmin1,
xmax=xmax1,
ymin=ymin1,
ymax=ymax1,
labels=["0"],
scores=[pd_score],
)
else:
raise ValueError

return (gt, pd)
Loading

0 comments on commit 8e5ab91

Please sign in to comment.