{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Create Table from COCO Instance Segmentation\n", "\n", "Create a 3LC Table from COCO-format dataset containing images with instance segmentation annotations for object detection and segmentation tasks.\n", "\n", "![img](../../images/instance-segmentation.jpg)\n", "\n", "\n", "\n", "COCO is one of the most popular formats for instance segmentation datasets, providing precise pixel-level masks for each object instance. This format is essential for tasks requiring both object detection and precise boundary delineation.\n", "\n", "This notebook demonstrates loading a COCO-format dataset and converting it to a 3LC Table. The resulting table contains image and segmentation columns with properly structured polygon or mask annotations from the COCO JSON format.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Project setup\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [ "parameters" ] }, "outputs": [], "source": [ "PROJECT_NAME = \"3LC Tutorials - COCO128\"\n", "DATASET_NAME = \"COCO128\"\n", "TABLE_NAME = \"initial-segmentation\"\n", "DATA_PATH = \"../../../data\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Install dependencies" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install 3lc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Imports\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "import tlc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create Segmentation Table\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "annotations_file = (Path(DATA_PATH) / \"coco128\" / \"annotations.json\").absolute()\n", "image_folder = (Path(DATA_PATH) / \"coco128\" / \"images\").absolute()\n", "\n", "assert annotations_file.exists()\n", "assert image_folder.exists()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "seg_table = tlc.Table.from_coco(\n", " annotations_file=annotations_file,\n", " image_folder=image_folder,\n", " table_name=TABLE_NAME,\n", " dataset_name=DATASET_NAME,\n", " project_name=PROJECT_NAME,\n", " task=\"segment\",\n", ")" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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.12.9" } }, "nbformat": 4, "nbformat_minor": 2 }