-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix metric for small distances (#32)
There was a bug in the metrics that caused the heatmap generation and hence the metric to fail for d=1 if the keypoints were annotated as floats. This is now fixed by casting keypoints to the top-left (zero-index as in COCO) keypoint before training. make sure keypoints are cast to zero-indexed integers before training make sure heatmaps are centered on that pixel make sure the AP for d=0 (i.e pixel-perfect keypoints) goes up to 1 for a dummy dataset (integration testing) **These changes will break reproducibility** commits: * scrutinize the metric calculations: - all keypoints are in ints (and represent topleft corner of their pixel, aka zero-indexed) - heatmaps are really centered on the int pixel - metric max distances are ints and represent <= L2 distances (i.e. pixel-perfect == dmax = 0) - integration test: dummy dataset results in good scores for all mAP threholds down to 0 * remove deprecated test that is now broken * update readme * extend readme * extend readme
- Loading branch information
Showing
9 changed files
with
231 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
.vscode/** | ||
|
||
datasets/ | ||
scripts/dummy_dataset/ | ||
**wandb/ | ||
lightning_logs** | ||
**.ckpt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Generate a COCO keypoints dataset of black images with circles on it for integration testing of the keypoint detector. \n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 192, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Requirement already satisfied: distinctipy in /fast_storage_2/symlinked_homes/tlips/conda/.conda/envs/keypoint-detection/lib/python3.9/site-packages (1.2.2)\n", | ||
"Requirement already satisfied: numpy in /home/tlips/.local/lib/python3.9/site-packages (from distinctipy) (1.25.2)\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import cv2\n", | ||
"import numpy as np \n", | ||
"from airo_dataset_tools.data_parsers.coco import CocoKeypointAnnotation, CocoImage, CocoKeypointCategory, CocoKeypointsDataset\n", | ||
"import pathlib\n", | ||
"!pip install distinctipy\n", | ||
"import distinctipy" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 193, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"n_images = 500\n", | ||
"n_categories = 2\n", | ||
"max_category_instances_per_image = 2\n", | ||
"\n", | ||
"image_resolution = (128, 128)\n", | ||
"circle_radius = 1" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 194, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\n", | ||
"\n", | ||
"DATA_DIR = pathlib.Path(\"./dummy_dataset\")\n", | ||
"DATA_DIR.mkdir(exist_ok=True)\n", | ||
"IMAGE_DIR = DATA_DIR / \"images\"\n", | ||
"IMAGE_DIR.mkdir(exist_ok=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 195, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"categories = []\n", | ||
"for category_idx in range(n_categories):\n", | ||
" coco_category = CocoKeypointCategory(\n", | ||
" id=category_idx,\n", | ||
" name=f\"dummy{category_idx}\",\n", | ||
" supercategory=f\"dummy{category_idx}\",\n", | ||
" keypoints=[f\"dummy{category_idx}\"]\n", | ||
" )\n", | ||
" categories.append(coco_category)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 196, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"category_colors = distinctipy.get_colors(n_categories)\n", | ||
"category_colors = [tuple([int(c * 255) for c in color]) for color in category_colors]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 197, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"coco_images = []\n", | ||
"cococ_annotations = []\n", | ||
"\n", | ||
"coco_instances_coutner = 0\n", | ||
"for image_idx in range(n_images):\n", | ||
" img = np.zeros((image_resolution[1],image_resolution[0],3), dtype=np.uint8)\n", | ||
" coco_images.append(CocoImage(id=image_idx, file_name=f\"images/img_{image_idx}.png\", height=image_resolution[1], width=image_resolution[0]))\n", | ||
" for category_idx in range(n_categories):\n", | ||
" n_instances = np.random.randint(0, max_category_instances_per_image+1)\n", | ||
" for instance_idx in range(n_instances):\n", | ||
" x = np.random.randint(2, image_resolution[0])\n", | ||
" y = np.random.randint(2, image_resolution[1])\n", | ||
" img = cv2.circle(img, (x, y), circle_radius, category_colors[category_idx], -1)\n", | ||
" cococ_annotations.append(CocoKeypointAnnotation(\n", | ||
" id=coco_instances_coutner,\n", | ||
" image_id=image_idx,\n", | ||
" category_id=category_idx,\n", | ||
" # as in coco datasets: zero-index, INT keypoints.\n", | ||
" # but add some random noise (simulating dataset with the exact pixel location instead of the zero-index int location)\n", | ||
" # to test if the detector can deal with this\n", | ||
" keypoints=[x + np.random.rand(1).item(), y + np.random.rand(1).item(), 1],\n", | ||
" num_keypoints=1,\n", | ||
" ))\n", | ||
" coco_instances_coutner += 1\n", | ||
"\n", | ||
" cv2.imwrite(str(DATA_DIR / \"images\"/f\"img_{image_idx}.png\"), img)\n", | ||
"\n", | ||
"coco_dataset = CocoKeypointsDataset(\n", | ||
" images=coco_images,\n", | ||
" annotations=cococ_annotations,\n", | ||
" categories=categories,\n", | ||
")\n", | ||
"\n", | ||
"with open(DATA_DIR / \"dummy_dataset.json\", \"w\") as f:\n", | ||
" f.write(coco_dataset.json())\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "keypoint-detection", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.13" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.