{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", " Try in Google Colab\n", " \n", " \n", " \n", " \n", " Share via nbviewer\n", " \n", " \n", " \n", " \n", " View on GitHub\n", " \n", " \n", " \n", " \n", " Download notebook\n", " \n", "
\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# **FiftyOne Keypoint Skeletons**" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Dataset already downloaded\n", "Loading 'quickstart'\n", " 100% |█████████████████| 200/200 [2.4s elapsed, 0s remaining, 82.8 samples/s] \n", "Dataset 'skeletons' created\n" ] }, { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Could not connect session, trying again in 10 seconds\n", "\n" ] } ], "source": [ "import fiftyone as fo\n", "import fiftyone.zoo as foz\n", "\n", "\n", "dataset = foz.load_zoo_dataset(\n", " \"quickstart\",\n", " dataset_name=\"skeletons\",\n", ")\n", "\n", "\n", "session = fo.launch_app(dataset)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Define your skeleton" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "dataset.skeletons = {\n", " \"points\": fo.KeypointSkeleton(\n", " labels=[\n", " \"left hand\" \"left shoulder\", \"right shoulder\", \"right hand\",\n", " \"left eye\", \"right eye\", \"mouth\",\n", " ],\n", " edges=[[0, 1, 2, 3], [4, 5, 6]],\n", " )\n", "}\n", "\n", "dataset.save()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!export FIFTYONE_CVAT_USERNAME=\"\"\n", "!export FIFTYONE_CVAT_PASSWORD=\"\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Annotate using one of FiftyOne's annotation integrations" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Dataset: skeletons\n", "Media type: image\n", "Num samples: 1\n", "Sample fields:\n", " id: fiftyone.core.fields.ObjectIdField\n", " filepath: fiftyone.core.fields.StringField\n", " tags: fiftyone.core.fields.ListField(fiftyone.core.fields.StringField)\n", " metadata: fiftyone.core.fields.EmbeddedDocumentField(fiftyone.core.metadata.ImageMetadata)\n", " ground_truth: fiftyone.core.fields.EmbeddedDocumentField(fiftyone.core.labels.Detections)\n", " uniqueness: fiftyone.core.fields.FloatField\n", " predictions: fiftyone.core.fields.EmbeddedDocumentField(fiftyone.core.labels.Detections)\n", "View stages:\n", " 1. MatchTags(tags=['annotate'], bool=True, all=False)" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ann_view = dataset.match_tags(\"annotate\")\n", "ann_view" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Computing metadata...\n", " 100% |█████████████████████| 1/1 [155.0ms elapsed, 0s remaining, 6.5 samples/s] \n", "Uploading samples to CVAT...\n", "Launching editor at 'http://localhost:8080/tasks/18/jobs/18'...\n" ] } ], "source": [ "\n", "# A unique identifer for this run\n", "anno_key = \"skeletons51\"\n", "\n", "# Upload the sample and launch CVAT\n", "anno_results = ann_view.annotate(\n", " anno_key,\n", " label_field=\"points\",\n", " label_type=\"keypoints\",\n", " classes=[\"person\"],\n", " launch_editor=True,\n", ")" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'points': {18: {'name': 'FiftyOne_skeletons',\n", " 'status': 'completed',\n", " 'assignee': None,\n", " 'last_updated': '2023-09-15T15:34:40.809777Z',\n", " 'jobs': {18: {'url': 'http://localhost:8080/api/jobs/18',\n", " 'id': 18,\n", " 'task_id': 18,\n", " 'project_id': None,\n", " 'assignee': None,\n", " 'guide_id': None,\n", " 'dimension': '2d',\n", " 'bug_tracker': None,\n", " 'status': 'completed',\n", " 'stage': 'acceptance',\n", " 'state': 'completed',\n", " 'mode': 'annotation',\n", " 'frame_count': 1,\n", " 'start_frame': 0,\n", " 'stop_frame': 0,\n", " 'data_chunk_size': 72,\n", " 'data_compressed_chunk_type': 'imageset',\n", " 'created_date': '2023-09-15T15:33:36.292099Z',\n", " 'updated_date': '2023-09-15T15:34:40.792068Z',\n", " 'issues': {'url': 'http://localhost:8080/api/issues?job_id=18',\n", " 'count': 0},\n", " 'labels': {'url': 'http://localhost:8080/api/labels?job_id=18',\n", " 'count': 1},\n", " 'type': 'annotation',\n", " 'organization': None}}}}}" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "anno_results.get_status()" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'points': {18: {'name': 'FiftyOne_skeletons',\n", " 'status': 'completed',\n", " 'assignee': None,\n", " 'last_updated': '2023-09-15T15:34:40.809777Z',\n", " 'jobs': {18: {'url': 'http://localhost:8080/api/jobs/18',\n", " 'id': 18,\n", " 'task_id': 18,\n", " 'project_id': None,\n", " 'assignee': None,\n", " 'guide_id': None,\n", " 'dimension': '2d',\n", " 'bug_tracker': None,\n", " 'status': 'completed',\n", " 'stage': 'acceptance',\n", " 'state': 'completed',\n", " 'mode': 'annotation',\n", " 'frame_count': 1,\n", " 'start_frame': 0,\n", " 'stop_frame': 0,\n", " 'data_chunk_size': 72,\n", " 'data_compressed_chunk_type': 'imageset',\n", " 'created_date': '2023-09-15T15:33:36.292099Z',\n", " 'updated_date': '2023-09-15T15:34:40.792068Z',\n", " 'issues': {'url': 'http://localhost:8080/api/issues?job_id=18',\n", " 'count': 0},\n", " 'labels': {'url': 'http://localhost:8080/api/labels?job_id=18',\n", " 'count': 1},\n", " 'type': 'annotation',\n", " 'organization': None}}}}}" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result = ann_view.load_annotation_results(anno_key)\n", "result.get_status()" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 100% |█████████████████████| 1/1 [8.2ms elapsed, 0s remaining, 122.0 samples/s] \n" ] }, { "data": { "text/plain": [ "{'name': 'skeletons',\n", " 'version': '0.21.6',\n", " 'media_type': 'image',\n", " 'sample_fields': {'id': 'fiftyone.core.fields.ObjectIdField',\n", " 'filepath': 'fiftyone.core.fields.StringField',\n", " 'tags': 'fiftyone.core.fields.ListField(fiftyone.core.fields.StringField)',\n", " 'metadata': 'fiftyone.core.fields.EmbeddedDocumentField(fiftyone.core.metadata.ImageMetadata)',\n", " 'ground_truth': 'fiftyone.core.fields.EmbeddedDocumentField(fiftyone.core.labels.Detections)',\n", " 'uniqueness': 'fiftyone.core.fields.FloatField',\n", " 'predictions': 'fiftyone.core.fields.EmbeddedDocumentField(fiftyone.core.labels.Detections)'},\n", " 'info': {},\n", " 'skeletons': {'points': SON([('labels', ['left handleft shoulder', 'right shoulder', 'right hand', 'left eye', 'right eye', 'mouth']), ('edges', [[0, 1, 2, 3], [4, 5, 6]])])},\n", " 'stages': [{'_cls': 'fiftyone.core.stages.MatchTags',\n", " 'kwargs': [['tags', ['annotate']], ['bool', True], ['all', False]]}],\n", " 'samples': [{'filepath': '/home/dan/fiftyone/quickstart/data/004126.jpg',\n", " 'tags': ['annotate'],\n", " 'metadata': {'_cls': 'ImageMetadata',\n", " 'size_bytes': 76725,\n", " 'mime_type': 'image/jpeg',\n", " 'width': 640,\n", " 'height': 367,\n", " 'num_channels': 3},\n", " 'ground_truth': {'_cls': 'Detections',\n", " 'detections': [{'_id': {'$oid': '5f452486ef00e6374aad1f3b'},\n", " '_cls': 'Detection',\n", " 'attributes': {},\n", " 'tags': [],\n", " 'label': 'person',\n", " 'bounding_box': [0.40128125,\n", " 0.10084468664850135,\n", " 0.4025625,\n", " 0.7338147138964578],\n", " 'area': 25741.941399999996,\n", " 'iscrowd': 0.0},\n", " {'_id': {'$oid': '5f452486ef00e6374aad1f3c'},\n", " '_cls': 'Detection',\n", " 'attributes': {},\n", " 'tags': [],\n", " 'label': 'skateboard',\n", " 'bounding_box': [0.42212500000000003,\n", " 0.6819891008174387,\n", " 0.369765625,\n", " 0.2647956403269755],\n", " 'area': 6746.244799999998,\n", " 'iscrowd': 0.0}]},\n", " 'uniqueness': 0.5988490085951711,\n", " 'predictions': {'_cls': 'Detections',\n", " 'detections': [{'_id': {'$oid': '5f452c62ef00e6374aadad97'},\n", " '_cls': 'Detection',\n", " 'attributes': {},\n", " 'tags': [],\n", " 'label': 'person',\n", " 'bounding_box': [0.4162792682647705,\n", " 0.10708199274962214,\n", " 0.38528170585632326,\n", " 0.7485176107214322],\n", " 'confidence': 0.9996997117996216},\n", " {'_id': {'$oid': '5f452c62ef00e6374aadad98'},\n", " '_cls': 'Detection',\n", " 'attributes': {},\n", " 'tags': [],\n", " 'label': 'skateboard',\n", " 'bounding_box': [0.42113075256347654,\n", " 0.7071953963193971,\n", " 0.35188612937927244,\n", " 0.2210996040531335],\n", " 'confidence': 0.9966714382171631},\n", " {'_id': {'$oid': '5f452c62ef00e6374aadad99'},\n", " '_cls': 'Detection',\n", " 'attributes': {},\n", " 'tags': [],\n", " 'label': 'skateboard',\n", " 'bounding_box': [0.42644128799438474,\n", " 0.7756693577571526,\n", " 0.25977129936218263,\n", " 0.1626938656175494],\n", " 'confidence': 0.26288551092147827},\n", " {'_id': {'$oid': '5f452c62ef00e6374aadad9a'},\n", " '_cls': 'Detection',\n", " 'attributes': {},\n", " 'tags': [],\n", " 'label': 'backpack',\n", " 'bounding_box': [0.4955601692199707,\n", " 0.2537781302220815,\n", " 0.1733004093170166,\n", " 0.1738174189014071],\n", " 'confidence': 0.09162653982639313},\n", " {'_id': {'$oid': '5f452c62ef00e6374aadad9b'},\n", " '_cls': 'Detection',\n", " 'attributes': {},\n", " 'tags': [],\n", " 'label': 'skateboard',\n", " 'bounding_box': [0.5207001686096191,\n", " 0.697685137756514,\n", " 0.2611091613769531,\n", " 0.16240049772756301],\n", " 'confidence': 0.07061836868524551}]}}]}" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ann_view.to_dict()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load the skeleton back in" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Downloading labels from CVAT...\n", "Download complete\n", "Loading labels for field 'points'...\n", " 100% |█████████████████████| 1/1 [5.3ms elapsed, 0s remaining, 189.9 samples/s] \n", "Deleting tasks...\n", " 100% |█████████████████████| 1/1 [108.0ms elapsed, 0s remaining, 9.3 samples/s] \n" ] }, { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "ann_view.load_annotations(\"skeletons51\", cleanup=True)\n", "\n", "session.view = ann_view" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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" } }, "nbformat": 4, "nbformat_minor": 2 }