diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml
index 1e3977a80..382176478 100644
--- a/.github/workflows/notebooks.yml
+++ b/.github/workflows/notebooks.yml
@@ -1,4 +1,4 @@
-name: Labelbox Python SDK Notebooks (Develop)
+name: Labelbox Example Notebook Workflow
on:
push:
@@ -13,25 +13,72 @@ on:
permissions:
contents: write
pull-requests: write
-
+
jobs:
- update:
+ # Get installs from rye and run rye run clean to format
+ format:
+ if: github.event.pull_request.merged == false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- - name: Install databooks
- run: pip install databooks
- - name: Remove notebook metadata
- run: echo "y" | databooks meta examples/. --rm-outs
+ - uses: ./.github/actions/python-package-shared-setup
+ with:
+ rye-version: ${{ vars.RYE_VERSION }}
+ python-version: 3.12
+ - name: Format
+ working-directory: examples
+ run: rye run clean
+ - name: Commit changes
+ run: |
+ git config --local user.email "github-actions[bot]@users.noreply.github.com"
+ git config --local user.name "github-actions[bot]"
+ git add examples/.
+ git commit -m ":art: Cleaned" || exit 0
+ - name: Push changes
+ uses: ad-m/github-push-action@master
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ branch: ${{ github.head_ref }}
+ # See if notebooks were added or deleted (name change counts as both)
+ changes:
+ needs: format
+ if: github.event.pull_request.merged == false
+ runs-on: ubuntu-latest
+ outputs:
+ addedOrModified: ${{ steps.filter.outputs.addedOrModified }}
+ steps:
+ - uses: dorny/paths-filter@v3
+ id: filter
+ with:
+ filters: |
+ addedOrModified:
+ - added|deleted: 'examples/**/*.ipynb'
+ # Create readme if the above job shows true using rye run create-readme
+ create:
+ needs: changes
+ if: ${{ needs.changes.outputs.addedOrModified == 'true' }} && github.event.pull_request.merged == false
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ ref: ${{ github.head_ref }}
+ fetch-depth: 0
+ - uses: ./.github/actions/python-package-shared-setup
+ with:
+ rye-version: ${{ vars.RYE_VERSION }}
+ python-version: 3.12
+ - name: Create readme
+ working-directory: examples
+ run: rye run create-readme
- name: Commit changes
run: |
- git config --local user.email "github-actions[bot]@users.noreply.github.com"
- git config --local user.name "github-actions[bot]"
- git add examples/.
- git commit -m "Removed metadata" || exit 0
+ git config --local user.email "github-actions[bot]@users.noreply.github.com"
+ git config --local user.name "github-actions[bot]"
+ git add examples/.
+ git commit -m ":memo: README updated" || exit 0
- name: Push changes
uses: ad-m/github-push-action@master
with:
diff --git a/.github/workflows/rdme-custompages.yml b/.github/workflows/rdme-custompages.yml
new file mode 100644
index 000000000..c39a2d550
--- /dev/null
+++ b/.github/workflows/rdme-custompages.yml
@@ -0,0 +1,27 @@
+name: ReadMe GitHub Action 🦉
+
+on:
+ pull_request:
+ branches: [develop]
+ types:
+ - closed
+ paths:
+ - examples/README.md
+
+jobs:
+ custompages:
+ if: github.event.pull_request.merged == true
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: ./.github/actions/python-package-shared-setup
+ with:
+ rye-version: ${{ vars.RYE_VERSION }}
+ python-version: 3.12
+ - name: Create readme
+ working-directory: examples
+ run: rye run create-doc-readme
+ - name: Run `custompages` command
+ uses: readmeio/rdme@v8
+ with:
+ rdme: custompages examples/tutorials.html --key=${{ secrets.README_API_KEY }}
diff --git a/examples/CONTRIBUTING.md b/examples/CONTRIBUTING.md
new file mode 100644
index 000000000..bb7dd5999
--- /dev/null
+++ b/examples/CONTRIBUTING.md
@@ -0,0 +1,52 @@
+# Contribution Guide
+
+Thank you for contributing to our notebook examples! To ensure that your contribution aligns with our guidelines, please carefully review the following guide.
+
+## Table of Contents
+
+- [General Notebook Requirements](#general-notebook-requirements)
+- [Branches and Tags](#branches-and-tags)
+- [Github Workflows](#github-workflows)
+- [General Prerequisites](#general-prerequisites)
+- [Styling Tools](#styling-tools)
+
+## General Notebook Requirements
+
+Review our [template notebook](template.ipynbs) for general overview on how notebooks should be structure. This notebook and section just serves as a guide and exceptions can be made. Here are our general requirements:
+
+1. Ensure that any modified notebooks run when edited.
+2. Ensure that you update any relevant headers and comments within the code block you may add or change.
+3. Notebooks should start with a top header below the Labelbox and link icons with the title of the notebook as a main header **#** and a overview of what the notebook shows.
+4. Use "labelbox[data]" over labelbox for installs to ensure you have the correct dependencies.
+5. Imports and installs should come after the main header under a **Setup** section.
+6. Labelbox and other platforms with clients and API keys should be specified under a single section.
+7. Subsections need a second level header **##** and an overview of the section.
+8. The last cell should be a clean up section to delete any labelbox objects created and commented out to prevent accidentally running code blocks.
+9. Notebook github action [workflows](#github-workflows) are required to run successfully before merging.
+
+> [!IMPORTANT]
+> Please make sure to remove any API keys before pushing changes
+
+## Branches and Tags
+
+- All development happens in feature branches ideally prefixed by contributor's initials. For example `fs/feature_name`.
+- Approved PRs are merged to the `develop` branch.
+- All releases align to a git tag.
+
+## Github Workflows
+
+- Github Branch Workflow
+ - When you push to a branch that contains files inside the examples directory, it will automatically reformat your notebook to match our given style and provide appropriate headers. Once this workflow is completed it will commit back to your branch which then you can pull.
+ - If your push contains new notebooks or modifies the names of notebooks the readme will be updated to reflect the change with updated links.
+
+## General Prerequisites
+
+[Rye](https://rye-up.com/) may be installed before contributing to the repository as it is the tool used to style our example notebooks. This could be used to avoid the github styling workflow. This is also the packaging tool used for the main SDK. The pyproject used for the example notebooks is a virtual package and does not get published.
+
+## Styling Tools
+
+Rye is setup in this directory to use a customs script that will run the notebooks through our formatting tools and create readmes.
+
+- `rye sync` in the examples folder to install the correct dev dependencies.
+- `rye run clean` runs a series of formatting tools.
+- `rye run create-readme` creates a readme based off our notebooks.
diff --git a/examples/Makefile b/examples/Makefile
deleted file mode 100644
index e815dbe42..000000000
--- a/examples/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
-
-upload:
- python scripts/upload_documentation.py --config-path 'scripts/config.json'
\ No newline at end of file
diff --git a/examples/README.md b/examples/README.md
index 08f083bc2..6e8faebec 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -17,54 +17,49 @@
- Basics |
-  |
-  |
+ Ontologies |
+  |
+  |
- Batches |
-  |
-  |
+ Data Rows |
+  |
+  |
- Custom Embeddings |
-  |
-  |
+ Batches |
+  |
+  |
Projects |
-  |
-  |
-
-
- User Management |
-  |
-  |
+  |
+  |
- Export V1 Migration Support |
-  |
-  |
+ Custom Embeddings |
+  |
+  |
Data Row Metadata |
-  |
-  |
+  |
+  |
- Ontologies |
-  |
-  |
+ Basics |
+  |
+  |
- Data Rows |
-  |
-  |
+ User Management |
+  |
+  |
-Foundry
+Exports
@@ -76,9 +71,19 @@
- Object Detection |
-  |
-  |
+ Export V1 to V2 Migration Support |
+  |
+  |
+
+
+ Composite Mask Export |
+  |
+  |
+
+
+ Export Data |
+  |
+  |
@@ -96,18 +101,18 @@
Project Setup |
-  |
-  |
+  |
+  |
Webhooks |
-  |
-  |
+  |
+  |
Queue Management |
-  |
-  |
+  |
+  |
@@ -124,69 +129,69 @@
- Import Labeled Dataset Image |
-  |
-  |
-
-
- Audio |
-  |
-  |
+ Conversational LLM Data Generation |
+  |
+  |
Video |
-  |
-  |
+  |
+  |
Text |
-  |
-  |
+  |
+  |
- Tiled |
-  |
-  |
+ Audio |
+  |
+  |
Conversational |
-  |
-  |
+  |
+  |
+
+
+ Import Labeled Dataset Image |
+  |
+  |
PDF |
-  |
-  |
+  |
+  |
- Conversational LLM Data Generation |
-  |
-  |
+ Image |
+  |
+  |
DICOM |
-  |
-  |
+  |
+  |
- Image |
-  |
-  |
+ Conversational LLM |
+  |
+  |
HTML |
-  |
-  |
+  |
+  |
- Conversational LLM |
-  |
-  |
+ Tiled |
+  |
+  |
-Prediction Upload
+Integrations
@@ -198,49 +203,29 @@
- Conversational Predictions |
-  |
-  |
-
-
- Text Predictions |
-  |
-  |
-
-
- HTML Predictions |
-  |
-  |
-
-
- Conversational LLM Predictions |
-  |
-  |
-
-
- Geospatial Predictions |
-  |
-  |
+ Huggingface Custom Embeddings |
+  |
+  |
- PDF Predictions |
-  |
-  |
+ Langchain |
+  |
+  |
- Video Predictions |
-  |
-  |
+ Meta SAM Video |
+  |
+  |
- Image Predictions |
-  |
-  |
+ Meta SAM |
+  |
+  |
-Exports
+Model Experiments
@@ -252,19 +237,29 @@
- Composite Mask Export |
-  |
-  |
+ Custom Metrics Demo |
+  |
+  |
- Export Data |
-  |
-  |
+ Model Slices |
+  |
+  |
+
+
+ Custom Metrics Basics |
+  |
+  |
+
+
+ Model Predictions to Project |
+  |
+  |
-Integrations
+Prediction Upload
@@ -276,63 +271,49 @@
- Meta SAM |
-  |
-  |
+ PDF Predictions |
+  |
+  |
- Meta SAM Video |
-  |
-  |
+ HTML Predictions |
+  |
+  |
- Langchain |
-  |
-  |
+ Conversational Predictions |
+  |
+  |
- Huggingface Custom Embeddings |
-  |
-  |
-
-
-
-
-Model Experiments
-
-
-
-
- Notebook |
- Github |
- Google Colab |
+ Image Predictions |
+  |
+  |
-
-
- Model Slices |
-  |
-  |
+ Text Predictions |
+  |
+  |
- Custom Metrics Basics |
-  |
-  |
+ Geospatial Predictions |
+  |
+  |
- Custom Metrics Demo |
-  |
-  |
+ Conversational LLM Predictions |
+  |
+  |
- Model Predictions to Project |
-  |
-  |
+ Video Predictions |
+  |
+  |
-Extras
+Foundry
@@ -344,9 +325,9 @@
- Classification Confusion Matrix |
-  |
-  |
+ Object Detection |
+  |
+  |
diff --git a/examples/annotation_import/audio.ipynb b/examples/annotation_import/audio.ipynb
index 052a4fc03..c798be914 100644
--- a/examples/annotation_import/audio.ipynb
+++ b/examples/annotation_import/audio.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -74,9 +74,7 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q 'labelbox[data]'"
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -90,11 +88,7 @@
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import uuid\n",
- "import labelbox.types as lb_types"
- ],
+ "source": "import labelbox as lb\nimport uuid\nimport labelbox.types as lb_types",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -109,11 +103,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your api key\n",
- "API_KEY = \"\"\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your api key\nAPI_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -127,72 +117,21 @@
},
{
"metadata": {},
- "source": [
- "##### Classification free text #####\n",
- "\n",
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"text_audio\",\n",
- " value=lb_types.Text(answer=\"free text audio annotation\"),\n",
- ")\n",
- "\n",
- "text_annotation_ndjson = {\n",
- " 'name': 'text_audio',\n",
- " 'answer': 'free text audio annotation',\n",
- "}"
- ],
+ "source": "##### Classification free text #####\n\ntext_annotation = lb_types.ClassificationAnnotation(\n name=\"text_audio\",\n value=lb_types.Text(answer=\"free text audio annotation\"),\n)\n\ntext_annotation_ndjson = {\n \"name\": \"text_audio\",\n \"answer\": \"free text audio annotation\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "##### Checklist Classification #######\n",
- "\n",
- "checklist_annotation= lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_audio\",\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\"\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\"\n",
- " )\n",
- " ]\n",
- " ),\n",
- " )\n",
- "\n",
- "\n",
- "checklist_annotation_ndjson = {\n",
- " 'name': 'checklist_audio',\n",
- " 'answers': [\n",
- " {'name': 'first_checklist_answer'},\n",
- " {'name': 'second_checklist_answer'}\n",
- " ],\n",
- "}"
- ],
+ "source": "##### Checklist Classification #######\n\nchecklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_audio\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n ]),\n)\n\nchecklist_annotation_ndjson = {\n \"name\":\n \"checklist_audio\",\n \"answers\": [\n {\n \"name\": \"first_checklist_answer\"\n },\n {\n \"name\": \"second_checklist_answer\"\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "######## Radio Classification ######\n",
- "\n",
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_audio\",\n",
- " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n",
- " name=\"second_radio_answer\")))\n",
- "\n",
- "radio_annotation_ndjson = {\n",
- " 'name': 'radio_audio',\n",
- " 'answer': {\n",
- " 'name': 'first_radio_answer'\n",
- " },\n",
- "}"
- ],
+ "source": "######## Radio Classification ######\n\nradio_annotation = lb_types.ClassificationAnnotation(\n name=\"radio_audio\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"second_radio_answer\")),\n)\n\nradio_annotation_ndjson = {\n \"name\": \"radio_audio\",\n \"answer\": {\n \"name\": \"first_radio_answer\"\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -213,22 +152,7 @@
},
{
"metadata": {},
- "source": [
- "# Create one Labelbox dataset\n",
- "\n",
- "global_key = \"sample-audio-1.mp3\"\n",
- "\n",
- "asset = {\n",
- " \"row_data\": \"https://storage.googleapis.com/labelbox-datasets/audio-sample-data/sample-audio-1.mp3\",\n",
- " \"global_key\": global_key\n",
- "}\n",
- "\n",
- "dataset = client.create_dataset(name=\"audio_annotation_import_demo_dataset\")\n",
- "task = dataset.create_data_rows([asset])\n",
- "task.wait_till_done()\n",
- "print(\"Errors:\", task.errors)\n",
- "print(\"Failed data rows: \", task.failed_data_rows)"
- ],
+ "source": "# Create one Labelbox dataset\n\nglobal_key = \"sample-audio-1.mp3\"\n\nasset = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/audio-sample-data/sample-audio-1.mp3\",\n \"global_key\":\n global_key,\n}\n\ndataset = client.create_dataset(name=\"audio_annotation_import_demo_dataset\")\ntask = dataset.create_data_rows([asset])\ntask.wait_till_done()\nprint(\"Errors:\", task.errors)\nprint(\"Failed data rows: \", task.failed_data_rows)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -246,33 +170,7 @@
},
{
"metadata": {},
- "source": [
- "ontology_builder = lb.OntologyBuilder(\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"text_audio\"),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_audio\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_audio\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\"),\n",
- " lb.Option(value=\"second_radio_answer\")\n",
- " ]\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Ontology Audio Annotations\", ontology_builder.asdict(), media_type=lb.MediaType.Audio)"
- ],
+ "source": "ontology_builder = lb.OntologyBuilder(classifications=[\n lb.Classification(class_type=lb.Classification.Type.TEXT,\n name=\"text_audio\"),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_audio\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_audio\",\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n])\n\nontology = client.create_ontology(\n \"Ontology Audio Annotations\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Audio,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -288,14 +186,7 @@
},
{
"metadata": {},
- "source": [
- "# Create Labelbox project\n",
- "project = client.create_project(name=\"audio_project\",\n",
- " media_type=lb.MediaType.Audio)\n",
- "\n",
- "# Setup your ontology\n",
- "project.setup_editor(ontology) # Connect your ontology and editor to your project"
- ],
+ "source": "# Create Labelbox project\nproject = client.create_project(name=\"audio_project\",\n media_type=lb.MediaType.Audio)\n\n# Setup your ontology\nproject.setup_editor(\n ontology) # Connect your ontology and editor to your project",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -309,18 +200,7 @@
},
{
"metadata": {},
- "source": [
- "# Setup Batches and Ontology\n",
- "\n",
- "# Create a batch to send to your MAL project\n",
- "batch = project.create_batch(\n",
- " \"first-batch-audio-demo\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")\n",
- "\n",
- "print(\"Batch: \", batch)"
- ],
+ "source": "# Setup Batches and Ontology\n\n# Create a batch to send to your MAL project\nbatch = project.create_batch(\n \"first-batch-audio-demo\", # Each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # Paginated collection of data row objects, list of data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)\n\nprint(\"Batch: \", batch)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -345,19 +225,7 @@
},
{
"metadata": {},
- "source": [
- "label = []\n",
- "label.append(\n",
- " lb_types.Label(\n",
- " data={\"global_key\" : global_key },\n",
- " annotations=[\n",
- " text_annotation,\n",
- " checklist_annotation,\n",
- " radio_annotation\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "label = []\nlabel.append(\n lb_types.Label(\n data={\"global_key\": global_key},\n annotations=[text_annotation, checklist_annotation, radio_annotation],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -372,18 +240,7 @@
},
{
"metadata": {},
- "source": [
- "label_ndjson = []\n",
- "for annotations in [text_annotation_ndjson,\n",
- " checklist_annotation_ndjson,\n",
- " radio_annotation_ndjson]:\n",
- " annotations.update({\n",
- " 'dataRow': {\n",
- " 'globalKey': global_key\n",
- " }\n",
- " })\n",
- " label_ndjson.append(annotations)"
- ],
+ "source": "label_ndjson = []\nfor annotations in [\n text_annotation_ndjson,\n checklist_annotation_ndjson,\n radio_annotation_ndjson,\n]:\n annotations.update({\"dataRow\": {\"globalKey\": global_key}})\n label_ndjson.append(annotations)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -405,18 +262,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload our label using Model-Assisted Labeling\n",
- "upload_job = lb.MALPredictionImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=f\"mal_job-{str(uuid.uuid4())}\",\n",
- " predictions=label)\n",
- "\n",
- "upload_job.wait_until_done();\n",
- "print(\"Errors:\", upload_job.errors)\n",
- "print(\"Status of uploads: \", upload_job.statuses)"
- ],
+ "source": "# Upload our label using Model-Assisted Labeling\nupload_job = lb.MALPredictionImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=f\"mal_job-{str(uuid.uuid4())}\",\n predictions=label,\n)\n\nupload_job.wait_until_done()\nprint(\"Errors:\", upload_job.errors)\nprint(\"Status of uploads: \", upload_job.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -430,18 +276,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload label for this data row in project\n",
- "upload_job = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"label_import_job\"+str(uuid.uuid4()),\n",
- " labels=label)\n",
- "\n",
- "upload_job.wait_until_done();\n",
- "print(\"Errors:\", upload_job.errors)\n",
- "print(\"Status of uploads: \", upload_job.statuses)"
- ],
+ "source": "# Upload label for this data row in project\nupload_job = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"label_import_job\" + str(uuid.uuid4()),\n labels=label,\n)\n\nupload_job.wait_until_done()\nprint(\"Errors:\", upload_job.errors)\nprint(\"Status of uploads: \", upload_job.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -455,10 +290,7 @@
},
{
"metadata": {},
- "source": [
- "# project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/annotation_import/conversational.ipynb b/examples/annotation_import/conversational.ipynb
index 35277b667..d62ae9ee8 100644
--- a/examples/annotation_import/conversational.ipynb
+++ b/examples/annotation_import/conversational.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -76,9 +76,7 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -92,11 +90,7 @@
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import uuid\n",
- "import labelbox.types as lb_types"
- ],
+ "source": "import labelbox as lb\nimport uuid\nimport labelbox.types as lb_types",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -111,11 +105,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your api key\n",
- "API_KEY = \"\"\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your api key\nAPI_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -129,182 +119,35 @@
},
{
"metadata": {},
- "source": [
- "# message based classifications\n",
- "ner_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"ner\",\n",
- " value=lb_types.ConversationEntity(\n",
- " start=0,\n",
- " end=8,\n",
- " message_id=\"4\"\n",
- " )\n",
- ")\n",
- "\n",
- "ner_annotation_ndjson = {\n",
- " \"name\": \"ner\",\n",
- " \"location\": {\n",
- " \"start\": 0,\n",
- " \"end\": 8\n",
- " },\n",
- " \"messageId\": \"4\"\n",
- " }"
- ],
+ "source": "# message based classifications\nner_annotation = lb_types.ObjectAnnotation(\n name=\"ner\",\n value=lb_types.ConversationEntity(start=0, end=8, message_id=\"4\"),\n)\n\nner_annotation_ndjson = {\n \"name\": \"ner\",\n \"location\": {\n \"start\": 0,\n \"end\": 8\n },\n \"messageId\": \"4\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "##### Classification free text #####\n",
- "\n",
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"text_convo\",\n",
- " value=lb_types.Text(answer=\"the answer to the text questions right here\"),\n",
- " message_id=\"0\"\n",
- ")\n",
- "\n",
- "\n",
- "text_annotation_ndjson = {\n",
- " \"name\": \"text_convo\",\n",
- " \"answer\": \"the answer to the text questions right here\",\n",
- " \"messageId\": \"0\"\n",
- "}"
- ],
+ "source": "##### Classification free text #####\n\ntext_annotation = lb_types.ClassificationAnnotation(\n name=\"text_convo\",\n value=lb_types.Text(answer=\"the answer to the text questions right here\"),\n message_id=\"0\",\n)\n\ntext_annotation_ndjson = {\n \"name\": \"text_convo\",\n \"answer\": \"the answer to the text questions right here\",\n \"messageId\": \"0\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "##### Checklist Classification #######\n",
- "\n",
- "checklist_annotation= lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_convo\", # must match your ontology feature\"s name\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\"\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\"\n",
- " )\n",
- " ]\n",
- " ),\n",
- " message_id=\"2\"\n",
- " )\n",
- "\n",
- "\n",
- "checklist_annotation_ndjson = {\n",
- " \"name\": \"checklist_convo\",\n",
- " \"answers\": [\n",
- " {\"name\": \"first_checklist_answer\"},\n",
- " {\"name\": \"second_checklist_answer\"}\n",
- " ],\n",
- " \"messageId\": \"2\"\n",
- "}"
- ],
+ "source": "##### Checklist Classification #######\n\nchecklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_convo\", # must match your ontology feature\"s name\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n ]),\n message_id=\"2\",\n)\n\nchecklist_annotation_ndjson = {\n \"name\": \"checklist_convo\",\n \"answers\": [\n {\n \"name\": \"first_checklist_answer\"\n },\n {\n \"name\": \"second_checklist_answer\"\n },\n ],\n \"messageId\": \"2\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "######## Radio Classification ######\n",
- "\n",
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_convo\",\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(name = \"first_radio_answer\")),\n",
- " message_id=\"0\"\n",
- ")\n",
- "\n",
- "radio_annotation_ndjson = {\n",
- " \"name\": \"radio_convo\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\"\n",
- " },\n",
- " \"messageId\": \"0\",\n",
- "}"
- ],
+ "source": "######## Radio Classification ######\n\nradio_annotation = lb_types.ClassificationAnnotation(\n name=\"radio_convo\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\")),\n message_id=\"0\",\n)\n\nradio_annotation_ndjson = {\n \"name\": \"radio_convo\",\n \"answer\": {\n \"name\": \"first_radio_answer\"\n },\n \"messageId\": \"0\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# ############ global nested classifications ###########\n",
- "# Message based\n",
- "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " message_id=\"10\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\",\n",
- "\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "# Message based\n",
- "nested_checklist_annotation_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"messageId\": \"10\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"classifications\" : [\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_sub_checklist_answer\"\n",
- " }\n",
- " }\n",
- " ]\n",
- " }]\n",
- "}\n",
- "# Global\n",
- "nested_radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "\n",
- "# Global\n",
- "nested_radio_annotation_ndjson = {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\",\n",
- " \"classifications\": [{\n",
- " \"name\":\"sub_radio_question\",\n",
- " \"answer\": { \"name\" : \"first_sub_radio_answer\"}\n",
- " }]\n",
- " }\n",
- "}\n",
- "\n"
- ],
+ "source": "# ############ global nested classifications ###########\n# Message based\nnested_checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n message_id=\"10\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\",)\n ]),\n )\n ],\n )\n ]),\n)\n# Message based\nnested_checklist_annotation_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"messageId\":\n \"10\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\"\n },\n }],\n }],\n}\n# Global\nnested_radio_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n)\n\n# Global\nnested_radio_annotation_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\"\n },\n }],\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -325,22 +168,7 @@
},
{
"metadata": {},
- "source": [
- "# Create one Labelbox dataset\n",
- "\n",
- "global_key = \"conversation-1.json\"\n",
- "\n",
- "asset = {\n",
- " \"row_data\": \"https://storage.googleapis.com/labelbox-developer-testing-assets/conversational_text/1000-conversations/conversation-1.json\",\n",
- " \"global_key\": global_key\n",
- "}\n",
- "\n",
- "dataset = client.create_dataset(name=\"conversational_annotation_import_demo_dataset\")\n",
- "task = dataset.create_data_rows([asset])\n",
- "task.wait_till_done()\n",
- "print(\"Errors:\", task.errors)\n",
- "print(\"Failed data rows: \", task.failed_data_rows)"
- ],
+ "source": "# Create one Labelbox dataset\n\nglobal_key = \"conversation-1.json\"\n\nasset = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-developer-testing-assets/conversational_text/1000-conversations/conversation-1.json\",\n \"global_key\":\n global_key,\n}\n\ndataset = client.create_dataset(\n name=\"conversational_annotation_import_demo_dataset\")\ntask = dataset.create_data_rows([asset])\ntask.wait_till_done()\nprint(\"Errors:\", task.errors)\nprint(\"Failed data rows: \", task.failed_data_rows)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -358,69 +186,7 @@
},
{
"metadata": {},
- "source": [
- "ontology_builder = lb.OntologyBuilder(\n",
- " tools=[\n",
- " lb.Tool(tool=lb.Tool.Type.NER,name=\"ner\"),\n",
- " ],\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " scope=lb.Classification.Scope.INDEX,\n",
- " name=\"text_convo\"),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " scope=lb.Classification.Scope.INDEX,\n",
- " name=\"checklist_convo\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_convo\",\n",
- " scope=lb.Classification.Scope.INDEX,\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\"),\n",
- " lb.Option(value=\"second_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " scope = lb.Classification.Scope.INDEX,\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ])\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " scope = lb.Classification.Scope.GLOBAL,\n",
- " options=[\n",
- " lb.Option(\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[lb.Option(\"first_sub_radio_answer\")]\n",
- " )\n",
- " ])\n",
- " ]\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Ontology Conversation Annotations\", ontology_builder.asdict())"
- ],
+ "source": "ontology_builder = lb.OntologyBuilder(\n tools=[\n lb.Tool(tool=lb.Tool.Type.NER, name=\"ner\"),\n ],\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.TEXT,\n scope=lb.Classification.Scope.INDEX,\n name=\"text_convo\",\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n scope=lb.Classification.Scope.INDEX,\n name=\"checklist_convo\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_convo\",\n scope=lb.Classification.Scope.INDEX,\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n scope=lb.Classification.Scope.INDEX,\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n scope=lb.Classification.Scope.GLOBAL,\n options=[\n lb.Option(\n \"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(\"first_sub_radio_answer\")],\n )\n ],\n )\n ],\n ),\n ],\n)\n\nontology = client.create_ontology(\"Ontology Conversation Annotations\",\n ontology_builder.asdict())",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -436,14 +202,7 @@
},
{
"metadata": {},
- "source": [
- "# Create Labelbox project\n",
- "project = client.create_project(name=\"Conversational Text Annotation Import Demo\",\n",
- " media_type=lb.MediaType.Conversational)\n",
- "\n",
- "# Setup your ontology\n",
- "project.setup_editor(ontology) # Connect your ontology and editor to your project"
- ],
+ "source": "# Create Labelbox project\nproject = client.create_project(\n name=\"Conversational Text Annotation Import Demo\",\n media_type=lb.MediaType.Conversational,\n)\n\n# Setup your ontology\nproject.setup_editor(\n ontology) # Connect your ontology and editor to your project",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -457,16 +216,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a batch to send to your MAL project\n",
- "batch = project.create_batch(\n",
- " \"first-batch-convo-demo\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")\n",
- "\n",
- "print(\"Batch: \", batch)"
- ],
+ "source": "# Create a batch to send to your MAL project\nbatch = project.create_batch(\n \"first-batch-convo-demo\", # Each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # Paginated collection of data row objects, list of data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)\n\nprint(\"Batch: \", batch)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -491,22 +241,7 @@
},
{
"metadata": {},
- "source": [
- "label = []\n",
- "label.append(\n",
- " lb_types.Label(\n",
- " data={\"global_key\" : global_key },\n",
- " annotations=[\n",
- " ner_annotation,\n",
- " text_annotation,\n",
- " checklist_annotation,\n",
- " radio_annotation,\n",
- " nested_radio_annotation,\n",
- " nested_checklist_annotation\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "label = []\nlabel.append(\n lb_types.Label(\n data={\"global_key\": global_key},\n annotations=[\n ner_annotation,\n text_annotation,\n checklist_annotation,\n radio_annotation,\n nested_radio_annotation,\n nested_checklist_annotation,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -521,23 +256,7 @@
},
{
"metadata": {},
- "source": [
- "label_ndjson = []\n",
- "for annotations in [\n",
- " ner_annotation_ndjson,\n",
- " text_annotation_ndjson,\n",
- " checklist_annotation_ndjson,\n",
- " radio_annotation_ndjson,\n",
- " nested_checklist_annotation_ndjson,\n",
- " nested_radio_annotation_ndjson\n",
- " ]:\n",
- " annotations.update({\n",
- " \"dataRow\": {\n",
- " \"globalKey\": global_key\n",
- " }\n",
- " })\n",
- " label_ndjson.append(annotations)"
- ],
+ "source": "label_ndjson = []\nfor annotations in [\n ner_annotation_ndjson,\n text_annotation_ndjson,\n checklist_annotation_ndjson,\n radio_annotation_ndjson,\n nested_checklist_annotation_ndjson,\n nested_radio_annotation_ndjson,\n]:\n annotations.update({\"dataRow\": {\"globalKey\": global_key}})\n label_ndjson.append(annotations)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -559,18 +278,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload our label using Model-Assisted Labeling\n",
- "upload_job = lb.MALPredictionImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=f\"mal_job-{str(uuid.uuid4())}\",\n",
- " predictions=label)\n",
- "\n",
- "upload_job.wait_until_done()\n",
- "print(\"Errors:\", upload_job.errors)\n",
- "print(\"Status of uploads: \", upload_job.statuses)"
- ],
+ "source": "# Upload our label using Model-Assisted Labeling\nupload_job = lb.MALPredictionImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=f\"mal_job-{str(uuid.uuid4())}\",\n predictions=label,\n)\n\nupload_job.wait_until_done()\nprint(\"Errors:\", upload_job.errors)\nprint(\"Status of uploads: \", upload_job.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -584,18 +292,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload label for this data row in project\n",
- "upload_job = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"label_import_job\"+str(uuid.uuid4()),\n",
- " labels=label)\n",
- "\n",
- "upload_job.wait_until_done()\n",
- "print(\"Errors:\", upload_job.errors)\n",
- "print(\"Status of uploads: \", upload_job.statuses)"
- ],
+ "source": "# Upload label for this data row in project\nupload_job = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"label_import_job\" + str(uuid.uuid4()),\n labels=label,\n)\n\nupload_job.wait_until_done()\nprint(\"Errors:\", upload_job.errors)\nprint(\"Status of uploads: \", upload_job.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -609,10 +306,7 @@
},
{
"metadata": {},
- "source": [
- "# project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/annotation_import/conversational_LLM.ipynb b/examples/annotation_import/conversational_LLM.ipynb
index 05edb17bc..fa1fe02b0 100644
--- a/examples/annotation_import/conversational_LLM.ipynb
+++ b/examples/annotation_import/conversational_LLM.ipynb
@@ -6,26 +6,22 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | \n",
- "\n"
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
{
"metadata": {},
"source": [
- "\n",
"\n",
- "\n",
" \n",
" | \n",
"\n",
"\n",
- "\n",
- "![]() \n",
" | "
],
@@ -41,9 +37,7 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -57,11 +51,7 @@
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import labelbox.types as lb_types\n",
- "import uuid"
- ],
+ "source": "import labelbox as lb\nimport labelbox.types as lb_types\nimport uuid",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -75,10 +65,7 @@
},
{
"metadata": {},
- "source": [
- "API_KEY = \"\"\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "API_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -99,25 +86,7 @@
},
{
"metadata": {},
- "source": [
- "ner_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"ner\",\n",
- " value=lb_types.ConversationEntity(\n",
- " start=0,\n",
- " end=8,\n",
- " message_id=\"message-1\"\n",
- " )\n",
- ")\n",
- "\n",
- "ner_annotation_ndjson = {\n",
- " \"name\": \"ner\",\n",
- " \"location\": {\n",
- " \"start\": 0,\n",
- " \"end\": 8\n",
- " },\n",
- " \"messageId\": \"message-1\"\n",
- " }"
- ],
+ "source": "ner_annotation = lb_types.ObjectAnnotation(\n name=\"ner\",\n value=lb_types.ConversationEntity(start=0, end=8, message_id=\"message-1\"),\n)\n\nner_annotation_ndjson = {\n \"name\": \"ner\",\n \"location\": {\n \"start\": 0,\n \"end\": 8\n },\n \"messageId\": \"message-1\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -131,21 +100,7 @@
},
{
"metadata": {},
- "source": [
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"Choose the best response\",\n",
- " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n",
- " name=\"Response B\")))\n",
- "\n",
- "\n",
- "\n",
- "radio_annotation_ndjson = {\n",
- " \"name\": \"Choose the best response\",\n",
- " \"answer\": {\n",
- " \"name\": \"Response B\"\n",
- " }\n",
- "}\n"
- ],
+ "source": "radio_annotation = lb_types.ClassificationAnnotation(\n name=\"Choose the best response\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"Response B\")),\n)\n\nradio_annotation_ndjson = {\n \"name\": \"Choose the best response\",\n \"answer\": {\n \"name\": \"Response B\"\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -159,19 +114,7 @@
},
{
"metadata": {},
- "source": [
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"Provide a reason for your choice\",\n",
- " value=lb_types.Text(answer=\"the answer to the text questions right here\")\n",
- ")\n",
- "\n",
- "\n",
- "text_annotation_ndjson = {\n",
- " \"name\": \"Provide a reason for your choice\",\n",
- " \"answer\": \"This is the more concise answer\"\n",
- "\n",
- "}"
- ],
+ "source": "text_annotation = lb_types.ClassificationAnnotation(\n name=\"Provide a reason for your choice\",\n value=lb_types.Text(answer=\"the answer to the text questions right here\"),\n)\n\ntext_annotation_ndjson = {\n \"name\": \"Provide a reason for your choice\",\n \"answer\": \"This is the more concise answer\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -185,32 +128,7 @@
},
{
"metadata": {},
- "source": [
- "checklist_annotation= lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_convo\", # must match your ontology feature\"s name\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\"\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\"\n",
- " )\n",
- " ]\n",
- " ),\n",
- " message_id=\"message-1\" # Message specific annotation\n",
- " )\n",
- "\n",
- "\n",
- "checklist_annotation_ndjson = {\n",
- " \"name\": \"checklist_convo\",\n",
- " \"answers\": [\n",
- " {\"name\": \"first_checklist_answer\"},\n",
- " {\"name\": \"second_checklist_answer\"}\n",
- " ],\n",
- " \"messageId\": \"message-1\"\n",
- "}"
- ],
+ "source": "checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_convo\", # must match your ontology feature\"s name\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n ]),\n message_id=\"message-1\", # Message specific annotation\n)\n\nchecklist_annotation_ndjson = {\n \"name\": \"checklist_convo\",\n \"answers\": [\n {\n \"name\": \"first_checklist_answer\"\n },\n {\n \"name\": \"second_checklist_answer\"\n },\n ],\n \"messageId\": \"message-1\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -224,75 +142,7 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "# Message based\n",
- "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " message_id=\"message-1\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\"\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "# Message based\n",
- "nested_checklist_annotation_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"messageId\": \"message-1\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"classifications\" : [\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_sub_checklist_answer\",\n",
- " }\n",
- " }\n",
- " ]\n",
- " }]\n",
- "}\n",
- "# Global\n",
- "nested_radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "#Global\n",
- "nested_radio_annotation_ndjson = {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\",\n",
- " \"classifications\": [{\n",
- " \"name\":\"sub_radio_question\",\n",
- " \"answer\": { \"name\" : \"first_sub_radio_answer\"}\n",
- " }]\n",
- " }\n",
- "}\n",
- "\n"
- ],
+ "source": "# Message based\nnested_checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n message_id=\"message-1\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n )\n ]),\n)\n# Message based\nnested_checklist_annotation_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"messageId\":\n \"message-1\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\",\n },\n }],\n }],\n}\n# Global\nnested_radio_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n)\n# Global\nnested_radio_annotation_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\"\n },\n }],\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -330,74 +180,14 @@
},
{
"metadata": {},
- "source": [
- "pairwise_shopping_2 = \"\"\"\n",
- " {\n",
- " \"type\": \"application/vnd.labelbox.conversational\",\n",
- " \"version\": 1,\n",
- " \"messages\": [\n",
- " {\n",
- " \"messageId\": \"message-0\",\n",
- " \"timestampUsec\": 1530718491,\n",
- " \"content\": \"Hi! How can I help?\",\n",
- " \"user\": {\n",
- " \"userId\": \"Bot 002\",\n",
- " \"name\": \"Bot\"\n",
- " },\n",
- " \"align\": \"left\",\n",
- " \"canLabel\": false\n",
- " },\n",
- " {\n",
- " \"messageId\": \"message-1\",\n",
- " \"timestampUsec\": 1530718503,\n",
- " \"content\": \"I just bought a vacuum cleaner from you guys like a week ago and it's already broken!!\",\n",
- " \"user\": {\n",
- " \"userId\": \"User 00686\",\n",
- " \"name\": \"User\"\n",
- " },\n",
- " \"align\": \"right\",\n",
- " \"canLabel\": true\n",
- " }\n",
- "\n",
- " ],\n",
- " \"modelOutputs\": [\n",
- " {\n",
- " \"title\": \"Response A\",\n",
- " \"content\": \"I'm really sorry to hear that your vacuum cleaner is not working as expected. We certainly understand how frustrating this can be, especially with a recent purchase. I assure you, we're here to help!\\n\\n To proceed with resolving this issue, could you please provide some details about the problem you're experiencing with the vacuum cleaner? Additionally, if you could share your order number or receipt details, that would be very helpful. We will definitely look into the available options for you, which may include a replacement or a refund, depending on the specific circumstances and our return policy.\\n\\n Your satisfaction is our priority, and we'll do our best to resolve this matter promptly and to your satisfaction.\",\n",
- " \"modelConfigName\": \"GPT-3.5 with temperature 0\"\n",
- " },\n",
- " {\n",
- " \"title\": \"Response B\",\n",
- " \"content\": \"I'm sorry about the issue with your vacuum cleaner. Please send us the order number or receipt details so we can quickly assist you with a replacement. Your satisfaction is important to us!\",\n",
- " \"modelConfigName\": \"Fine Tuned GPT-3.5 with demo data\"\n",
- " }\n",
- " ]\n",
- "}\n",
- "\"\"\""
- ],
+ "source": "pairwise_shopping_2 = \"\"\"\n {\n \"type\": \"application/vnd.labelbox.conversational\",\n \"version\": 1,\n \"messages\": [\n {\n \"messageId\": \"message-0\",\n \"timestampUsec\": 1530718491,\n \"content\": \"Hi! How can I help?\",\n \"user\": {\n \"userId\": \"Bot 002\",\n \"name\": \"Bot\"\n },\n \"align\": \"left\",\n \"canLabel\": false\n },\n {\n \"messageId\": \"message-1\",\n \"timestampUsec\": 1530718503,\n \"content\": \"I just bought a vacuum cleaner from you guys like a week ago and it's already broken!!\",\n \"user\": {\n \"userId\": \"User 00686\",\n \"name\": \"User\"\n },\n \"align\": \"right\",\n \"canLabel\": true\n }\n\n ],\n \"modelOutputs\": [\n {\n \"title\": \"Response A\",\n \"content\": \"I'm really sorry to hear that your vacuum cleaner is not working as expected. We certainly understand how frustrating this can be, especially with a recent purchase. I assure you, we're here to help!\\n\\n To proceed with resolving this issue, could you please provide some details about the problem you're experiencing with the vacuum cleaner? Additionally, if you could share your order number or receipt details, that would be very helpful. We will definitely look into the available options for you, which may include a replacement or a refund, depending on the specific circumstances and our return policy.\\n\\n Your satisfaction is our priority, and we'll do our best to resolve this matter promptly and to your satisfaction.\",\n \"modelConfigName\": \"GPT-3.5 with temperature 0\"\n },\n {\n \"title\": \"Response B\",\n \"content\": \"I'm sorry about the issue with your vacuum cleaner. Please send us the order number or receipt details so we can quickly assist you with a replacement. Your satisfaction is important to us!\",\n \"modelConfigName\": \"Fine Tuned GPT-3.5 with demo data\"\n }\n ]\n}\n\"\"\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "global_key = \"pairwise_shooping_asset\"\n",
- "\n",
- "# Upload data rows\n",
- "convo_data = {\n",
- " \"row_data\": \"https://storage.googleapis.com/labelbox-datasets/conversational-sample-data/pairwise_shopping_2.json\",\n",
- " \"global_key\": global_key\n",
- "}\n",
- "\n",
- "# Create a dataset\n",
- "dataset = client.create_dataset(name=\"pairwise_annotation_demo\")\n",
- "# Create a datarows\n",
- "task = dataset.create_data_rows([convo_data])\n",
- "task.wait_till_done()\n",
- "print(\"Errors:\",task.errors)\n",
- "print(\"Failed data rows:\", task.failed_data_rows)\n"
- ],
+ "source": "global_key = \"pairwise_shooping_asset\"\n\n# Upload data rows\nconvo_data = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/conversational-sample-data/pairwise_shopping_2.json\",\n \"global_key\":\n global_key,\n}\n\n# Create a dataset\ndataset = client.create_dataset(name=\"pairwise_annotation_demo\")\n# Create a datarows\ntask = dataset.create_data_rows([convo_data])\ntask.wait_till_done()\nprint(\"Errors:\", task.errors)\nprint(\"Failed data rows:\", task.failed_data_rows)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -411,69 +201,7 @@
},
{
"metadata": {},
- "source": [
- "# Create an ontology with relevant classifications\n",
- "\n",
- "ontology_builder = lb.OntologyBuilder(\n",
- " tools=[\n",
- " lb.Tool(tool=lb.Tool.Type.NER,name=\"ner\"),\n",
- " ],\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " scope=lb.Classification.Scope.GLOBAL,\n",
- " name=\"Choose the best response\",\n",
- " options=[lb.Option(value=\"Response A\"), lb.Option(value=\"Response B\"), lb.Option(value=\"Tie\")]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"Provide a reason for your choice\"\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " scope=lb.Classification.Scope.INDEX,\n",
- " name=\"checklist_convo\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " scope = lb.Classification.Scope.INDEX,\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ])\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " scope = lb.Classification.Scope.GLOBAL,\n",
- " options=[\n",
- " lb.Option(\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[lb.Option(\"first_sub_radio_answer\")]\n",
- " )\n",
- " ])\n",
- " ]\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Pairwise comparison ontology\", ontology_builder.asdict(), media_type=lb.MediaType.Conversational)\n",
- "\n"
- ],
+ "source": "# Create an ontology with relevant classifications\n\nontology_builder = lb.OntologyBuilder(\n tools=[\n lb.Tool(tool=lb.Tool.Type.NER, name=\"ner\"),\n ],\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n scope=lb.Classification.Scope.GLOBAL,\n name=\"Choose the best response\",\n options=[\n lb.Option(value=\"Response A\"),\n lb.Option(value=\"Response B\"),\n lb.Option(value=\"Tie\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.TEXT,\n name=\"Provide a reason for your choice\",\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n scope=lb.Classification.Scope.INDEX,\n name=\"checklist_convo\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n scope=lb.Classification.Scope.INDEX,\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n scope=lb.Classification.Scope.GLOBAL,\n options=[\n lb.Option(\n \"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(\"first_sub_radio_answer\")],\n )\n ],\n )\n ],\n ),\n ],\n)\n\nontology = client.create_ontology(\n \"Pairwise comparison ontology\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Conversational,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -487,14 +215,7 @@
},
{
"metadata": {},
- "source": [
- "# Create Labelbox project\n",
- "project = client.create_project(name=\"Conversational Text Annotation Import Demo (Pairwise comparison)\",\n",
- " media_type=lb.MediaType.Conversational)\n",
- "\n",
- "# Setup your ontology\n",
- "project.setup_editor(ontology) # Connect your ontology and editor to your project"
- ],
+ "source": "# Create Labelbox project\nproject = client.create_project(\n name=\"Conversational Text Annotation Import Demo (Pairwise comparison)\",\n media_type=lb.MediaType.Conversational,\n)\n\n# Setup your ontology\nproject.setup_editor(\n ontology) # Connect your ontology and editor to your project",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -508,16 +229,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a batch to send to your project\n",
- "batch = project.create_batch(\n",
- " \"first-batch-convo-demo\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")\n",
- "\n",
- "print(\"Batch: \", batch)"
- ],
+ "source": "# Create a batch to send to your project\nbatch = project.create_batch(\n \"first-batch-convo-demo\", # Each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # Paginated collection of data row objects, list of data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)\n\nprint(\"Batch: \", batch)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -538,22 +250,7 @@
},
{
"metadata": {},
- "source": [
- "label = []\n",
- "label.append(\n",
- " lb_types.Label(\n",
- " data={\"global_key\" : global_key },\n",
- " annotations=[\n",
- " ner_annotation,\n",
- " text_annotation,\n",
- " checklist_annotation,\n",
- " radio_annotation,\n",
- " nested_radio_annotation,\n",
- " nested_checklist_annotation\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "label = []\nlabel.append(\n lb_types.Label(\n data={\"global_key\": global_key},\n annotations=[\n ner_annotation,\n text_annotation,\n checklist_annotation,\n radio_annotation,\n nested_radio_annotation,\n nested_checklist_annotation,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -567,23 +264,7 @@
},
{
"metadata": {},
- "source": [
- "label_ndjson = []\n",
- "for annotations in [\n",
- " ner_annotation_ndjson,\n",
- " text_annotation_ndjson,\n",
- " checklist_annotation_ndjson,\n",
- " radio_annotation_ndjson,\n",
- " nested_checklist_annotation_ndjson,\n",
- " nested_radio_annotation_ndjson\n",
- " ]:\n",
- " annotations.update({\n",
- " \"dataRow\": {\n",
- " \"globalKey\": global_key\n",
- " }\n",
- " })\n",
- " label_ndjson.append(annotations)"
- ],
+ "source": "label_ndjson = []\nfor annotations in [\n ner_annotation_ndjson,\n text_annotation_ndjson,\n checklist_annotation_ndjson,\n radio_annotation_ndjson,\n nested_checklist_annotation_ndjson,\n nested_radio_annotation_ndjson,\n]:\n annotations.update({\"dataRow\": {\"globalKey\": global_key}})\n label_ndjson.append(annotations)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -604,17 +285,7 @@
},
{
"metadata": {},
- "source": [
- "upload_job = lb.MALPredictionImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=f\"mal_job-{str(uuid.uuid4())}\",\n",
- " predictions=label)\n",
- "\n",
- "upload_job.wait_until_done()\n",
- "print(\"Errors:\", upload_job.errors)\n",
- "print(\"Status of uploads: \", upload_job.statuses)"
- ],
+ "source": "upload_job = lb.MALPredictionImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=f\"mal_job-{str(uuid.uuid4())}\",\n predictions=label,\n)\n\nupload_job.wait_until_done()\nprint(\"Errors:\", upload_job.errors)\nprint(\"Status of uploads: \", upload_job.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -622,23 +293,13 @@
{
"metadata": {},
"source": [
- "## Label Import"
+ "### Label Import"
],
"cell_type": "markdown"
},
{
"metadata": {},
- "source": [
- "upload_job = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"label_import_job\"+str(uuid.uuid4()),\n",
- " labels=label)\n",
- "\n",
- "upload_job.wait_until_done();\n",
- "print(\"Errors:\", upload_job.errors)\n",
- "print(\"Status of uploads: \", upload_job.statuses)"
- ],
+ "source": "upload_job = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"label_import_job\" + str(uuid.uuid4()),\n labels=label,\n)\n\nupload_job.wait_until_done()\nprint(\"Errors:\", upload_job.errors)\nprint(\"Status of uploads: \", upload_job.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/annotation_import/conversational_LLM_data_generation.ipynb b/examples/annotation_import/conversational_LLM_data_generation.ipynb
index 6215f9c95..8fb71b846 100644
--- a/examples/annotation_import/conversational_LLM_data_generation.ipynb
+++ b/examples/annotation_import/conversational_LLM_data_generation.ipynb
@@ -6,25 +6,21 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | \n",
- "\n"
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
{
"metadata": {},
"source": [
- "\n",
"\n",
- "\n",
" \n",
" | \n",
"\n",
"\n",
- "\n",
" \n",
" | "
@@ -41,9 +37,7 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -57,10 +51,7 @@
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import uuid"
- ],
+ "source": "import labelbox as lb\nimport uuid",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -74,10 +65,7 @@
},
{
"metadata": {},
- "source": [
- "API_KEY = \"\"\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "API_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -106,12 +94,7 @@
},
{
"metadata": {},
- "source": [
- "prompt_annotation_ndjson = {\n",
- " \"name\": \"Follow the prompt and select answers\",\n",
- " \"answer\": \"This is an example of a prompt\"\n",
- "}"
- ],
+ "source": "prompt_annotation_ndjson = {\n \"name\": \"Follow the prompt and select answers\",\n \"answer\": \"This is an example of a prompt\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -132,14 +115,7 @@
},
{
"metadata": {},
- "source": [
- "response_radio_annotation_ndjson= {\n",
- " \"name\": \"response_radio\",\n",
- " \"answer\": {\n",
- " \"name\": \"response_a\"\n",
- " }\n",
- "}"
- ],
+ "source": "response_radio_annotation_ndjson = {\n \"name\": \"response_radio\",\n \"answer\": {\n \"name\": \"response_a\"\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -153,13 +129,7 @@
},
{
"metadata": {},
- "source": [
- "# Only NDJson is currently supported\n",
- "response_text_annotation_ndjson = {\n",
- " \"name\": \"Provide a reason for your choice\",\n",
- " \"answer\": \"This is an example of a response text\"\n",
- "}\n"
- ],
+ "source": "# Only NDJson is currently supported\nresponse_text_annotation_ndjson = {\n \"name\": \"Provide a reason for your choice\",\n \"answer\": \"This is an example of a response text\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -173,19 +143,7 @@
},
{
"metadata": {},
- "source": [
- "response_checklist_annotation_ndjson = {\n",
- " \"name\": \"response_checklist\",\n",
- " \"answer\": [\n",
- " {\n",
- " \"name\": \"response_a\"\n",
- " },\n",
- " {\n",
- " \"name\": \"response_c\"\n",
- " }\n",
- " ]\n",
- "}"
- ],
+ "source": "response_checklist_annotation_ndjson = {\n \"name\": \"response_checklist\",\n \"answer\": [{\n \"name\": \"response_a\"\n }, {\n \"name\": \"response_c\"\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -211,13 +169,7 @@
},
{
"metadata": {},
- "source": [
- "# Enter the project id\n",
- "project_id = \"\"\n",
- "\n",
- "# Select one of the global keys from the data rows generated\n",
- "global_key = \"\""
- ],
+ "source": "# Enter the project id\nproject_id = \"\"\n\n# Select one of the global keys from the data rows generated\nglobal_key = \"\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -252,107 +204,7 @@
},
{
"metadata": {},
- "source": [
- "ontology_json = \"\"\"\n",
- "{\n",
- " \"tools\": [],\n",
- " \"relationships\": [],\n",
- " \"classifications\": [\n",
- " {\n",
- " \"schemaNodeId\": \"clpvq9d0002yt07zy0khq42rp\",\n",
- " \"featureSchemaId\": \"clpvq9d0002ys07zyf2eo9p14\",\n",
- " \"type\": \"prompt\",\n",
- " \"name\": \"Follow the prompt and select answers\",\n",
- " \"archived\": false,\n",
- " \"required\": true,\n",
- " \"options\": [],\n",
- " \"instructions\": \"Follow the prompt and select answers\",\n",
- " \"minCharacters\": 5,\n",
- " \"maxCharacters\": 100\n",
- " },\n",
- " {\n",
- " \"schemaNodeId\": \"clpvq9d0002yz07zy0fjg28z7\",\n",
- " \"featureSchemaId\": \"clpvq9d0002yu07zy28ik5w3i\",\n",
- " \"type\": \"response-radio\",\n",
- " \"name\": \"response_radio\",\n",
- " \"instructions\": \"response_radio\",\n",
- " \"scope\": \"global\",\n",
- " \"required\": true,\n",
- " \"archived\": false,\n",
- " \"options\": [\n",
- " {\n",
- " \"schemaNodeId\": \"clpvq9d0002yw07zyci2q5adq\",\n",
- " \"featureSchemaId\": \"clpvq9d0002yv07zyevmz1yoj\",\n",
- " \"value\": \"response_a\",\n",
- " \"label\": \"response_a\",\n",
- " \"position\": 0,\n",
- " \"options\": []\n",
- " },\n",
- " {\n",
- " \"schemaNodeId\": \"clpvq9d0002yy07zy8pe48zdj\",\n",
- " \"featureSchemaId\": \"clpvq9d0002yx07zy0jvmdxk8\",\n",
- " \"value\": \"response_b\",\n",
- " \"label\": \"response_b\",\n",
- " \"position\": 1,\n",
- " \"options\": []\n",
- " }\n",
- " ]\n",
- " },\n",
- " {\n",
- " \"schemaNodeId\": \"clpvq9d0002z107zygf8l62ys\",\n",
- " \"featureSchemaId\": \"clpvq9d0002z007zyg26115f9\",\n",
- " \"type\": \"response-text\",\n",
- " \"name\": \"provide_a_reason_for_your_choice\",\n",
- " \"instructions\": \"Provide a reason for your choice\",\n",
- " \"scope\": \"global\",\n",
- " \"required\": true,\n",
- " \"archived\": false,\n",
- " \"options\": [],\n",
- " \"minCharacters\": 5,\n",
- " \"maxCharacters\": 100\n",
- " },\n",
- " {\n",
- " \"schemaNodeId\": \"clpvq9d0102z907zy8b10hjcj\",\n",
- " \"featureSchemaId\": \"clpvq9d0002z207zy6xla7f82\",\n",
- " \"type\": \"response-checklist\",\n",
- " \"name\": \"response_checklist\",\n",
- " \"instructions\": \"response_checklist\",\n",
- " \"scope\": \"global\",\n",
- " \"required\": true,\n",
- " \"archived\": false,\n",
- " \"options\": [\n",
- " {\n",
- " \"schemaNodeId\": \"clpvq9d0102z407zy0adq0rfr\",\n",
- " \"featureSchemaId\": \"clpvq9d0002z307zy6dqb8xsw\",\n",
- " \"value\": \"response_a\",\n",
- " \"label\": \"response_a\",\n",
- " \"position\": 0,\n",
- " \"options\": []\n",
- " },\n",
- " {\n",
- " \"schemaNodeId\": \"clpvq9d0102z607zych8b2z5d\",\n",
- " \"featureSchemaId\": \"clpvq9d0102z507zyfwfgacrn\",\n",
- " \"value\": \"response_c\",\n",
- " \"label\": \"response_c\",\n",
- " \"position\": 1,\n",
- " \"options\": []\n",
- " },\n",
- " {\n",
- " \"schemaNodeId\": \"clpvq9d0102z807zy03y7gysp\",\n",
- " \"featureSchemaId\": \"clpvq9d0102z707zyh61y5o3u\",\n",
- " \"value\": \"response_d\",\n",
- " \"label\": \"response_d\",\n",
- " \"position\": 2,\n",
- " \"options\": []\n",
- " }\n",
- " ]\n",
- " }\n",
- " ],\n",
- " \"realTime\": false\n",
- "}\n",
- "\n",
- "\"\"\""
- ],
+ "source": "ontology_json = \"\"\"\n{\n \"tools\": [],\n \"relationships\": [],\n \"classifications\": [\n {\n \"schemaNodeId\": \"clpvq9d0002yt07zy0khq42rp\",\n \"featureSchemaId\": \"clpvq9d0002ys07zyf2eo9p14\",\n \"type\": \"prompt\",\n \"name\": \"Follow the prompt and select answers\",\n \"archived\": false,\n \"required\": true,\n \"options\": [],\n \"instructions\": \"Follow the prompt and select answers\",\n \"minCharacters\": 5,\n \"maxCharacters\": 100\n },\n {\n \"schemaNodeId\": \"clpvq9d0002yz07zy0fjg28z7\",\n \"featureSchemaId\": \"clpvq9d0002yu07zy28ik5w3i\",\n \"type\": \"response-radio\",\n \"name\": \"response_radio\",\n \"instructions\": \"response_radio\",\n \"scope\": \"global\",\n \"required\": true,\n \"archived\": false,\n \"options\": [\n {\n \"schemaNodeId\": \"clpvq9d0002yw07zyci2q5adq\",\n \"featureSchemaId\": \"clpvq9d0002yv07zyevmz1yoj\",\n \"value\": \"response_a\",\n \"label\": \"response_a\",\n \"position\": 0,\n \"options\": []\n },\n {\n \"schemaNodeId\": \"clpvq9d0002yy07zy8pe48zdj\",\n \"featureSchemaId\": \"clpvq9d0002yx07zy0jvmdxk8\",\n \"value\": \"response_b\",\n \"label\": \"response_b\",\n \"position\": 1,\n \"options\": []\n }\n ]\n },\n {\n \"schemaNodeId\": \"clpvq9d0002z107zygf8l62ys\",\n \"featureSchemaId\": \"clpvq9d0002z007zyg26115f9\",\n \"type\": \"response-text\",\n \"name\": \"provide_a_reason_for_your_choice\",\n \"instructions\": \"Provide a reason for your choice\",\n \"scope\": \"global\",\n \"required\": true,\n \"archived\": false,\n \"options\": [],\n \"minCharacters\": 5,\n \"maxCharacters\": 100\n },\n {\n \"schemaNodeId\": \"clpvq9d0102z907zy8b10hjcj\",\n \"featureSchemaId\": \"clpvq9d0002z207zy6xla7f82\",\n \"type\": \"response-checklist\",\n \"name\": \"response_checklist\",\n \"instructions\": \"response_checklist\",\n \"scope\": \"global\",\n \"required\": true,\n \"archived\": false,\n \"options\": [\n {\n \"schemaNodeId\": \"clpvq9d0102z407zy0adq0rfr\",\n \"featureSchemaId\": \"clpvq9d0002z307zy6dqb8xsw\",\n \"value\": \"response_a\",\n \"label\": \"response_a\",\n \"position\": 0,\n \"options\": []\n },\n {\n \"schemaNodeId\": \"clpvq9d0102z607zych8b2z5d\",\n \"featureSchemaId\": \"clpvq9d0102z507zyfwfgacrn\",\n \"value\": \"response_c\",\n \"label\": \"response_c\",\n \"position\": 1,\n \"options\": []\n },\n {\n \"schemaNodeId\": \"clpvq9d0102z807zy03y7gysp\",\n \"featureSchemaId\": \"clpvq9d0102z707zyh61y5o3u\",\n \"value\": \"response_d\",\n \"label\": \"response_d\",\n \"position\": 2,\n \"options\": []\n }\n ]\n }\n ],\n \"realTime\": false\n}\n\n\"\"\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -366,21 +218,7 @@
},
{
"metadata": {},
- "source": [
- "label_ndjson = []\n",
- "for annotations in [\n",
- " prompt_annotation_ndjson,\n",
- " response_radio_annotation_ndjson,\n",
- " response_text_annotation_ndjson,\n",
- " response_checklist_annotation_ndjson\n",
- " ]:\n",
- " annotations.update({\n",
- " \"dataRow\": {\n",
- " \"globalKey\": global_key\n",
- " }\n",
- " })\n",
- " label_ndjson.append(annotations)"
- ],
+ "source": "label_ndjson = []\nfor annotations in [\n prompt_annotation_ndjson,\n response_radio_annotation_ndjson,\n response_text_annotation_ndjson,\n response_checklist_annotation_ndjson,\n]:\n annotations.update({\"dataRow\": {\"globalKey\": global_key}})\n label_ndjson.append(annotations)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -394,9 +232,7 @@
},
{
"metadata": {},
- "source": [
- "project = client.get_project(project_id=project_id)"
- ],
+ "source": "project = client.get_project(project_id=project_id)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -410,17 +246,7 @@
},
{
"metadata": {},
- "source": [
- "upload_job = lb.MALPredictionImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=f\"mal_job-{str(uuid.uuid4())}\",\n",
- " predictions=label_ndjson)\n",
- "\n",
- "upload_job.wait_until_done()\n",
- "print(\"Errors:\", upload_job.errors)\n",
- "print(\"Status of uploads: \", upload_job.statuses)"
- ],
+ "source": "upload_job = lb.MALPredictionImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=f\"mal_job-{str(uuid.uuid4())}\",\n predictions=label_ndjson,\n)\n\nupload_job.wait_until_done()\nprint(\"Errors:\", upload_job.errors)\nprint(\"Status of uploads: \", upload_job.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -434,17 +260,7 @@
},
{
"metadata": {},
- "source": [
- "upload_job = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"label_import_job\"+str(uuid.uuid4()),\n",
- " labels=label_ndjson)\n",
- "\n",
- "upload_job.wait_until_done();\n",
- "print(\"Errors:\", upload_job.errors)\n",
- "print(\"Status of uploads: \", upload_job.statuses)"
- ],
+ "source": "upload_job = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"label_import_job\" + str(uuid.uuid4()),\n labels=label_ndjson,\n)\n\nupload_job.wait_until_done()\nprint(\"Errors:\", upload_job.errors)\nprint(\"Status of uploads: \", upload_job.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/annotation_import/dicom.ipynb b/examples/annotation_import/dicom.ipynb
index f7beb1822..cd4c88497 100644
--- a/examples/annotation_import/dicom.ipynb
+++ b/examples/annotation_import/dicom.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -21,10 +21,9 @@
"\n",
"\n",
"\n",
- "\n",
" \n",
- " | "
+ ""
],
"cell_type": "markdown"
},
@@ -56,20 +55,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q 'labelbox[data]'"
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import labelbox.types as lb_types\n",
- "import uuid"
- ],
+ "source": "import labelbox as lb\nimport labelbox.types as lb_types\nimport uuid",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -84,11 +77,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your api key\n",
- "API_KEY=None\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your api key\nAPI_KEY = None\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -102,109 +91,14 @@
},
{
"metadata": {},
- "source": [
- "######## Polyline ########\n",
- "polyline_annotation = [\n",
- " lb_types.DICOMObjectAnnotation(\n",
- " name=\"line_dicom\",\n",
- " group_key=lb_types.GroupKey.AXIAL,\n",
- " frame=1,\n",
- " value=lb_types.Line(points=[\n",
- " lb_types.Point(x=10, y=10),\n",
- " lb_types.Point(x=200, y=20),\n",
- " lb_types.Point(x=250, y=250)\n",
- " ]),\n",
- " segment_index=0,\n",
- " keyframe=True,\n",
- " ),\n",
- " lb_types.DICOMObjectAnnotation(\n",
- " name=\"line_dicom\",\n",
- " group_key=lb_types.GroupKey.AXIAL,\n",
- " frame=20,\n",
- " value=lb_types.Line(points=[\n",
- " lb_types.Point(x=10, y=10),\n",
- " lb_types.Point(x=200, y=10),\n",
- " lb_types.Point(x=300, y=300)\n",
- " ]),\n",
- " segment_index=1,\n",
- " keyframe=True,\n",
- " ),\n",
- "]\n",
- "\n",
- "polyline_annotation_ndjson = {\n",
- " 'name': 'line_dicom',\n",
- " 'groupKey': 'axial', # should be 'axial', 'sagittal', or 'coronal'\n",
- " 'segments': [\n",
- " {\n",
- " 'keyframes': [{\n",
- " 'frame': 1,\n",
- " 'line': [\n",
- " {'x': 10, 'y': 10},\n",
- " {'x': 200, 'y': 20},\n",
- " {'x': 250, 'y': 250},\n",
- " ]\n",
- " }]},\n",
- " {\n",
- " 'keyframes' : [{\n",
- " 'frame': 20,\n",
- " 'line': [\n",
- " {'x': 10, 'y': 10},\n",
- " {'x': 200, 'y': 10},\n",
- " {'x': 300, 'y': 300},\n",
- " ]\n",
- " }]}\n",
- " ],\n",
- "}"
- ],
+ "source": "######## Polyline ########\npolyline_annotation = [\n lb_types.DICOMObjectAnnotation(\n name=\"line_dicom\",\n group_key=lb_types.GroupKey.AXIAL,\n frame=1,\n value=lb_types.Line(points=[\n lb_types.Point(x=10, y=10),\n lb_types.Point(x=200, y=20),\n lb_types.Point(x=250, y=250),\n ]),\n segment_index=0,\n keyframe=True,\n ),\n lb_types.DICOMObjectAnnotation(\n name=\"line_dicom\",\n group_key=lb_types.GroupKey.AXIAL,\n frame=20,\n value=lb_types.Line(points=[\n lb_types.Point(x=10, y=10),\n lb_types.Point(x=200, y=10),\n lb_types.Point(x=300, y=300),\n ]),\n segment_index=1,\n keyframe=True,\n ),\n]\n\npolyline_annotation_ndjson = {\n \"name\":\n \"line_dicom\",\n \"groupKey\":\n \"axial\", # should be 'axial', 'sagittal', or 'coronal'\n \"segments\": [\n {\n \"keyframes\": [{\n \"frame\":\n 1,\n \"line\": [\n {\n \"x\": 10,\n \"y\": 10\n },\n {\n \"x\": 200,\n \"y\": 20\n },\n {\n \"x\": 250,\n \"y\": 250\n },\n ],\n }]\n },\n {\n \"keyframes\": [{\n \"frame\":\n 20,\n \"line\": [\n {\n \"x\": 10,\n \"y\": 10\n },\n {\n \"x\": 200,\n \"y\": 10\n },\n {\n \"x\": 300,\n \"y\": 300\n },\n ],\n }]\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "######## Segmentation Masks ########\n",
- "\n",
- "mask_annotation = [\n",
- " lb_types.DICOMMaskAnnotation(\n",
- " group_key='axial',\n",
- " frames=[\n",
- " lb_types.MaskFrame(\n",
- " index=1,\n",
- " instance_uri=\"https://storage.googleapis.com/labelbox-datasets/dicom-sample-data/sample-mask-1.png\"\n",
- " ),\n",
- " lb_types.MaskFrame(\n",
- " index=5,\n",
- " instance_uri=\"https://storage.googleapis.com/labelbox-datasets/dicom-sample-data/sample-mask-1.png\"\n",
- " )\n",
- " ],\n",
- " instances=[\n",
- " lb_types.MaskInstance(\n",
- " color_rgb=(255, 255, 255),\n",
- " name=\"segmentation_mask_dicom\"\n",
- " )\n",
- " ])\n",
- "]\n",
- "\n",
- "mask_annotation_ndjson = {\n",
- " 'groupKey': 'axial',\n",
- " 'masks': {\n",
- " 'frames': [{\n",
- " 'index': 1,\n",
- " 'instanceURI': \"https://storage.googleapis.com/labelbox-datasets/dicom-sample-data/sample-mask-1.png\"\n",
- " }, {\n",
- " 'index': 5,\n",
- " 'instanceURI': \"https://storage.googleapis.com/labelbox-datasets/dicom-sample-data/sample-mask-1.png\"\n",
- " }],\n",
- " 'instances': [\n",
- " {\n",
- " 'colorRGB': (255, 255, 255),\n",
- " 'name': 'segmentation_mask_dicom'\n",
- " }\n",
- " ]\n",
- " },\n",
- "}\n"
- ],
+ "source": "######## Segmentation Masks ########\n\nmask_annotation = [\n lb_types.DICOMMaskAnnotation(\n group_key=\"axial\",\n frames=[\n lb_types.MaskFrame(\n index=1,\n instance_uri=\n \"https://storage.googleapis.com/labelbox-datasets/dicom-sample-data/sample-mask-1.png\",\n ),\n lb_types.MaskFrame(\n index=5,\n instance_uri=\n \"https://storage.googleapis.com/labelbox-datasets/dicom-sample-data/sample-mask-1.png\",\n ),\n ],\n instances=[\n lb_types.MaskInstance(color_rgb=(255, 255, 255),\n name=\"segmentation_mask_dicom\")\n ],\n )\n]\n\nmask_annotation_ndjson = {\n \"groupKey\": \"axial\",\n \"masks\": {\n \"frames\": [\n {\n \"index\":\n 1,\n \"instanceURI\":\n \"https://storage.googleapis.com/labelbox-datasets/dicom-sample-data/sample-mask-1.png\",\n },\n {\n \"index\":\n 5,\n \"instanceURI\":\n \"https://storage.googleapis.com/labelbox-datasets/dicom-sample-data/sample-mask-1.png\",\n },\n ],\n \"instances\": [{\n \"colorRGB\": (255, 255, 255),\n \"name\": \"segmentation_mask_dicom\"\n }],\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -225,19 +119,7 @@
},
{
"metadata": {},
- "source": [
- "global_key = \"sample-dicom-1.dcm\"\n",
- "asset = {\n",
- " \"row_data\": \"https://storage.googleapis.com/labelbox-datasets/dicom-sample-data/sample-dicom-1.dcm\",\n",
- " \"global_key\": global_key,\n",
- "}\n",
- "\n",
- "dataset = client.create_dataset(name=\"dicom_demo_dataset\")\n",
- "task = dataset.create_data_rows([asset])\n",
- "task.wait_till_done()\n",
- "print(\"Errors :\",task.errors)\n",
- "print(\"Failed data rows:\" ,task.failed_data_rows)"
- ],
+ "source": "global_key = \"sample-dicom-1.dcm\"\nasset = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/dicom-sample-data/sample-dicom-1.dcm\",\n \"global_key\":\n global_key,\n}\n\ndataset = client.create_dataset(name=\"dicom_demo_dataset\")\ntask = dataset.create_data_rows([asset])\ntask.wait_till_done()\nprint(\"Errors :\", task.errors)\nprint(\"Failed data rows:\", task.failed_data_rows)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -257,16 +139,7 @@
},
{
"metadata": {},
- "source": [
- "ontology_builder = lb.OntologyBuilder(\n",
- " tools=[\n",
- " lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=\"segmentation_mask_dicom\"),\n",
- " lb.Tool(tool=lb.Tool.Type.LINE, name=\"line_dicom\"),\n",
- " ]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Ontology DICOM Annotations\", ontology_builder.asdict(), media_type=lb.MediaType.Dicom)"
- ],
+ "source": "ontology_builder = lb.OntologyBuilder(tools=[\n lb.Tool(\n tool=lb.Tool.Type.RASTER_SEGMENTATION,\n name=\"segmentation_mask_dicom\",\n ),\n lb.Tool(tool=lb.Tool.Type.LINE, name=\"line_dicom\"),\n])\n\nontology = client.create_ontology(\n \"Ontology DICOM Annotations\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Dicom,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -281,15 +154,7 @@
},
{
"metadata": {},
- "source": [
- "# Project defaults to batch mode with benchmark quality settings if this argument is not provided\n",
- "# Queue mode will be deprecated once dataset mode is deprecated\n",
- "\n",
- "project = client.create_project(name=\"dicom_project_demo\", media_type=lb.MediaType.Dicom)\n",
- "\n",
- "## connect ontology to your project\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "# Project defaults to batch mode with benchmark quality settings if this argument is not provided\n# Queue mode will be deprecated once dataset mode is deprecated\n\nproject = client.create_project(name=\"dicom_project_demo\",\n media_type=lb.MediaType.Dicom)\n\n## connect ontology to your project\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -303,18 +168,7 @@
},
{
"metadata": {},
- "source": [
- "# Create batches\n",
- "\n",
- "# Create a batch to send to your MAL project\n",
- "batch = project.create_batch(\n",
- " \"first-batch-dicom-demo\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # a list of data row objects, data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")\n",
- "\n",
- "print(\"Batch: \", batch)"
- ],
+ "source": "# Create batches\n\n# Create a batch to send to your MAL project\nbatch = project.create_batch(\n \"first-batch-dicom-demo\", # Each batch in a project must have a unique name\n global_keys=[global_key\n ], # a list of data row objects, data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)\n\nprint(\"Batch: \", batch)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -338,16 +192,7 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "annotations_list = polyline_annotation + mask_annotation\n",
- "labels = [\n",
- " lb_types.Label(\n",
- " data={\"global_key\" : global_key },\n",
- " annotations=annotations_list\n",
- " )\n",
- "]"
- ],
+ "source": "annotations_list = polyline_annotation + mask_annotation\nlabels = [\n lb_types.Label(data={\"global_key\": global_key},\n annotations=annotations_list)\n]",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -362,20 +207,7 @@
},
{
"metadata": {},
- "source": [
- "label_ndjson = []\n",
- "\n",
- "for annotation in [\n",
- " polyline_annotation_ndjson,\n",
- " mask_annotation_ndjson\n",
- "]:\n",
- " annotation.update({\n",
- " 'dataRow': {\n",
- " 'globalKey': global_key\n",
- " }\n",
- " })\n",
- " label_ndjson.append(annotation)\n"
- ],
+ "source": "label_ndjson = []\n\nfor annotation in [polyline_annotation_ndjson, mask_annotation_ndjson]:\n annotation.update({\"dataRow\": {\"globalKey\": global_key}})\n label_ndjson.append(annotation)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -397,19 +229,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload MAL label for this data row in project\n",
- "upload_job_mal = lb.MALPredictionImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"mal_import_job-\" + str(uuid.uuid4()),\n",
- " predictions=labels)\n",
- "\n",
- "upload_job_mal.wait_until_done();\n",
- "print(\"Errors:\", upload_job_mal.errors)\n",
- "print(\"Status of uploads: \", upload_job_mal.statuses)\n",
- "print(\" \")"
- ],
+ "source": "# Upload MAL label for this data row in project\nupload_job_mal = lb.MALPredictionImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"mal_import_job-\" + str(uuid.uuid4()),\n predictions=labels,\n)\n\nupload_job_mal.wait_until_done()\nprint(\"Errors:\", upload_job_mal.errors)\nprint(\"Status of uploads: \", upload_job_mal.statuses)\nprint(\" \")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -423,19 +243,7 @@
},
{
"metadata": {},
- "source": [
- "upload_job_label_import = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name = \"label_import_job-\" + str(uuid.uuid4()),\n",
- " labels=labels\n",
- ")\n",
- "\n",
- "upload_job_label_import.wait_until_done()\n",
- "print(\"Errors:\", upload_job_label_import.errors)\n",
- "print(\"Status of uploads: \", upload_job_label_import.statuses)\n",
- "print(\" \")"
- ],
+ "source": "upload_job_label_import = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"label_import_job-\" + str(uuid.uuid4()),\n labels=labels,\n)\n\nupload_job_label_import.wait_until_done()\nprint(\"Errors:\", upload_job_label_import.errors)\nprint(\"Status of uploads: \", upload_job_label_import.statuses)\nprint(\" \")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -449,11 +257,7 @@
},
{
"metadata": {},
- "source": [
- "# Delete Project\n",
- "# project.delete()\n",
- "# dataset.delete()\n"
- ],
+ "source": "# Delete Project\n# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/annotation_import/html.ipynb b/examples/annotation_import/html.ipynb
index 4a1e388a1..7ef731bce 100644
--- a/examples/annotation_import/html.ipynb
+++ b/examples/annotation_import/html.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -74,9 +74,7 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -90,11 +88,7 @@
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import uuid\n",
- "import labelbox.types as lb_types"
- ],
+ "source": "import labelbox as lb\nimport uuid\nimport labelbox.types as lb_types",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -109,11 +103,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your api key\n",
- "API_KEY = \"\"\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your api key\nAPI_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -127,142 +117,28 @@
},
{
"metadata": {},
- "source": [
- "##### Classification free text #####\n",
- "\n",
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"text_html\",\n",
- " value=lb_types.Text(answer=\"sample text\"),\n",
- ")\n",
- "\n",
- "text_annotation_ndjson = {\n",
- " \"name\": \"text_html\",\n",
- " \"answer\": \"sample text\",\n",
- "}"
- ],
+ "source": "##### Classification free text #####\n\ntext_annotation = lb_types.ClassificationAnnotation(\n name=\"text_html\",\n value=lb_types.Text(answer=\"sample text\"),\n)\n\ntext_annotation_ndjson = {\n \"name\": \"text_html\",\n \"answer\": \"sample text\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "##### Checklist Classification #######\n",
- "\n",
- "checklist_annotation= lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_html\", # must match your ontology feature\"s name\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\"\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\"\n",
- " )\n",
- " ]\n",
- " ),\n",
- " )\n",
- "\n",
- "\n",
- "checklist_annotation_ndjson = {\n",
- " \"name\": \"checklist_html\",\n",
- " \"answers\": [\n",
- " {\"name\": \"first_checklist_answer\"},\n",
- " {\"name\": \"second_checklist_answer\"}\n",
- " ],\n",
- "}"
- ],
+ "source": "##### Checklist Classification #######\n\nchecklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_html\", # must match your ontology feature\"s name\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n ]),\n)\n\nchecklist_annotation_ndjson = {\n \"name\":\n \"checklist_html\",\n \"answers\": [\n {\n \"name\": \"first_checklist_answer\"\n },\n {\n \"name\": \"second_checklist_answer\"\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "######## Radio Classification ######\n",
- "\n",
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_html\",\n",
- " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n",
- " name=\"second_radio_answer\")))\n",
- "\n",
- "radio_annotation_ndjson = {\n",
- " \"name\": \"radio_html\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\"\n",
- " },\n",
- "}"
- ],
+ "source": "######## Radio Classification ######\n\nradio_annotation = lb_types.ClassificationAnnotation(\n name=\"radio_html\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"second_radio_answer\")),\n)\n\nradio_annotation_ndjson = {\n \"name\": \"radio_html\",\n \"answer\": {\n \"name\": \"first_radio_answer\"\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########## Classification - Radio and Checklist (with subclassifcations) ##########\n",
- "\n",
- "nested_radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\")\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "\n",
- "nested_radio_annotation_ndjson= {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\",\n",
- " \"classifications\": [{\n",
- " \"name\":\"sub_radio_question\",\n",
- " \"answer\": { \"name\" : \"first_sub_radio_answer\"}\n",
- "\n",
- " }]\n",
- " }\n",
- "}\n",
- "\n",
- "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\")]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "\n",
- "nested_checklist_annotation_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"classifications\" : [\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\"name\": \"first_sub_checklist_answer\"}\n",
- "\n",
- " }\n",
- " ]\n",
- " }]\n",
- "}"
- ],
+ "source": "########## Classification - Radio and Checklist (with subclassifcations) ##########\n\nnested_radio_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n)\n\nnested_radio_annotation_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\"\n },\n }],\n },\n}\n\nnested_checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n )\n ]),\n)\n\nnested_checklist_annotation_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\"\n },\n }],\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -283,25 +159,7 @@
},
{
"metadata": {},
- "source": [
- "# Create one Labelbox dataset\n",
- "\n",
- "global_key = \"sample_html_1.html\"\n",
- "\n",
- "asset = {\n",
- " \"row_data\": \"https://storage.googleapis.com/labelbox-datasets/html_sample_data/sample_html_1.html\",\n",
- " \"global_key\": global_key\n",
- "}\n",
- "\n",
- "dataset = client.create_dataset(\n",
- " name=\"html_annotation_import_demo_dataset\",\n",
- " iam_integration=None # Removing this argument will default to the organziation's default iam integration\n",
- ")\n",
- "task = dataset.create_data_rows([asset])\n",
- "task.wait_till_done()\n",
- "print(\"Errors:\", task.errors)\n",
- "print(\"Failed data rows: \", task.failed_data_rows)"
- ],
+ "source": "# Create one Labelbox dataset\n\nglobal_key = \"sample_html_1.html\"\n\nasset = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/html_sample_data/sample_html_1.html\",\n \"global_key\":\n global_key,\n}\n\ndataset = client.create_dataset(\n name=\"html_annotation_import_demo_dataset\",\n iam_integration=\n None, # Removing this argument will default to the organziation's default iam integration\n)\ntask = dataset.create_data_rows([asset])\ntask.wait_till_done()\nprint(\"Errors:\", task.errors)\nprint(\"Failed data rows: \", task.failed_data_rows)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -319,65 +177,7 @@
},
{
"metadata": {},
- "source": [
- "ontology_builder = lb.OntologyBuilder(\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"text_html\"),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_html\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_html\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\"),\n",
- " lb.Option(value=\"second_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_sub_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " ]\n",
- " )\n",
- " ],\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Ontology HTML Annotations\", ontology_builder.asdict(), media_type=lb.MediaType.Html)"
- ],
+ "source": "ontology_builder = lb.OntologyBuilder(classifications=[\n lb.Classification(class_type=lb.Classification.Type.TEXT, name=\"text_html\"),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_html\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_html\",\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n options=[\n lb.Option(\n value=\"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(value=\"first_sub_radio_answer\")],\n ),\n ],\n )\n ],\n ),\n])\n\nontology = client.create_ontology(\n \"Ontology HTML Annotations\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Html,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -393,14 +193,7 @@
},
{
"metadata": {},
- "source": [
- "# Create Labelbox project\n",
- "project = client.create_project(name=\"HTML Import Annotation Demo\",\n",
- " media_type=lb.MediaType.Html)\n",
- "\n",
- "# Setup your ontology\n",
- "project.setup_editor(ontology) # Connect your ontology and editor to your project"
- ],
+ "source": "# Create Labelbox project\nproject = client.create_project(name=\"HTML Import Annotation Demo\",\n media_type=lb.MediaType.Html)\n\n# Setup your ontology\nproject.setup_editor(\n ontology) # Connect your ontology and editor to your project",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -414,18 +207,7 @@
},
{
"metadata": {},
- "source": [
- "# Setup Batches and Ontology\n",
- "\n",
- "# Create a batch to send to your MAL project\n",
- "batch = project.create_batch(\n",
- " \"first-batch-html-demo\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")\n",
- "\n",
- "print(\"Batch: \", batch)"
- ],
+ "source": "# Setup Batches and Ontology\n\n# Create a batch to send to your MAL project\nbatch = project.create_batch(\n \"first-batch-html-demo\", # Each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # Paginated collection of data row objects, list of data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)\n\nprint(\"Batch: \", batch)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -450,21 +232,7 @@
},
{
"metadata": {},
- "source": [
- "label = []\n",
- "label.append(\n",
- " lb_types.Label(\n",
- " data={\"global_key\" : global_key },\n",
- " annotations=[\n",
- " text_annotation,\n",
- " checklist_annotation,\n",
- " radio_annotation,\n",
- " nested_checklist_annotation,\n",
- " nested_radio_annotation\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "label = []\nlabel.append(\n lb_types.Label(\n data={\"global_key\": global_key},\n annotations=[\n text_annotation,\n checklist_annotation,\n radio_annotation,\n nested_checklist_annotation,\n nested_radio_annotation,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -479,21 +247,7 @@
},
{
"metadata": {},
- "source": [
- "label_ndjson = []\n",
- "for annotations in [text_annotation_ndjson,\n",
- " checklist_annotation_ndjson,\n",
- " radio_annotation_ndjson,\n",
- " nested_radio_annotation_ndjson,\n",
- " nested_checklist_annotation_ndjson\n",
- " ]:\n",
- " annotations.update({\n",
- " \"dataRow\": {\n",
- " \"globalKey\": global_key\n",
- " }\n",
- " })\n",
- " label_ndjson.append(annotations)"
- ],
+ "source": "label_ndjson = []\nfor annotations in [\n text_annotation_ndjson,\n checklist_annotation_ndjson,\n radio_annotation_ndjson,\n nested_radio_annotation_ndjson,\n nested_checklist_annotation_ndjson,\n]:\n annotations.update({\"dataRow\": {\"globalKey\": global_key}})\n label_ndjson.append(annotations)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -515,18 +269,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload our label using Model-Assisted Labeling\n",
- "upload_job = lb.MALPredictionImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=f\"mal_job-{str(uuid.uuid4())}\",\n",
- " predictions=label)\n",
- "\n",
- "upload_job.wait_until_done();\n",
- "print(\"Errors:\", upload_job.errors)\n",
- "print(\"Status of uploads: \", upload_job.statuses)"
- ],
+ "source": "# Upload our label using Model-Assisted Labeling\nupload_job = lb.MALPredictionImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=f\"mal_job-{str(uuid.uuid4())}\",\n predictions=label,\n)\n\nupload_job.wait_until_done()\nprint(\"Errors:\", upload_job.errors)\nprint(\"Status of uploads: \", upload_job.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -540,18 +283,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload label for this data row in project\n",
- "upload_job = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"label_import_job\"+str(uuid.uuid4()),\n",
- " labels=label)\n",
- "\n",
- "upload_job.wait_until_done();\n",
- "print(\"Errors:\", upload_job.errors)\n",
- "print(\"Status of uploads: \", upload_job.statuses)"
- ],
+ "source": "# Upload label for this data row in project\nupload_job = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"label_import_job\" + str(uuid.uuid4()),\n labels=label,\n)\n\nupload_job.wait_until_done()\nprint(\"Errors:\", upload_job.errors)\nprint(\"Status of uploads: \", upload_job.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -565,10 +297,7 @@
},
{
"metadata": {},
- "source": [
- "# project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/annotation_import/image.ipynb b/examples/annotation_import/image.ipynb
index ec6e64d6c..b8c6cd2a6 100644
--- a/examples/annotation_import/image.ipynb
+++ b/examples/annotation_import/image.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -20,9 +20,6 @@
"src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\">\n",
"\n",
"\n",
- "\n",
- "\n",
- "\n",
"\n",
" \n",
@@ -74,24 +71,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import uuid\n",
- "from PIL import Image\n",
- "import requests\n",
- "import base64\n",
- "import labelbox as lb\n",
- "import labelbox.types as lb_types\n",
- "from io import BytesIO\n"
- ],
+ "source": "import uuid\nfrom PIL import Image\nimport requests\nimport base64\nimport labelbox as lb\nimport labelbox.types as lb_types\nfrom io import BytesIO",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -107,10 +94,7 @@
},
{
"metadata": {},
- "source": [
- "API_KEY =\"\"\n",
- "client = lb.Client(API_KEY)"
- ],
+ "source": "API_KEY = \"\"\nclient = lb.Client(API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -131,21 +115,7 @@
},
{
"metadata": {},
- "source": [
- "# Python annotation\n",
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question\",\n",
- " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n",
- " name=\"second_radio_answer\")))\n",
- "\n",
- "# NDJSON\n",
- "radio_annotation_ndjson = {\n",
- " \"name\": \"radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"second_radio_answer\"\n",
- " }\n",
- "}"
- ],
+ "source": "# Python annotation\nradio_annotation = lb_types.ClassificationAnnotation(\n name=\"radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"second_radio_answer\")),\n)\n\n# NDJSON\nradio_annotation_ndjson = {\n \"name\": \"radio_question\",\n \"answer\": {\n \"name\": \"second_radio_answer\"\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -159,25 +129,7 @@
},
{
"metadata": {},
- "source": [
- "# Python annotation\n",
- "checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question\", # must match your ontology feature\"s name\n",
- " value=lb_types.Checklist(answer=[\n",
- " lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n",
- " lb_types.ClassificationAnswer(name=\"second_checklist_answer\")\n",
- " ]))\n",
- "\n",
- "# NDJSON\n",
- "checklist_annotation_ndjson = {\n",
- " \"name\": \"checklist_question\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\"\n",
- " }, {\n",
- " \"name\": \"second_checklist_answer\"\n",
- " }]\n",
- "}"
- ],
+ "source": "# Python annotation\nchecklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_question\", # must match your ontology feature\"s name\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n ]),\n)\n\n# NDJSON\nchecklist_annotation_ndjson = {\n \"name\":\n \"checklist_question\",\n \"answer\": [\n {\n \"name\": \"first_checklist_answer\"\n },\n {\n \"name\": \"second_checklist_answer\"\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -192,71 +144,7 @@
},
{
"metadata": {},
- "source": [
- "nested_radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "# NDJSON\n",
- "nested_radio_annotation_ndjson = {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\",\n",
- " \"classifications\": [{\n",
- " \"name\": \"sub_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_sub_radio_answer\"\n",
- " }\n",
- " }]\n",
- " }\n",
- "}\n",
- "\n",
- "\n",
- "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\"\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "\n",
- "nested_checklist_annotation_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"classifications\": [{\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_sub_checklist_answer\"\n",
- " }\n",
- " }]\n",
- " }]\n",
- "}"
- ],
+ "source": "nested_radio_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n)\n# NDJSON\nnested_radio_annotation_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\"\n },\n }],\n },\n}\n\nnested_checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n )\n ]),\n)\n\nnested_checklist_annotation_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\"\n },\n }],\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -270,18 +158,7 @@
},
{
"metadata": {},
- "source": [
- "# Python annotation\n",
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"free_text\", # must match your ontology feature\"s name\n",
- " value=lb_types.Text(answer=\"sample text\"))\n",
- "\n",
- "# NDJSON\n",
- "text_annotation_ndjson = {\n",
- " \"name\": \"free_text\",\n",
- " \"answer\": \"sample text\",\n",
- "}"
- ],
+ "source": "# Python annotation\ntext_annotation = lb_types.ClassificationAnnotation(\n name=\"free_text\", # must match your ontology feature\"s name\n value=lb_types.Text(answer=\"sample text\"),\n)\n\n# NDJSON\ntext_annotation_ndjson = {\n \"name\": \"free_text\",\n \"answer\": \"sample text\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -297,67 +174,7 @@
},
{
"metadata": {},
- "source": [
- "# Python Annotation\n",
- "bbox_source = lb_types.ObjectAnnotation(\n",
- " name=\"bounding_box\",\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=2096, y=1264),\n",
- " end=lb_types.Point(x=2240, y=1689),\n",
- " ),\n",
- ")\n",
- "\n",
- "bbox_target = lb_types.ObjectAnnotation(\n",
- " name=\"bounding_box\",\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=2272, y=1346),\n",
- " end=lb_types.Point(x=2416, y=1704),\n",
- " ),\n",
- ")\n",
- "\n",
- "relationship = lb_types.RelationshipAnnotation(\n",
- " name=\"relationship\",\n",
- " value=lb_types.Relationship(\n",
- " source=bbox_source,\n",
- " target=bbox_target,\n",
- " type=lb_types.Relationship.Type.UNIDIRECTIONAL,\n",
- " ))\n",
- "\n",
- "## Only supported for MAL imports\n",
- "uuid_source = str(uuid.uuid4())\n",
- "uuid_target = str(uuid.uuid4())\n",
- "\n",
- "bbox_source_ndjson = {\n",
- " \"uuid\": uuid_source,\n",
- " \"name\": \"bounding_box\",\n",
- " \"bbox\": {\n",
- " \"top\": 1264.0,\n",
- " \"left\": 2096.0,\n",
- " \"height\": 425.0,\n",
- " \"width\": 144.0\n",
- " }\n",
- "}\n",
- "\n",
- "bbox_target_ndjson = {\n",
- " \"uuid\": uuid_target,\n",
- " \"name\": \"bounding_box\",\n",
- " \"bbox\": {\n",
- " \"top\": 1346.0,\n",
- " \"left\": 2272.0,\n",
- " \"height\": 358.0,\n",
- " \"width\": 144.0\n",
- " }\n",
- "}\n",
- "\n",
- "relationship_ndjson = {\n",
- " \"name\": \"relationship\",\n",
- " \"relationship\": {\n",
- " \"source\": uuid_source,\n",
- " \"target\": uuid_target,\n",
- " \"type\": \"unidirectional\"\n",
- " }\n",
- "}"
- ],
+ "source": "# Python Annotation\nbbox_source = lb_types.ObjectAnnotation(\n name=\"bounding_box\",\n value=lb_types.Rectangle(\n start=lb_types.Point(x=2096, y=1264),\n end=lb_types.Point(x=2240, y=1689),\n ),\n)\n\nbbox_target = lb_types.ObjectAnnotation(\n name=\"bounding_box\",\n value=lb_types.Rectangle(\n start=lb_types.Point(x=2272, y=1346),\n end=lb_types.Point(x=2416, y=1704),\n ),\n)\n\nrelationship = lb_types.RelationshipAnnotation(\n name=\"relationship\",\n value=lb_types.Relationship(\n source=bbox_source,\n target=bbox_target,\n type=lb_types.Relationship.Type.UNIDIRECTIONAL,\n ),\n)\n\n## Only supported for MAL imports\nuuid_source = str(uuid.uuid4())\nuuid_target = str(uuid.uuid4())\n\nbbox_source_ndjson = {\n \"uuid\": uuid_source,\n \"name\": \"bounding_box\",\n \"bbox\": {\n \"top\": 1264.0,\n \"left\": 2096.0,\n \"height\": 425.0,\n \"width\": 144.0\n },\n}\n\nbbox_target_ndjson = {\n \"uuid\": uuid_target,\n \"name\": \"bounding_box\",\n \"bbox\": {\n \"top\": 1346.0,\n \"left\": 2272.0,\n \"height\": 358.0,\n \"width\": 144.0\n },\n}\n\nrelationship_ndjson = {\n \"name\": \"relationship\",\n \"relationship\": {\n \"source\": uuid_source,\n \"target\": uuid_target,\n \"type\": \"unidirectional\",\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -371,26 +188,7 @@
},
{
"metadata": {},
- "source": [
- "# Python annotation\n",
- "bbox_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"bounding_box\", # must match your ontology feature\"s name\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=1690, y=977), # x = left, y = top\n",
- " end=lb_types.Point(x=1915, y=1307), # x= left + width , y = top + height\n",
- " ))\n",
- "\n",
- "# NDJSON\n",
- "bbox_annotation_ndjson = {\n",
- " \"name\": \"bounding_box\",\n",
- " \"bbox\": {\n",
- " \"top\": 977,\n",
- " \"left\": 1690,\n",
- " \"height\": 330,\n",
- " \"width\": 225\n",
- " }\n",
- "}"
- ],
+ "source": "# Python annotation\nbbox_annotation = lb_types.ObjectAnnotation(\n name=\"bounding_box\", # must match your ontology feature\"s name\n value=lb_types.Rectangle(\n start=lb_types.Point(x=1690, y=977), # x = left, y = top\n end=lb_types.Point(x=1915,\n y=1307), # x= left + width , y = top + height\n ),\n)\n\n# NDJSON\nbbox_annotation_ndjson = {\n \"name\": \"bounding_box\",\n \"bbox\": {\n \"top\": 977,\n \"left\": 1690,\n \"height\": 330,\n \"width\": 225\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -404,38 +202,7 @@
},
{
"metadata": {},
- "source": [
- "# Python annotation\n",
- "bbox_with_radio_subclass_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"bbox_with_radio_subclass\",\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=541, y=933), # x = left, y = top\n",
- " end=lb_types.Point(x=871, y=1124), # x= left + width , y = top + height\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\")))\n",
- " ])\n",
- "\n",
- "## NDJSON\n",
- "bbox_with_radio_subclass_ndjson = {\n",
- " \"name\": \"bbox_with_radio_subclass\",\n",
- " \"classifications\": [{\n",
- " \"name\": \"sub_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_sub_radio_answer\"\n",
- " }\n",
- " }],\n",
- " \"bbox\": {\n",
- " \"top\": 933,\n",
- " \"left\": 541,\n",
- " \"height\": 191,\n",
- " \"width\": 330\n",
- " }\n",
- "}"
- ],
+ "source": "# Python annotation\nbbox_with_radio_subclass_annotation = lb_types.ObjectAnnotation(\n name=\"bbox_with_radio_subclass\",\n value=lb_types.Rectangle(\n start=lb_types.Point(x=541, y=933), # x = left, y = top\n end=lb_types.Point(x=871, y=1124), # x= left + width , y = top + height\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n)\n\n## NDJSON\nbbox_with_radio_subclass_ndjson = {\n \"name\": \"bbox_with_radio_subclass\",\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\"\n },\n }],\n \"bbox\": {\n \"top\": 933,\n \"left\": 541,\n \"height\": 191,\n \"width\": 330\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -449,52 +216,7 @@
},
{
"metadata": {},
- "source": [
- "# Python annotation\n",
- "polygon_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"polygon\", # must match your ontology feature\"s name\n",
- " value=lb_types.Polygon( # Coordinates for the vertices of your polygon\n",
- " points=[\n",
- " lb_types.Point(x=1489.581, y=183.934),\n",
- " lb_types.Point(x=2278.306, y=256.885),\n",
- " lb_types.Point(x=2428.197, y=200.437),\n",
- " lb_types.Point(x=2560.0, y=335.419),\n",
- " lb_types.Point(x=2557.386, y=503.165),\n",
- " lb_types.Point(x=2320.596, y=503.103),\n",
- " lb_types.Point(x=2156.083, y=628.943),\n",
- " lb_types.Point(x=2161.111, y=785.519),\n",
- " lb_types.Point(x=2002.115, y=894.647),\n",
- " lb_types.Point(x=1838.456, y=877.874),\n",
- " lb_types.Point(x=1436.53, y=874.636),\n",
- " lb_types.Point(x=1411.403, y=758.579),\n",
- " lb_types.Point(x=1353.853, y=751.74),\n",
- " lb_types.Point(x=1345.264, y=453.461),\n",
- " lb_types.Point(x=1426.011, y=421.129)\n",
- " ]))\n",
- "\n",
- "# NDJSON\n",
- "polygon_annotation_ndjson = {\n",
- " \"name\": \"polygon\",\n",
- " \"polygon\": [\n",
- " {\"x\": 1489.581, \"y\": 183.934},\n",
- " {\"x\": 2278.306, \"y\": 256.885},\n",
- " {\"x\": 2428.197, \"y\": 200.437},\n",
- " {\"x\": 2560.0, \"y\": 335.419},\n",
- " {\"x\": 2557.386, \"y\": 503.165},\n",
- " {\"x\": 2320.596, \"y\": 503.103},\n",
- " {\"x\": 2156.083, \"y\": 628.943},\n",
- " {\"x\": 2161.111, \"y\": 785.519},\n",
- " {\"x\": 2002.115, \"y\": 894.647},\n",
- " {\"x\": 1838.456, \"y\": 877.874},\n",
- " {\"x\": 1436.53, \"y\": 874.636},\n",
- " {\"x\": 1411.403, \"y\": 758.579},\n",
- " {\"x\": 1353.853, \"y\": 751.74},\n",
- " {\"x\": 1345.264, \"y\": 453.461},\n",
- " {\"x\": 1426.011, \"y\": 421.129},\n",
- " {\"x\": 1489.581, \"y\": 183.934}\n",
- " ]\n",
- "}"
- ],
+ "source": "# Python annotation\npolygon_annotation = lb_types.ObjectAnnotation(\n name=\"polygon\", # must match your ontology feature\"s name\n value=lb_types.Polygon( # Coordinates for the vertices of your polygon\n points=[\n lb_types.Point(x=1489.581, y=183.934),\n lb_types.Point(x=2278.306, y=256.885),\n lb_types.Point(x=2428.197, y=200.437),\n lb_types.Point(x=2560.0, y=335.419),\n lb_types.Point(x=2557.386, y=503.165),\n lb_types.Point(x=2320.596, y=503.103),\n lb_types.Point(x=2156.083, y=628.943),\n lb_types.Point(x=2161.111, y=785.519),\n lb_types.Point(x=2002.115, y=894.647),\n lb_types.Point(x=1838.456, y=877.874),\n lb_types.Point(x=1436.53, y=874.636),\n lb_types.Point(x=1411.403, y=758.579),\n lb_types.Point(x=1353.853, y=751.74),\n lb_types.Point(x=1345.264, y=453.461),\n lb_types.Point(x=1426.011, y=421.129),\n ]),\n)\n\n# NDJSON\npolygon_annotation_ndjson = {\n \"name\":\n \"polygon\",\n \"polygon\": [\n {\n \"x\": 1489.581,\n \"y\": 183.934\n },\n {\n \"x\": 2278.306,\n \"y\": 256.885\n },\n {\n \"x\": 2428.197,\n \"y\": 200.437\n },\n {\n \"x\": 2560.0,\n \"y\": 335.419\n },\n {\n \"x\": 2557.386,\n \"y\": 503.165\n },\n {\n \"x\": 2320.596,\n \"y\": 503.103\n },\n {\n \"x\": 2156.083,\n \"y\": 628.943\n },\n {\n \"x\": 2161.111,\n \"y\": 785.519\n },\n {\n \"x\": 2002.115,\n \"y\": 894.647\n },\n {\n \"x\": 1838.456,\n \"y\": 877.874\n },\n {\n \"x\": 1436.53,\n \"y\": 874.636\n },\n {\n \"x\": 1411.403,\n \"y\": 758.579\n },\n {\n \"x\": 1353.853,\n \"y\": 751.74\n },\n {\n \"x\": 1345.264,\n \"y\": 453.461\n },\n {\n \"x\": 1426.011,\n \"y\": 421.129\n },\n {\n \"x\": 1489.581,\n \"y\": 183.934\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -509,97 +231,14 @@
},
{
"metadata": {},
- "source": [
- "# First we need to extract all the unique colors from the composite mask\n",
- "def extract_rgb_colors_from_url(image_url):\n",
- " response = requests.get(image_url)\n",
- " img = Image.open(BytesIO(response.content))\n",
- "\n",
- " colors = set()\n",
- " for x in range(img.width):\n",
- " for y in range(img.height):\n",
- " pixel = img.getpixel((x, y))\n",
- " if pixel[:3] != (0,0,0):\n",
- " colors.add(pixel[:3]) # Get only the RGB values\n",
- "\n",
- " return colors"
- ],
+ "source": "# First we need to extract all the unique colors from the composite mask\ndef extract_rgb_colors_from_url(image_url):\n response = requests.get(image_url)\n img = Image.open(BytesIO(response.content))\n\n colors = set()\n for x in range(img.width):\n for y in range(img.height):\n pixel = img.getpixel((x, y))\n if pixel[:3] != (0, 0, 0):\n colors.add(pixel[:3]) # Get only the RGB values\n\n return colors",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "\n",
- "cp_mask_url = \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/composite_mask.png\"\n",
- "colors = extract_rgb_colors_from_url(cp_mask_url)\n",
- "response = requests.get(cp_mask_url)\n",
- "\n",
- "mask_data = lb.types.MaskData(im_bytes=response.content) # You can also use \"url\" instead of img_bytes to pass the PNG mask url.\n",
- "rgb_colors_for_mask_with_text_subclass_tool = [(73, 39, 85), (111, 87, 176), (23, 169, 254)]\n",
- "\n",
- "cp_mask = []\n",
- "for color in colors:\n",
- " # We are assigning the color related to the mask_with_text_subclass tool by identifying the unique RGB colors\n",
- " if color in rgb_colors_for_mask_with_text_subclass_tool:\n",
- " cp_mask.append(\n",
- " lb_types.ObjectAnnotation(\n",
- " name = \"mask_with_text_subclass\", # must match your ontology feature\"s name\n",
- " value=lb_types.Mask(\n",
- " mask=mask_data,\n",
- " color=color),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_free_text\",\n",
- " value=lb_types.Text(answer=\"free text answer sample\")\n",
- " )]\n",
- " )\n",
- " )\n",
- " else:\n",
- " # Create ObjectAnnotation for other masks\n",
- " cp_mask.append(\n",
- " lb_types.ObjectAnnotation(\n",
- " name=\"mask\",\n",
- " value=lb_types.Mask(\n",
- " mask=mask_data,\n",
- " color=color\n",
- " )\n",
- " )\n",
- " )\n",
- "\n",
- "\n",
- "# NDJSON using bytes array\n",
- "cp_mask_ndjson = []\n",
- "\n",
- "#Using bytes array.\n",
- "response = requests.get(cp_mask_url)\n",
- "im_bytes = base64.b64encode(response.content).decode('utf-8')\n",
- "for color in colors:\n",
- " if color in rgb_colors_for_mask_with_text_subclass_tool:\n",
- " cp_mask_ndjson.append({\n",
- " \"name\": \"mask_with_text_subclass\",\n",
- " \"mask\": {\"imBytes\": im_bytes,\n",
- " \"colorRGB\": color },\n",
- " \"classifications\":[{\n",
- " \"name\": \"sub_free_text\",\n",
- " \"answer\": \"free text answer\"\n",
- " }]\n",
- " }\n",
- " )\n",
- " else:\n",
- " cp_mask_ndjson.append({\n",
- " \"name\": \"mask\",\n",
- " \"classifications\": [],\n",
- " \"mask\": {\n",
- " \"imBytes\": im_bytes,\n",
- " \"colorRGB\": color\n",
- " }\n",
- " }\n",
- " )\n",
- "\n",
- "\n"
- ],
+ "source": "cp_mask_url = \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/composite_mask.png\"\ncolors = extract_rgb_colors_from_url(cp_mask_url)\nresponse = requests.get(cp_mask_url)\n\nmask_data = lb.types.MaskData(\n im_bytes=response.content\n) # You can also use \"url\" instead of img_bytes to pass the PNG mask url.\nrgb_colors_for_mask_with_text_subclass_tool = [\n (73, 39, 85),\n (111, 87, 176),\n (23, 169, 254),\n]\n\ncp_mask = []\nfor color in colors:\n # We are assigning the color related to the mask_with_text_subclass tool by identifying the unique RGB colors\n if color in rgb_colors_for_mask_with_text_subclass_tool:\n cp_mask.append(\n lb_types.ObjectAnnotation(\n name=\n \"mask_with_text_subclass\", # must match your ontology feature\"s name\n value=lb_types.Mask(mask=mask_data, color=color),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_free_text\",\n value=lb_types.Text(answer=\"free text answer sample\"),\n )\n ],\n ))\n else:\n # Create ObjectAnnotation for other masks\n cp_mask.append(\n lb_types.ObjectAnnotation(name=\"mask\",\n value=lb_types.Mask(mask=mask_data,\n color=color)))\n\n# NDJSON using bytes array\ncp_mask_ndjson = []\n\n# Using bytes array.\nresponse = requests.get(cp_mask_url)\nim_bytes = base64.b64encode(response.content).decode(\"utf-8\")\nfor color in colors:\n if color in rgb_colors_for_mask_with_text_subclass_tool:\n cp_mask_ndjson.append({\n \"name\":\n \"mask_with_text_subclass\",\n \"mask\": {\n \"imBytes\": im_bytes,\n \"colorRGB\": color\n },\n \"classifications\": [{\n \"name\": \"sub_free_text\",\n \"answer\": \"free text answer\"\n }],\n })\n else:\n cp_mask_ndjson.append({\n \"name\": \"mask\",\n \"classifications\": [],\n \"mask\": {\n \"imBytes\": im_bytes,\n \"colorRGB\": color\n },\n })",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -613,23 +252,7 @@
},
{
"metadata": {},
- "source": [
- "# Python annotation\n",
- "point_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"point\", # must match your ontology feature\"s name\n",
- " value=lb_types.Point(x=1166.606, y=1441.768),\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "point_annotation_ndjson = {\n",
- " \"name\": \"point\",\n",
- " \"classifications\": [],\n",
- " \"point\": {\n",
- " \"x\": 1166.606,\n",
- " \"y\": 1441.768\n",
- " }\n",
- "}"
- ],
+ "source": "# Python annotation\npoint_annotation = lb_types.ObjectAnnotation(\n name=\"point\", # must match your ontology feature\"s name\n value=lb_types.Point(x=1166.606, y=1441.768),\n)\n\n# NDJSON\npoint_annotation_ndjson = {\n \"name\": \"point\",\n \"classifications\": [],\n \"point\": {\n \"x\": 1166.606,\n \"y\": 1441.768\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -643,65 +266,7 @@
},
{
"metadata": {},
- "source": [
- "# Python annotation\n",
- "polyline_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"polyline\", # must match your ontology feature\"s name\n",
- " value=lb_types.Line( # Coordinates for the keypoints in your polyline\n",
- " points=[\n",
- " lb_types.Point(x=2534.353, y=249.471),\n",
- " lb_types.Point(x=2429.492, y=182.092),\n",
- " lb_types.Point(x=2294.322, y=221.962),\n",
- " lb_types.Point(x=2224.491, y=180.463),\n",
- " lb_types.Point(x=2136.123, y=204.716),\n",
- " lb_types.Point(x=1712.247, y=173.949),\n",
- " lb_types.Point(x=1703.838, y=84.438),\n",
- " lb_types.Point(x=1579.772, y=82.61),\n",
- " lb_types.Point(x=1583.442, y=167.552),\n",
- " lb_types.Point(x=1478.869, y=164.903),\n",
- " lb_types.Point(x=1418.941, y=318.149),\n",
- " lb_types.Point(x=1243.128, y=400.815),\n",
- " lb_types.Point(x=1022.067, y=319.007),\n",
- " lb_types.Point(x=892.367, y=379.216),\n",
- " lb_types.Point(x=670.273, y=364.408),\n",
- " lb_types.Point(x=613.114, y=288.16),\n",
- " lb_types.Point(x=377.559, y=238.251),\n",
- " lb_types.Point(x=368.087, y=185.064),\n",
- " lb_types.Point(x=246.557, y=167.286),\n",
- " lb_types.Point(x=236.648, y=285.61),\n",
- " lb_types.Point(x=90.929, y=326.412)\n",
- " ]),\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "polyline_annotation_ndjson = {\n",
- " \"name\": \"polyline\",\n",
- " \"classifications\": [],\n",
- " \"line\": [\n",
- " {\"x\": 2534.353, \"y\": 249.471},\n",
- " {\"x\": 2429.492, \"y\": 182.092},\n",
- " {\"x\": 2294.322, \"y\": 221.962},\n",
- " {\"x\": 2224.491, \"y\": 180.463},\n",
- " {\"x\": 2136.123, \"y\": 204.716},\n",
- " {\"x\": 1712.247, \"y\": 173.949},\n",
- " {\"x\": 1703.838, \"y\": 84.438},\n",
- " {\"x\": 1579.772, \"y\": 82.61},\n",
- " {\"x\": 1583.442, \"y\": 167.552},\n",
- " {\"x\": 1478.869, \"y\": 164.903},\n",
- " {\"x\": 1418.941, \"y\": 318.149},\n",
- " {\"x\": 1243.128, \"y\": 400.815},\n",
- " {\"x\": 1022.067, \"y\": 319.007},\n",
- " {\"x\": 892.367, \"y\": 379.216},\n",
- " {\"x\": 670.273, \"y\": 364.408},\n",
- " {\"x\": 613.114, \"y\": 288.16},\n",
- " {\"x\": 377.559, \"y\": 238.251},\n",
- " {\"x\": 368.087, \"y\": 185.064},\n",
- " {\"x\": 246.557, \"y\": 167.286},\n",
- " {\"x\": 236.648, \"y\": 285.61},\n",
- " {\"x\": 90.929, \"y\": 326.412}\n",
- " ]\n",
- "}"
- ],
+ "source": "# Python annotation\npolyline_annotation = lb_types.ObjectAnnotation(\n name=\"polyline\", # must match your ontology feature\"s name\n value=lb_types.Line( # Coordinates for the keypoints in your polyline\n points=[\n lb_types.Point(x=2534.353, y=249.471),\n lb_types.Point(x=2429.492, y=182.092),\n lb_types.Point(x=2294.322, y=221.962),\n lb_types.Point(x=2224.491, y=180.463),\n lb_types.Point(x=2136.123, y=204.716),\n lb_types.Point(x=1712.247, y=173.949),\n lb_types.Point(x=1703.838, y=84.438),\n lb_types.Point(x=1579.772, y=82.61),\n lb_types.Point(x=1583.442, y=167.552),\n lb_types.Point(x=1478.869, y=164.903),\n lb_types.Point(x=1418.941, y=318.149),\n lb_types.Point(x=1243.128, y=400.815),\n lb_types.Point(x=1022.067, y=319.007),\n lb_types.Point(x=892.367, y=379.216),\n lb_types.Point(x=670.273, y=364.408),\n lb_types.Point(x=613.114, y=288.16),\n lb_types.Point(x=377.559, y=238.251),\n lb_types.Point(x=368.087, y=185.064),\n lb_types.Point(x=246.557, y=167.286),\n lb_types.Point(x=236.648, y=285.61),\n lb_types.Point(x=90.929, y=326.412),\n ]),\n)\n\n# NDJSON\npolyline_annotation_ndjson = {\n \"name\":\n \"polyline\",\n \"classifications\": [],\n \"line\": [\n {\n \"x\": 2534.353,\n \"y\": 249.471\n },\n {\n \"x\": 2429.492,\n \"y\": 182.092\n },\n {\n \"x\": 2294.322,\n \"y\": 221.962\n },\n {\n \"x\": 2224.491,\n \"y\": 180.463\n },\n {\n \"x\": 2136.123,\n \"y\": 204.716\n },\n {\n \"x\": 1712.247,\n \"y\": 173.949\n },\n {\n \"x\": 1703.838,\n \"y\": 84.438\n },\n {\n \"x\": 1579.772,\n \"y\": 82.61\n },\n {\n \"x\": 1583.442,\n \"y\": 167.552\n },\n {\n \"x\": 1478.869,\n \"y\": 164.903\n },\n {\n \"x\": 1418.941,\n \"y\": 318.149\n },\n {\n \"x\": 1243.128,\n \"y\": 400.815\n },\n {\n \"x\": 1022.067,\n \"y\": 319.007\n },\n {\n \"x\": 892.367,\n \"y\": 379.216\n },\n {\n \"x\": 670.273,\n \"y\": 364.408\n },\n {\n \"x\": 613.114,\n \"y\": 288.16\n },\n {\n \"x\": 377.559,\n \"y\": 238.251\n },\n {\n \"x\": 368.087,\n \"y\": 185.064\n },\n {\n \"x\": 246.557,\n \"y\": 167.286\n },\n {\n \"x\": 236.648,\n \"y\": 285.61\n },\n {\n \"x\": 90.929,\n \"y\": 326.412\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -723,41 +288,14 @@
},
{
"metadata": {},
- "source": [
- "# send a sample image as batch to the project\n",
- "global_key = \"2560px-Kitano_Street_Kobe01s5s4110.jpeg\"\n",
- "\n",
- "test_img_url = {\n",
- " \"row_data\":\n",
- " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n",
- " \"global_key\":\n",
- " global_key\n",
- "}\n",
- "\n",
- "dataset = client.create_dataset(name=\"image-demo-dataset\")\n",
- "task = dataset.create_data_rows([test_img_url])\n",
- "task.wait_till_done()\n",
- "\n",
- "print(f\"Failed data rows: {task.failed_data_rows}\")\n",
- "print(f\"Errors: {task.errors}\")\n",
- "\n",
- "if task.errors:\n",
- " for error in task.errors:\n",
- " if 'Duplicate global key' in error['message'] and dataset.row_count == 0:\n",
- " # If the global key already exists in the workspace the dataset will be created empty, so we can delete it.\n",
- " print(f\"Deleting empty dataset: {dataset}\")\n",
- " dataset.delete()\n",
- "\n"
- ],
+ "source": "# send a sample image as batch to the project\nglobal_key = \"2560px-Kitano_Street_Kobe01s5s4110.jpeg\"\n\ntest_img_url = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n}\n\ndataset = client.create_dataset(name=\"image-demo-dataset\")\ntask = dataset.create_data_rows([test_img_url])\ntask.wait_till_done()\n\nprint(f\"Failed data rows: {task.failed_data_rows}\")\nprint(f\"Errors: {task.errors}\")\n\nif task.errors:\n for error in task.errors:\n if (\"Duplicate global key\" in error[\"message\"] and\n dataset.row_count == 0):\n # If the global key already exists in the workspace the dataset will be created empty, so we can delete it.\n print(f\"Deleting empty dataset: {dataset}\")\n dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "print(dataset)"
- ],
+ "source": "print(dataset)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -774,79 +312,7 @@
},
{
"metadata": {},
- "source": [
- "ontology_builder = lb.OntologyBuilder(\n",
- " classifications=[ # List of Classification objects\n",
- " lb.Classification(class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\"),\n",
- " lb.Option(value=\"second_radio_answer\")\n",
- " ]),\n",
- " lb.Classification(class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]),\n",
- " lb.Classification(class_type=lb.Classification.Type.TEXT,\n",
- " name=\"free_text\"),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " options=[\n",
- " lb.Option(\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[lb.Option(\"first_sub_radio_answer\")])\n",
- " ])\n",
- " ]),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " options=[\n",
- " lb.Option(\n",
- " \"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")])\n",
- " ])\n",
- " ]),\n",
- " ],\n",
- " tools=[ # List of Tool objects\n",
- " lb.Tool(tool=lb.Tool.Type.BBOX, name=\"bounding_box\"),\n",
- " lb.Tool(tool=lb.Tool.Type.BBOX,\n",
- " name=\"bbox_with_radio_subclass\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[lb.Option(value=\"first_sub_radio_answer\")]),\n",
- " ]),\n",
- " lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"polygon\"),\n",
- " lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=\"mask\"),\n",
- " lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION,\n",
- " name=\"mask_with_text_subclass\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"sub_free_text\")\n",
- " ]\n",
- " ),\n",
- " lb.Tool(tool=lb.Tool.Type.POINT, name=\"point\"),\n",
- " lb.Tool(tool=lb.Tool.Type.LINE, name=\"polyline\"),\n",
- " lb.Tool(tool=lb.Tool.Type.RELATIONSHIP, name=\"relationship\")\n",
- " ])\n",
- "\n",
- "ontology = client.create_ontology(\"Image Annotation Import Demo Ontology\",\n",
- " ontology_builder.asdict(),\n",
- " media_type=lb.MediaType.Image\n",
- " )"
- ],
+ "source": "ontology_builder = lb.OntologyBuilder(\n classifications=[ # List of Classification objects\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_question\",\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_question\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n ),\n lb.Classification(class_type=lb.Classification.Type.TEXT,\n name=\"free_text\"),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n options=[\n lb.Option(\n \"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(\"first_sub_radio_answer\")],\n )\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n ],\n tools=[ # List of Tool objects\n lb.Tool(tool=lb.Tool.Type.BBOX, name=\"bounding_box\"),\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"bbox_with_radio_subclass\",\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(value=\"first_sub_radio_answer\")],\n ),\n ],\n ),\n lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"polygon\"),\n lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=\"mask\"),\n lb.Tool(\n tool=lb.Tool.Type.RASTER_SEGMENTATION,\n name=\"mask_with_text_subclass\",\n classifications=[\n lb.Classification(class_type=lb.Classification.Type.TEXT,\n name=\"sub_free_text\")\n ],\n ),\n lb.Tool(tool=lb.Tool.Type.POINT, name=\"point\"),\n lb.Tool(tool=lb.Tool.Type.LINE, name=\"polyline\"),\n lb.Tool(tool=lb.Tool.Type.RELATIONSHIP, name=\"relationship\"),\n ],\n)\n\nontology = client.create_ontology(\n \"Image Annotation Import Demo Ontology\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -861,14 +327,7 @@
},
{
"metadata": {},
- "source": [
- "# Project defaults to batch mode with benchmark quality settings if this argument is not provided\n",
- "# Queue mode will be deprecated once dataset mode is deprecated\n",
- "project = client.create_project(name=\"Image Annotation Import Demo\",\n",
- " media_type=lb.MediaType.Image)\n",
- "\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "# Project defaults to batch mode with benchmark quality settings if this argument is not provided\n# Queue mode will be deprecated once dataset mode is deprecated\nproject = client.create_project(name=\"Image Annotation Import Demo\",\n media_type=lb.MediaType.Image)\n\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -882,17 +341,7 @@
},
{
"metadata": {},
- "source": [
- "batch = project.create_batch(\n",
- " \"image-demo-batch\", # each batch in a project must have a unique name\n",
- " global_keys=[\n",
- " global_key\n",
- " ], # paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=1 # priority between 1(highest) - 5(lowest)\n",
- ")\n",
- "\n",
- "print(f\"Batch: {batch}\")"
- ],
+ "source": "batch = project.create_batch(\n \"image-demo-batch\", # each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # paginated collection of data row objects, list of data row ids or global keys\n priority=1, # priority between 1(highest) - 5(lowest)\n)\n\nprint(f\"Batch: {batch}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -919,28 +368,7 @@
},
{
"metadata": {},
- "source": [
- "label = []\n",
- "annotations = [\n",
- " radio_annotation,\n",
- " nested_radio_annotation,\n",
- " checklist_annotation,\n",
- " nested_checklist_annotation,\n",
- " text_annotation,\n",
- " bbox_annotation,\n",
- " bbox_with_radio_subclass_annotation,\n",
- " polygon_annotation,\n",
- " point_annotation,\n",
- " polyline_annotation,\n",
- " bbox_source,\n",
- " bbox_target,\n",
- " relationship\n",
- "] + cp_mask\n",
- "\n",
- "label.append(\n",
- " lb_types.Label(data={\"global_key\" : global_key },\n",
- " annotations=annotations))"
- ],
+ "source": "label = []\nannotations = [\n radio_annotation,\n nested_radio_annotation,\n checklist_annotation,\n nested_checklist_annotation,\n text_annotation,\n bbox_annotation,\n bbox_with_radio_subclass_annotation,\n polygon_annotation,\n point_annotation,\n polyline_annotation,\n bbox_source,\n bbox_target,\n relationship,\n] + cp_mask\n\nlabel.append(\n lb_types.Label(data={\"global_key\": global_key}, annotations=annotations))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -955,32 +383,7 @@
},
{
"metadata": {},
- "source": [
- "label_ndjson = []\n",
- "annotations = [\n",
- " radio_annotation_ndjson,\n",
- " nested_radio_annotation_ndjson,\n",
- " nested_checklist_annotation_ndjson,\n",
- " checklist_annotation_ndjson,\n",
- " text_annotation_ndjson,\n",
- " bbox_annotation_ndjson,\n",
- " bbox_with_radio_subclass_ndjson,\n",
- " polygon_annotation_ndjson,\n",
- " point_annotation_ndjson,\n",
- " polyline_annotation_ndjson,\n",
- " bbox_source_ndjson,\n",
- " bbox_target_ndjson,\n",
- " relationship_ndjson, ## Only supported for MAL imports\n",
- "] + cp_mask_ndjson\n",
- "\n",
- "for annotation in annotations:\n",
- " annotation.update({\n",
- " \"dataRow\": {\n",
- " \"globalKey\": global_key\n",
- " }\n",
- " })\n",
- " label_ndjson.append(annotation)"
- ],
+ "source": "label_ndjson = []\nannotations = [\n radio_annotation_ndjson,\n nested_radio_annotation_ndjson,\n nested_checklist_annotation_ndjson,\n checklist_annotation_ndjson,\n text_annotation_ndjson,\n bbox_annotation_ndjson,\n bbox_with_radio_subclass_ndjson,\n polygon_annotation_ndjson,\n point_annotation_ndjson,\n polyline_annotation_ndjson,\n bbox_source_ndjson,\n bbox_target_ndjson,\n relationship_ndjson, ## Only supported for MAL imports\n] + cp_mask_ndjson\n\nfor annotation in annotations:\n annotation.update({\"dataRow\": {\"globalKey\": global_key}})\n label_ndjson.append(annotation)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1002,19 +405,7 @@
},
{
"metadata": {},
- "source": [
- "# upload MAL labels for this data row in project\n",
- "upload_job = lb.MALPredictionImport.create_from_objects(\n",
- " client=client,\n",
- " project_id=project.uid,\n",
- " name=\"mal_job\" + str(uuid.uuid4()),\n",
- " predictions=label\n",
- ")\n",
- "upload_job.wait_until_done()\n",
- "\n",
- "print(f\"Errors: {upload_job.errors}\")\n",
- "print(f\"Status of uploads: {upload_job.statuses}\")"
- ],
+ "source": "# upload MAL labels for this data row in project\nupload_job = lb.MALPredictionImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"mal_job\" + str(uuid.uuid4()),\n predictions=label,\n)\nupload_job.wait_until_done()\n\nprint(f\"Errors: {upload_job.errors}\")\nprint(f\"Status of uploads: {upload_job.statuses}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1028,29 +419,14 @@
},
{
"metadata": {},
- "source": [
- "# Relationships are not supported with LabelImport\n",
- "# For this demo either run MAL or Ground Truth, not both\n",
- "\n",
- "# Upload label for this data row in project\n",
- "# upload_job = lb.LabelImport.create_from_objects(\n",
- "# client = client,\n",
- "# project_id = project.uid,\n",
- "# name=\"label_import_job\"+str(uuid.uuid4()),\n",
- "# labels=label)\n",
- "\n",
- "# print(\"Errors:\", upload_job.errors)\n",
- "# print(\"Status of uploads: \", upload_job.statuses)"
- ],
+ "source": "# Relationships are not supported with LabelImport\n# For this demo either run MAL or Ground Truth, not both\n\n# Upload label for this data row in project\n# upload_job = lb.LabelImport.create_from_objects(\n# client = client,\n# project_id = project.uid,\n# name=\"label_import_job\"+str(uuid.uuid4()),\n# labels=label)\n\n# print(\"Errors:\", upload_job.errors)\n# print(\"Status of uploads: \", upload_job.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# project.delete()"
- ],
+ "source": "# project.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/annotation_import/import_labeled_dataset_image.ipynb b/examples/annotation_import/import_labeled_dataset_image.ipynb
index 52e55203d..9ebd52883 100644
--- a/examples/annotation_import/import_labeled_dataset_image.ipynb
+++ b/examples/annotation_import/import_labeled_dataset_image.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- " | \n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -20,11 +20,8 @@
"src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\">\n",
"\n",
"\n",
- "\n",
- "\n",
- "\n",
"\n",
- "![]() \n",
" | "
],
@@ -32,29 +29,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "from labelbox.schema.data_row_metadata import DataRowMetadataField, DataRowMetadataKind\n",
- "import datetime\n",
- "import random\n",
- "import os\n",
- "import json\n",
- "from PIL import Image\n",
- "from labelbox.schema.ontology import OntologyBuilder, Tool\n",
- "import requests\n",
- "from tqdm.notebook import tqdm\n",
- "import uuid\n",
- "from labelbox.data.annotation_types import Label, ImageData, ObjectAnnotation, Rectangle, Point"
- ],
+ "source": "import labelbox as lb\nfrom labelbox.schema.data_row_metadata import (\n DataRowMetadataField,\n DataRowMetadataKind,\n)\nimport datetime\nimport random\nimport os\nimport json\nfrom PIL import Image\nfrom labelbox.schema.ontology import OntologyBuilder, Tool\nimport requests\nfrom tqdm.notebook import tqdm\nimport uuid\nfrom labelbox.data.annotation_types import (\n Label,\n ImageData,\n ObjectAnnotation,\n Rectangle,\n Point,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -68,11 +50,7 @@
},
{
"metadata": {},
- "source": [
- "# Initialize the Labelbox client\n",
- "API_KEY = \"\"\n",
- "client = lb.Client(API_KEY)"
- ],
+ "source": "# Initialize the Labelbox client\nAPI_KEY = \"\"\nclient = lb.Client(API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -86,43 +64,21 @@
},
{
"metadata": {},
- "source": [
- "# Function to download files\n",
- "def download_files(filemap):\n",
- " path, uri = filemap\n",
- " if not os.path.exists(path):\n",
- " response = requests.get(uri, stream=True)\n",
- " with open(path, 'wb') as f:\n",
- " for chunk in response.iter_content(chunk_size=8192):\n",
- " f.write(chunk)\n",
- " return path"
- ],
+ "source": "# Function to download files\ndef download_files(filemap):\n path, uri = filemap\n if not os.path.exists(path):\n response = requests.get(uri, stream=True)\n with open(path, \"wb\") as f:\n for chunk in response.iter_content(chunk_size=8192):\n f.write(chunk)\n return path",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Download data rows and annotations\n",
- "DATA_ROWS_URL = \"https://storage.googleapis.com/labelbox-datasets/VHR_geospatial/geospatial_datarows.json\"\n",
- "ANNOTATIONS_URL = \"https://storage.googleapis.com/labelbox-datasets/VHR_geospatial/geospatial_annotations.json\"\n",
- "download_files((\"data_rows.json\", DATA_ROWS_URL))\n",
- "download_files((\"annotations.json\", ANNOTATIONS_URL))"
- ],
+ "source": "# Download data rows and annotations\nDATA_ROWS_URL = \"https://storage.googleapis.com/labelbox-datasets/VHR_geospatial/geospatial_datarows.json\"\nANNOTATIONS_URL = \"https://storage.googleapis.com/labelbox-datasets/VHR_geospatial/geospatial_annotations.json\"\ndownload_files((\"data_rows.json\", DATA_ROWS_URL))\ndownload_files((\"annotations.json\", ANNOTATIONS_URL))",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Load data rows and annotations\n",
- "with open('data_rows.json') as fp:\n",
- " data_rows = json.load(fp)\n",
- "with open('annotations.json') as fp:\n",
- " annotations = json.load(fp)"
- ],
+ "source": "# Load data rows and annotations\nwith open(\"data_rows.json\") as fp:\n data_rows = json.load(fp)\nwith open(\"annotations.json\") as fp:\n annotations = json.load(fp)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -136,11 +92,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a new dataset\n",
- "dataset = client.create_dataset(name=\"Geospatial vessel detection\")\n",
- "print(f\"Created dataset with ID: {dataset.uid}\")"
- ],
+ "source": "# Create a new dataset\ndataset = client.create_dataset(name=\"Geospatial vessel detection\")\nprint(f\"Created dataset with ID: {dataset.uid}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -154,50 +106,14 @@
},
{
"metadata": {},
- "source": [
- "# Here is an example of adding two metadata fields to your Data Rows: a \"captureDateTime\" field with datetime value, and a \"tag\" field with string value\n",
- "metadata_ontology = client.get_data_row_metadata_ontology()\n",
- "datetime_schema_id = metadata_ontology.reserved_by_name[\"captureDateTime\"].uid\n",
- "tag_schema_id = metadata_ontology.reserved_by_name[\"tag\"].uid\n",
- "tag_items = [\"WorldView-1\", \"WorldView-2\", \"WorldView-3\", \"WorldView-4\"]\n",
- "\n",
- "for datarow in tqdm(data_rows):\n",
- " dt = datetime.datetime.utcnow() + datetime.timedelta(days=random.random()*30) # this is random datetime value\n",
- " tag_item = random.choice(tag_items) # this is a random tag value\n",
- "\n",
- " # Option 1: Specify metadata with a list of DataRowMetadataField. This is the recommended option since it comes with validation for metadata fields.\n",
- " metadata_fields = [\n",
- " DataRowMetadataField(schema_id=datetime_schema_id, value=dt),\n",
- " DataRowMetadataField(schema_id=tag_schema_id, value=tag_item)\n",
- " ]\n",
- "\n",
- " # Option 2: Uncomment to try. Alternatively, you can specify the metadata fields with dictionary format without declaring the DataRowMetadataField objects. It is equivalent to Option 1.\n",
- " # metadata_fields = [\n",
- " # {\"schema_id\": datetime_schema_id, \"value\": dt},\n",
- " # {\"schema_id\": tag_schema_id, \"value\": tag_item}\n",
- " # ]\n",
- "\n",
- " datarow[\"metadata_fields\"] = metadata_fields"
- ],
+ "source": "# Here is an example of adding two metadata fields to your Data Rows: a \"captureDateTime\" field with datetime value, and a \"tag\" field with string value\nmetadata_ontology = client.get_data_row_metadata_ontology()\ndatetime_schema_id = metadata_ontology.reserved_by_name[\"captureDateTime\"].uid\ntag_schema_id = metadata_ontology.reserved_by_name[\"tag\"].uid\ntag_items = [\"WorldView-1\", \"WorldView-2\", \"WorldView-3\", \"WorldView-4\"]\n\nfor datarow in tqdm(data_rows):\n dt = datetime.datetime.utcnow() + datetime.timedelta(\n days=random.random() * 30) # this is random datetime value\n tag_item = random.choice(tag_items) # this is a random tag value\n\n # Option 1: Specify metadata with a list of DataRowMetadataField. This is the recommended option since it comes with validation for metadata fields.\n metadata_fields = [\n DataRowMetadataField(schema_id=datetime_schema_id, value=dt),\n DataRowMetadataField(schema_id=tag_schema_id, value=tag_item),\n ]\n\n # Option 2: Uncomment to try. Alternatively, you can specify the metadata fields with dictionary format without declaring the DataRowMetadataField objects. It is equivalent to Option 1.\n # metadata_fields = [\n # {\"schema_id\": datetime_schema_id, \"value\": dt},\n # {\"schema_id\": tag_schema_id, \"value\": tag_item}\n # ]\n\n datarow[\"metadata_fields\"] = metadata_fields",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "task = dataset.create_data_rows(data_rows)\n",
- "task.wait_till_done()\n",
- "print(f\"Failed data rows: {task.failed_data_rows}\")\n",
- "print(f\"Errors: {task.errors}\")\n",
- "\n",
- "if task.errors:\n",
- " for error in task.errors:\n",
- " if 'Duplicate global key' in error['message'] and dataset.row_count == 0:\n",
- " # If the global key already exists in the workspace the dataset will be created empty, so we can delete it.\n",
- " print(f\"Deleting empty dataset: {dataset}\")\n",
- " dataset.delete()"
- ],
+ "source": "task = dataset.create_data_rows(data_rows)\ntask.wait_till_done()\nprint(f\"Failed data rows: {task.failed_data_rows}\")\nprint(f\"Errors: {task.errors}\")\n\nif task.errors:\n for error in task.errors:\n if (\"Duplicate global key\" in error[\"message\"] and\n dataset.row_count == 0):\n # If the global key already exists in the workspace the dataset will be created empty, so we can delete it.\n print(f\"Deleting empty dataset: {dataset}\")\n dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -211,10 +127,7 @@
},
{
"metadata": {},
- "source": [
- "datarow = next(dataset.data_rows())\n",
- "print(datarow)"
- ],
+ "source": "datarow = next(dataset.data_rows())\nprint(datarow)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -228,27 +141,7 @@
},
{
"metadata": {},
- "source": [
- "# Initialize the OntologyBuilder\n",
- "ontology_builder = OntologyBuilder()\n",
- "\n",
- "# Assuming 'annotations' is defined and contains the necessary data\n",
- "for category in annotations['categories']:\n",
- " print(category['name'])\n",
- " # Add tools to the ontology builder\n",
- " ontology_builder.add_tool(Tool(tool=Tool.Type.BBOX, name=category['name']))\n",
- "\n",
- "# Create the ontology in Labelbox\n",
- "ontology = client.create_ontology(\"Vessel Detection Ontology\",\n",
- " ontology_builder.asdict(),\n",
- " media_type=lb.MediaType.Image)\n",
- "print(f\"Created ontology with ID: {ontology.uid}\")\n",
- "\n",
- "# Create a project and set up the ontology\n",
- "project = client.create_project(name=\"Vessel Detection\", media_type=lb.MediaType.Image)\n",
- "project.setup_editor(ontology=ontology)\n",
- "print(f\"Created project with ID: {project.uid}\")"
- ],
+ "source": "# Initialize the OntologyBuilder\nontology_builder = OntologyBuilder()\n\n# Assuming 'annotations' is defined and contains the necessary data\nfor category in annotations[\"categories\"]:\n print(category[\"name\"])\n # Add tools to the ontology builder\n ontology_builder.add_tool(Tool(tool=Tool.Type.BBOX, name=category[\"name\"]))\n\n# Create the ontology in Labelbox\nontology = client.create_ontology(\n \"Vessel Detection Ontology\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)\nprint(f\"Created ontology with ID: {ontology.uid}\")\n\n# Create a project and set up the ontology\nproject = client.create_project(name=\"Vessel Detection\",\n media_type=lb.MediaType.Image)\nproject.setup_editor(ontology=ontology)\nprint(f\"Created project with ID: {project.uid}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -262,49 +155,7 @@
},
{
"metadata": {},
- "source": [
- "client.enable_experimental = True\n",
- "\n",
- "# Minimal ExportV2 parameters focused solely on data row IDs\n",
- "export_params = {\n",
- " \"data_row_details\": True # Only export data row details\n",
- "}\n",
- "\n",
- "# Initiate the streamable export task from catalog\n",
- "dataset = client.get_dataset(dataset.uid) # Update with the actual dataset ID\n",
- "export_task = dataset.export(params=export_params)\n",
- "export_task.wait_till_done()\n",
- "print(export_task)\n",
- "\n",
- "data_rows = []\n",
- "\n",
- "# Callback used for JSON Converter to correctly collect data row IDs\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " # Parse the JSON string to access the data\n",
- " data = json.loads(output.json_str)\n",
- "\n",
- " # Correctly extract and append DataRow ID\n",
- " if 'data_row' in data and 'id' in data['data_row']:\n",
- " data_rows.append(data['data_row']['id'])\n",
- "\n",
- "# Process the stream if there are results\n",
- "if export_task.has_result():\n",
- " export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)\n",
- "\n",
- "# Randomly select 200 Data Rows (or fewer if the dataset has less than 200 data rows)\n",
- "sampled_data_rows = random.sample(data_rows, min(len(data_rows), 200))\n",
- "\n",
- "# Create a new batch in the project and add the sampled data rows\n",
- "batch = project.create_batch(\n",
- " \"Initial batch\", # name of the batch\n",
- " sampled_data_rows, # list of Data Rows\n",
- " 1 # priority between 1-5\n",
- ")\n",
- "print(f\"Created batch with ID: {batch.uid}\")"
- ],
+ "source": "client.enable_experimental = True\n\n# Minimal ExportV2 parameters focused solely on data row IDs\nexport_params = {\"data_row_details\": True} # Only export data row details\n\n# Initiate the streamable export task from catalog\ndataset = client.get_dataset(dataset.uid) # Update with the actual dataset ID\nexport_task = dataset.export(params=export_params)\nexport_task.wait_till_done()\nprint(export_task)\n\ndata_rows = []\n\n\n# Callback used for JSON Converter to correctly collect data row IDs\ndef json_stream_handler(output: lb.JsonConverterOutput):\n # Parse the JSON string to access the data\n data = json.loads(output.json_str)\n\n # Correctly extract and append DataRow ID\n if \"data_row\" in data and \"id\" in data[\"data_row\"]:\n data_rows.append(data[\"data_row\"][\"id\"])\n\n\n# Process the stream if there are results\nif export_task.has_result():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\n# Randomly select 200 Data Rows (or fewer if the dataset has less than 200 data rows)\nsampled_data_rows = random.sample(data_rows, min(len(data_rows), 200))\n\n# Create a new batch in the project and add the sampled data rows\nbatch = project.create_batch(\n \"Initial batch\", # name of the batch\n sampled_data_rows, # list of Data Rows\n 1, # priority between 1-5\n)\nprint(f\"Created batch with ID: {batch.uid}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -318,87 +169,14 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "# Set export parameters focused on data row details\n",
- "export_params = {\n",
- " \"data_row_details\": True, # Only export data row details\n",
- " \"batch_ids\": [batch.uid], # Optional: Include batch ids to filter by specific batches\n",
- "}\n",
- "\n",
- "# Initialize the streamable export task from project\n",
- "export_task = project.export(params=export_params)\n",
- "export_task.wait_till_done()\n",
- "\n",
- "data_rows = []\n",
- "\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " data_row = json.loads(output.json_str)\n",
- " data_rows.append(data_row)\n",
- "\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- "\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)\n",
- "\n",
- "labels = []\n",
- "for datarow in data_rows:\n",
- " annotations_list = []\n",
- " # Access the 'data_row' dictionary first\n",
- " data_row_dict = datarow['data_row']\n",
- " folder = data_row_dict['external_id'].split(\"/\")[0]\n",
- " id = data_row_dict['external_id'].split(\"/\")[1]\n",
- "\n",
- " if folder == \"positive_image_set\":\n",
- " for image in annotations['images']:\n",
- " if image['file_name'] == id:\n",
- " for annotation in annotations['annotations']:\n",
- " if annotation['image_id'] == image['id']:\n",
- " bbox = annotation['bbox']\n",
- " category_id = annotation['category_id'] - 1\n",
- " class_name = None\n",
- " ontology = ontology_builder.asdict() # Get the ontology dictionary\n",
- " for category in ontology['tools']:\n",
- " if category['name'] == annotations['categories'][category_id]['name']:\n",
- " class_name = category['name']\n",
- " break\n",
- " if class_name:\n",
- " annotations_list.append(ObjectAnnotation(\n",
- " name=class_name,\n",
- " value=Rectangle(start=Point(x=bbox[0], y=bbox[1]), end=Point(x=bbox[2]+bbox[0], y=bbox[3]+bbox[1]))\n",
- " ))\n",
- " image_data = {\"uid\":data_row_dict['id']}\n",
- " labels.append(Label(data=image_data, annotations=annotations_list))"
- ],
+ "source": "# Set export parameters focused on data row details\nexport_params = {\n \"data_row_details\": True, # Only export data row details\n \"batch_ids\": [batch.uid\n ], # Optional: Include batch ids to filter by specific batches\n}\n\n# Initialize the streamable export task from project\nexport_task = project.export(params=export_params)\nexport_task.wait_till_done()\n\ndata_rows = []\n\n\ndef json_stream_handler(output: lb.JsonConverterOutput):\n data_row = json.loads(output.json_str)\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nlabels = []\nfor datarow in data_rows:\n annotations_list = []\n # Access the 'data_row' dictionary first\n data_row_dict = datarow[\"data_row\"]\n folder = data_row_dict[\"external_id\"].split(\"/\")[0]\n id = data_row_dict[\"external_id\"].split(\"/\")[1]\n\n if folder == \"positive_image_set\":\n for image in annotations[\"images\"]:\n if image[\"file_name\"] == id:\n for annotation in annotations[\"annotations\"]:\n if annotation[\"image_id\"] == image[\"id\"]:\n bbox = annotation[\"bbox\"]\n category_id = annotation[\"category_id\"] - 1\n class_name = None\n ontology = (ontology_builder.asdict()\n ) # Get the ontology dictionary\n for category in ontology[\"tools\"]:\n if (category[\"name\"] == annotations[\"categories\"]\n [category_id][\"name\"]):\n class_name = category[\"name\"]\n break\n if class_name:\n annotations_list.append(\n ObjectAnnotation(\n name=class_name,\n value=Rectangle(\n start=Point(x=bbox[0], y=bbox[1]),\n end=Point(\n x=bbox[2] + bbox[0],\n y=bbox[3] + bbox[1],\n ),\n ),\n ))\n image_data = {\"uid\": data_row_dict[\"id\"]}\n labels.append(Label(data=image_data, annotations=annotations_list))",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "upload_job = lb.LabelImport.create_from_objects(\n",
- " client=client,\n",
- " project_id=project.uid,\n",
- " name=f\"label_import_job_{str(uuid.uuid4())}\",\n",
- " labels=labels\n",
- ")\n",
- "\n",
- "# Wait for the upload to finish and print the results\n",
- "upload_job.wait_until_done()\n",
- "\n",
- "print(f\"Errors: {upload_job.errors}\")\n",
- "print(f\"Status of uploads: {upload_job.statuses}\")"
- ],
+ "source": "upload_job = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=f\"label_import_job_{str(uuid.uuid4())}\",\n labels=labels,\n)\n\n# Wait for the upload to finish and print the results\nupload_job.wait_until_done()\n\nprint(f\"Errors: {upload_job.errors}\")\nprint(f\"Status of uploads: {upload_job.statuses}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/annotation_import/pdf.ipynb b/examples/annotation_import/pdf.ipynb
index 4465631f4..5c0742ba5 100644
--- a/examples/annotation_import/pdf.ipynb
+++ b/examples/annotation_import/pdf.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -68,22 +68,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import uuid\n",
- "import json\n",
- "import requests\n",
- "import labelbox as lb\n",
- "import labelbox.types as lb_types\n"
- ],
+ "source": "import uuid\nimport json\nimport requests\nimport labelbox as lb\nimport labelbox.types as lb_types",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -98,11 +90,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your api key\n",
- "API_KEY = \"\"\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your api key\nAPI_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -116,494 +104,70 @@
},
{
"metadata": {},
- "source": [
- "########## Entity ##########\n",
- "\n",
- "# Annotation Types\n",
- "entities_annotations = lb_types.ObjectAnnotation(\n",
- " name=\"named_entity\",\n",
- " value= lb_types.DocumentEntity(\n",
- " name=\"named_entity\",\n",
- " textSelections=[\n",
- " lb_types.DocumentTextSelection(\n",
- " token_ids=[],\n",
- " group_id=\"\",\n",
- " page=1\n",
- " )\n",
- " ]\n",
- " )\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "entities_annotations_ndjson = {\n",
- " \"name\": \"named_entity\",\n",
- " \"textSelections\": [\n",
- " {\n",
- " \"tokenIds\": [\n",
- " \"\",\n",
- " ],\n",
- " \"groupId\": \"\",\n",
- " \"page\": 1,\n",
- " }\n",
- " ]\n",
- "}"
- ],
+ "source": "########## Entity ##########\n\n# Annotation Types\nentities_annotations = lb_types.ObjectAnnotation(\n name=\"named_entity\",\n value=lb_types.DocumentEntity(\n name=\"named_entity\",\n textSelections=[\n lb_types.DocumentTextSelection(token_ids=[], group_id=\"\", page=1)\n ],\n ),\n)\n\n# NDJSON\nentities_annotations_ndjson = {\n \"name\":\n \"named_entity\",\n \"textSelections\": [{\n \"tokenIds\": [\"\",],\n \"groupId\": \"\",\n \"page\": 1,\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########### Radio Classification #########\n",
- "\n",
- "# Annotation types\n",
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question\",\n",
- " value=lb_types.Radio(answer =\n",
- " lb_types.ClassificationAnswer(name = \"first_radio_answer\")\n",
- " )\n",
- ")\n",
- "# NDJSON\n",
- "radio_annotation_ndjson = {\n",
- " \"name\": \"radio_question\",\n",
- " \"answer\": {\"name\": \"first_radio_answer\"}\n",
- "}"
- ],
+ "source": "########### Radio Classification #########\n\n# Annotation types\nradio_annotation = lb_types.ClassificationAnnotation(\n name=\"radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\")),\n)\n# NDJSON\nradio_annotation_ndjson = {\n \"name\": \"radio_question\",\n \"answer\": {\n \"name\": \"first_radio_answer\"\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "############ Checklist Classification ###########\n",
- "\n",
- "# Annotation types\n",
- "checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question\",\n",
- " value=lb_types.Checklist(answer = [\n",
- " lb_types.ClassificationAnswer(name = \"first_checklist_answer\"),\n",
- " lb_types.ClassificationAnswer(name = \"second_checklist_answer\")\n",
- " ])\n",
- " )\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "checklist_annotation_ndjson = {\n",
- " \"name\": \"checklist_question\",\n",
- " \"answer\": [\n",
- " {\"name\": \"first_checklist_answer\"},\n",
- " {\"name\": \"second_checklist_answer\"}\n",
- " ]\n",
- "}"
- ],
+ "source": "############ Checklist Classification ###########\n\n# Annotation types\nchecklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n ]),\n)\n\n# NDJSON\nchecklist_annotation_ndjson = {\n \"name\":\n \"checklist_question\",\n \"answer\": [\n {\n \"name\": \"first_checklist_answer\"\n },\n {\n \"name\": \"second_checklist_answer\"\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "############ Bounding Box ###########\n",
- "\n",
- "bbox_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"bounding_box\", # must match your ontology feature\"s name\n",
- " value=lb_types.DocumentRectangle(\n",
- " start=lb_types.Point(x=102.771, y=135.3), # x = left, y = top\n",
- " end=lb_types.Point(x=518.571, y=245.143), # x= left + width , y = top + height\n",
- " page=0,\n",
- " unit=lb_types.RectangleUnit.POINTS\n",
- " )\n",
- " )\n",
- "\n",
- "bbox_annotation_ndjson = {\n",
- " \"name\": \"bounding_box\",\n",
- " \"bbox\": {\n",
- " \"top\": 135.3,\n",
- " \"left\": 102.771,\n",
- " \"height\": 109.843,\n",
- " \"width\": 415.8\n",
- " },\n",
- " \"page\": 0,\n",
- " \"unit\": \"POINTS\"\n",
- "}"
- ],
+ "source": "############ Bounding Box ###########\n\nbbox_annotation = lb_types.ObjectAnnotation(\n name=\"bounding_box\", # must match your ontology feature\"s name\n value=lb_types.DocumentRectangle(\n start=lb_types.Point(x=102.771, y=135.3), # x = left, y = top\n end=lb_types.Point(x=518.571,\n y=245.143), # x= left + width , y = top + height\n page=0,\n unit=lb_types.RectangleUnit.POINTS,\n ),\n)\n\nbbox_annotation_ndjson = {\n \"name\": \"bounding_box\",\n \"bbox\": {\n \"top\": 135.3,\n \"left\": 102.771,\n \"height\": 109.843,\n \"width\": 415.8\n },\n \"page\": 0,\n \"unit\": \"POINTS\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# ############ global nested classifications ###########\n",
- "\n",
- "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\"\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "\n",
- "nested_checklist_annotation_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"classifications\" : [\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\"name\": \"first_sub_checklist_answer\"}\n",
- " }\n",
- " ]\n",
- " }]\n",
- "}\n",
- "\n",
- "nested_radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "\n",
- "\n",
- "nested_radio_annotation_ndjson = {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\",\n",
- " \"classifications\": [{\n",
- " \"name\":\"sub_radio_question\",\n",
- " \"answer\": { \"name\" : \"first_sub_radio_answer\"}\n",
- " }]\n",
- " }\n",
- "}\n",
- "\n"
- ],
+ "source": "# ############ global nested classifications ###########\n\nnested_checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n )\n ]),\n)\n\nnested_checklist_annotation_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\"\n },\n }],\n }],\n}\n\nnested_radio_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n)\n\nnested_radio_annotation_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\"\n },\n }],\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "############## Classification Free-form text ##############\n",
- "\n",
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"free_text\", # must match your ontology feature\"s name\n",
- " value=lb_types.Text(answer=\"sample text\")\n",
- ")\n",
- "\n",
- "\n",
- "text_annotation_ndjson = {\n",
- " \"name\": \"free_text\",\n",
- " \"answer\": \"sample text\"\n",
- "}"
- ],
+ "source": "############## Classification Free-form text ##############\n\ntext_annotation = lb_types.ClassificationAnnotation(\n name=\"free_text\", # must match your ontology feature\"s name\n value=lb_types.Text(answer=\"sample text\"),\n)\n\ntext_annotation_ndjson = {\"name\": \"free_text\", \"answer\": \"sample text\"}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "######### BBOX with nested classifications #########\n",
- "\n",
- "bbox_with_radio_subclass_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"bbox_with_radio_subclass\",\n",
- " value=lb_types.DocumentRectangle(\n",
- " start=lb_types.Point(x=317.271, y=226.757), # x = left, y = top\n",
- " end=lb_types.Point(x=566.657, y=420.986), # x= left + width , y = top + height\n",
- " unit=lb_types.RectangleUnit.POINTS,\n",
- " page=1\n",
- " ),\n",
- " classifications=[\n",
- " \tlb_types.ClassificationAnnotation(\n",
- " \tname=\"sub_radio_question\",\n",
- " \t\tvalue=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"second_sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"second_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "bbox_with_radio_subclass_annotation_ndjson = {\n",
- " \"name\": \"bbox_with_radio_subclass\",\n",
- " \"classifications\": [\n",
- " {\n",
- " \"name\": \"sub_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_sub_radio_answer\",\n",
- " \"classifications\": [\n",
- " {\n",
- " \"name\": \"second_sub_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"second_sub_radio_answer\"}\n",
- " }\n",
- " ]\n",
- " }\n",
- " }\n",
- " ],\n",
- " \"bbox\": {\n",
- " \"top\": 226.757,\n",
- " \"left\": 317.271,\n",
- " \"height\": 194.229,\n",
- " \"width\": 249.386\n",
- " },\n",
- " \"page\": 1,\n",
- " \"unit\": \"POINTS\"\n",
- "}"
- ],
+ "source": "######### BBOX with nested classifications #########\n\nbbox_with_radio_subclass_annotation = lb_types.ObjectAnnotation(\n name=\"bbox_with_radio_subclass\",\n value=lb_types.DocumentRectangle(\n start=lb_types.Point(x=317.271, y=226.757), # x = left, y = top\n end=lb_types.Point(x=566.657,\n y=420.986), # x= left + width , y = top + height\n unit=lb_types.RectangleUnit.POINTS,\n page=1,\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"second_sub_radio_question\",\n value=lb_types.Radio(\n answer=lb_types.ClassificationAnswer(\n name=\"second_sub_radio_answer\")),\n )\n ],\n )),\n )\n ],\n)\n\nbbox_with_radio_subclass_annotation_ndjson = {\n \"name\": \"bbox_with_radio_subclass\",\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\":\n \"first_sub_radio_answer\",\n \"classifications\": [{\n \"name\": \"second_sub_radio_question\",\n \"answer\": {\n \"name\": \"second_sub_radio_answer\"\n },\n }],\n },\n }],\n \"bbox\": {\n \"top\": 226.757,\n \"left\": 317.271,\n \"height\": 194.229,\n \"width\": 249.386,\n },\n \"page\": 1,\n \"unit\": \"POINTS\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "############ NER with nested classifications ########\n",
- "\n",
- "\n",
- "ner_with_checklist_subclass_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"ner_with_checklist_subclass\",\n",
- " value=lb_types.DocumentEntity(\n",
- " name=\"ner_with_checklist_subclass\",\n",
- " text_selections=[\n",
- " lb_types.DocumentTextSelection(\n",
- " token_ids=[],\n",
- " group_id=\"\",\n",
- " page=1\n",
- " )\n",
- " ]\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(name=\"first_sub_checklist_answer\")]\n",
- " )\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "\n",
- "ner_with_checklist_subclass_annotation_ndjson = {\n",
- " \"name\": \"ner_with_checklist_subclass\",\n",
- " \"classifications\":[\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": [{\"name\": \"first_sub_checklist_answer\"}]\n",
- " }\n",
- " ],\n",
- " \"textSelections\": [\n",
- " {\n",
- " \"tokenIds\": [\n",
- " \"\"\n",
- " ],\n",
- " \"groupId\": \"\",\n",
- " \"page\": 1\n",
- " }\n",
- " ]\n",
- "}\n",
- "\n"
- ],
+ "source": "############ NER with nested classifications ########\n\nner_with_checklist_subclass_annotation = lb_types.ObjectAnnotation(\n name=\"ner_with_checklist_subclass\",\n value=lb_types.DocumentEntity(\n name=\"ner_with_checklist_subclass\",\n text_selections=[\n lb_types.DocumentTextSelection(token_ids=[], group_id=\"\", page=1)\n ],\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n)\n\nner_with_checklist_subclass_annotation_ndjson = {\n \"name\":\n \"ner_with_checklist_subclass\",\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": [{\n \"name\": \"first_sub_checklist_answer\"\n }],\n }],\n \"textSelections\": [{\n \"tokenIds\": [\"\"],\n \"groupId\": \"\",\n \"page\": 1\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "######### Relationships ##########\n",
- "entity_source = lb_types.ObjectAnnotation(\n",
- " name=\"named_entity\",\n",
- " value= lb_types.DocumentEntity(\n",
- " name=\"named_entity\",\n",
- " textSelections=[\n",
- " lb_types.DocumentTextSelection(\n",
- " token_ids=[],\n",
- " group_id=\"\",\n",
- " page=1\n",
- " )\n",
- " ]\n",
- " )\n",
- ")\n",
- "\n",
- "entity_target = lb_types.ObjectAnnotation(\n",
- " name=\"named_entity\",\n",
- " value=lb_types.DocumentEntity(\n",
- " name=\"named_entity\",\n",
- " textSelections=[\n",
- " lb_types.DocumentTextSelection(\n",
- " token_ids=[],\n",
- " group_id=\"\",\n",
- " page=1\n",
- " )\n",
- " ]\n",
- " )\n",
- ")\n",
- "\n",
- "entity_relationship = lb_types.RelationshipAnnotation(\n",
- " name=\"relationship\",\n",
- " value=lb_types.Relationship(\n",
- " source=entity_source,\n",
- " target=entity_target,\n",
- " type=lb_types.Relationship.Type.UNIDIRECTIONAL,\n",
- " ))\n",
- "\n",
- "## Only supported for MAL imports\n",
- "uuid_source = str(uuid.uuid4())\n",
- "uuid_target = str(uuid.uuid4())\n",
- "\n",
- "entity_source_ndjson = {\n",
- " \"name\": \"named_entity\",\n",
- " \"uuid\": uuid_source,\n",
- " \"textSelections\": [\n",
- " {\n",
- " \"tokenIds\": [\n",
- " \"\"\n",
- " ],\n",
- " \"groupId\": \"\",\n",
- " \"page\": 1\n",
- " }\n",
- " ]\n",
- "\n",
- "}\n",
- "\n",
- "entity_target_ndjson = {\n",
- " \"name\": \"named_entity\",\n",
- " \"uuid\": uuid_target,\n",
- " \"textSelections\": [\n",
- " {\n",
- " \"tokenIds\": [\n",
- " \"\"\n",
- " ],\n",
- " \"groupId\": \"\",\n",
- " \"page\": 1\n",
- " }\n",
- " ]\n",
- "}\n",
- "ner_relationship_annotation_ndjson = {\n",
- " \"name\": \"relationship\",\n",
- " \"relationship\": {\n",
- " \"source\": uuid_source,\n",
- " \"target\": uuid_target,\n",
- " \"type\": \"unidirectional\"\n",
- " }\n",
- "}\n",
- "\n",
- "\n"
- ],
+ "source": "######### Relationships ##########\nentity_source = lb_types.ObjectAnnotation(\n name=\"named_entity\",\n value=lb_types.DocumentEntity(\n name=\"named_entity\",\n textSelections=[\n lb_types.DocumentTextSelection(token_ids=[], group_id=\"\", page=1)\n ],\n ),\n)\n\nentity_target = lb_types.ObjectAnnotation(\n name=\"named_entity\",\n value=lb_types.DocumentEntity(\n name=\"named_entity\",\n textSelections=[\n lb_types.DocumentTextSelection(token_ids=[], group_id=\"\", page=1)\n ],\n ),\n)\n\nentity_relationship = lb_types.RelationshipAnnotation(\n name=\"relationship\",\n value=lb_types.Relationship(\n source=entity_source,\n target=entity_target,\n type=lb_types.Relationship.Type.UNIDIRECTIONAL,\n ),\n)\n\n## Only supported for MAL imports\nuuid_source = str(uuid.uuid4())\nuuid_target = str(uuid.uuid4())\n\nentity_source_ndjson = {\n \"name\":\n \"named_entity\",\n \"uuid\":\n uuid_source,\n \"textSelections\": [{\n \"tokenIds\": [\"\"],\n \"groupId\": \"\",\n \"page\": 1\n }],\n}\n\nentity_target_ndjson = {\n \"name\":\n \"named_entity\",\n \"uuid\":\n uuid_target,\n \"textSelections\": [{\n \"tokenIds\": [\"\"],\n \"groupId\": \"\",\n \"page\": 1\n }],\n}\nner_relationship_annotation_ndjson = {\n \"name\": \"relationship\",\n \"relationship\": {\n \"source\": uuid_source,\n \"target\": uuid_target,\n \"type\": \"unidirectional\",\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "######### BBOX with relationships #############\n",
- "# Python Annotation\n",
- "bbox_source = lb_types.ObjectAnnotation(\n",
- " name=\"bounding_box\",\n",
- " value=lb_types.DocumentRectangle(\n",
- " start=lb_types.Point(x=188.257, y=68.875), # x = left, y = top\n",
- " end=lb_types.Point(x=270.907, y=149.556), # x = left + width , y = top + height\n",
- " unit=lb_types.RectangleUnit.POINTS,\n",
- " page=1\n",
- " ),\n",
- ")\n",
- "\n",
- "bbox_target = lb_types.ObjectAnnotation(\n",
- " name=\"bounding_box\",\n",
- " value=lb_types.DocumentRectangle(\n",
- " start=lb_types.Point(x=96.424, y=66.251),\n",
- " end=lb_types.Point(x=179.074, y=146.932),\n",
- " unit=lb_types.RectangleUnit.POINTS,\n",
- " page=1\n",
- " ),\n",
- ")\n",
- "\n",
- "bbox_relationship = lb_types.RelationshipAnnotation(\n",
- " name=\"relationship\",\n",
- " value=lb_types.Relationship(\n",
- " source=bbox_source,\n",
- " target=bbox_target,\n",
- " type=lb_types.Relationship.Type.UNIDIRECTIONAL,\n",
- " ))\n",
- "\n",
- "\n",
- "## Only supported for MAL imports\n",
- "uuid_source_2 = str(uuid.uuid4())\n",
- "uuid_target_2 = str(uuid.uuid4())\n",
- "\n",
- "bbox_source_ndjson = {\n",
- " \"name\": \"bounding_box\",\n",
- " \"uuid\": uuid_source_2,\n",
- " \"bbox\": {\n",
- " \"top\": 68.875,\n",
- " \"left\": 188.257,\n",
- " \"height\": 80.681,\n",
- " \"width\": 82.65\n",
- " },\n",
- " \"page\": 1,\n",
- " \"unit\": \"POINTS\"\n",
- "}\n",
- "\n",
- "bbox_target_ndjson = {\n",
- " \"name\": \"bounding_box\",\n",
- " \"uuid\": uuid_target_2,\n",
- " \"bbox\": {\n",
- " \"top\": 66.251,\n",
- " \"left\": 96.424,\n",
- " \"height\": 80.681,\n",
- " \"width\": 82.65\n",
- " },\n",
- " \"page\": 1,\n",
- " \"unit\": \"POINTS\"\n",
- "}\n",
- "\n",
- "bbox_relationship_annotation_ndjson = {\n",
- " \"name\": \"relationship\",\n",
- " \"relationship\": {\n",
- " \"source\": uuid_source_2,\n",
- " \"target\": uuid_target_2,\n",
- " \"type\": \"unidirectional\"\n",
- " }\n",
- "}"
- ],
+ "source": "######### BBOX with relationships #############\n# Python Annotation\nbbox_source = lb_types.ObjectAnnotation(\n name=\"bounding_box\",\n value=lb_types.DocumentRectangle(\n start=lb_types.Point(x=188.257, y=68.875), # x = left, y = top\n end=lb_types.Point(x=270.907,\n y=149.556), # x = left + width , y = top + height\n unit=lb_types.RectangleUnit.POINTS,\n page=1,\n ),\n)\n\nbbox_target = lb_types.ObjectAnnotation(\n name=\"bounding_box\",\n value=lb_types.DocumentRectangle(\n start=lb_types.Point(x=96.424, y=66.251),\n end=lb_types.Point(x=179.074, y=146.932),\n unit=lb_types.RectangleUnit.POINTS,\n page=1,\n ),\n)\n\nbbox_relationship = lb_types.RelationshipAnnotation(\n name=\"relationship\",\n value=lb_types.Relationship(\n source=bbox_source,\n target=bbox_target,\n type=lb_types.Relationship.Type.UNIDIRECTIONAL,\n ),\n)\n\n## Only supported for MAL imports\nuuid_source_2 = str(uuid.uuid4())\nuuid_target_2 = str(uuid.uuid4())\n\nbbox_source_ndjson = {\n \"name\": \"bounding_box\",\n \"uuid\": uuid_source_2,\n \"bbox\": {\n \"top\": 68.875,\n \"left\": 188.257,\n \"height\": 80.681,\n \"width\": 82.65\n },\n \"page\": 1,\n \"unit\": \"POINTS\",\n}\n\nbbox_target_ndjson = {\n \"name\": \"bounding_box\",\n \"uuid\": uuid_target_2,\n \"bbox\": {\n \"top\": 66.251,\n \"left\": 96.424,\n \"height\": 80.681,\n \"width\": 82.65\n },\n \"page\": 1,\n \"unit\": \"POINTS\",\n}\n\nbbox_relationship_annotation_ndjson = {\n \"name\": \"relationship\",\n \"relationship\": {\n \"source\": uuid_source_2,\n \"target\": uuid_target_2,\n \"type\": \"unidirectional\",\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -641,29 +205,7 @@
},
{
"metadata": {},
- "source": [
- "global_key = \"0801.3483_doc.pdf\"\n",
- "img_url = {\n",
- " \"row_data\": {\n",
- " \"pdf_url\": \"https://storage.googleapis.com/labelbox-datasets/arxiv-pdf/data/99-word-token-pdfs/0801.3483.pdf\"\n",
- " },\n",
- " \"global_key\": global_key\n",
- "}\n",
- "\n",
- "\n",
- "dataset = client.create_dataset(name=\"pdf_demo_dataset\")\n",
- "task = dataset.create_data_rows([img_url])\n",
- "task.wait_till_done()\n",
- "print(f\"Failed data rows: {task.failed_data_rows}\")\n",
- "print(f\"Errors: {task.errors}\")\n",
- "\n",
- "if task.errors:\n",
- " for error in task.errors:\n",
- " if 'Duplicate global key' in error['message'] and dataset.row_count == 0:\n",
- " # If the global key already exists in the workspace the dataset will be created empty, so we can delete it.\n",
- " print(f\"Deleting empty dataset: {dataset}\")\n",
- " dataset.delete()"
- ],
+ "source": "global_key = \"0801.3483_doc.pdf\"\nimg_url = {\n \"row_data\": {\n \"pdf_url\":\n \"https://storage.googleapis.com/labelbox-datasets/arxiv-pdf/data/99-word-token-pdfs/0801.3483.pdf\"\n },\n \"global_key\": global_key,\n}\n\ndataset = client.create_dataset(name=\"pdf_demo_dataset\")\ntask = dataset.create_data_rows([img_url])\ntask.wait_till_done()\nprint(f\"Failed data rows: {task.failed_data_rows}\")\nprint(f\"Errors: {task.errors}\")\n\nif task.errors:\n for error in task.errors:\n if (\"Duplicate global key\" in error[\"message\"] and\n dataset.row_count == 0):\n # If the global key already exists in the workspace the dataset will be created empty, so we can delete it.\n print(f\"Deleting empty dataset: {dataset}\")\n dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -678,104 +220,7 @@
},
{
"metadata": {},
- "source": [
- "## Setup the ontology and link the tools created above.\n",
- "\n",
- "ontology_builder = lb.OntologyBuilder(\n",
- " classifications=[ # List of Classification objects\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_question\",\n",
- " scope = lb.Classification.Scope.GLOBAL,\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\"),\n",
- " lb.Option(value=\"second_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_question\",\n",
- " scope = lb.Classification.Scope.GLOBAL,\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"free_text\",\n",
- " scope = lb.Classification.Scope.GLOBAL\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " scope = lb.Classification.Scope.GLOBAL,\n",
- " options=[\n",
- " lb.Option(\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[lb.Option(\"first_sub_radio_answer\")]\n",
- " )\n",
- " ])\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " scope = lb.Classification.Scope.GLOBAL,\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ])\n",
- " ]\n",
- " ),\n",
- " ],\n",
- " tools=[ # List of Tool objects\n",
- " lb.Tool( tool=lb.Tool.Type.BBOX,name=\"bounding_box\"),\n",
- " lb.Tool(tool=lb.Tool.Type.NER, name=\"named_entity\"),\n",
- " lb.Tool(tool=lb.Tool.Type.RELATIONSHIP,name=\"relationship\"),\n",
- " lb.Tool(tool=lb.Tool.Type.NER,\n",
- " name=\"ner_with_checklist_subclass\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_sub_checklist_answer\")\n",
- " ]\n",
- " )\n",
- " ]),\n",
- " lb.Tool( tool=lb.Tool.Type.BBOX,\n",
- " name=\"bbox_with_radio_subclass\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[\n",
- " lb.Option(\n",
- " value=\"first_sub_radio_answer\" ,\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"second_sub_radio_question\",\n",
- " options=[lb.Option(\"second_sub_radio_answer\")]\n",
- " )]\n",
- " )]\n",
- " )]\n",
- " )]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Document Annotation Import Demo\",\n",
- " ontology_builder.asdict(),\n",
- " media_type=lb.MediaType.Document)"
- ],
+ "source": "## Setup the ontology and link the tools created above.\n\nontology_builder = lb.OntologyBuilder(\n classifications=[ # List of Classification objects\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_question\",\n scope=lb.Classification.Scope.GLOBAL,\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_question\",\n scope=lb.Classification.Scope.GLOBAL,\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.TEXT,\n name=\"free_text\",\n scope=lb.Classification.Scope.GLOBAL,\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n scope=lb.Classification.Scope.GLOBAL,\n options=[\n lb.Option(\n \"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(\"first_sub_radio_answer\")],\n )\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n scope=lb.Classification.Scope.GLOBAL,\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n ],\n tools=[ # List of Tool objects\n lb.Tool(tool=lb.Tool.Type.BBOX, name=\"bounding_box\"),\n lb.Tool(tool=lb.Tool.Type.NER, name=\"named_entity\"),\n lb.Tool(tool=lb.Tool.Type.RELATIONSHIP, name=\"relationship\"),\n lb.Tool(\n tool=lb.Tool.Type.NER,\n name=\"ner_with_checklist_subclass\",\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(value=\"first_sub_checklist_answer\")],\n )\n ],\n ),\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"bbox_with_radio_subclass\",\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[\n lb.Option(\n value=\"first_sub_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"second_sub_radio_question\",\n options=[\n lb.Option(\"second_sub_radio_answer\")\n ],\n )\n ],\n )\n ],\n )\n ],\n ),\n ],\n)\n\nontology = client.create_ontology(\n \"Document Annotation Import Demo\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Document,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -789,12 +234,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Labelbox project\n",
- "project = client.create_project(name=\"PDF_annotation_demo\",\n",
- " media_type=lb.MediaType.Document)\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "# Create a Labelbox project\nproject = client.create_project(name=\"PDF_annotation_demo\",\n media_type=lb.MediaType.Document)\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -808,13 +248,7 @@
},
{
"metadata": {},
- "source": [
- "project.create_batch(\n",
- " \"PDF_annotation_batch\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")"
- ],
+ "source": "project.create_batch(\n \"PDF_annotation_batch\", # Each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # Paginated collection of data row objects, list of data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -848,98 +282,14 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "client.enable_experimental = True\n",
- "task = lb.DataRow.export(client=client,global_keys=[global_key])\n",
- "task.wait_till_done()\n",
- "stream = task.get_stream()\n",
- "\n",
- "text_layer = \"\"\n",
- "for output in stream:\n",
- " output_json = json.loads(output.json_str)\n",
- " text_layer = output_json['media_attributes']['text_layer_url']\n",
- "print(text_layer)"
- ],
+ "source": "client.enable_experimental = True\ntask = lb.DataRow.export(client=client, global_keys=[global_key])\ntask.wait_till_done()\nstream = task.get_stream()\n\ntext_layer = \"\"\nfor output in stream:\n output_json = json.loads(output.json_str)\n text_layer = output_json[\"media_attributes\"][\"text_layer_url\"]\nprint(text_layer)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "\n",
- "# Helper method\n",
- "def update_text_selections(annotation, group_id, list_tokens, page):\n",
- " return annotation.update({\n",
- " \"textSelections\": [\n",
- " {\n",
- " \"groupId\": group_id,\n",
- " \"tokenIds\": list_tokens,\n",
- " \"page\": page\n",
- " }\n",
- " ]\n",
- " })\n",
- "\n",
- "\n",
- "# Fetch the content of the text layer\n",
- "res = requests.get(text_layer)\n",
- "\n",
- "# Phrases that we want to annotation obtained from the text layer url\n",
- "content_phrases = [\"Metal-insulator (MI) transitions have been one of the\" ,\n",
- " \"T. Sasaki, N. Yoneyama, and N. Kobayashi\",\n",
- " \"Organic charge transfer salts based on the donor\",\n",
- " \"the experimental investigations on this issue have not\"]\n",
- "\n",
- "# Parse the text layer\n",
- "text_selections = []\n",
- "text_selections_ner = []\n",
- "text_selections_source = []\n",
- "text_selections_target = []\n",
- "\n",
- "for obj in json.loads(res.text):\n",
- " for group in obj[\"groups\"]:\n",
- " if group[\"content\"] == content_phrases[0]:\n",
- " list_tokens = [x[\"id\"] for x in group[\"tokens\"]]\n",
- " # build text selections for Python Annotation Types\n",
- " document_text_selection = lb_types.DocumentTextSelection(groupId=group[\"id\"], tokenIds=list_tokens, page=1)\n",
- " text_selections.append(document_text_selection)\n",
- " # build text selection for the NDJson annotations\n",
- " update_text_selections(annotation=entities_annotations_ndjson,\n",
- " group_id=group[\"id\"], # id representing group of words\n",
- " list_tokens=list_tokens, # ids representing individual words from the group\n",
- " page=1)\n",
- " if group[\"content\"] == content_phrases[1]:\n",
- " list_tokens_2 = [x[\"id\"] for x in group[\"tokens\"]]\n",
- " # build text selections for Python Annotation Types\n",
- " ner_text_selection = lb_types.DocumentTextSelection(groupId=group[\"id\"], tokenIds=list_tokens_2, page=1)\n",
- " text_selections_ner.append(ner_text_selection)\n",
- " # build text selection for the NDJson annotations\n",
- " update_text_selections(annotation=ner_with_checklist_subclass_annotation_ndjson,\n",
- " group_id=group[\"id\"], # id representing group of words\n",
- " list_tokens=list_tokens_2, # ids representing individual words from the group\n",
- " page=1)\n",
- " if group[\"content\"] == content_phrases[2]:\n",
- " relationship_source = [x[\"id\"] for x in group[\"tokens\"]]\n",
- " # build text selections for Python Annotation Types\n",
- " text_selection_entity_source = lb_types.DocumentTextSelection(groupId=group[\"id\"], tokenIds=relationship_source, page=1)\n",
- " text_selections_source.append(text_selection_entity_source)\n",
- " # build text selection for the NDJson annotations\n",
- " update_text_selections(annotation=entity_source_ndjson,\n",
- " group_id=group[\"id\"], # id representing group of words\n",
- " list_tokens=relationship_source, # ids representing individual words from the group\n",
- " page=1)\n",
- " if group[\"content\"] == content_phrases[3]:\n",
- " relationship_target = [x[\"id\"] for x in group[\"tokens\"]]\n",
- " # build text selections for Python Annotation Types\n",
- " text_selection_entity_target = lb_types.DocumentTextSelection(group_id=group[\"id\"], tokenIds=relationship_target, page=1)\n",
- " text_selections_target.append(text_selection_entity_target)\n",
- " # build text selections forthe NDJson annotations\n",
- " update_text_selections(annotation=entity_target_ndjson,\n",
- " group_id=group[\"id\"], # id representing group of words\n",
- " list_tokens=relationship_target, # ids representing individual words from the group\n",
- " page=1)\n"
- ],
+ "source": "# Helper method\ndef update_text_selections(annotation, group_id, list_tokens, page):\n return annotation.update({\n \"textSelections\": [{\n \"groupId\": group_id,\n \"tokenIds\": list_tokens,\n \"page\": page\n }]\n })\n\n\n# Fetch the content of the text layer\nres = requests.get(text_layer)\n\n# Phrases that we want to annotation obtained from the text layer url\ncontent_phrases = [\n \"Metal-insulator (MI) transitions have been one of the\",\n \"T. Sasaki, N. Yoneyama, and N. Kobayashi\",\n \"Organic charge transfer salts based on the donor\",\n \"the experimental investigations on this issue have not\",\n]\n\n# Parse the text layer\ntext_selections = []\ntext_selections_ner = []\ntext_selections_source = []\ntext_selections_target = []\n\nfor obj in json.loads(res.text):\n for group in obj[\"groups\"]:\n if group[\"content\"] == content_phrases[0]:\n list_tokens = [x[\"id\"] for x in group[\"tokens\"]]\n # build text selections for Python Annotation Types\n document_text_selection = lb_types.DocumentTextSelection(\n groupId=group[\"id\"], tokenIds=list_tokens, page=1)\n text_selections.append(document_text_selection)\n # build text selection for the NDJson annotations\n update_text_selections(\n annotation=entities_annotations_ndjson,\n group_id=group[\"id\"], # id representing group of words\n list_tokens=\n list_tokens, # ids representing individual words from the group\n page=1,\n )\n if group[\"content\"] == content_phrases[1]:\n list_tokens_2 = [x[\"id\"] for x in group[\"tokens\"]]\n # build text selections for Python Annotation Types\n ner_text_selection = lb_types.DocumentTextSelection(\n groupId=group[\"id\"], tokenIds=list_tokens_2, page=1)\n text_selections_ner.append(ner_text_selection)\n # build text selection for the NDJson annotations\n update_text_selections(\n annotation=ner_with_checklist_subclass_annotation_ndjson,\n group_id=group[\"id\"], # id representing group of words\n list_tokens=\n list_tokens_2, # ids representing individual words from the group\n page=1,\n )\n if group[\"content\"] == content_phrases[2]:\n relationship_source = [x[\"id\"] for x in group[\"tokens\"]]\n # build text selections for Python Annotation Types\n text_selection_entity_source = lb_types.DocumentTextSelection(\n groupId=group[\"id\"], tokenIds=relationship_source, page=1)\n text_selections_source.append(text_selection_entity_source)\n # build text selection for the NDJson annotations\n update_text_selections(\n annotation=entity_source_ndjson,\n group_id=group[\"id\"], # id representing group of words\n list_tokens=\n relationship_source, # ids representing individual words from the group\n page=1,\n )\n if group[\"content\"] == content_phrases[3]:\n relationship_target = [x[\"id\"] for x in group[\"tokens\"]]\n # build text selections for Python Annotation Types\n text_selection_entity_target = lb_types.DocumentTextSelection(\n group_id=group[\"id\"], tokenIds=relationship_target, page=1)\n text_selections_target.append(text_selection_entity_target)\n # build text selections forthe NDJson annotations\n update_text_selections(\n annotation=entity_target_ndjson,\n group_id=group[\"id\"], # id representing group of words\n list_tokens=\n relationship_target, # ids representing individual words from the group\n page=1,\n )",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -953,58 +303,14 @@
},
{
"metadata": {},
- "source": [
- "#re-write the entity annotation with text selections\n",
- "entities_annotation_document_entity = lb_types.DocumentEntity(name=\"named_entity\", textSelections = text_selections)\n",
- "entities_annotation = lb_types.ObjectAnnotation(name=\"named_entity\",value=entities_annotation_document_entity)\n",
- "\n",
- "# re-write the entity annotation + subclassification with text selections\n",
- "classifications = [\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(name=\"first_sub_checklist_answer\")]\n",
- " )\n",
- " )\n",
- " ]\n",
- "ner_annotation_with_subclass = lb_types.DocumentEntity(name=\"ner_with_checklist_subclass\", textSelections= text_selections_ner)\n",
- "ner_with_checklist_subclass_annotation = lb_types.ObjectAnnotation(name=\"ner_with_checklist_subclass\",\n",
- " value=ner_annotation_with_subclass,\n",
- " classifications=classifications)\n",
- "\n",
- "#re-write the entity source and target annotations withe text selectios\n",
- "entity_source_doc = lb_types.DocumentEntity(name=\"named_entity\", text_selections= text_selections_source)\n",
- "entity_source = lb_types.ObjectAnnotation(name=\"named_entity\", value=entity_source_doc)\n",
- "\n",
- "entity_target_doc = lb_types.DocumentEntity(name=\"named_entity\", text_selections=text_selections_target)\n",
- "entity_target = lb_types.ObjectAnnotation(name=\"named_entity\", value=entity_target_doc)\n",
- "\n",
- "# re-write the entity relationship with the re-created entities\n",
- "entity_relationship = lb_types.RelationshipAnnotation(\n",
- " name=\"relationship\",\n",
- " value=lb_types.Relationship(\n",
- " source=entity_source,\n",
- " target=entity_target,\n",
- " type=lb_types.Relationship.Type.UNIDIRECTIONAL,\n",
- " ))\n"
- ],
+ "source": "# re-write the entity annotation with text selections\nentities_annotation_document_entity = lb_types.DocumentEntity(\n name=\"named_entity\", textSelections=text_selections)\nentities_annotation = lb_types.ObjectAnnotation(\n name=\"named_entity\", value=entities_annotation_document_entity)\n\n# re-write the entity annotation + subclassification with text selections\nclassifications = [\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_sub_checklist_answer\")\n ]),\n )\n]\nner_annotation_with_subclass = lb_types.DocumentEntity(\n name=\"ner_with_checklist_subclass\", textSelections=text_selections_ner)\nner_with_checklist_subclass_annotation = lb_types.ObjectAnnotation(\n name=\"ner_with_checklist_subclass\",\n value=ner_annotation_with_subclass,\n classifications=classifications,\n)\n\n# re-write the entity source and target annotations withe text selectios\nentity_source_doc = lb_types.DocumentEntity(\n name=\"named_entity\", text_selections=text_selections_source)\nentity_source = lb_types.ObjectAnnotation(name=\"named_entity\",\n value=entity_source_doc)\n\nentity_target_doc = lb_types.DocumentEntity(\n name=\"named_entity\", text_selections=text_selections_target)\nentity_target = lb_types.ObjectAnnotation(name=\"named_entity\",\n value=entity_target_doc)\n\n# re-write the entity relationship with the re-created entities\nentity_relationship = lb_types.RelationshipAnnotation(\n name=\"relationship\",\n value=lb_types.Relationship(\n source=entity_source,\n target=entity_target,\n type=lb_types.Relationship.Type.UNIDIRECTIONAL,\n ),\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Final NDJSON and python annotations\n",
- "print(f\"entities_annotations_ndjson={entities_annotations_ndjson}\")\n",
- "print(f\"entities_annotation={entities_annotation}\")\n",
- "print(f\"nested_entities_annotation_ndjson={ner_with_checklist_subclass_annotation_ndjson}\")\n",
- "print(f\"nested_entities_annotation={ner_with_checklist_subclass_annotation}\")\n",
- "print(f\"entity_source_ndjson={entity_source_ndjson}\")\n",
- "print(f\"entity_target_ndjson={entity_target_ndjson}\")\n",
- "print(f\"entity_source={entity_source}\")\n",
- "print(f\"entity_target={entity_target}\")"
- ],
+ "source": "# Final NDJSON and python annotations\nprint(f\"entities_annotations_ndjson={entities_annotations_ndjson}\")\nprint(f\"entities_annotation={entities_annotation}\")\nprint(\n f\"nested_entities_annotation_ndjson={ner_with_checklist_subclass_annotation_ndjson}\"\n)\nprint(f\"nested_entities_annotation={ner_with_checklist_subclass_annotation}\")\nprint(f\"entity_source_ndjson={entity_source_ndjson}\")\nprint(f\"entity_target_ndjson={entity_target_ndjson}\")\nprint(f\"entity_source={entity_source}\")\nprint(f\"entity_target={entity_target}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1019,32 +325,7 @@
},
{
"metadata": {},
- "source": [
- "labels = []\n",
- "\n",
- "labels.append(\n",
- " lb_types.Label(\n",
- " data={\"global_key\" : global_key },\n",
- " annotations = [\n",
- " entities_annotation,\n",
- " checklist_annotation,\n",
- " nested_checklist_annotation,\n",
- " text_annotation,\n",
- " radio_annotation,\n",
- " nested_radio_annotation,\n",
- " bbox_annotation,\n",
- " bbox_with_radio_subclass_annotation,\n",
- " ner_with_checklist_subclass_annotation,\n",
- " entity_source,\n",
- " entity_target,\n",
- " entity_relationship,# Only supported for MAL imports\n",
- " bbox_source,\n",
- " bbox_target,\n",
- " bbox_relationship # Only supported for MAL imports\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "labels = []\n\nlabels.append(\n lb_types.Label(\n data={\"global_key\": global_key},\n annotations=[\n entities_annotation,\n checklist_annotation,\n nested_checklist_annotation,\n text_annotation,\n radio_annotation,\n nested_radio_annotation,\n bbox_annotation,\n bbox_with_radio_subclass_annotation,\n ner_with_checklist_subclass_annotation,\n entity_source,\n entity_target,\n entity_relationship, # Only supported for MAL imports\n bbox_source,\n bbox_target,\n bbox_relationship, # Only supported for MAL imports\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1059,32 +340,7 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "label_ndjson = []\n",
- "for annot in [\n",
- " entities_annotations_ndjson,\n",
- " checklist_annotation_ndjson,\n",
- " nested_checklist_annotation_ndjson,\n",
- " text_annotation_ndjson,\n",
- " radio_annotation_ndjson,\n",
- " nested_radio_annotation_ndjson,\n",
- " bbox_annotation_ndjson,\n",
- " bbox_with_radio_subclass_annotation_ndjson,\n",
- " ner_with_checklist_subclass_annotation_ndjson,\n",
- " entity_source_ndjson,\n",
- " entity_target_ndjson,\n",
- " ner_relationship_annotation_ndjson, # Only supported for MAL imports\n",
- " bbox_source_ndjson,\n",
- " bbox_target_ndjson,\n",
- " bbox_relationship_annotation_ndjson # Only supported for MAL imports\n",
- " ]:\n",
- " annot.update({\n",
- " \"dataRow\": {\"globalKey\": global_key},\n",
- " })\n",
- " label_ndjson.append(annot)\n",
- "\n"
- ],
+ "source": "label_ndjson = []\nfor annot in [\n entities_annotations_ndjson,\n checklist_annotation_ndjson,\n nested_checklist_annotation_ndjson,\n text_annotation_ndjson,\n radio_annotation_ndjson,\n nested_radio_annotation_ndjson,\n bbox_annotation_ndjson,\n bbox_with_radio_subclass_annotation_ndjson,\n ner_with_checklist_subclass_annotation_ndjson,\n entity_source_ndjson,\n entity_target_ndjson,\n ner_relationship_annotation_ndjson, # Only supported for MAL imports\n bbox_source_ndjson,\n bbox_target_ndjson,\n bbox_relationship_annotation_ndjson, # Only supported for MAL imports\n]:\n annot.update({\n \"dataRow\": {\n \"globalKey\": global_key\n },\n })\n label_ndjson.append(annot)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1106,18 +362,7 @@
},
{
"metadata": {},
- "source": [
- "upload_job = lb.MALPredictionImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"pdf_annotation_upload\" + str(uuid.uuid4()),\n",
- " predictions=labels)\n",
- "\n",
- "upload_job.wait_until_done()\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job.errors)\n",
- "print(\"Status of uploads: \", upload_job.statuses)"
- ],
+ "source": "upload_job = lb.MALPredictionImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"pdf_annotation_upload\" + str(uuid.uuid4()),\n predictions=labels,\n)\n\nupload_job.wait_until_done()\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job.errors)\nprint(\"Status of uploads: \", upload_job.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1131,19 +376,7 @@
},
{
"metadata": {},
- "source": [
- "# Uncomment this code when excluding relationships from label import\n",
- "## Relationships are not currently supported for label import\n",
- "\n",
- "# upload_job = lb.LabelImport.create_from_objects(\n",
- "# client = client,\n",
- "# project_id = project.uid,\n",
- "# name=\"label_import_job\"+str(uuid.uuid4()),\n",
- "# labels=labels) ## Remove unsupported relationships from the labels list\n",
- "\n",
- "# print(\"Errors:\", upload_job.errors)\n",
- "# print(\"Status of uploads: \", upload_job.statuses)"
- ],
+ "source": "# Uncomment this code when excluding relationships from label import\n## Relationships are not currently supported for label import\n\n# upload_job = lb.LabelImport.create_from_objects(\n# client = client,\n# project_id = project.uid,\n# name=\"label_import_job\"+str(uuid.uuid4()),\n# labels=labels) ## Remove unsupported relationships from the labels list\n\n# print(\"Errors:\", upload_job.errors)\n# print(\"Status of uploads: \", upload_job.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/annotation_import/text.ipynb b/examples/annotation_import/text.ipynb
index 749320caf..1d4bb99d6 100644
--- a/examples/annotation_import/text.ipynb
+++ b/examples/annotation_import/text.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -76,21 +76,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import labelbox.types as lb_types\n",
- "import uuid\n",
- "import json"
- ],
+ "source": "import labelbox as lb\nimport labelbox.types as lb_types\nimport uuid\nimport json",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -105,11 +98,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your api key\n",
- "API_KEY=\"\"\n",
- "client = lb.Client(API_KEY)\n"
- ],
+ "source": "# Add your api key\nAPI_KEY = \"\"\nclient = lb.Client(API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -130,167 +119,35 @@
},
{
"metadata": {},
- "source": [
- "########## Entities ##########\n",
- "\n",
- "# Python annotation\n",
- "named_entity = lb_types.TextEntity(start=10, end=20)\n",
- "named_entitity_annotation = lb_types.ObjectAnnotation(value=named_entity, name = \"named_entity\")\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "entities_ndjson = {\n",
- " \"name\": \"named_entity\",\n",
- " \"location\": {\n",
- " \"start\": 67,\n",
- " \"end\": 128\n",
- " }\n",
- "}"
- ],
+ "source": "########## Entities ##########\n\n# Python annotation\nnamed_entity = lb_types.TextEntity(start=10, end=20)\nnamed_entitity_annotation = lb_types.ObjectAnnotation(value=named_entity,\n name=\"named_entity\")\n\n# NDJSON\nentities_ndjson = {\n \"name\": \"named_entity\",\n \"location\": {\n \"start\": 67,\n \"end\": 128\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########## Classification - Radio (single choice ) ##########\n",
- "\n",
- "# Python annotation\n",
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question\",\n",
- " value=lb_types.Radio(answer =\n",
- " lb_types.ClassificationAnswer(name = \"first_radio_answer\")\n",
- " )\n",
- ")\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "radio_annotation_ndjson = {\n",
- " \"name\": \"radio_question\",\n",
- " \"answer\": {\"name\": \"first_radio_answer\"}\n",
- "}"
- ],
+ "source": "########## Classification - Radio (single choice ) ##########\n\n# Python annotation\nradio_annotation = lb_types.ClassificationAnnotation(\n name=\"radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\")),\n)\n\n# NDJSON\nradio_annotation_ndjson = {\n \"name\": \"radio_question\",\n \"answer\": {\n \"name\": \"first_radio_answer\"\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########## Classification - Radio and Checklist (with subclassifications) ##########\n",
- "\n",
- "nested_radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "# NDJSON\n",
- "nested_radio_annotation_ndjson= {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\",\n",
- " \"classifications\": [{\n",
- " \"name\":\"sub_radio_question\",\n",
- " \"answer\": { \"name\" : \"first_sub_radio_answer\"}\n",
- " }]\n",
- " }\n",
- "}\n",
- "\n",
- "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\"\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "nested_checklist_annotation_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"classifications\" : [\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\"name\": \"first_sub_checklist_answer\"}\n",
- " }\n",
- " ]\n",
- " }]\n",
- "}"
- ],
+ "source": "########## Classification - Radio and Checklist (with subclassifications) ##########\n\nnested_radio_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n)\n# NDJSON\nnested_radio_annotation_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\"\n },\n }],\n },\n}\n\nnested_checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n )\n ]),\n)\nnested_checklist_annotation_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\"\n },\n }],\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########## Classification - Checklist (Multi-choice) ##########\n",
- "\n",
- "# Python annotation\n",
- "checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question\",\n",
- " value=lb_types.Checklist(answer = [\n",
- " lb_types.ClassificationAnswer(name = \"first_checklist_answer\"),\n",
- " lb_types.ClassificationAnswer(name = \"second_checklist_answer\"),\n",
- " lb_types.ClassificationAnswer(name = \"third_checklist_answer\")\n",
- " ])\n",
- " )\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "checklist_annotation_ndjson = {\n",
- " \"name\": \"checklist_question\",\n",
- " \"answer\": [\n",
- " {\"name\": \"first_checklist_answer\"},\n",
- " {\"name\": \"second_checklist_answer\"},\n",
- " {\"name\": \"third_checklist_answer\"},\n",
- " ]\n",
- "}"
- ],
+ "source": "########## Classification - Checklist (Multi-choice) ##########\n\n# Python annotation\nchecklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"third_checklist_answer\"),\n ]),\n)\n\n# NDJSON\nchecklist_annotation_ndjson = {\n \"name\":\n \"checklist_question\",\n \"answer\": [\n {\n \"name\": \"first_checklist_answer\"\n },\n {\n \"name\": \"second_checklist_answer\"\n },\n {\n \"name\": \"third_checklist_answer\"\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########## Classification Free-Form text ##########\n",
- "\n",
- "# Python annotation\n",
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name = \"free_text\",\n",
- " value = lb_types.Text(answer=\"sample text\")\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "text_annotation_ndjson = {\n",
- " \"name\": \"free_text\",\n",
- " \"answer\": \"sample text\",\n",
- "}"
- ],
+ "source": "########## Classification Free-Form text ##########\n\n# Python annotation\ntext_annotation = lb_types.ClassificationAnnotation(\n name=\"free_text\", value=lb_types.Text(answer=\"sample text\"))\n\n# NDJSON\ntext_annotation_ndjson = {\n \"name\": \"free_text\",\n \"answer\": \"sample text\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -311,25 +168,7 @@
},
{
"metadata": {},
- "source": [
- "# You can now include ohter fields like attachments, media type and metadata in the data row creation step: https://docs.labelbox.com/reference/text-file\n",
- "global_key = \"lorem-ipsum.txt\"\n",
- "text_asset = {\n",
- " \"row_data\": \"https://storage.googleapis.com/labelbox-sample-datasets/nlp/lorem-ipsum.txt\",\n",
- " \"global_key\": global_key,\n",
- " \"media_type\": \"TEXT\",\n",
- " \"attachments\": [{\"type\": \"TEXT_URL\", \"value\": \"https://storage.googleapis.com/labelbox-sample-datasets/Docs/text_attachment.txt\"}]\n",
- " }\n",
- "\n",
- "dataset = client.create_dataset(\n",
- " name=\"text_annotation_import_demo_dataset\",\n",
- " iam_integration=None # Removing this argument will default to the organziation's default iam integration\n",
- ")\n",
- "task = dataset.create_data_rows([text_asset])\n",
- "task.wait_till_done()\n",
- "print(\"Errors:\",task.errors)\n",
- "print(\"Failed data rows:\", task.failed_data_rows)"
- ],
+ "source": "# You can now include ohter fields like attachments, media type and metadata in the data row creation step: https://docs.labelbox.com/reference/text-file\nglobal_key = \"lorem-ipsum.txt\"\ntext_asset = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-sample-datasets/nlp/lorem-ipsum.txt\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"TEXT\",\n \"attachments\": [{\n \"type\":\n \"TEXT_URL\",\n \"value\":\n \"https://storage.googleapis.com/labelbox-sample-datasets/Docs/text_attachment.txt\",\n }],\n}\n\ndataset = client.create_dataset(\n name=\"text_annotation_import_demo_dataset\",\n iam_integration=\n None, # Removing this argument will default to the organziation's default iam integration\n)\ntask = dataset.create_data_rows([text_asset])\ntask.wait_till_done()\nprint(\"Errors:\", task.errors)\nprint(\"Failed data rows:\", task.failed_data_rows)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -348,72 +187,7 @@
},
{
"metadata": {},
- "source": [
- "## Setup the ontology and link the tools created above.\n",
- "\n",
- "ontology_builder = lb.OntologyBuilder(\n",
- " classifications=[ # List of Classification objects\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_question\",\n",
- " options=[lb.Option(value=\"first_radio_answer\")]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_sub_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " ]\n",
- " ),\n",
- " ],\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\"),\n",
- " lb.Option(value=\"third_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification( # Text classification given the name \"text\"\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"free_text\"\n",
- " )\n",
- " ],\n",
- " tools=[ # List of Tool objects\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.NER,\n",
- " name=\"named_entity\"\n",
- " ),\n",
- " ]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Ontology Text Annotations\", ontology_builder.asdict())\n"
- ],
+ "source": "## Setup the ontology and link the tools created above.\n\nontology_builder = lb.OntologyBuilder(\n classifications=[ # List of Classification objects\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_question\",\n options=[lb.Option(value=\"first_radio_answer\")],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n options=[\n lb.Option(\n value=\"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(value=\"first_sub_radio_answer\")],\n ),\n ],\n ),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_question\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n lb.Option(value=\"third_checklist_answer\"),\n ],\n ),\n lb.Classification( # Text classification given the name \"text\"\n class_type=lb.Classification.Type.TEXT,\n name=\"free_text\"),\n ],\n tools=[ # List of Tool objects\n lb.Tool(tool=lb.Tool.Type.NER, name=\"named_entity\"),\n ],\n)\n\nontology = client.create_ontology(\"Ontology Text Annotations\",\n ontology_builder.asdict())",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -428,16 +202,7 @@
},
{
"metadata": {},
- "source": [
- "# Project defaults to batch mode with benchmark quality settings if this argument is not provided\n",
- "# Queue mode will be deprecated once dataset mode is deprecated\n",
- "\n",
- "project = client.create_project(name=\"Text Annotation Import Demo\",\n",
- " media_type=lb.MediaType.Text)\n",
- "\n",
- "\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "# Project defaults to batch mode with benchmark quality settings if this argument is not provided\n# Queue mode will be deprecated once dataset mode is deprecated\n\nproject = client.create_project(name=\"Text Annotation Import Demo\",\n media_type=lb.MediaType.Text)\n\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -451,18 +216,7 @@
},
{
"metadata": {},
- "source": [
- "# Setup Batches and Ontology\n",
- "\n",
- "# Create a batch to send to your MAL project\n",
- "batch = project.create_batch(\n",
- " \"first-batch-text-demo\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")\n",
- "\n",
- "print(\"Batch: \", batch)"
- ],
+ "source": "# Setup Batches and Ontology\n\n# Create a batch to send to your MAL project\nbatch = project.create_batch(\n \"first-batch-text-demo\", # Each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # Paginated collection of data row objects, list of data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)\n\nprint(\"Batch: \", batch)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -487,23 +241,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Label\n",
- "labels = []\n",
- "labels.append(\n",
- " lb_types.Label(\n",
- " data={\"global_key\" : global_key },\n",
- " annotations = [\n",
- " named_entitity_annotation,\n",
- " radio_annotation,\n",
- " checklist_annotation,\n",
- " text_annotation,\n",
- " nested_checklist_annotation,\n",
- " nested_radio_annotation\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "# Create a Label\nlabels = []\nlabels.append(\n lb_types.Label(\n data={\"global_key\": global_key},\n annotations=[\n named_entitity_annotation,\n radio_annotation,\n checklist_annotation,\n text_annotation,\n nested_checklist_annotation,\n nested_radio_annotation,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -517,20 +255,7 @@
},
{
"metadata": {},
- "source": [
- "label_ndjson = []\n",
- "for annotations in [entities_ndjson,\n",
- " radio_annotation_ndjson,\n",
- " checklist_annotation_ndjson,\n",
- " text_annotation_ndjson,\n",
- " nested_radio_annotation_ndjson,\n",
- " nested_checklist_annotation_ndjson,\n",
- " ] :\n",
- " annotations.update({\n",
- " \"dataRow\": { \"globalKey\": global_key }\n",
- " })\n",
- " label_ndjson.append(annotations)"
- ],
+ "source": "label_ndjson = []\nfor annotations in [\n entities_ndjson,\n radio_annotation_ndjson,\n checklist_annotation_ndjson,\n text_annotation_ndjson,\n nested_radio_annotation_ndjson,\n nested_checklist_annotation_ndjson,\n]:\n annotations.update({\"dataRow\": {\"globalKey\": global_key}})\n label_ndjson.append(annotations)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -554,18 +279,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload MAL label for this data row in project\n",
- "upload_job_mal = lb.MALPredictionImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"mal_import_job\"+str(uuid.uuid4()),\n",
- " predictions=labels)\n",
- "\n",
- "upload_job_mal.wait_until_done()\n",
- "print(\"Errors:\", upload_job_mal.errors)\n",
- "print(\"Status of uploads: \", upload_job_mal.statuses)"
- ],
+ "source": "# Upload MAL label for this data row in project\nupload_job_mal = lb.MALPredictionImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"mal_import_job\" + str(uuid.uuid4()),\n predictions=labels,\n)\n\nupload_job_mal.wait_until_done()\nprint(\"Errors:\", upload_job_mal.errors)\nprint(\"Status of uploads: \", upload_job_mal.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -579,18 +293,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload label for this data row in project\n",
- "upload_job_label_import = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"label_import_job\"+str(uuid.uuid4()),\n",
- " labels=labels)\n",
- "\n",
- "upload_job_label_import.wait_until_done()\n",
- "print(\"Errors:\", upload_job_label_import.errors)\n",
- "print(\"Status of uploads: \", upload_job_label_import.statuses)"
- ],
+ "source": "# Upload label for this data row in project\nupload_job_label_import = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"label_import_job\" + str(uuid.uuid4()),\n labels=labels,\n)\n\nupload_job_label_import.wait_until_done()\nprint(\"Errors:\", upload_job_label_import.errors)\nprint(\"Status of uploads: \", upload_job_label_import.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -604,10 +307,7 @@
},
{
"metadata": {},
- "source": [
- "# project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/annotation_import/tiled.ipynb b/examples/annotation_import/tiled.ipynb
index 69b3f5982..19cb28d4e 100644
--- a/examples/annotation_import/tiled.ipynb
+++ b/examples/annotation_import/tiled.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -75,24 +75,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q 'labelbox[data]'"
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "\n",
- "import uuid\n",
- "import numpy as np\n",
- "import cv2\n",
- "import labelbox as lb\n",
- "import labelbox.types as lb_types\n",
- "\n"
- ],
+ "source": "import uuid\nimport numpy as np\nimport cv2\nimport labelbox as lb\nimport labelbox.types as lb_types",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -107,10 +97,7 @@
},
{
"metadata": {},
- "source": [
- "API_KEY = \"\"\n",
- "client = lb.Client(API_KEY)"
- ],
+ "source": "API_KEY = \"\"\nclient = lb.Client(API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -131,582 +118,63 @@
},
{
"metadata": {},
- "source": [
- "####### Point #######\n",
- "\n",
- "# Python Annotation\n",
- "point_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"point_geo\",\n",
- " value = lb_types.Point(x=-99.20647859573366, y=19.40018029091072),\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "point_annotation_ndjson = {\n",
- " \"name\": \"point_geo\",\n",
- " \"point\": {\n",
- " \"x\": -99.20647859573366,\n",
- " \"y\": 19.40018029091072\n",
- " }\n",
- "}"
- ],
+ "source": "####### Point #######\n\n# Python Annotation\npoint_annotation = lb_types.ObjectAnnotation(\n name=\"point_geo\",\n value=lb_types.Point(x=-99.20647859573366, y=19.40018029091072),\n)\n\n# NDJSON\npoint_annotation_ndjson = {\n \"name\": \"point_geo\",\n \"point\": {\n \"x\": -99.20647859573366,\n \"y\": 19.40018029091072\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "####### Polyline #######\n",
- "# Coordinates\n",
- "coords = [\n",
- " [\n",
- " -99.20842051506044,\n",
- " 19.40032196622975\n",
- " ],\n",
- " [\n",
- " -99.20809864997865,\n",
- " 19.39758963475322\n",
- " ],\n",
- " [\n",
- " -99.20758366584778,\n",
- " 19.39776167179227\n",
- " ],\n",
- " [\n",
- " -99.20728325843811,\n",
- " 19.3973265189299\n",
- " ]\n",
- " ]\n",
- "\n",
- "line_points = []\n",
- "line_points_ndjson = []\n",
- "\n",
- "for sub in coords:\n",
- " line_points.append(lb_types.Point(x=sub[0], y=sub[1]))\n",
- " line_points_ndjson.append({\"x\":sub[0], \"y\":sub[1]})\n",
- "\n",
- "# Python Annotation\n",
- "polyline_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"polyline_geo\",\n",
- " value = lb_types.Line(points=line_points),\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "polyline_annotation_ndjson = {\n",
- " \"name\": \"polyline_geo\",\n",
- " \"line\": line_points_ndjson\n",
- "}"
- ],
+ "source": "####### Polyline #######\n# Coordinates\ncoords = [\n [-99.20842051506044, 19.40032196622975],\n [-99.20809864997865, 19.39758963475322],\n [-99.20758366584778, 19.39776167179227],\n [-99.20728325843811, 19.3973265189299],\n]\n\nline_points = []\nline_points_ndjson = []\n\nfor sub in coords:\n line_points.append(lb_types.Point(x=sub[0], y=sub[1]))\n line_points_ndjson.append({\"x\": sub[0], \"y\": sub[1]})\n\n# Python Annotation\npolyline_annotation = lb_types.ObjectAnnotation(\n name=\"polyline_geo\",\n value=lb_types.Line(points=line_points),\n)\n\n# NDJSON\npolyline_annotation_ndjson = {\n \"name\": \"polyline_geo\",\n \"line\": line_points_ndjson,\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "####### Polygon #######\n",
- "# Coordinates in the desired EPSG coordinate system\n",
- "coords_polygon = [\n",
- " [\n",
- " -99.21042680740356,\n",
- " 19.40036244486966\n",
- " ],\n",
- " [\n",
- " -99.2104160785675,\n",
- " 19.40017017124035\n",
- " ],\n",
- " [\n",
- " -99.2103409767151,\n",
- " 19.400008256428897\n",
- " ],\n",
- " [\n",
- " -99.21014785766603,\n",
- " 19.400008256428897\n",
- " ],\n",
- " [\n",
- " -99.21019077301027,\n",
- " 19.39983622176518\n",
- " ],\n",
- " [\n",
- " -99.21022295951845,\n",
- " 19.399674306621385\n",
- " ],\n",
- " [\n",
- " -99.21029806137086,\n",
- " 19.39951239131646\n",
- " ],\n",
- " [\n",
- " -99.2102873325348,\n",
- " 19.399340356128437\n",
- " ],\n",
- " [\n",
- " -99.21025514602663,\n",
- " 19.399117722085677\n",
- " ],\n",
- " [\n",
- " -99.21024441719057,\n",
- " 19.39892544698541\n",
- " ],\n",
- " [\n",
- " -99.2102336883545,\n",
- " 19.39874329141769\n",
- " ],\n",
- " [\n",
- " -99.21021223068239,\n",
- " 19.398561135646027\n",
- " ],\n",
- " [\n",
- " -99.21018004417421,\n",
- " 19.398399219233365\n",
- " ],\n",
- " [\n",
- " -99.21011567115785,\n",
- " 19.39822718286836\n",
- " ],\n",
- " [\n",
- " -99.20992255210878,\n",
- " 19.398136104719125\n",
- " ],\n",
- " [\n",
- " -99.20974016189577,\n",
- " 19.398085505725305\n",
- " ],\n",
- " [\n",
- " -99.20957922935487,\n",
- " 19.398004547302467\n",
- " ],\n",
- " [\n",
- " -99.20939683914186,\n",
- " 19.39792358883935\n",
- " ],\n",
- " [\n",
- " -99.20918226242067,\n",
- " 19.39786286996558\n",
- " ],\n",
- " [\n",
- " -99.20899987220764,\n",
- " 19.397822390703805\n",
- " ],\n",
- " [\n",
- " -99.20891404151918,\n",
- " 19.397994427496787\n",
- " ],\n",
- " [\n",
- " -99.20890331268312,\n",
- " 19.398176583902874\n",
- " ],\n",
- " [\n",
- " -99.20889258384706,\n",
- " 19.398368859888045\n",
- " ],\n",
- " [\n",
- " -99.20889258384706,\n",
- " 19.398540896103246\n",
- " ],\n",
- " [\n",
- " -99.20890331268312,\n",
- " 19.39872305189756\n",
- " ],\n",
- " [\n",
- " -99.20889258384706,\n",
- " 19.39890520748796\n",
- " ],\n",
- " [\n",
- " -99.20889258384706,\n",
- " 19.39907724313608\n",
- " ],\n",
- " [\n",
- " -99.20889258384706,\n",
- " 19.399259398329956\n",
- " ],\n",
- " [\n",
- " -99.20890331268312,\n",
- " 19.399431433603585\n",
- " ],\n",
- " [\n",
- " -99.20890331268312,\n",
- " 19.39961358840092\n",
- " ],\n",
- " [\n",
- " -99.20890331268312,\n",
- " 19.399785623300048\n",
- " ],\n",
- " [\n",
- " -99.20897841453552,\n",
- " 19.399937418648214\n",
- " ],\n",
- " [\n",
- " -99.20919299125673,\n",
- " 19.399937418648214\n",
- " ],\n",
- " [\n",
- " -99.2093861103058,\n",
- " 19.39991717927664\n",
- " ],\n",
- " [\n",
- " -99.20956850051881,\n",
- " 19.39996777770086\n",
- " ],\n",
- " [\n",
- " -99.20961141586305,\n",
- " 19.40013981222548\n",
- " ],\n",
- " [\n",
- " -99.20963287353517,\n",
- " 19.40032196622975\n",
- " ],\n",
- " [\n",
- " -99.20978307724,\n",
- " 19.4004130431554\n",
- " ],\n",
- " [\n",
- " -99.20996546745302,\n",
- " 19.40039280384301\n",
- " ],\n",
- " [\n",
- " -99.21019077301027,\n",
- " 19.400372564528084\n",
- " ],\n",
- " [\n",
- " -99.21042680740356,\n",
- " 19.40036244486966\n",
- " ]\n",
- "\n",
- "]\n",
- "\n",
- "polygon_points = []\n",
- "polygon_points_ndjson = []\n",
- "\n",
- "for sub in coords_polygon:\n",
- " polygon_points.append(lb_types.Point(x=sub[0], y=sub[1]))\n",
- " polygon_points_ndjson.append({\"x\":sub[0], \"y\":sub[1]})\n",
- "\n",
- "# Python Annotation\n",
- "polygon_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"polygon_geo\",\n",
- " value = lb_types.Polygon(points=polygon_points),\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "polygon_annotation_ndjson = {\n",
- " \"name\": \"polygon_geo\",\n",
- " \"polygon\": polygon_points_ndjson\n",
- "}"
- ],
+ "source": "####### Polygon #######\n# Coordinates in the desired EPSG coordinate system\ncoords_polygon = [\n [-99.21042680740356, 19.40036244486966],\n [-99.2104160785675, 19.40017017124035],\n [-99.2103409767151, 19.400008256428897],\n [-99.21014785766603, 19.400008256428897],\n [-99.21019077301027, 19.39983622176518],\n [-99.21022295951845, 19.399674306621385],\n [-99.21029806137086, 19.39951239131646],\n [-99.2102873325348, 19.399340356128437],\n [-99.21025514602663, 19.399117722085677],\n [-99.21024441719057, 19.39892544698541],\n [-99.2102336883545, 19.39874329141769],\n [-99.21021223068239, 19.398561135646027],\n [-99.21018004417421, 19.398399219233365],\n [-99.21011567115785, 19.39822718286836],\n [-99.20992255210878, 19.398136104719125],\n [-99.20974016189577, 19.398085505725305],\n [-99.20957922935487, 19.398004547302467],\n [-99.20939683914186, 19.39792358883935],\n [-99.20918226242067, 19.39786286996558],\n [-99.20899987220764, 19.397822390703805],\n [-99.20891404151918, 19.397994427496787],\n [-99.20890331268312, 19.398176583902874],\n [-99.20889258384706, 19.398368859888045],\n [-99.20889258384706, 19.398540896103246],\n [-99.20890331268312, 19.39872305189756],\n [-99.20889258384706, 19.39890520748796],\n [-99.20889258384706, 19.39907724313608],\n [-99.20889258384706, 19.399259398329956],\n [-99.20890331268312, 19.399431433603585],\n [-99.20890331268312, 19.39961358840092],\n [-99.20890331268312, 19.399785623300048],\n [-99.20897841453552, 19.399937418648214],\n [-99.20919299125673, 19.399937418648214],\n [-99.2093861103058, 19.39991717927664],\n [-99.20956850051881, 19.39996777770086],\n [-99.20961141586305, 19.40013981222548],\n [-99.20963287353517, 19.40032196622975],\n [-99.20978307724, 19.4004130431554],\n [-99.20996546745302, 19.40039280384301],\n [-99.21019077301027, 19.400372564528084],\n [-99.21042680740356, 19.40036244486966],\n]\n\npolygon_points = []\npolygon_points_ndjson = []\n\nfor sub in coords_polygon:\n polygon_points.append(lb_types.Point(x=sub[0], y=sub[1]))\n polygon_points_ndjson.append({\"x\": sub[0], \"y\": sub[1]})\n\n# Python Annotation\npolygon_annotation = lb_types.ObjectAnnotation(\n name=\"polygon_geo\",\n value=lb_types.Polygon(points=polygon_points),\n)\n\n# NDJSON\npolygon_annotation_ndjson = {\n \"name\": \"polygon_geo\",\n \"polygon\": polygon_points_ndjson,\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "####### Bounding Box #######\n",
- "coord_object = {\n",
- " \"coordinates\" : [[\n",
- " [\n",
- " -99.20746564865112,\n",
- " 19.39799442829336\n",
- " ],\n",
- " [\n",
- " -99.20746564865112,\n",
- " 19.39925939999194\n",
- " ],\n",
- " [\n",
- " -99.20568466186523,\n",
- " 19.39925939999194\n",
- " ],\n",
- " [\n",
- " -99.20568466186523,\n",
- " 19.39799442829336\n",
- " ],\n",
- " [\n",
- " -99.20746564865112,\n",
- " 19.39799442829336\n",
- " ]\n",
- " ]]\n",
- "}\n",
- "\n",
- "\n",
- "\n",
- "\n",
- "bbox_top_left = lb_types.Point(x= -99.20746564865112, y=19.39799442829336)\n",
- "bbox_bottom_right = lb_types.Point(x=-99.20568466186523, y=19.39925939999194)\n",
- "\n",
- "# Python Annotation\n",
- "bbox_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"bbox_geo\",\n",
- " value = lb_types.Rectangle(start=bbox_top_left, end=bbox_bottom_right)\n",
- ")\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "bbox_annotation_ndjson = {\n",
- " \"name\" : \"bbox_geo\",\n",
- " \"bbox\" : {\n",
- " 'top': coord_object[\"coordinates\"][0][1][1],\n",
- " 'left': coord_object[\"coordinates\"][0][1][0],\n",
- " 'height': coord_object[\"coordinates\"][0][3][1] - coord_object[\"coordinates\"][0][1][1],\n",
- " 'width': coord_object[\"coordinates\"][0][3][0] - coord_object[\"coordinates\"][0][1][0]\n",
- " }\n",
- "}\n"
- ],
+ "source": "####### Bounding Box #######\ncoord_object = {\n \"coordinates\": [[\n [-99.20746564865112, 19.39799442829336],\n [-99.20746564865112, 19.39925939999194],\n [-99.20568466186523, 19.39925939999194],\n [-99.20568466186523, 19.39799442829336],\n [-99.20746564865112, 19.39799442829336],\n ]]\n}\n\nbbox_top_left = lb_types.Point(x=-99.20746564865112, y=19.39799442829336)\nbbox_bottom_right = lb_types.Point(x=-99.20568466186523, y=19.39925939999194)\n\n# Python Annotation\nbbox_annotation = lb_types.ObjectAnnotation(\n name=\"bbox_geo\",\n value=lb_types.Rectangle(start=bbox_top_left, end=bbox_bottom_right),\n)\n\n# NDJSON\nbbox_annotation_ndjson = {\n \"name\": \"bbox_geo\",\n \"bbox\": {\n \"top\":\n coord_object[\"coordinates\"][0][1][1],\n \"left\":\n coord_object[\"coordinates\"][0][1][0],\n \"height\":\n coord_object[\"coordinates\"][0][3][1] -\n coord_object[\"coordinates\"][0][1][1],\n \"width\":\n coord_object[\"coordinates\"][0][3][0] -\n coord_object[\"coordinates\"][0][1][0],\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "####### Classification - radio (single choice) #######\n",
- "\n",
- "# Python Annotation\n",
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question_geo\",\n",
- " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(name=\"first_radio_answer\"))\n",
- ")\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "radio_annotation_ndjson = {\n",
- " \"name\": \"radio_question_geo\",\n",
- " \"answer\": { \"name\": \"first_radio_answer\"}\n",
- "}"
- ],
+ "source": "####### Classification - radio (single choice) #######\n\n# Python Annotation\nradio_annotation = lb_types.ClassificationAnnotation(\n name=\"radio_question_geo\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\")),\n)\n\n# NDJSON\nradio_annotation_ndjson = {\n \"name\": \"radio_question_geo\",\n \"answer\": {\n \"name\": \"first_radio_answer\"\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "####### Classification - Checklist (multi-choice) #######\n",
- "\n",
- "coord_object_checklist = {\n",
- " \"coordinates\": [\n",
- " [\n",
- " [\n",
- " -99.210266,\n",
- " 19.39540372195134\n",
- " ],\n",
- " [\n",
- " -99.210266,\n",
- " 19.396901\n",
- " ],\n",
- " [\n",
- " -99.20621067903966,\n",
- " 19.396901\n",
- " ],\n",
- " [\n",
- " -99.20621067903966,\n",
- " 19.39540372195134\n",
- " ],\n",
- " [\n",
- " -99.210266,\n",
- " 19.39540372195134\n",
- " ]\n",
- " ]\n",
- " ]\n",
- "}\n",
- "\n",
- "# Python Annotation\n",
- "bbox_with_checklist_subclass = lb_types.ObjectAnnotation(\n",
- " name=\"bbox_checklist_geo\",\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=-99.210266, y=19.39540372195134), # Top left\n",
- " end=lb_types.Point(x=-99.20621067903966, y=19.396901), # Bottom right\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_class_name\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(name=\"first_checklist_answer\")]\n",
- " )\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "bbox_with_checklist_subclass_ndjson = {\n",
- " \"name\": \"bbox_checklist_geo\",\n",
- " \"classifications\": [{\n",
- " \"name\": \"checklist_class_name\",\n",
- " \"answer\": [\n",
- " { \"name\":\"first_checklist_answer\" }\n",
- " ]\n",
- " }],\n",
- " \"bbox\": {\n",
- " 'top': coord_object_checklist[\"coordinates\"][0][1][1],\n",
- " 'left': coord_object_checklist[\"coordinates\"][0][1][0],\n",
- " 'height': coord_object_checklist[\"coordinates\"][0][3][1] - coord_object_checklist[\"coordinates\"][0][1][1],\n",
- " 'width': coord_object_checklist[\"coordinates\"][0][3][0] - coord_object_checklist[\"coordinates\"][0][1][0]\n",
- " }\n",
- "}"
- ],
+ "source": "####### Classification - Checklist (multi-choice) #######\n\ncoord_object_checklist = {\n \"coordinates\": [[\n [-99.210266, 19.39540372195134],\n [-99.210266, 19.396901],\n [-99.20621067903966, 19.396901],\n [-99.20621067903966, 19.39540372195134],\n [-99.210266, 19.39540372195134],\n ]]\n}\n\n# Python Annotation\nbbox_with_checklist_subclass = lb_types.ObjectAnnotation(\n name=\"bbox_checklist_geo\",\n value=lb_types.Rectangle(\n start=lb_types.Point(x=-99.210266, y=19.39540372195134), # Top left\n end=lb_types.Point(x=-99.20621067903966, y=19.396901), # Bottom right\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"checklist_class_name\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\")\n ]),\n )\n ],\n)\n\n# NDJSON\nbbox_with_checklist_subclass_ndjson = {\n \"name\": \"bbox_checklist_geo\",\n \"classifications\": [{\n \"name\": \"checklist_class_name\",\n \"answer\": [{\n \"name\": \"first_checklist_answer\"\n }],\n }],\n \"bbox\": {\n \"top\":\n coord_object_checklist[\"coordinates\"][0][1][1],\n \"left\":\n coord_object_checklist[\"coordinates\"][0][1][0],\n \"height\":\n coord_object_checklist[\"coordinates\"][0][3][1] -\n coord_object_checklist[\"coordinates\"][0][1][1],\n \"width\":\n coord_object_checklist[\"coordinates\"][0][3][0] -\n coord_object_checklist[\"coordinates\"][0][1][0],\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "####### Classification free form text with bbox #######\n",
- "\n",
- "coord_object_text ={\n",
- " \"coordinates\": [\n",
- " [\n",
- " [\n",
- " -99.21019613742828,\n",
- " 19.397447957052933\n",
- " ],\n",
- " [\n",
- " -99.21019613742828,\n",
- " 19.39772119262215\n",
- " ],\n",
- " [\n",
- " -99.20986354351044,\n",
- " 19.39772119262215\n",
- " ],\n",
- " [\n",
- " -99.20986354351044,\n",
- " 19.397447957052933\n",
- " ],\n",
- " [\n",
- " -99.21019613742828,\n",
- " 19.397447957052933\n",
- " ]\n",
- " ]\n",
- " ]\n",
- "}\n",
- "# Python Annotation\n",
- "bbox_with_free_text_subclass = lb_types.ObjectAnnotation(\n",
- " name=\"bbox_text_geo\",\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=-99.21019613742828, y=19.397447957052933), # Top left\n",
- " end=lb_types.Point(x=-99.20986354351044, y=19.39772119262215), # Bottom right\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"free_text_geo\",\n",
- " value=lb_types.Text(answer=\"sample text\")\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "bbox_with_free_text_subclass_ndjson = {\n",
- " \"name\":\"bbox_text_geo\",\n",
- " \"classifications\": [{\n",
- " \"name\": \"free_text_geo\",\n",
- " \"answer\": \"sample text\"\n",
- " }],\n",
- " \"bbox\": {\n",
- " 'top': coord_object_text[\"coordinates\"][0][1][1],\n",
- " 'left': coord_object_text[\"coordinates\"][0][1][0],\n",
- " 'height': coord_object_text[\"coordinates\"][0][3][1] - coord_object_text[\"coordinates\"][0][1][1],\n",
- " 'width': coord_object_text[\"coordinates\"][0][3][0] - coord_object_text[\"coordinates\"][0][1][0]\n",
- " }\n",
- "}"
- ],
+ "source": "####### Classification free form text with bbox #######\n\ncoord_object_text = {\n \"coordinates\": [[\n [-99.21019613742828, 19.397447957052933],\n [-99.21019613742828, 19.39772119262215],\n [-99.20986354351044, 19.39772119262215],\n [-99.20986354351044, 19.397447957052933],\n [-99.21019613742828, 19.397447957052933],\n ]]\n}\n# Python Annotation\nbbox_with_free_text_subclass = lb_types.ObjectAnnotation(\n name=\"bbox_text_geo\",\n value=lb_types.Rectangle(\n start=lb_types.Point(x=-99.21019613742828,\n y=19.397447957052933), # Top left\n end=lb_types.Point(x=-99.20986354351044,\n y=19.39772119262215), # Bottom right\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"free_text_geo\", value=lb_types.Text(answer=\"sample text\"))\n ],\n)\n\n# NDJSON\nbbox_with_free_text_subclass_ndjson = {\n \"name\": \"bbox_text_geo\",\n \"classifications\": [{\n \"name\": \"free_text_geo\",\n \"answer\": \"sample text\"\n }],\n \"bbox\": {\n \"top\":\n coord_object_text[\"coordinates\"][0][1][1],\n \"left\":\n coord_object_text[\"coordinates\"][0][1][0],\n \"height\":\n coord_object_text[\"coordinates\"][0][3][1] -\n coord_object_text[\"coordinates\"][0][1][1],\n \"width\":\n coord_object_text[\"coordinates\"][0][3][0] -\n coord_object_text[\"coordinates\"][0][1][0],\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "####### Classification - Checklist (multi-choice) #######\n",
- "\n",
- "# Python Annotation\n",
- "checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question_geo\",\n",
- " value=lb_types.Checklist(answer = [\n",
- " lb_types.ClassificationAnswer(name = \"first_checklist_answer\"),\n",
- " lb_types.ClassificationAnswer(name = \"second_checklist_answer\"),\n",
- " lb_types.ClassificationAnswer(name = \"third_checklist_answer\")\n",
- " ])\n",
- " )\n",
- "\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "checklist_annotation_ndjson = {\n",
- " 'name': 'checklist_question_geo',\n",
- " 'answer': [\n",
- " {'name': 'first_checklist_answer'},\n",
- " {'name': 'second_checklist_answer'},\n",
- " {'name': 'third_checklist_answer'},\n",
- " ]\n",
- "}"
- ],
+ "source": "####### Classification - Checklist (multi-choice) #######\n\n# Python Annotation\nchecklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_question_geo\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"third_checklist_answer\"),\n ]),\n)\n\n# NDJSON\nchecklist_annotation_ndjson = {\n \"name\":\n \"checklist_question_geo\",\n \"answer\": [\n {\n \"name\": \"first_checklist_answer\"\n },\n {\n \"name\": \"second_checklist_answer\"\n },\n {\n \"name\": \"third_checklist_answer\"\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########## Classification - Radio and Checklist (with subclassifications) ##########\n",
- "\n",
- "nested_radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "# NDJSON\n",
- "nested_radio_annotation_ndjson= {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\",\n",
- " \"classifications\": [{\n",
- " \"name\":\"sub_radio_question\",\n",
- " \"answer\": { \"name\" : \"first_sub_radio_answer\"}\n",
- " }]\n",
- " }\n",
- "}\n",
- "\n",
- "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\"\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "nested_checklist_annotation_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"classifications\" : [\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\"name\": \"first_sub_checklist_answer\"}\n",
- " }\n",
- " ]\n",
- " }]\n",
- "}"
- ],
+ "source": "########## Classification - Radio and Checklist (with subclassifications) ##########\n\nnested_radio_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n)\n# NDJSON\nnested_radio_annotation_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\"\n },\n }],\n },\n}\n\nnested_checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n )\n ]),\n)\nnested_checklist_annotation_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\"\n },\n }],\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -727,34 +195,7 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "top_left_bound = lb_types.Point(x=-99.21052827588443, y=19.400498983095076)\n",
- "bottom_right_bound = lb_types.Point(x=-99.20534818927473, y=19.39533555271248)\n",
- "\n",
- "epsg = lb_types.EPSG.EPSG4326\n",
- "bounds = lb_types.TiledBounds(epsg=epsg, bounds=[top_left_bound, bottom_right_bound])\n",
- "global_key = \"mexico_city\"\n",
- "\n",
- "tile_layer = lb_types.TileLayer(\n",
- " url=\"https://s3-us-west-1.amazonaws.com/lb-tiler-layers/mexico_city/{z}/{x}/{y}.png\"\n",
- ")\n",
- "\n",
- "tiled_image_data = lb_types.TiledImageData(tile_layer=tile_layer,\n",
- " tile_bounds=bounds,\n",
- " zoom_levels=[17, 23])\n",
- "\n",
- "asset = {\n",
- " \"row_data\": tiled_image_data.asdict(),\n",
- " \"global_key\": global_key,\n",
- " \"media_type\": \"TMS_GEO\"\n",
- "}\n",
- "\n",
- "dataset = client.create_dataset(name=\"geo_demo_dataset\")\n",
- "task= dataset.create_data_rows([asset])\n",
- "print(\"Errors:\",task.errors)\n",
- "print(\"Failed data rows:\", task.failed_data_rows)"
- ],
+ "source": "top_left_bound = lb_types.Point(x=-99.21052827588443, y=19.400498983095076)\nbottom_right_bound = lb_types.Point(x=-99.20534818927473, y=19.39533555271248)\n\nepsg = lb_types.EPSG.EPSG4326\nbounds = lb_types.TiledBounds(epsg=epsg,\n bounds=[top_left_bound, bottom_right_bound])\nglobal_key = \"mexico_city\"\n\ntile_layer = lb_types.TileLayer(\n url=\n \"https://s3-us-west-1.amazonaws.com/lb-tiler-layers/mexico_city/{z}/{x}/{y}.png\"\n)\n\ntiled_image_data = lb_types.TiledImageData(tile_layer=tile_layer,\n tile_bounds=bounds,\n zoom_levels=[17, 23])\n\nasset = {\n \"row_data\": tiled_image_data.asdict(),\n \"global_key\": global_key,\n \"media_type\": \"TMS_GEO\",\n}\n\ndataset = client.create_dataset(name=\"geo_demo_dataset\")\ntask = dataset.create_data_rows([asset])\nprint(\"Errors:\", task.errors)\nprint(\"Failed data rows:\", task.failed_data_rows)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -769,93 +210,7 @@
},
{
"metadata": {},
- "source": [
- "ontology_builder = lb.OntologyBuilder(\n",
- " tools=[\n",
- " lb.Tool(tool=lb.Tool.Type.POINT, name=\"point_geo\"),\n",
- " lb.Tool(tool=lb.Tool.Type.LINE, name=\"polyline_geo\"),\n",
- " lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"polygon_geo\"),\n",
- " lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"polygon_geo_2\"),\n",
- " lb.Tool(tool=lb.Tool.Type.BBOX, name=\"bbox_geo\"),\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.BBOX,\n",
- " name=\"bbox_checklist_geo\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_class_name\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " ]\n",
- " ),\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.BBOX,\n",
- " name=\"bbox_text_geo\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"free_text_geo\"\n",
- " ),\n",
- " ]\n",
- " )\n",
- " ],\n",
- " classifications = [\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_question_geo\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\"),\n",
- " lb.Option(value=\"third_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_question_geo\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\")\n",
- " ]\n",
- " ),\n",
- "\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_sub_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " ]\n",
- " ),\n",
- " ],\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Ontology Geospatial Annotations\", ontology_builder.asdict(), media_type=lb.MediaType.Geospatial_Tile)"
- ],
+ "source": "ontology_builder = lb.OntologyBuilder(\n tools=[\n lb.Tool(tool=lb.Tool.Type.POINT, name=\"point_geo\"),\n lb.Tool(tool=lb.Tool.Type.LINE, name=\"polyline_geo\"),\n lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"polygon_geo\"),\n lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"polygon_geo_2\"),\n lb.Tool(tool=lb.Tool.Type.BBOX, name=\"bbox_geo\"),\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"bbox_checklist_geo\",\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_class_name\",\n options=[lb.Option(value=\"first_checklist_answer\")],\n ),\n ],\n ),\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"bbox_text_geo\",\n classifications=[\n lb.Classification(class_type=lb.Classification.Type.TEXT,\n name=\"free_text_geo\"),\n ],\n ),\n ],\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_question_geo\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n lb.Option(value=\"third_checklist_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_question_geo\",\n options=[lb.Option(value=\"first_radio_answer\")],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n options=[\n lb.Option(\n value=\"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(value=\"first_sub_radio_answer\")],\n ),\n ],\n ),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n ],\n)\n\nontology = client.create_ontology(\n \"Ontology Geospatial Annotations\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Geospatial_Tile,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -870,16 +225,7 @@
},
{
"metadata": {},
- "source": [
- "# Project defaults to batch mode with benchmark quality settings if this argument is not provided\n",
- "# Queue mode will be deprecated once dataset mode is deprecated\n",
- "\n",
- "project = client.create_project(name=\"Geospatial Project Demo\",\n",
- " media_type=lb.MediaType.Geospatial_Tile)\n",
- "\n",
- "\n",
- "project.setup_editor(ontology)\n"
- ],
+ "source": "# Project defaults to batch mode with benchmark quality settings if this argument is not provided\n# Queue mode will be deprecated once dataset mode is deprecated\n\nproject = client.create_project(name=\"Geospatial Project Demo\",\n media_type=lb.MediaType.Geospatial_Tile)\n\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -893,18 +239,7 @@
},
{
"metadata": {},
- "source": [
- "# Setup Batches and Ontology\n",
- "\n",
- "# Create a batch to send to your MAL project\n",
- "batch = project.create_batch(\n",
- " \"first-batch-geo-demo\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")\n",
- "\n",
- "print(\"Batch: \", batch)"
- ],
+ "source": "# Setup Batches and Ontology\n\n# Create a batch to send to your MAL project\nbatch = project.create_batch(\n \"first-batch-geo-demo\", # Each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # Paginated collection of data row objects, list of data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)\n\nprint(\"Batch: \", batch)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -929,61 +264,14 @@
},
{
"metadata": {},
- "source": [
- " ## Lets create another polygon annotation with python annotation tools that draws the image using cv2 python libraries\n",
- "\n",
- "hsv = cv2.cvtColor(tiled_image_data.value, cv2.COLOR_RGB2HSV)\n",
- "mask = cv2.inRange(hsv, (25, 50, 25), (100, 150, 255))\n",
- "kernel = np.ones((15, 20), np.uint8)\n",
- "mask = cv2.erode(mask, kernel)\n",
- "mask = cv2.dilate(mask, kernel)\n",
- "mask_annotation = lb_types.MaskData.from_2D_arr(mask)\n",
- "mask_data = lb_types.Mask(mask=mask_annotation, color=[255, 255, 255])\n",
- "h, w, _ = tiled_image_data.value.shape\n",
- "pixel_bounds = lb_types.TiledBounds(epsg=lb_types.EPSG.SIMPLEPIXEL,\n",
- " bounds=[lb_types.Point(x=0, y=0),\n",
- " lb_types.Point(x=w, y=h)])\n",
- "transformer = lb_types.EPSGTransformer.create_pixel_to_geo_transformer(\n",
- " src_epsg=pixel_bounds.epsg,\n",
- " pixel_bounds=pixel_bounds,\n",
- " geo_bounds=tiled_image_data.tile_bounds,\n",
- " zoom=20)\n",
- "pixel_polygons = mask_data.shapely.simplify(3)\n",
- "list_of_polygons = [transformer(lb_types.Polygon.from_shapely(p)) for p in pixel_polygons.geoms]\n",
- "polygon_annotation_two = lb_types.ObjectAnnotation(value=list_of_polygons[0], name=\"polygon_geo_2\")\n"
- ],
+ "source": "## Lets create another polygon annotation with python annotation tools that draws the image using cv2 python libraries\n\nhsv = cv2.cvtColor(tiled_image_data.value, cv2.COLOR_RGB2HSV)\nmask = cv2.inRange(hsv, (25, 50, 25), (100, 150, 255))\nkernel = np.ones((15, 20), np.uint8)\nmask = cv2.erode(mask, kernel)\nmask = cv2.dilate(mask, kernel)\nmask_annotation = lb_types.MaskData.from_2D_arr(mask)\nmask_data = lb_types.Mask(mask=mask_annotation, color=[255, 255, 255])\nh, w, _ = tiled_image_data.value.shape\npixel_bounds = lb_types.TiledBounds(\n epsg=lb_types.EPSG.SIMPLEPIXEL,\n bounds=[lb_types.Point(x=0, y=0),\n lb_types.Point(x=w, y=h)],\n)\ntransformer = lb_types.EPSGTransformer.create_pixel_to_geo_transformer(\n src_epsg=pixel_bounds.epsg,\n pixel_bounds=pixel_bounds,\n geo_bounds=tiled_image_data.tile_bounds,\n zoom=20,\n)\npixel_polygons = mask_data.shapely.simplify(3)\nlist_of_polygons = [\n transformer(lb_types.Polygon.from_shapely(p)) for p in pixel_polygons.geoms\n]\npolygon_annotation_two = lb_types.ObjectAnnotation(value=list_of_polygons[0],\n name=\"polygon_geo_2\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "labels =[]\n",
- "labels.append(\n",
- " lb_types.Label(\n",
- " data={\n",
- " \"global_key\": global_key,\n",
- " \"tile_layer\": tile_layer,\n",
- " \"tile_bounds\":bounds,\n",
- " \"zoom_levels\": [12, 20]\n",
- " },\n",
- " annotations = [\n",
- " point_annotation,\n",
- " polyline_annotation,\n",
- " polygon_annotation,\n",
- " bbox_annotation,\n",
- " radio_annotation,\n",
- " bbox_with_checklist_subclass,\n",
- " bbox_with_free_text_subclass,\n",
- " checklist_annotation,\n",
- " polygon_annotation_two,\n",
- " nested_checklist_annotation,\n",
- " nested_radio_annotation\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "labels = []\nlabels.append(\n lb_types.Label(\n data={\n \"global_key\": global_key,\n \"tile_layer\": tile_layer,\n \"tile_bounds\": bounds,\n \"zoom_levels\": [12, 20],\n },\n annotations=[\n point_annotation,\n polyline_annotation,\n polygon_annotation,\n bbox_annotation,\n radio_annotation,\n bbox_with_checklist_subclass,\n bbox_with_free_text_subclass,\n checklist_annotation,\n polygon_annotation_two,\n nested_checklist_annotation,\n nested_radio_annotation,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -998,27 +286,7 @@
},
{
"metadata": {},
- "source": [
- "label_ndjson = []\n",
- "\n",
- "for annotations in [point_annotation_ndjson,\n",
- " polyline_annotation_ndjson,\n",
- " polygon_annotation_ndjson,\n",
- " bbox_annotation_ndjson,\n",
- " radio_annotation_ndjson,\n",
- " bbox_with_checklist_subclass_ndjson,\n",
- " bbox_with_free_text_subclass_ndjson,\n",
- " checklist_annotation_ndjson,\n",
- " nested_checklist_annotation_ndjson,\n",
- " nested_radio_annotation_ndjson\n",
- " ]:\n",
- " annotations.update({\n",
- " 'dataRow': {\n",
- " 'globalKey': global_key\n",
- " }\n",
- " })\n",
- " label_ndjson.append(annotations)\n"
- ],
+ "source": "label_ndjson = []\n\nfor annotations in [\n point_annotation_ndjson,\n polyline_annotation_ndjson,\n polygon_annotation_ndjson,\n bbox_annotation_ndjson,\n radio_annotation_ndjson,\n bbox_with_checklist_subclass_ndjson,\n bbox_with_free_text_subclass_ndjson,\n checklist_annotation_ndjson,\n nested_checklist_annotation_ndjson,\n nested_radio_annotation_ndjson,\n]:\n annotations.update({\"dataRow\": {\"globalKey\": global_key}})\n label_ndjson.append(annotations)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1040,18 +308,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload MAL label for this data row in project\n",
- "upload_job = lb.MALPredictionImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"mal_import_job\"+str(uuid.uuid4()),\n",
- " predictions=labels)\n",
- "\n",
- "upload_job.wait_until_done();\n",
- "print(\"Errors:\", upload_job.errors)\n",
- "print(\"Status of uploads: \", upload_job.statuses)"
- ],
+ "source": "# Upload MAL label for this data row in project\nupload_job = lb.MALPredictionImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"mal_import_job\" + str(uuid.uuid4()),\n predictions=labels,\n)\n\nupload_job.wait_until_done()\nprint(\"Errors:\", upload_job.errors)\nprint(\"Status of uploads: \", upload_job.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1065,18 +322,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload label for this data row in project\n",
- "upload_job = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"label_geo_import_job\"+str(uuid.uuid4()),\n",
- " labels=labels)\n",
- "\n",
- "upload_job.wait_until_done();\n",
- "print(\"Errors:\", upload_job.errors)\n",
- "print(\"Status of uploads: \", upload_job.statuses)"
- ],
+ "source": "# Upload label for this data row in project\nupload_job = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"label_geo_import_job\" + str(uuid.uuid4()),\n labels=labels,\n)\n\nupload_job.wait_until_done()\nprint(\"Errors:\", upload_job.errors)\nprint(\"Status of uploads: \", upload_job.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1090,11 +336,7 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "# project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/annotation_import/video.ipynb b/examples/annotation_import/video.ipynb
index b3eda6b9b..726e22738 100644
--- a/examples/annotation_import/video.ipynb
+++ b/examples/annotation_import/video.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -21,10 +21,9 @@
"\n",
"\n",
"\n",
- "\n",
" \n",
- " | "
+ ""
],
"cell_type": "markdown"
},
@@ -57,26 +56,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import uuid\n",
- "from PIL import Image\n",
- "import requests\n",
- "import base64\n",
- "import labelbox as lb\n",
- "import labelbox.types as lb_types\n",
- "from io import BytesIO\n",
- "import pprint\n",
- "pp = pprint.PrettyPrinter(indent=4)"
- ],
+ "source": "import uuid\nfrom PIL import Image\nimport requests\nimport base64\nimport labelbox as lb\nimport labelbox.types as lb_types\nfrom io import BytesIO\nimport pprint\n\npp = pprint.PrettyPrinter(indent=4)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -91,11 +78,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your api key\n",
- "API_KEY=\"\"\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your api key\nAPI_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -116,60 +99,7 @@
},
{
"metadata": {},
- "source": [
- "# Confidence scores are not supported for frame specific bounding box annotations and VideoObjectAnnotation class\n",
- "\n",
- "# bbox dimensions\n",
- "bbox_dm = {\n",
- " \"top\":617,\n",
- " \"left\":1371,\n",
- " \"height\":419,\n",
- " \"width\":505\n",
- "}\n",
- "\n",
- "# Python Annotation\n",
- "bbox_annotation = [\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_video\",\n",
- " keyframe=True,\n",
- " frame=13,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]), # x = left, y = top\n",
- " end=lb_types.Point(x=bbox_dm[\"left\"] + bbox_dm[\"width\"], y=bbox_dm[\"top\"] + bbox_dm[\"height\"]), # x= left + width , y = top + height\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_video\",\n",
- " keyframe=True,\n",
- " frame=19,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]),\n",
- " end=lb_types.Point(x=bbox_dm[\"left\"] + bbox_dm[\"width\"], y=bbox_dm[\"top\"] + bbox_dm[\"height\"]),\n",
- " )\n",
- " )\n",
- "]\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "bbox_annotation_ndjson = {\n",
- " \"name\" : \"bbox_video\",\n",
- " \"segments\" : [{\n",
- " \"keyframes\" : [\n",
- " {\n",
- " \"frame\": 13,\n",
- " \"bbox\" : bbox_dm\n",
- " },\n",
- " {\n",
- " \"frame\": 19,\n",
- " \"bbox\" : bbox_dm\n",
- " }\n",
- " ]\n",
- " }\n",
- " ]\n",
- "}"
- ],
+ "source": "# Confidence scores are not supported for frame specific bounding box annotations and VideoObjectAnnotation class\n\n# bbox dimensions\nbbox_dm = {\"top\": 617, \"left\": 1371, \"height\": 419, \"width\": 505}\n\n# Python Annotation\nbbox_annotation = [\n lb_types.VideoObjectAnnotation(\n name=\"bbox_video\",\n keyframe=True,\n frame=13,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm[\"left\"],\n y=bbox_dm[\"top\"]), # x = left, y = top\n end=lb_types.Point(\n x=bbox_dm[\"left\"] + bbox_dm[\"width\"],\n y=bbox_dm[\"top\"] + bbox_dm[\"height\"],\n ), # x= left + width , y = top + height\n ),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"bbox_video\",\n keyframe=True,\n frame=19,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]),\n end=lb_types.Point(\n x=bbox_dm[\"left\"] + bbox_dm[\"width\"],\n y=bbox_dm[\"top\"] + bbox_dm[\"height\"],\n ),\n ),\n ),\n]\n\n# NDJSON\nbbox_annotation_ndjson = {\n \"name\":\n \"bbox_video\",\n \"segments\": [{\n \"keyframes\": [\n {\n \"frame\": 13,\n \"bbox\": bbox_dm\n },\n {\n \"frame\": 19,\n \"bbox\": bbox_dm\n },\n ]\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -183,31 +113,7 @@
},
{
"metadata": {},
- "source": [
- "# Python Annotation\n",
- "point_annotation = [\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"point_video\",\n",
- " keyframe=True,\n",
- " frame=17,\n",
- " value = lb_types.Point(x=660.134, y=407.926),\n",
- " )\n",
- "]\n",
- "\n",
- "# NDJSON\n",
- "point_annotation_ndjson = {\n",
- " \"name\": \"point_video\",\n",
- " \"segments\": [{\n",
- " \"keyframes\": [{\n",
- " \"frame\": 17,\n",
- " \"point\" : {\n",
- " \"x\": 660.134 ,\n",
- " \"y\": 407.926\n",
- " }\n",
- " }]\n",
- " }]\n",
- "}"
- ],
+ "source": "# Python Annotation\npoint_annotation = [\n lb_types.VideoObjectAnnotation(\n name=\"point_video\",\n keyframe=True,\n frame=17,\n value=lb_types.Point(x=660.134, y=407.926),\n )\n]\n\n# NDJSON\npoint_annotation_ndjson = {\n \"name\":\n \"point_video\",\n \"segments\": [{\n \"keyframes\": [{\n \"frame\": 17,\n \"point\": {\n \"x\": 660.134,\n \"y\": 407.926\n }\n }]\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -221,111 +127,7 @@
},
{
"metadata": {},
- "source": [
- "######## Polyline ########\n",
- "\n",
- "# Python Annotation\n",
- "polyline_annotation = [\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"line_video_frame\",\n",
- " keyframe=True,\n",
- " frame=5,\n",
- " segment_index=0,\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=680, y=100), lb_types.Point(x=100, y=190)]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"line_video_frame\",\n",
- " keyframe=True,\n",
- " frame=20,\n",
- " segment_index=0,\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=680, y=100), lb_types.Point(x=100, y=190)]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"line_video_frame\",\n",
- " keyframe=True,\n",
- " frame=24,\n",
- " segment_index=1,\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=680, y=100), lb_types.Point(x=100, y=190)]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"line_video_frame\",\n",
- " keyframe=True,\n",
- " frame=45,\n",
- " segment_index=1,\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=680, y=100), lb_types.Point(x=100, y=190)]\n",
- " )\n",
- " )\n",
- "\n",
- "]\n",
- "\n",
- "# NDJSON\n",
- "polyline_frame_annotation_ndjson = {\n",
- " \"name\": \"line_video_frame\",\n",
- " \"segments\": [\n",
- " {\n",
- " \"keyframes\": [\n",
- " {\n",
- " \"frame\": 5,\n",
- " \"line\": [{\n",
- " \"x\": 680,\n",
- " \"y\": 100\n",
- " },{\n",
- " \"x\": 100,\n",
- " \"y\": 190\n",
- " },{\n",
- " \"x\": 190,\n",
- " \"y\": 220\n",
- " }]\n",
- " },\n",
- " {\n",
- " \"frame\": 20,\n",
- " \"line\": [{\n",
- " \"x\": 680,\n",
- " \"y\": 180\n",
- " },{\n",
- " \"x\": 100,\n",
- " \"y\": 200\n",
- " },{\n",
- " \"x\": 200,\n",
- " \"y\": 260\n",
- " }]\n",
- " }\n",
- " ]\n",
- " },\n",
- " {\n",
- " \"keyframes\": [\n",
- " {\n",
- " \"frame\": 24,\n",
- " \"line\": [{\n",
- " \"x\": 300,\n",
- " \"y\": 310\n",
- " },{\n",
- " \"x\": 330,\n",
- " \"y\": 430\n",
- " }]\n",
- " },\n",
- " {\n",
- " \"frame\": 45,\n",
- " \"line\": [{\n",
- " \"x\": 600,\n",
- " \"y\": 810\n",
- " },{\n",
- " \"x\": 900,\n",
- " \"y\": 930\n",
- " }]\n",
- " }\n",
- " ]\n",
- " }\n",
- " ]\n",
- "}"
- ],
+ "source": "######## Polyline ########\n\n# Python Annotation\npolyline_annotation = [\n lb_types.VideoObjectAnnotation(\n name=\"line_video_frame\",\n keyframe=True,\n frame=5,\n segment_index=0,\n value=lb_types.Line(\n points=[lb_types.Point(x=680, y=100),\n lb_types.Point(x=100, y=190)]),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"line_video_frame\",\n keyframe=True,\n frame=20,\n segment_index=0,\n value=lb_types.Line(\n points=[lb_types.Point(x=680, y=100),\n lb_types.Point(x=100, y=190)]),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"line_video_frame\",\n keyframe=True,\n frame=24,\n segment_index=1,\n value=lb_types.Line(\n points=[lb_types.Point(x=680, y=100),\n lb_types.Point(x=100, y=190)]),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"line_video_frame\",\n keyframe=True,\n frame=45,\n segment_index=1,\n value=lb_types.Line(\n points=[lb_types.Point(x=680, y=100),\n lb_types.Point(x=100, y=190)]),\n ),\n]\n\n# NDJSON\npolyline_frame_annotation_ndjson = {\n \"name\":\n \"line_video_frame\",\n \"segments\": [\n {\n \"keyframes\": [\n {\n \"frame\":\n 5,\n \"line\": [\n {\n \"x\": 680,\n \"y\": 100\n },\n {\n \"x\": 100,\n \"y\": 190\n },\n {\n \"x\": 190,\n \"y\": 220\n },\n ],\n },\n {\n \"frame\":\n 20,\n \"line\": [\n {\n \"x\": 680,\n \"y\": 180\n },\n {\n \"x\": 100,\n \"y\": 200\n },\n {\n \"x\": 200,\n \"y\": 260\n },\n ],\n },\n ]\n },\n {\n \"keyframes\": [\n {\n \"frame\": 24,\n \"line\": [{\n \"x\": 300,\n \"y\": 310\n }, {\n \"x\": 330,\n \"y\": 430\n }],\n },\n {\n \"frame\": 45,\n \"line\": [{\n \"x\": 600,\n \"y\": 810\n }, {\n \"x\": 900,\n \"y\": 930\n }],\n },\n ]\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -339,73 +141,7 @@
},
{
"metadata": {},
- "source": [
- "# Python Annotation\n",
- "radio_annotation = [\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"radio_class\",\n",
- " frame=9,\n",
- " segment_index=0,\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(name = \"first_radio_answer\"))\n",
- " ),\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"radio_class\",\n",
- " frame=15,\n",
- " segment_index=0,\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(name = \"first_radio_answer\"))\n",
- " )\n",
- "]\n",
- "\n",
- "## NDJSON\n",
- "frame_radio_classification_ndjson = {\n",
- " \"name\": \"radio_class\",\n",
- " \"answer\": { \"name\": \"first_radio_answer\", \"frames\": [{\"start\": 9, \"end\": 15}]}\n",
- "}\n",
- "\n",
- "#Python annotation\n",
- "checklist_annotation= [\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"checklist_class\",\n",
- " frame=29,\n",
- " segment_index=0,\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\"\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\"\n",
- " )\n",
- " ]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"checklist_class\",\n",
- " frame=35,\n",
- " segment_index=0,\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\"\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\"\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- "]\n",
- "\n",
- "\n",
- "## NDJSON\n",
- "frame_checklist_classification_ndjson = {\n",
- " \"name\": \"checklist_class\",\n",
- " \"answer\": [\n",
- " { \"name\": \"first_checklist_answer\" , \"frames\": [{\"start\": 29, \"end\": 35 }]},\n",
- " { \"name\": \"second_checklist_answer\" , \"frames\": [{\"start\": 29, \"end\": 35 }]}\n",
- " ]\n",
- "}"
- ],
+ "source": "# Python Annotation\nradio_annotation = [\n lb_types.VideoClassificationAnnotation(\n name=\"radio_class\",\n frame=9,\n segment_index=0,\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\")),\n ),\n lb_types.VideoClassificationAnnotation(\n name=\"radio_class\",\n frame=15,\n segment_index=0,\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\")),\n ),\n]\n\n## NDJSON\nframe_radio_classification_ndjson = {\n \"name\": \"radio_class\",\n \"answer\": {\n \"name\": \"first_radio_answer\",\n \"frames\": [{\n \"start\": 9,\n \"end\": 15\n }],\n },\n}\n\n# Python annotation\nchecklist_annotation = [\n lb_types.VideoClassificationAnnotation(\n name=\"checklist_class\",\n frame=29,\n segment_index=0,\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n ]),\n ),\n lb_types.VideoClassificationAnnotation(\n name=\"checklist_class\",\n frame=35,\n segment_index=0,\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n ]),\n ),\n]\n\n## NDJSON\nframe_checklist_classification_ndjson = {\n \"name\":\n \"checklist_class\",\n \"answer\": [\n {\n \"name\": \"first_checklist_answer\",\n \"frames\": [{\n \"start\": 29,\n \"end\": 35\n }],\n },\n {\n \"name\": \"second_checklist_answer\",\n \"frames\": [{\n \"start\": 29,\n \"end\": 35\n }],\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -419,46 +155,7 @@
},
{
"metadata": {},
- "source": [
- "##### Global Classifications #######\n",
- "\n",
- "# Python Annotation\n",
- "## For global classifications use ClassificationAnnotation\n",
- "global_radio_annotation = [lb_types.ClassificationAnnotation(\n",
- " name=\"radio_class_global\",\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(name = \"first_radio_answer\"))\n",
- ")]\n",
- "\n",
- "# NDJSON\n",
- "global_radio_classification_ndjson = {\n",
- " \"name\": \"radio_class_global\",\n",
- " \"answer\": { \"name\": \"first_radio_answer\"}\n",
- "}\n",
- "\n",
- "# Python annotation\n",
- "global_checklist_annotation=[lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_class_global\",\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\"\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\"\n",
- " )\n",
- " ]\n",
- " )\n",
- " )]\n",
- "\n",
- "# NDJSON\n",
- "global_checklist_classification_ndjson = {\n",
- " \"name\": \"checklist_class_global\",\n",
- " \"answer\": [\n",
- " { \"name\": \"first_checklist_answer\" },\n",
- " { \"name\": \"second_checklist_answer\"}\n",
- " ]\n",
- "}"
- ],
+ "source": "##### Global Classifications #######\n\n# Python Annotation\n## For global classifications use ClassificationAnnotation\nglobal_radio_annotation = [\n lb_types.ClassificationAnnotation(\n name=\"radio_class_global\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\")),\n )\n]\n\n# NDJSON\nglobal_radio_classification_ndjson = {\n \"name\": \"radio_class_global\",\n \"answer\": {\n \"name\": \"first_radio_answer\"\n },\n}\n\n# Python annotation\nglobal_checklist_annotation = [\n lb_types.ClassificationAnnotation(\n name=\"checklist_class_global\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n ]),\n )\n]\n\n# NDJSON\nglobal_checklist_classification_ndjson = {\n \"name\":\n \"checklist_class_global\",\n \"answer\": [\n {\n \"name\": \"first_checklist_answer\"\n },\n {\n \"name\": \"second_checklist_answer\"\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -472,72 +169,7 @@
},
{
"metadata": {},
- "source": [
- "########## Nested Global Classification ###########\n",
- "\n",
- "# Python Annotation\n",
- "nested_radio_annotation =[lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")]\n",
- "\n",
- "# NDJSON\n",
- "nested_radio_annotation_ndjson = {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\"name\": \"first_radio_answer\",\n",
- " \"classifications\" : [\n",
- " {\"name\": \"sub_radio_question\", \"answer\": {\"name\": \"first_sub_radio_answer\"}}\n",
- " ]\n",
- " }\n",
- "}\n",
- "\n",
- "# Python Annotation\n",
- "nested_checklist_annotation = [lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\"\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")]\n",
- "\n",
- "# NDJSON\n",
- "nested_checklist_annotation_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"classifications\" : [\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\"name\": \"first_sub_checklist_answer\"}\n",
- " }\n",
- " ]\n",
- " }]\n",
- "}"
- ],
+ "source": "########## Nested Global Classification ###########\n\n# Python Annotation\nnested_radio_annotation = [\n lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n )\n]\n\n# NDJSON\nnested_radio_annotation_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\"\n },\n }],\n },\n}\n\n# Python Annotation\nnested_checklist_annotation = [\n lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n )\n ]),\n )\n]\n\n# NDJSON\nnested_checklist_annotation_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\"\n },\n }],\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -551,18 +183,7 @@
},
{
"metadata": {},
- "source": [
- "######### Free text classification ###########\n",
- "text_annotation = [lb_types.ClassificationAnnotation(\n",
- " name=\"free_text\", # must match your ontology feature\"s name\n",
- " value=lb_types.Text(answer=\"sample text\")\n",
- ")]\n",
- "\n",
- "text_annotation_ndjson = {\n",
- " \"name\": \"free_text\",\n",
- " \"answer\": \"sample text\",\n",
- "}"
- ],
+ "source": "######### Free text classification ###########\ntext_annotation = [\n lb_types.ClassificationAnnotation(\n name=\"free_text\", # must match your ontology feature\"s name\n value=lb_types.Text(answer=\"sample text\"),\n )\n]\n\ntext_annotation_ndjson = {\n \"name\": \"free_text\",\n \"answer\": \"sample text\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -576,98 +197,7 @@
},
{
"metadata": {},
- "source": [
- "# Confidence scores are not supported for frame specific bounding box annotations with sub-classifications\n",
- "\n",
- "# bounding box dimensions\n",
- "bbox_dm2 = {\n",
- " \"top\": 146.0,\n",
- " \"left\": 98.0,\n",
- " \"height\": 382.0,\n",
- " \"width\": 341.0\n",
- "}\n",
- "\n",
- "# Python Annotation\n",
- "frame_bbox_with_checklist_subclass_annotation = [\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_class\",\n",
- " keyframe=True,\n",
- " frame=10,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]), # x = left, y = top\n",
- " end=lb_types.Point(x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"], y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"]), # x= left + width , y = top + height\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_class\",\n",
- " keyframe=True,\n",
- " frame=11,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]),\n",
- " end=lb_types.Point(x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"], y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"]),\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_class\",\n",
- " value=lb_types.Checklist(answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\")])\n",
- " )\n",
- " ]\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_class\",\n",
- " keyframe=True,\n",
- " frame=13,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]),\n",
- " end=lb_types.Point(x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"], y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"]),\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_class\",\n",
- " value=lb_types.Checklist(answer=[lb_types.ClassificationAnswer(\n",
- " name=\"second_checklist_answer\")])\n",
- " )\n",
- " ]\n",
- " )\n",
- "]\n",
- "\n",
- "frame_bbox_with_checklist_subclass_annotation_ndjson = {\n",
- " \"name\": \"bbox_class\",\n",
- " \"segments\": [{\n",
- " \"keyframes\": [\n",
- " {\n",
- " \"frame\": 10,\n",
- " \"bbox\": bbox_dm2\n",
- " },\n",
- " {\n",
- " \"frame\": 11,\n",
- " \"bbox\": bbox_dm2,\n",
- " \"classifications\": [\n",
- " {\n",
- " \"name\": \"checklist_class\",\n",
- " \"answer\": [{\"name\": \"first_checklist_answer\"}]\n",
- " }\n",
- " ]\n",
- " },\n",
- " {\n",
- " \"frame\": 13,\n",
- " \"bbox\": bbox_dm2,\n",
- " \"classifications\": [\n",
- " {\n",
- " \"name\": \"checklist_class\",\n",
- " \"answer\": [{\"name\": \"second_checklist_answer\"}]\n",
- " }\n",
- " ]\n",
- " }\n",
- " ]\n",
- " }\n",
- " ]\n",
- "}"
- ],
+ "source": "# Confidence scores are not supported for frame specific bounding box annotations with sub-classifications\n\n# bounding box dimensions\nbbox_dm2 = {\"top\": 146.0, \"left\": 98.0, \"height\": 382.0, \"width\": 341.0}\n\n# Python Annotation\nframe_bbox_with_checklist_subclass_annotation = [\n lb_types.VideoObjectAnnotation(\n name=\"bbox_class\",\n keyframe=True,\n frame=10,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm2[\"left\"],\n y=bbox_dm2[\"top\"]), # x = left, y = top\n end=lb_types.Point(\n x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"],\n y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"],\n ), # x= left + width , y = top + height\n ),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"bbox_class\",\n keyframe=True,\n frame=11,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]),\n end=lb_types.Point(\n x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"],\n y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"],\n ),\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"checklist_class\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\")\n ]),\n )\n ],\n ),\n lb_types.VideoObjectAnnotation(\n name=\"bbox_class\",\n keyframe=True,\n frame=13,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]),\n end=lb_types.Point(\n x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"],\n y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"],\n ),\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"checklist_class\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"second_checklist_answer\")\n ]),\n )\n ],\n ),\n]\n\nframe_bbox_with_checklist_subclass_annotation_ndjson = {\n \"name\":\n \"bbox_class\",\n \"segments\": [{\n \"keyframes\": [\n {\n \"frame\": 10,\n \"bbox\": bbox_dm2\n },\n {\n \"frame\":\n 11,\n \"bbox\":\n bbox_dm2,\n \"classifications\": [{\n \"name\": \"checklist_class\",\n \"answer\": [{\n \"name\": \"first_checklist_answer\"\n }],\n }],\n },\n {\n \"frame\":\n 13,\n \"bbox\":\n bbox_dm2,\n \"classifications\": [{\n \"name\": \"checklist_class\",\n \"answer\": [{\n \"name\": \"second_checklist_answer\"\n }],\n }],\n },\n ]\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -681,113 +211,14 @@
},
{
"metadata": {},
- "source": [
- "def extract_rgb_colors_from_url(image_url):\n",
- " response = requests.get(image_url)\n",
- " img = Image.open(BytesIO(response.content))\n",
- "\n",
- " colors = set()\n",
- " for x in range(img.width):\n",
- " for y in range(img.height):\n",
- " pixel = img.getpixel((x, y))\n",
- " if pixel[:3] != (0,0,0):\n",
- " colors.add(pixel[:3]) # Get only the RGB values\n",
- "\n",
- " return colors"
- ],
+ "source": "def extract_rgb_colors_from_url(image_url):\n response = requests.get(image_url)\n img = Image.open(BytesIO(response.content))\n\n colors = set()\n for x in range(img.width):\n for y in range(img.height):\n pixel = img.getpixel((x, y))\n if pixel[:3] != (0, 0, 0):\n colors.add(pixel[:3]) # Get only the RGB values\n\n return colors",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "### Raster Segmentation (Byte string array)\n",
- "## For this example we are going to to pass all the annotations payload in a single VideoMaskAnnotation\n",
- "\n",
- "\n",
- "# Single mask\n",
- "url = \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/frame_24_composite_mask.png\"\n",
- "response = requests.get(url)\n",
- "img_bytes = base64.b64encode(response.content).decode('utf-8')\n",
- "\n",
- "# We are generating our frames and instances in this step, and will later add them to the VideoMaskAnnotation that will contain\n",
- "# all frames and instances\n",
- "frames_mask_single=[\n",
- " lb_types.MaskFrame(\n",
- " index=20,\n",
- " im_bytes=response.content # Instead of bytes you could also pass an instance URI : instance_uri=url\n",
- " )\n",
- "]\n",
- "instances_mask_single=[\n",
- " lb_types.MaskInstance(color_rgb=(76, 104, 177), name= \"video_mask\")\n",
- "]\n",
- "\n",
- "\n",
- "## Add multiple masks using multiple tools in different frames - Note that only once composite mask can exist per frame\n",
- "frames_cp_mask_url = [\n",
- " {\"1\": \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/frame_1_composite_mask.png\"},\n",
- " {\"24\": \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/frame_24_composite_mask.png\"},\n",
- " {\"26\": \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/frame_26_composite_mask.png\" }\n",
- "]\n",
- "\n",
- "rgb_mask_tool = [(227, 135, 126) ,(169, 248, 152),(83, 152, 103)]\n",
- "cp_masks = []\n",
- "unique_colors = set()\n",
- "\n",
- "\n",
- "lb_frames = []\n",
- "lb_instances = []\n",
- "counter = 0\n",
- "\n",
- "for d in frames_cp_mask_url:\n",
- " for frame_no, v in d.items():\n",
- " response = requests.get(v)\n",
- " colors = extract_rgb_colors_from_url(v)\n",
- " for color in colors:\n",
- " if not color in unique_colors:\n",
- " unique_colors.add(color)\n",
- " name = \"video_mask\" if color in rgb_mask_tool else \"mask_with_text_subclass\"\n",
- " lb_instances.append(lb_types.MaskInstance(color_rgb=color, name=name))\n",
- " counter += 1\n",
- " lb_frames.append(\n",
- " lb_types.MaskFrame(\n",
- " index=frame_no,\n",
- " im_bytes=response.content\n",
- " )\n",
- " )\n",
- "cp_masks.append(lb_types.VideoMaskAnnotation(\n",
- " frames=lb_frames + frames_mask_single,\n",
- " instances=lb_instances + instances_mask_single\n",
- "))\n",
- "\n",
- "pp.pprint(lb_frames)\n",
- "pp.pprint(cp_masks)\n",
- "\n",
- "\n",
- "\n",
- "# NDJSON - single tool\n",
- "video_mask_ndjson_bytes_2 = {\n",
- " 'masks': {\n",
- " 'frames': [\n",
- " {\n",
- " \"index\" : 31,\n",
- " \"imBytes\": img_bytes,\n",
- " },\n",
- " {\n",
- " \"index\" : 34,\n",
- " \"imBytes\": img_bytes,\n",
- " }\n",
- " ],\n",
- " 'instances': [\n",
- " {\n",
- " \"colorRGB\" : [76, 104, 177],\n",
- " \"name\" : \"video_mask\"\n",
- " }\n",
- " ]\n",
- " }\n",
- " }"
- ],
+ "source": "### Raster Segmentation (Byte string array)\n## For this example we are going to to pass all the annotations payload in a single VideoMaskAnnotation\n\n# Single mask\nurl = \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/frame_24_composite_mask.png\"\nresponse = requests.get(url)\nimg_bytes = base64.b64encode(response.content).decode(\"utf-8\")\n\n# We are generating our frames and instances in this step, and will later add them to the VideoMaskAnnotation that will contain\n# all frames and instances\nframes_mask_single = [\n lb_types.MaskFrame(\n index=20,\n im_bytes=response.\n content, # Instead of bytes you could also pass an instance URI : instance_uri=url\n )\n]\ninstances_mask_single = [\n lb_types.MaskInstance(color_rgb=(76, 104, 177), name=\"video_mask\")\n]\n\n## Add multiple masks using multiple tools in different frames - Note that only once composite mask can exist per frame\nframes_cp_mask_url = [\n {\n \"1\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/frame_1_composite_mask.png\"\n },\n {\n \"24\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/frame_24_composite_mask.png\"\n },\n {\n \"26\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/frame_26_composite_mask.png\"\n },\n]\n\nrgb_mask_tool = [(227, 135, 126), (169, 248, 152), (83, 152, 103)]\ncp_masks = []\nunique_colors = set()\n\nlb_frames = []\nlb_instances = []\ncounter = 0\n\nfor d in frames_cp_mask_url:\n for frame_no, v in d.items():\n response = requests.get(v)\n colors = extract_rgb_colors_from_url(v)\n for color in colors:\n if not color in unique_colors:\n unique_colors.add(color)\n name = (\"video_mask\" if color in rgb_mask_tool else\n \"mask_with_text_subclass\")\n lb_instances.append(\n lb_types.MaskInstance(color_rgb=color, name=name))\n counter += 1\n lb_frames.append(\n lb_types.MaskFrame(index=frame_no, im_bytes=response.content))\ncp_masks.append(\n lb_types.VideoMaskAnnotation(\n frames=lb_frames + frames_mask_single,\n instances=lb_instances + instances_mask_single,\n ))\n\npp.pprint(lb_frames)\npp.pprint(cp_masks)\n\n# NDJSON - single tool\nvideo_mask_ndjson_bytes_2 = {\n \"masks\": {\n \"frames\": [\n {\n \"index\": 31,\n \"imBytes\": img_bytes,\n },\n {\n \"index\": 34,\n \"imBytes\": img_bytes,\n },\n ],\n \"instances\": [{\n \"colorRGB\": [76, 104, 177],\n \"name\": \"video_mask\"\n }],\n }\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -801,88 +232,7 @@
},
{
"metadata": {},
- "source": [
- "# Fist instance of bounding box ranging from frame 22 to 27\n",
- "bbox_annotation_1 = [\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_video\",\n",
- " keyframe=True,\n",
- " frame=22,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]), # x = left, y = top\n",
- " end=lb_types.Point(x=bbox_dm[\"left\"] + bbox_dm[\"width\"], y=bbox_dm[\"top\"] + bbox_dm[\"height\"]), # x= left + width , y = top + height\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_video\",\n",
- " keyframe=True,\n",
- " frame=27,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]),\n",
- " end=lb_types.Point(x=bbox_dm[\"left\"] + bbox_dm[\"width\"], y=bbox_dm[\"top\"] + bbox_dm[\"height\"]),\n",
- " )\n",
- " )\n",
- "]\n",
- "# NDJSON example:\n",
- "bbox_frame_annotation_ndjson = {\n",
- " \"name\": \"bbox_video\",\n",
- " \"segments\": [{\n",
- " \"keyframes\": [\n",
- " {\n",
- " \"frame\": 22,\n",
- " \"bbox\": bbox_dm\n",
- " },\n",
- " {\n",
- " \"frame\": 27,\n",
- " \"bbox\": bbox_dm2\n",
- " }\n",
- "\n",
- " ]\n",
- " }]\n",
- "}\n",
- "\n",
- "# Second instance of bounding box ranging from frame 22 to 27\n",
- "bbox_annotation_2 = [\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_video\",\n",
- " keyframe=True,\n",
- " frame=22,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]),\n",
- " end=lb_types.Point(x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"], y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"]),\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_video\",\n",
- " keyframe=True,\n",
- " frame=27,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]),\n",
- " end=lb_types.Point(x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"], y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"]),\n",
- " )\n",
- " )\n",
- "]\n",
- "# NDJSON\n",
- "bbox_frame_annotation_ndjson2 = {\n",
- " \"name\": \"bbox_video\",\n",
- " \"segments\": [{\n",
- " \"keyframes\": [\n",
- " {\n",
- " \"frame\": 22,\n",
- " \"bbox\": bbox_dm\n",
- " },\n",
- " {\n",
- " \"frame\": 27,\n",
- " \"bbox\": bbox_dm2\n",
- " }\n",
- " ]\n",
- " }]\n",
- " }\n"
- ],
+ "source": "# Fist instance of bounding box ranging from frame 22 to 27\nbbox_annotation_1 = [\n lb_types.VideoObjectAnnotation(\n name=\"bbox_video\",\n keyframe=True,\n frame=22,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm[\"left\"],\n y=bbox_dm[\"top\"]), # x = left, y = top\n end=lb_types.Point(\n x=bbox_dm[\"left\"] + bbox_dm[\"width\"],\n y=bbox_dm[\"top\"] + bbox_dm[\"height\"],\n ), # x= left + width , y = top + height\n ),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"bbox_video\",\n keyframe=True,\n frame=27,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]),\n end=lb_types.Point(\n x=bbox_dm[\"left\"] + bbox_dm[\"width\"],\n y=bbox_dm[\"top\"] + bbox_dm[\"height\"],\n ),\n ),\n ),\n]\n# NDJSON example:\nbbox_frame_annotation_ndjson = {\n \"name\":\n \"bbox_video\",\n \"segments\": [{\n \"keyframes\": [\n {\n \"frame\": 22,\n \"bbox\": bbox_dm\n },\n {\n \"frame\": 27,\n \"bbox\": bbox_dm2\n },\n ]\n }],\n}\n\n# Second instance of bounding box ranging from frame 22 to 27\nbbox_annotation_2 = [\n lb_types.VideoObjectAnnotation(\n name=\"bbox_video\",\n keyframe=True,\n frame=22,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]),\n end=lb_types.Point(\n x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"],\n y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"],\n ),\n ),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"bbox_video\",\n keyframe=True,\n frame=27,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]),\n end=lb_types.Point(\n x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"],\n y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"],\n ),\n ),\n ),\n]\n# NDJSON\nbbox_frame_annotation_ndjson2 = {\n \"name\":\n \"bbox_video\",\n \"segments\": [{\n \"keyframes\": [\n {\n \"frame\": 22,\n \"bbox\": bbox_dm\n },\n {\n \"frame\": 27,\n \"bbox\": bbox_dm2\n },\n ]\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -903,30 +253,7 @@
},
{
"metadata": {},
- "source": [
- "global_key = \"sample-video-jellyfish.mp4\"\n",
- "asset = {\n",
- " \"row_data\": \"https://storage.googleapis.com/labelbox-datasets/video-sample-data/sample-video-2.mp4\",\n",
- " \"global_key\": global_key,\n",
- " \"media_type\": \"VIDEO\"\n",
- " }\n",
- "\n",
- "dataset = client.create_dataset(\n",
- " name=\"video_demo_dataset\",\n",
- " iam_integration=None # If this argument is removed, labelbox will use the default integration for your organization.\n",
- ")\n",
- "task = dataset.create_data_rows([asset])\n",
- "task.wait_till_done()\n",
- "print(f\"Failed data rows: {task.failed_data_rows}\")\n",
- "print(f\"Errors: {task.errors}\")\n",
- "\n",
- "if task.errors:\n",
- " for error in task.errors:\n",
- " if 'Duplicate global key' in error['message'] and dataset.row_count == 0:\n",
- " # If the global key already exists in the workspace the dataset will be created empty, so we can delete it.\n",
- " print(f\"Deleting empty dataset: {dataset}\")\n",
- " dataset.delete()"
- ],
+ "source": "global_key = \"sample-video-jellyfish.mp4\"\nasset = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/video-sample-data/sample-video-2.mp4\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"VIDEO\",\n}\n\ndataset = client.create_dataset(\n name=\"video_demo_dataset\",\n iam_integration=\n None, # If this argument is removed, labelbox will use the default integration for your organization.\n)\ntask = dataset.create_data_rows([asset])\ntask.wait_till_done()\nprint(f\"Failed data rows: {task.failed_data_rows}\")\nprint(f\"Errors: {task.errors}\")\n\nif task.errors:\n for error in task.errors:\n if (\"Duplicate global key\" in error[\"message\"] and\n dataset.row_count == 0):\n # If the global key already exists in the workspace the dataset will be created empty, so we can delete it.\n print(f\"Deleting empty dataset: {dataset}\")\n dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -946,112 +273,7 @@
},
{
"metadata": {},
- "source": [
- "ontology_builder = lb.OntologyBuilder(\n",
- " tools=[\n",
- " lb.Tool(tool=lb.Tool.Type.BBOX, name=\"bbox_video\"),\n",
- " lb.Tool(tool=lb.Tool.Type.POINT, name=\"point_video\"),\n",
- " lb.Tool(tool=lb.Tool.Type.LINE, name=\"line_video_frame\"),\n",
- " lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=\"video_mask\"),\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.BBOX, name=\"bbox_class\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"checklist_class\",\n",
- " scope = lb.Classification.Scope.INDEX,\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " )\n",
- " ]\n",
- " ),\n",
- " lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION,\n",
- " name=\"mask_with_text_subclass\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"sub_free_text\")\n",
- " ]\n",
- " )\n",
- " ],\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_class\",\n",
- " scope = lb.Classification.Scope.INDEX, ## Need to defined scope for frame classifications\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_class\",\n",
- " scope = lb.Classification.Scope.INDEX,\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\"),\n",
- " lb.Option(value=\"second_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " options=[\n",
- " lb.Option(\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[lb.Option(\"first_sub_radio_answer\")]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_class_global\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\"),\n",
- " lb.Option(value=\"second_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_class_global\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"free_text\"\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Video Annotation Import Demo Ontology\",\n",
- " ontology_builder.asdict(),\n",
- " media_type=lb.MediaType.Video)"
- ],
+ "source": "ontology_builder = lb.OntologyBuilder(\n tools=[\n lb.Tool(tool=lb.Tool.Type.BBOX, name=\"bbox_video\"),\n lb.Tool(tool=lb.Tool.Type.POINT, name=\"point_video\"),\n lb.Tool(tool=lb.Tool.Type.LINE, name=\"line_video_frame\"),\n lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=\"video_mask\"),\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"bbox_class\",\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"checklist_class\",\n scope=lb.Classification.Scope.INDEX,\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n )\n ],\n ),\n lb.Tool(\n tool=lb.Tool.Type.RASTER_SEGMENTATION,\n name=\"mask_with_text_subclass\",\n classifications=[\n lb.Classification(class_type=lb.Classification.Type.TEXT,\n name=\"sub_free_text\")\n ],\n ),\n ],\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_class\",\n scope=lb.Classification.Scope.\n INDEX, ## Need to defined scope for frame classifications\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_class\",\n scope=lb.Classification.Scope.INDEX,\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n options=[\n lb.Option(\n \"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(\"first_sub_radio_answer\")],\n )\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_class_global\",\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_class_global\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n ),\n lb.Classification(class_type=lb.Classification.Type.TEXT,\n name=\"free_text\"),\n ],\n)\n\nontology = client.create_ontology(\n \"Video Annotation Import Demo Ontology\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Video,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1066,13 +288,7 @@
},
{
"metadata": {},
- "source": [
- "project = client.create_project(name=\"Video Annotation Import Demo\",\n",
- " media_type=lb.MediaType.Video)\n",
- "\n",
- "## connect ontology to your project\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "project = client.create_project(name=\"Video Annotation Import Demo\",\n media_type=lb.MediaType.Video)\n\n## connect ontology to your project\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1086,15 +302,7 @@
},
{
"metadata": {},
- "source": [
- "batch = project.create_batch(\n",
- " \"first-batch-video-demo2\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # A paginated collection of data row objects, a list of data rows or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")\n",
- "\n",
- "print(\"Batch: \", batch)"
- ],
+ "source": "batch = project.create_batch(\n \"first-batch-video-demo2\", # Each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # A paginated collection of data row objects, a list of data rows or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)\n\nprint(\"Batch: \", batch)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1118,33 +326,7 @@
},
{
"metadata": {},
- "source": [
- "label = []\n",
- "annotations_list = [\n",
- " checklist_annotation,\n",
- " radio_annotation,\n",
- " bbox_annotation,\n",
- " frame_bbox_with_checklist_subclass_annotation,\n",
- " bbox_annotation_1,\n",
- " bbox_annotation_2,\n",
- " point_annotation,\n",
- " polyline_annotation,\n",
- " global_checklist_annotation,\n",
- " global_radio_annotation,\n",
- " nested_checklist_annotation,\n",
- " nested_radio_annotation,\n",
- " text_annotation,\n",
- " cp_masks\n",
- " ]\n",
- "\n",
- "for annotation in annotations_list:\n",
- " label.append(\n",
- " lb_types.Label(\n",
- " data= {\"global_key\": global_key},\n",
- " annotations = annotation\n",
- " )\n",
- " )\n"
- ],
+ "source": "label = []\nannotations_list = [\n checklist_annotation,\n radio_annotation,\n bbox_annotation,\n frame_bbox_with_checklist_subclass_annotation,\n bbox_annotation_1,\n bbox_annotation_2,\n point_annotation,\n polyline_annotation,\n global_checklist_annotation,\n global_radio_annotation,\n nested_checklist_annotation,\n nested_radio_annotation,\n text_annotation,\n cp_masks,\n]\n\nfor annotation in annotations_list:\n label.append(\n lb_types.Label(data={\"global_key\": global_key}, annotations=annotation))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1166,34 +348,7 @@
},
{
"metadata": {},
- "source": [
- "label_ndjson = []\n",
- "\n",
- "annotations_list_ndjson = [\n",
- " point_annotation_ndjson,\n",
- " bbox_annotation_ndjson,\n",
- " polyline_frame_annotation_ndjson,\n",
- " frame_checklist_classification_ndjson,\n",
- " frame_radio_classification_ndjson,\n",
- " nested_radio_annotation_ndjson,\n",
- " nested_checklist_annotation_ndjson,\n",
- " frame_bbox_with_checklist_subclass_annotation_ndjson,\n",
- " global_radio_classification_ndjson,\n",
- " global_checklist_classification_ndjson,\n",
- " text_annotation_ndjson,\n",
- " bbox_frame_annotation_ndjson,\n",
- " bbox_frame_annotation_ndjson2,\n",
- " video_mask_ndjson_bytes_2\n",
- "]\n",
- "\n",
- "for annotation in annotations_list_ndjson:\n",
- " annotation.update({\n",
- " \"dataRow\": {\n",
- " \"globalKey\": global_key\n",
- " }\n",
- " })\n",
- " label_ndjson.append(annotation)\n"
- ],
+ "source": "label_ndjson = []\n\nannotations_list_ndjson = [\n point_annotation_ndjson,\n bbox_annotation_ndjson,\n polyline_frame_annotation_ndjson,\n frame_checklist_classification_ndjson,\n frame_radio_classification_ndjson,\n nested_radio_annotation_ndjson,\n nested_checklist_annotation_ndjson,\n frame_bbox_with_checklist_subclass_annotation_ndjson,\n global_radio_classification_ndjson,\n global_checklist_classification_ndjson,\n text_annotation_ndjson,\n bbox_frame_annotation_ndjson,\n bbox_frame_annotation_ndjson2,\n video_mask_ndjson_bytes_2,\n]\n\nfor annotation in annotations_list_ndjson:\n annotation.update({\"dataRow\": {\"globalKey\": global_key}})\n label_ndjson.append(annotation)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1215,19 +370,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload MAL label for this data row in project\n",
- "upload_job_mal = lb.MALPredictionImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"mal_import_job-\" + str(uuid.uuid4()),\n",
- " predictions=label)\n",
- "\n",
- "upload_job_mal.wait_until_done()\n",
- "print(\"Errors:\", upload_job_mal.errors)\n",
- "print(\"Status of uploads: \", upload_job_mal.statuses)\n",
- "print(\" \")"
- ],
+ "source": "# Upload MAL label for this data row in project\nupload_job_mal = lb.MALPredictionImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"mal_import_job-\" + str(uuid.uuid4()),\n predictions=label,\n)\n\nupload_job_mal.wait_until_done()\nprint(\"Errors:\", upload_job_mal.errors)\nprint(\"Status of uploads: \", upload_job_mal.statuses)\nprint(\" \")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1241,21 +384,7 @@
},
{
"metadata": {},
- "source": [
- "# For this demo either run MAL or Ground truth import, not both.\n",
- "\n",
- "# upload_job_label_import = lb.LabelImport.create_from_objects(\n",
- "# client = client,\n",
- "# project_id = project.uid,\n",
- "# name = \"label_import_job-\" + str(uuid.uuid4()),\n",
- "# labels=label\n",
- "# )\n",
- "\n",
- "# upload_job_label_import.wait_until_done()\n",
- "# print(\"Errors:\", upload_job_label_import.errors)\n",
- "# print(\"Status of uploads: \", upload_job_label_import.statuses)\n",
- "# print(\" \")"
- ],
+ "source": "# For this demo either run MAL or Ground truth import, not both.\n\n# upload_job_label_import = lb.LabelImport.create_from_objects(\n# client = client,\n# project_id = project.uid,\n# name = \"label_import_job-\" + str(uuid.uuid4()),\n# labels=label\n# )\n\n# upload_job_label_import.wait_until_done()\n# print(\"Errors:\", upload_job_label_import.errors)\n# print(\"Status of uploads: \", upload_job_label_import.statuses)\n# print(\" \")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1269,11 +398,7 @@
},
{
"metadata": {},
- "source": [
- "# Delete Project\n",
- "# project.delete()\n",
- "#dataset.delete()\n"
- ],
+ "source": "# Delete Project\n# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/assets/2560px-Kitano_Street_Kobe01s5s4110.jpg b/examples/assets/2560px-Kitano_Street_Kobe01s5s4110.jpg
deleted file mode 100644
index 456d3fd3b..000000000
Binary files a/examples/assets/2560px-Kitano_Street_Kobe01s5s4110.jpg and /dev/null differ
diff --git a/examples/assets/mapillary_sample.csv b/examples/assets/mapillary_sample.csv
deleted file mode 100644
index 39946b292..000000000
--- a/examples/assets/mapillary_sample.csv
+++ /dev/null
@@ -1,100 +0,0 @@
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/kZk7l0m2V7nnqhmsyVoAJA.jpg,training/images/kZk7l0m2V7nnqhmsyVoAJA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/PoD0CQAItRXopSCapAomHQ.jpg,training/images/PoD0CQAItRXopSCapAomHQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/UOUce6pCCsjZUDQXtKvQeg.jpg,training/images/UOUce6pCCsjZUDQXtKvQeg.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/qKFq4pjmpaZIvkJQlCKidw.jpg,training/images/qKFq4pjmpaZIvkJQlCKidw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/tTgFAOl40AKV9MZwp1CXEw.jpg,training/images/tTgFAOl40AKV9MZwp1CXEw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/68Ifrdr6d5CO88kYytaIzw.jpg,training/images/68Ifrdr6d5CO88kYytaIzw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/68XYas1ADxW1lQfC_j3F0Q.jpg,training/images/68XYas1ADxW1lQfC_j3F0Q.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/Dp04ASGp5yx6CliO-FA_VA.jpg,training/images/Dp04ASGp5yx6CliO-FA_VA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/_mbbZwa1o49OlYhrnSQxfg.jpg,training/images/_mbbZwa1o49OlYhrnSQxfg.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/FQFvVttE5P5ypLm5iGDgUQ.jpg,training/images/FQFvVttE5P5ypLm5iGDgUQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/U6RnrAjXMMBCX4SDEnUScQ.jpg,training/images/U6RnrAjXMMBCX4SDEnUScQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/JBBoKJDVD29N2R-G3Ljivw.jpg,training/images/JBBoKJDVD29N2R-G3Ljivw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/Cw3H34f4qc5mKF3ZtXMGFw.jpg,training/images/Cw3H34f4qc5mKF3ZtXMGFw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/AGvJIvHH4tOQ4htlt1OfPQ.jpg,training/images/AGvJIvHH4tOQ4htlt1OfPQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/8elMC15QdDxkyjfUMDF_dw.jpg,training/images/8elMC15QdDxkyjfUMDF_dw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/obcP57e5lbgam-_jzod6sA.jpg,training/images/obcP57e5lbgam-_jzod6sA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/0Bt3m_mPk8_jhCdeWzEGLw.jpg,training/images/0Bt3m_mPk8_jhCdeWzEGLw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/gKixCQtUkC4aNByMjwbpsQ.jpg,training/images/gKixCQtUkC4aNByMjwbpsQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/NWVBiMFnp0dNFk1epzSpGQ.jpg,training/images/NWVBiMFnp0dNFk1epzSpGQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/dAMDv5Hd4rw5AMSD1u0xCQ.jpg,training/images/dAMDv5Hd4rw5AMSD1u0xCQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/SCP4Jy5MXHPQfOmvey6-4A.jpg,training/images/SCP4Jy5MXHPQfOmvey6-4A.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/We3m55yJEo2vEbv-BksKqQ.jpg,training/images/We3m55yJEo2vEbv-BksKqQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/ean7gKcwAeAO24dLJIsIag.jpg,training/images/ean7gKcwAeAO24dLJIsIag.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/U8EgEcKY3xfpGZGwfj1Y5Q.jpg,training/images/U8EgEcKY3xfpGZGwfj1Y5Q.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/fn6zKpG_MJzwvuu1cAyi-w.jpg,training/images/fn6zKpG_MJzwvuu1cAyi-w.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/U3AUsNKJtGxt3s5kd-w3FA.jpg,training/images/U3AUsNKJtGxt3s5kd-w3FA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/6bJlU6-y6LYJ7P9tz5HwxA.jpg,training/images/6bJlU6-y6LYJ7P9tz5HwxA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/ILFinfuTTovBfHAU_6fXbQ.jpg,training/images/ILFinfuTTovBfHAU_6fXbQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/VzE1_tDhYY0ZwLJ5JDwIog.jpg,training/images/VzE1_tDhYY0ZwLJ5JDwIog.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/pqVP5zno7C1ib8VxDlwF_Q.jpg,training/images/pqVP5zno7C1ib8VxDlwF_Q.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/EJDylABDjFh-cYtCyE0N3A.jpg,training/images/EJDylABDjFh-cYtCyE0N3A.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/pj1GP4g9YmeuLufkKW1y4w.jpg,training/images/pj1GP4g9YmeuLufkKW1y4w.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/kgdDdKnOg-bJ4zU3e0GYHQ.jpg,training/images/kgdDdKnOg-bJ4zU3e0GYHQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/tvsUbziGqgQyql1uw4yc0Q.jpg,training/images/tvsUbziGqgQyql1uw4yc0Q.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/P1Vz4pQqz9YyuTe_2phXzQ.jpg,training/images/P1Vz4pQqz9YyuTe_2phXzQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/4AFnYQ4ubgG5PGLYOpfwrQ.jpg,training/images/4AFnYQ4ubgG5PGLYOpfwrQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/2Fcdo9pR7WbzOzCjr2Y5tg.jpg,training/images/2Fcdo9pR7WbzOzCjr2Y5tg.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/u3RRAcic_3Brj9m3XyDLXw.jpg,training/images/u3RRAcic_3Brj9m3XyDLXw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/sIzNxdaXU_PlRHwO8HjQXw.jpg,training/images/sIzNxdaXU_PlRHwO8HjQXw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/k7t-bPnuaQEHCkfdur68Dg.jpg,training/images/k7t-bPnuaQEHCkfdur68Dg.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/lD5ZgcZvRe8qVnbRWBbs6Q.jpg,training/images/lD5ZgcZvRe8qVnbRWBbs6Q.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/sKyHFo_yiRpGP9rFRY1KNA.jpg,training/images/sKyHFo_yiRpGP9rFRY1KNA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/0Ok3Sz1Dhr5FBUjkoO24xw.jpg,training/images/0Ok3Sz1Dhr5FBUjkoO24xw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/J4SCfwMpRCS8lh-AR7CMJw.jpg,training/images/J4SCfwMpRCS8lh-AR7CMJw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/7xKvRIFzFLfnmwMPGFjZfQ.jpg,training/images/7xKvRIFzFLfnmwMPGFjZfQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/rLugtHA_OqGmDZ4ocz9CWg.jpg,training/images/rLugtHA_OqGmDZ4ocz9CWg.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/rJlO9MQcQO26i3FlvBkrJw.jpg,training/images/rJlO9MQcQO26i3FlvBkrJw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/8CfzEhWiUKj_AZifeCmj-g.jpg,training/images/8CfzEhWiUKj_AZifeCmj-g.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/yF-UqX4rkwv3fH7bt3vTAg.jpg,training/images/yF-UqX4rkwv3fH7bt3vTAg.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/VzKhfCIQMewZ5vLLQcXTDQ.jpg,training/images/VzKhfCIQMewZ5vLLQcXTDQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/VIhdyN5ieuwJBvzo6XtMyg.jpg,training/images/VIhdyN5ieuwJBvzo6XtMyg.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/tU-XPKVdFEh8gJTipJex1w.jpg,training/images/tU-XPKVdFEh8gJTipJex1w.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/EtobqglMr0IjgYL1zdS3oQ.jpg,training/images/EtobqglMr0IjgYL1zdS3oQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/vNPTqIo-NLmFSMyputJF1g.jpg,training/images/vNPTqIo-NLmFSMyputJF1g.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/c9rgbiv0TK-6evZu3Mws-g.jpg,training/images/c9rgbiv0TK-6evZu3Mws-g.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/ctaAVl2-2O_fAHxfcerp4w.jpg,training/images/ctaAVl2-2O_fAHxfcerp4w.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/6EmgKA4In5Y-MQBscivM7A.jpg,training/images/6EmgKA4In5Y-MQBscivM7A.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/Ab8wVHpk__ojJQWlv4j_ow.jpg,training/images/Ab8wVHpk__ojJQWlv4j_ow.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/Z7D6wcrTf2WWpO5gMvyKcQ.jpg,training/images/Z7D6wcrTf2WWpO5gMvyKcQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/UpN-qhIYSuDm69E9L4n6Lg.jpg,training/images/UpN-qhIYSuDm69E9L4n6Lg.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/MIAlcaLm7c6asLL2NbrWjA.jpg,training/images/MIAlcaLm7c6asLL2NbrWjA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/kbKR6zkGb4rmnPbXm30nNA.jpg,training/images/kbKR6zkGb4rmnPbXm30nNA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/iXnmKWADB-SvnNX32JQk0Q.jpg,training/images/iXnmKWADB-SvnNX32JQk0Q.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/4lmKD8XHZBfptBzkg5HdXA.jpg,training/images/4lmKD8XHZBfptBzkg5HdXA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/RfY03oO3YW_Of5-whOv0qQ.jpg,training/images/RfY03oO3YW_Of5-whOv0qQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/ewBSwnRuCC_Xkg64eHOnhQ.jpg,training/images/ewBSwnRuCC_Xkg64eHOnhQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/gc2sYMu9mrUhX2DX75JBzg.jpg,training/images/gc2sYMu9mrUhX2DX75JBzg.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/ED92LBTvz6LeSIwbbOyS8A.jpg,training/images/ED92LBTvz6LeSIwbbOyS8A.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/jWbex8hfixVSAcQLPexA4A.jpg,training/images/jWbex8hfixVSAcQLPexA4A.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/4QnX1QLSCUjjKHVN2m80dw.jpg,training/images/4QnX1QLSCUjjKHVN2m80dw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/YhPqBXitBGD-my_I5tIzyw.jpg,training/images/YhPqBXitBGD-my_I5tIzyw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/JR6FYSOzGdZ2iGfdUJd8gw.jpg,training/images/JR6FYSOzGdZ2iGfdUJd8gw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/aFed752KJaSG2TikYCC3HA.jpg,training/images/aFed752KJaSG2TikYCC3HA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/6xLGJYlbYD0GoPewrWAKUA.jpg,training/images/6xLGJYlbYD0GoPewrWAKUA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/WNbXfbdP8NFO_s-iabyfww.jpg,training/images/WNbXfbdP8NFO_s-iabyfww.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/yVdNRdqHwo0M6Dowhb-zjA.jpg,training/images/yVdNRdqHwo0M6Dowhb-zjA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/F-tYSSw3YDjb-hArun1-1A.jpg,training/images/F-tYSSw3YDjb-hArun1-1A.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/EAeHeW-HuEoprssx8w9czw.jpg,training/images/EAeHeW-HuEoprssx8w9czw.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/3zzVwxQIuYzX-9FVu6MKAg.jpg,training/images/3zzVwxQIuYzX-9FVu6MKAg.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/-zZvqUIoMscnxGRg_b6AWA.jpg,training/images/-zZvqUIoMscnxGRg_b6AWA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/rjw8Hrwc4_UPcROllsbLGQ.jpg,training/images/rjw8Hrwc4_UPcROllsbLGQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/CoG8c9yxubnjMgbm22W95A.jpg,training/images/CoG8c9yxubnjMgbm22W95A.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/klrFi15yG2gCTQPfEertHQ.jpg,training/images/klrFi15yG2gCTQPfEertHQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/MF0JeDTRshpIZ8SYb7Sy1w.jpg,training/images/MF0JeDTRshpIZ8SYb7Sy1w.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/r0lC8be9Qvfi-ycXo1tB3w.jpg,training/images/r0lC8be9Qvfi-ycXo1tB3w.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/ZU7aRLI_PbvB1y_203MWVA.jpg,training/images/ZU7aRLI_PbvB1y_203MWVA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/-nvTzJ-2am0mxQPqnZzZBA.jpg,training/images/-nvTzJ-2am0mxQPqnZzZBA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/p4sYDNS69hIS0vA7lULRcg.jpg,training/images/p4sYDNS69hIS0vA7lULRcg.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/OMwoSqgTR09a8qT4R9GkXA.jpg,training/images/OMwoSqgTR09a8qT4R9GkXA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/dKM4xuG0sifb7_KyQ-WdBA.jpg,training/images/dKM4xuG0sifb7_KyQ-WdBA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/wfpOKIPoe-Xrk0TwJc11nQ.jpg,training/images/wfpOKIPoe-Xrk0TwJc11nQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/70Pv1m9RIxB34Sc9sfpgEA.jpg,training/images/70Pv1m9RIxB34Sc9sfpgEA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/OjNE5FUGkxXLdv2GIrtQZg.jpg,training/images/OjNE5FUGkxXLdv2GIrtQZg.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/r5KkHSwFjKU1pfYaAGorkg.jpg,training/images/r5KkHSwFjKU1pfYaAGorkg.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/ECbzIgEyzp8hY6fbB4Tp_g.jpg,training/images/ECbzIgEyzp8hY6fbB4Tp_g.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/xi9uVnE4yOqECSPxcbByWA.jpg,training/images/xi9uVnE4yOqECSPxcbByWA.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/PZzzUa4eM6Xw6J47UUe1Ow.jpg,training/images/PZzzUa4eM6Xw6J47UUe1Ow.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/QmvPdO6L8jQgPQFYYGFnNQ.jpg,training/images/QmvPdO6L8jQgPQFYYGFnNQ.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/Vtner0MBgPIYRjmpLMPv5g.jpg,training/images/Vtner0MBgPIYRjmpLMPv5g.jpg
-https://labelbox.s3-us-west-2.amazonaws.com/datasets/mapillary_vistas/training/images/e-SKbauA2EMHkU5pC5Cyzg.jpg,training/images/e-SKbauA2EMHkU5pC5Cyzg.jpg
diff --git a/examples/assets/ti_basics.png b/examples/assets/ti_basics.png
deleted file mode 100644
index ed4057d3b..000000000
Binary files a/examples/assets/ti_basics.png and /dev/null differ
diff --git a/examples/basics/basics.ipynb b/examples/basics/basics.ipynb
index 6ed7b6403..3b7796603 100644
--- a/examples/basics/basics.ipynb
+++ b/examples/basics/basics.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -39,19 +39,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install labelbox"
- ],
+ "source": "%pip install \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import random"
- ],
+ "source": "import labelbox as lb",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -59,67 +54,35 @@
{
"metadata": {},
"source": [
- "# API Key and Client\n",
- "Provide a valid api key below in order to properly connect to the Labelbox Client."
+ "## API key and client\n",
+ "Provide a valid API key below in order to properly connect to the Labelbox Client."
],
"cell_type": "markdown"
},
{
"metadata": {},
- "source": [
- "# Add your api key\n",
- "API_KEY=None\n",
- "# To get your API key go to: Workspace settings -> API -> Create API Key\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your API key\nAPI_KEY = None\n# To get your API key go to: Workspace settings -> API -> Create API Key\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# For the purpose of this demo get a single project/dataset id from your organization\n",
- "\n",
- "# Get a single Project id\n",
- "# get_projects returns a PaginatedCollection object, which is iterable.\n",
- "project = next(client.get_projects())\n",
- "project_id=project.uid\n",
- "project_name=project.name\n",
- "print(\"Project ID: \", project_id)\n",
- "print(\"Project Name:\", project_name)\n",
- "\n",
- "print(\"-\" * 40)\n",
- "\n",
- "# Get a single dataset id\n",
- "# get_datasets returns a PaginatedCollection object, which is iterable.\n",
- "dataset = next(client.get_datasets())\n",
- "dataset_id = dataset.uid\n",
- "dataset_name = dataset.name\n",
- "print(\"Dataset ID: \", dataset_id)\n",
- "print(\"Dataset Name:\" , dataset_name)"
- ],
+ "source": "# For the purpose of this demo get a single project/dataset id from your organization\n\n# Get a single Project id\n# get_projects returns a PaginatedCollection object, which is iterable.\nproject = next(client.get_projects())\nproject_id = project.uid\nproject_name = project.name\nprint(\"Project ID: \", project_id)\nprint(\"Project Name:\", project_name)\n\nprint(\"-\" * 40)\n\n# Get a single dataset id\n# get_datasets returns a PaginatedCollection object, which is iterable.\ndataset = next(client.get_datasets())\ndataset_id = dataset.uid\ndataset_name = dataset.name\nprint(\"Dataset ID: \", dataset_id)\nprint(\"Dataset Name:\", dataset_name)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Fetch the project and dataset by using the IDs fetched in the previous cell\n",
- "project = client.get_project(project_id)\n",
- "dataset = client.get_dataset(dataset_id)"
- ],
+ "source": "# Fetch the project and dataset by using the IDs fetched in the previous cell\nproject = client.get_project(project_id)\ndataset = client.get_dataset(dataset_id)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "print(\"Project: \", project)\n",
- "print(\"Dataset: \", dataset)"
- ],
+ "source": "print(\"Project: \", project)\nprint(\"Dataset: \", dataset)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -135,10 +98,7 @@
},
{
"metadata": {},
- "source": [
- "print(project.name)\n",
- "print(dataset.name)"
- ],
+ "source": "print(project.name)\nprint(dataset.name)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -152,10 +112,7 @@
},
{
"metadata": {},
- "source": [
- "project.update(description=\"new description field\")\n",
- "print(project.description)\n"
- ],
+ "source": "project.update(description=\"new description field\")\nprint(project.description)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -171,29 +128,14 @@
},
{
"metadata": {},
- "source": [
- "labels_paginated_collection = project.labels()\n",
- "print(\"Type of collection: \", type(labels_paginated_collection))\n",
- "\n",
- "# A paginated collection can be parsed by using list()\n",
- "# list(paginated...) should be avoided for queries that could return more than a dozen results\n",
- "print(\"Number of labels :\", len(list(labels_paginated_collection)))"
- ],
+ "source": "labels_paginated_collection = project.labels()\nprint(\"Type of collection: \", type(labels_paginated_collection))\n\n# A paginated collection can be parsed by using list()\n# list(paginated...) should be avoided for queries that could return more than a dozen results\nprint(\"Number of labels :\", len(list(labels_paginated_collection)))",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Note that if you selected a `project_id` without any labels this will raise `StopIteration`\n",
- "# Iterate over the paginated collection\n",
- "try:\n",
- " single_label = next(project.labels())\n",
- " print(single_label)\n",
- "except StopIteration:\n",
- " print(\"Project has no labels !\")"
- ],
+ "source": "# Note that if you selected a `project_id` without any labels this will raise `StopIteration`\n# Iterate over the paginated collection\ntry:\n single_label = next(project.labels())\n print(single_label)\nexcept StopIteration:\n print(\"Project has no labels !\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -209,21 +151,7 @@
},
{
"metadata": {},
- "source": [
- "datasets = client.get_datasets(where=lb.Dataset.name == dataset_name)\n",
- "\n",
- "projects = client.get_projects(\n",
- " where=((lb.Project.name == project_name) &\n",
- " (lb.Project.description == \"new description field\")))\n",
- "\n",
- "# The above two queries return PaginatedCollections because the filter parameters aren't guaranteed to be unique.\n",
- "# So even if there is one element returned it is in a paginatedCollection.\n",
- "print(projects)\n",
- "print(next(projects, None))\n",
- "print(next(projects, None))\n",
- "print(next(projects, None))\n",
- "# We can see there is only one."
- ],
+ "source": "datasets = client.get_datasets(where=lb.Dataset.name == dataset_name)\n\nprojects = client.get_projects(\n where=((lb.Project.name == project_name) &\n (lb.Project.description == \"new description field\")))\n\n# The above two queries return PaginatedCollections because the filter parameters aren't guaranteed to be unique.\n# So even if there is one element returned it is in a paginatedCollection.\nprint(projects)\nprint(next(projects, None))\nprint(next(projects, None))\nprint(next(projects, None))\n# We can see there is only one.",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -248,15 +176,7 @@
},
{
"metadata": {},
- "source": [
- "sample_project_batches = project.batches()\n",
- "\n",
- "list(sample_project_batches)\n",
- "\n",
- "for b in sample_project_batches:\n",
- " print(f\" Name of project : {b.project().name}\")\n",
- " print(f\" Name of batches in project: {b.name}\")"
- ],
+ "source": "sample_project_batches = project.batches()\n\nlist(sample_project_batches)\n\nfor b in sample_project_batches:\n print(f\" Name of project : {b.project().name}\")\n print(f\" Name of batches in project: {b.name}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/basics/batches.ipynb b/examples/basics/batches.ipynb
index 4424bb68e..2d07682b5 100644
--- a/examples/basics/batches.ipynb
+++ b/examples/basics/batches.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -21,7 +21,7 @@
"\n",
"\n",
"\n",
- "![]() \n",
" | "
],
@@ -50,21 +50,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install \"labelbox[data]\" -q"
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import random\n",
- "import uuid\n",
- "import json"
- ],
+ "source": "import labelbox as lb\nimport random\nimport uuid\nimport json",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -79,12 +72,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your API key\n",
- "API_KEY = \"\"\n",
- "# To get your API key go to: Workspace settings -> API -> Create API Key\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your API key\nAPI_KEY = None\n# To get your API key go to: Workspace settings -> API -> Create API Key\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -98,23 +86,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a dataset\n",
- "dataset = client.create_dataset(name=\"Demo-Batches-Colab\")\n",
- "\n",
- "uploads = []\n",
- "# Generate data rows\n",
- "for i in range(1,9):\n",
- " uploads.append({\n",
- " 'row_data': f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n",
- " \"global_key\": \"TEST-ID-%id\" % uuid.uuid1(),\n",
- " })\n",
- "\n",
- "data_rows = dataset.create_data_rows(uploads)\n",
- "data_rows.wait_till_done()\n",
- "print(\"ERRORS: \" , data_rows.errors)\n",
- "print(\"RESULT URL: \", data_rows.result_url)"
- ],
+ "source": "# Create a dataset\ndataset = client.create_dataset(name=\"Demo-Batches-Colab\")\n\nuploads = []\n# Generate data rows\nfor i in range(1, 9):\n uploads.append({\n \"row_data\":\n f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n \"global_key\":\n \"TEST-ID-%id\" % uuid.uuid1(),\n })\n\ndata_rows = dataset.create_data_rows(uploads)\ndata_rows.wait_till_done()\nprint(\"ERRORS: \", data_rows.errors)\nprint(\"RESULT URL: \", data_rows.result_url)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -128,13 +100,7 @@
},
{
"metadata": {},
- "source": [
- "project = client.create_project(\n",
- " name=\"Demo-Batches-Project\",\n",
- " media_type=lb.MediaType.Image\n",
- ")\n",
- "print(\"Project Name: \", project.name, \"Project ID: \", project.uid)"
- ],
+ "source": "project = client.create_project(name=\"Demo-Batches-Project\",\n media_type=lb.MediaType.Image)\nprint(\"Project Name: \", project.name, \"Project ID: \", project.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -155,42 +121,14 @@
},
{
"metadata": {},
- "source": [
- "client.enable_experimental = True\n",
- "\n",
- "export_task = dataset.export()\n",
- "export_task.wait_till_done()\n",
- "\n",
- "data_rows = []\n",
- "\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " data_row = json.loads(output.json_str)\n",
- " data_rows.append(data_row)\n",
- "\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- "\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)"
- ],
+ "source": "client.enable_experimental = True\n\nexport_task = dataset.export()\nexport_task.wait_till_done()\n\ndata_rows = []\n\n\ndef json_stream_handler(output: lb.JsonConverterOutput):\n data_row = json.loads(output.json_str)\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "global_keys = [data_row[\"data_row\"][\"global_key\"] for data_row in data_rows]\n",
- "print(\"Number of global keys:\", len(global_keys))"
- ],
+ "source": "global_keys = [data_row[\"data_row\"][\"global_key\"] for data_row in data_rows]\nprint(\"Number of global keys:\", len(global_keys))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -205,9 +143,7 @@
},
{
"metadata": {},
- "source": [
- "sample = random.sample(global_keys, 4)"
- ],
+ "source": "sample = random.sample(global_keys, 4)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -222,15 +158,7 @@
},
{
"metadata": {},
- "source": [
- "batch = project.create_batch(\n",
- " name=\"Demo-First-Batch\", # Each batch in a project must have a unique name\n",
- " global_keys=sample, # A list of data rows or data row ids\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")\n",
- "# number of data rows in the batch\n",
- "print(\"Number of data rows in batch: \", batch.size)"
- ],
+ "source": "batch = project.create_batch(\n name=\"Demo-First-Batch\", # Each batch in a project must have a unique name\n global_keys=sample, # A list of data rows or data row ids\n priority=5, # priority between 1(Highest) - 5(lowest)\n)\n# number of data rows in the batch\nprint(\"Number of data rows in batch: \", batch.size)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -251,24 +179,7 @@
},
{
"metadata": {},
- "source": [
- "# First, we must create a second project so that we can re-use the data rows we already created.\n",
- "second_project = client.create_project(\n",
- " name=\"Second-Demo-Batches-Project\",\n",
- " media_type=lb.MediaType.Image\n",
- ")\n",
- "print(\"Project Name: \", second_project.name, \"Project ID: \", second_project.uid)\n",
- "\n",
- "# Then, use the method that will create multiple batches if necessary.\n",
- "task = second_project.create_batches(\n",
- " name_prefix=\"demo-create-batches-\",\n",
- " global_keys=global_keys,\n",
- " priority=5\n",
- ")\n",
- "\n",
- "print(\"Errors: \", task.errors())\n",
- "print(\"Result: \", task.result())"
- ],
+ "source": "# First, we must create a second project so that we can re-use the data rows we already created.\nsecond_project = client.create_project(name=\"Second-Demo-Batches-Project\",\n media_type=lb.MediaType.Image)\nprint(\"Project Name: \", second_project.name, \"Project ID: \", second_project.uid)\n\n# Then, use the method that will create multiple batches if necessary.\ntask = second_project.create_batches(name_prefix=\"demo-create-batches-\",\n global_keys=global_keys,\n priority=5)\n\nprint(\"Errors: \", task.errors())\nprint(\"Result: \", task.result())",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -286,24 +197,7 @@
},
{
"metadata": {},
- "source": [
- "# First, we must create a third project so that we can re-use the data rows we already created.\n",
- "third_project = client.create_project(\n",
- " name=\"Third-Demo-Batches-Project\",\n",
- " media_type=lb.MediaType.Image\n",
- ")\n",
- "print(\"Project Name: \", third_project.name, \"Project ID: \", third_project.uid)\n",
- "\n",
- "# Then, use the method to create batches from a dataset.\n",
- "task = third_project.create_batches_from_dataset(\n",
- " name_prefix=\"demo-batches-from-dataset-\",\n",
- " dataset_id=dataset.uid,\n",
- " priority=5\n",
- ")\n",
- "\n",
- "print(\"Errors: \", task.errors())\n",
- "print(\"Result: \", task.result())"
- ],
+ "source": "# First, we must create a third project so that we can re-use the data rows we already created.\nthird_project = client.create_project(name=\"Third-Demo-Batches-Project\",\n media_type=lb.MediaType.Image)\nprint(\"Project Name: \", third_project.name, \"Project ID: \", third_project.uid)\n\n# Then, use the method to create batches from a dataset.\ntask = third_project.create_batches_from_dataset(\n name_prefix=\"demo-batches-from-dataset-\",\n dataset_id=dataset.uid,\n priority=5)\n\nprint(\"Errors: \", task.errors())\nprint(\"Result: \", task.result())",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -339,31 +233,7 @@
},
{
"metadata": {},
- "source": [
- "classification_features = [\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"Quality Issues\",\n",
- " options=[\n",
- " lb.Option(value=\"blurry\", label=\"Blurry\"),\n",
- " lb.Option(value=\"distorted\", label=\"Distorted\")\n",
- " ]\n",
- " )\n",
- "]\n",
- "\n",
- "ontology_builder = lb.OntologyBuilder(\n",
- " tools=[],\n",
- " classifications=classification_features\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\n",
- " \"Ontology from new features\",\n",
- " ontology_builder.asdict(),\n",
- " media_type=lb.MediaType.Image\n",
- ")\n",
- "\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "classification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\nontology_builder = lb.OntologyBuilder(tools=[],\n classifications=classification_features)\n\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)\n\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -377,67 +247,21 @@
},
{
"metadata": {},
- "source": [
- "client.enable_experimental = True\n",
- "\n",
- "export_params = {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"batch_ids\" : [batch.uid] # Include batch ids if you only want to export specific batches, otherwise,\n",
- " #you can export all the data without using this parameter\n",
- "}\n",
- "filters = {}\n",
- "\n",
- "# A task is returned, this provides additional information about the status of your task, such as\n",
- "# any errors encountered\n",
- "export_task = project.export(params=export_params, filters=filters)\n",
- "export_task.wait_till_done()"
- ],
+ "source": "client.enable_experimental = True\n\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"performance_details\": True,\n \"batch_ids\": [\n batch.uid\n ], # Include batch ids if you only want to export specific batches, otherwise,\n # you can export all the data without using this parameter\n}\nfilters = {}\n\n# A task is returned, this provides additional information about the status of your task, such as\n# any errors encountered\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "data_rows = []\n",
- "\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " data_row = json.loads(output.json_str)\n",
- " data_rows.append(data_row)\n",
- "\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- "\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)"
- ],
+ "source": "data_rows = []\n\n\ndef json_stream_handler(output: lb.JsonConverterOutput):\n data_row = json.loads(output.json_str)\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "## Export the data row iDs\n",
- "data_rows = [dr for dr in data_rows]\n",
- "print(\"Data rows in batch: \", data_rows)\n",
- "\n",
- "## List the batches in your project\n",
- "for batch in project.batches():\n",
- " print(\"Batch name: \", batch.name , \" Batch ID:\", batch.uid)\n"
- ],
+ "source": "## Export the data row iDs\ndata_rows = [dr for dr in data_rows]\nprint(\"Data rows in batch: \", data_rows)\n\n## List the batches in your project\nfor batch in project.batches():\n print(\"Batch name: \", batch.name, \" Batch ID:\", batch.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -451,10 +275,7 @@
},
{
"metadata": {},
- "source": [
- "# Archiving a batch removes all queued data rows in the batch from the project\n",
- "batch.remove_queued_data_rows()"
- ],
+ "source": "# Archiving a batch removes all queued data rows in the batch from the project\nbatch.remove_queued_data_rows()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -469,16 +290,7 @@
},
{
"metadata": {},
- "source": [
- "# Delete Batch\n",
- "#batch.delete()\n",
- "\n",
- "# Delete Project\n",
- "#project.delete()\n",
- "\n",
- "# Delete DataSet\n",
- "#dataset.delete()"
- ],
+ "source": "# Delete Batch\n# batch.delete()\n\n# Delete Project\n# project.delete()\n\n# Delete DataSet\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/basics/custom_embeddings.ipynb b/examples/basics/custom_embeddings.ipynb
index 20221a80a..45a0b2df0 100644
--- a/examples/basics/custom_embeddings.ipynb
+++ b/examples/basics/custom_embeddings.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -16,12 +16,12 @@
"metadata": {},
"source": [
"\n",
- "![]() \n",
" | \n",
"\n",
"\n",
- "![]() \n",
" | "
],
@@ -45,22 +45,14 @@
},
{
"metadata": {},
- "source": [
- "!pip3 install -q \"labelbox[data]\""
- ],
+ "source": "%pip3 install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import numpy as np\n",
- "import json\n",
- "import uuid\n",
- "import random"
- ],
+ "source": "import labelbox as lb\nimport numpy as np\nimport json\nimport uuid\nimport random",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -74,10 +66,7 @@
},
{
"metadata": {},
- "source": [
- "API_KEY = \"\"\n",
- "client = lb.Client(API_KEY)"
- ],
+ "source": "API_KEY = \"\"\nclient = lb.Client(API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -99,55 +88,28 @@
},
{
"metadata": {},
- "source": [
- "DATASET_ID = \"\""
- ],
+ "source": "DATASET_ID = \"\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "dataset = client.get_dataset(dataset_id=DATASET_ID)\n",
- "export_task = dataset.export()\n",
- "export_task.wait_till_done()"
- ],
+ "source": "dataset = client.get_dataset(dataset_id=DATASET_ID)\nexport_task = dataset.export()\nexport_task.wait_till_done()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "data_rows = []\n",
- "\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " data_row = json.loads(output.json_str)\n",
- " data_rows.append(data_row)\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)"
- ],
+ "source": "data_rows = []\n\n\ndef json_stream_handler(output: lb.JsonConverterOutput):\n data_row = json.loads(output.json_str)\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "data_row_dict = [{\"data_row_id\": dr[\"data_row\"][\"id\"]} for dr in data_rows]\n",
- "data_row_dict = data_row_dict[:1000] # keep the first 1000 examples for the sake of this demo"
- ],
+ "source": "data_row_dict = [{\"data_row_id\": dr[\"data_row\"][\"id\"]} for dr in data_rows]\ndata_row_dict = data_row_dict[:\n 1000] # keep the first 1000 examples for the sake of this demo",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -168,12 +130,7 @@
},
{
"metadata": {},
- "source": [
- "nb_data_rows = len(data_row_dict)\n",
- "print(\"Number of data rows: \", nb_data_rows)\n",
- "# Labelbox supports custom embedding vectors of dimension up to 2048\n",
- "custom_embeddings = [list(np.random.random(2048)) for _ in range(nb_data_rows)]"
- ],
+ "source": "nb_data_rows = len(data_row_dict)\nprint(\"Number of data rows: \", nb_data_rows)\n# Labelbox supports custom embedding vectors of dimension up to 2048\ncustom_embeddings = [list(np.random.random(2048)) for _ in range(nb_data_rows)]",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -187,9 +144,7 @@
},
{
"metadata": {},
- "source": [
- "embeddings = client.get_embeddings()"
- ],
+ "source": "embeddings = client.get_embeddings()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -203,10 +158,7 @@
},
{
"metadata": {},
- "source": [
- "# Name of the custom embedding must be unique\n",
- "embedding = client.create_embedding(\"my_custom_embedding_2048_dimensions\", 2048)"
- ],
+ "source": "# Name of the custom embedding must be unique\nembedding = client.create_embedding(\"my_custom_embedding_2048_dimensions\", 2048)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -227,13 +179,7 @@
},
{
"metadata": {},
- "source": [
- "payload = []\n",
- "for data_row_dict, custom_embedding in zip(data_row_dict,custom_embeddings):\n",
- " payload.append({\"key\": lb.UniqueId(data_row_dict['data_row_id']), \"embeddings\": [{\"embedding_id\": embedding.id, \"vector\": custom_embedding}]})\n",
- "\n",
- "print('payload', len(payload),payload[:1])"
- ],
+ "source": "payload = []\nfor data_row_dict, custom_embedding in zip(data_row_dict, custom_embeddings):\n payload.append({\n \"key\":\n lb.UniqueId(data_row_dict[\"data_row_id\"]),\n \"embeddings\": [{\n \"embedding_id\": embedding.id,\n \"vector\": custom_embedding\n }],\n })\n\nprint(\"payload\", len(payload), payload[:1])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -254,12 +200,7 @@
},
{
"metadata": {},
- "source": [
- "task = dataset.upsert_data_rows(payload)\n",
- "task.wait_till_done()\n",
- "print(task.errors)\n",
- "print(task.status)"
- ],
+ "source": "task = dataset.upsert_data_rows(payload)\ntask.wait_till_done()\nprint(task.errors)\nprint(task.status)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -273,11 +214,7 @@
},
{
"metadata": {},
- "source": [
- "# Count how many data rows have a specific custom embedding (this can take a couple of minutes)\n",
- "count = embedding.get_imported_vector_count()\n",
- "print(count)"
- ],
+ "source": "# Count how many data rows have a specific custom embedding (this can take a couple of minutes)\ncount = embedding.get_imported_vector_count()\nprint(count)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -291,9 +228,7 @@
},
{
"metadata": {},
- "source": [
- "#embedding.delete()"
- ],
+ "source": "# embedding.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -314,10 +249,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a dataset\n",
- "dataset_new = client.create_dataset(name=\"data_rows_with_embeddings\")"
- ],
+ "source": "# Create a dataset\ndataset_new = client.create_dataset(name=\"data_rows_with_embeddings\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -331,10 +263,7 @@
},
{
"metadata": {},
- "source": [
- "embedding = client.get_embedding_by_name(\"my_custom_embedding_2048_dimensions\")\n",
- "vector = [random.uniform(1.0, 2.0) for _ in range(embedding.dims)]"
- ],
+ "source": "embedding = client.get_embedding_by_name(\"my_custom_embedding_2048_dimensions\")\nvector = [random.uniform(1.0, 2.0) for _ in range(embedding.dims)]",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -348,25 +277,7 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "uploads = []\n",
- "# Generate data rows\n",
- "for i in range(1,9):\n",
- " uploads.append({\n",
- " \"row_data\": f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n",
- " \"global_key\": \"TEST-ID-%id\" % uuid.uuid1(),\n",
- " \"embeddings\": [{\n",
- " \"embedding_id\": embedding.id,\n",
- " \"vector\": vector\n",
- " }]\n",
- " })\n",
- "\n",
- "task1 = dataset_new.create_data_rows(uploads)\n",
- "task1.wait_till_done()\n",
- "print(\"ERRORS: \" , task1.errors)\n",
- "print(\"RESULTS:\" , task1.result)"
- ],
+ "source": "uploads = []\n# Generate data rows\nfor i in range(1, 9):\n uploads.append({\n \"row_data\":\n f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n \"global_key\":\n \"TEST-ID-%id\" % uuid.uuid1(),\n \"embeddings\": [{\n \"embedding_id\": embedding.id,\n \"vector\": vector\n }],\n })\n\ntask1 = dataset_new.create_data_rows(uploads)\ntask1.wait_till_done()\nprint(\"ERRORS: \", task1.errors)\nprint(\"RESULTS:\", task1.result)",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/basics/data_row_metadata.ipynb b/examples/basics/data_row_metadata.ipynb
index 8bbee9be9..fa5970ce2 100644
--- a/examples/basics/data_row_metadata.ipynb
+++ b/examples/basics/data_row_metadata.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -71,34 +71,21 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "from datetime import datetime\n",
- "from pprint import pprint\n",
- "from labelbox.schema.data_row_metadata import DataRowMetadataKind\n",
- "from uuid import uuid4"
- ],
+ "source": "import labelbox as lb\nfrom datetime import datetime\nfrom pprint import pprint\nfrom labelbox.schema.data_row_metadata import DataRowMetadataKind\nfrom uuid import uuid4",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Add your API key\n",
- "API_KEY = \"\"\n",
- "# To get your API key go to: Workspace settings -> API -> Create API Key\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your API key\nAPI_KEY = \"\"\n# To get your API key go to: Workspace settings -> API -> Create API Key\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -112,20 +99,14 @@
},
{
"metadata": {},
- "source": [
- "mdo = client.get_data_row_metadata_ontology()"
- ],
+ "source": "mdo = client.get_data_row_metadata_ontology()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# list all your metadata ontology as a dictionary accessable by id\n",
- "metadata_ontologies = mdo.fields_by_id\n",
- "pprint(metadata_ontologies, indent=2)"
- ],
+ "source": "# list all your metadata ontology as a dictionary accessable by id\nmetadata_ontologies = mdo.fields_by_id\npprint(metadata_ontologies, indent=2)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -139,30 +120,21 @@
},
{
"metadata": {},
- "source": [
- "split_field = mdo.reserved_by_name[\"split\"]\n",
- "split_field"
- ],
+ "source": "split_field = mdo.reserved_by_name[\"split\"]\nsplit_field",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "tag_field = mdo.reserved_by_name[\"tag\"]\n",
- "tag_field"
- ],
+ "source": "tag_field = mdo.reserved_by_name[\"tag\"]\ntag_field",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "train_field = mdo.reserved_by_name[\"split\"][\"train\"]\n",
- "train_field"
- ],
+ "source": "train_field = mdo.reserved_by_name[\"split\"][\"train\"]\ntrain_field",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -188,25 +160,7 @@
},
{
"metadata": {},
- "source": [
- "# Construct a metadata field of string kind\n",
- "tag_metadata_field = lb.DataRowMetadataField(\n",
- " name=\"tag\",\n",
- " value=\"tag_string\",\n",
- ")\n",
- "\n",
- "# Construct an metadata field of datetime kind\n",
- "capture_datetime_field = lb.DataRowMetadataField(\n",
- " name=\"captureDateTime\",\n",
- " value=datetime.utcnow(),\n",
- ")\n",
- "\n",
- "# Construct a metadata field of Enums options\n",
- "split_metadata_field = lb.DataRowMetadataField(\n",
- " name=\"split\",\n",
- " value=\"train\",\n",
- ")\n"
- ],
+ "source": "# Construct a metadata field of string kind\ntag_metadata_field = lb.DataRowMetadataField(\n name=\"tag\",\n value=\"tag_string\",\n)\n\n# Construct an metadata field of datetime kind\ncapture_datetime_field = lb.DataRowMetadataField(\n name=\"captureDateTime\",\n value=datetime.utcnow(),\n)\n\n# Construct a metadata field of Enums options\nsplit_metadata_field = lb.DataRowMetadataField(\n name=\"split\",\n value=\"train\",\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -220,26 +174,7 @@
},
{
"metadata": {},
- "source": [
- "# Construct a dictionary of string metadata\n",
- "tag_metadata_field_dict = {\n",
- " \"name\": \"tag\",\n",
- " \"value\": \"tag_string\",\n",
- "}\n",
- "\n",
- "# Construct a dictionary of datetime metadata\n",
- "capture_datetime_field_dict = {\n",
- " \"name\": \"captureDateTime\",\n",
- " \"value\": datetime.utcnow(),\n",
- "}\n",
- "\n",
- "# Construct a dictionary of Enums options metadata\n",
- "split_metadata_field_dict = {\n",
- " \"name\": \"split\",\n",
- " \"value\": \"train\",\n",
- "}\n",
- "\n"
- ],
+ "source": "# Construct a dictionary of string metadata\ntag_metadata_field_dict = {\n \"name\": \"tag\",\n \"value\": \"tag_string\",\n}\n\n# Construct a dictionary of datetime metadata\ncapture_datetime_field_dict = {\n \"name\": \"captureDateTime\",\n \"value\": datetime.utcnow(),\n}\n\n# Construct a dictionary of Enums options metadata\nsplit_metadata_field_dict = {\n \"name\": \"split\",\n \"value\": \"train\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -253,66 +188,21 @@
},
{
"metadata": {},
- "source": [
- "# Final\n",
- "custom_metadata_fields = []\n",
- "\n",
- "# Create the schema for the metadata\n",
- "number_schema = mdo.create_schema(\n",
- " name=\"numberMetadataCustom\",\n",
- " kind=DataRowMetadataKind.number\n",
- ")\n",
- "\n",
- "# Add fields to the metadata schema\n",
- "data_row_metadata_fields_number = lb.DataRowMetadataField(\n",
- " name=number_schema.name,\n",
- " value=5.0\n",
- ")\n",
- "\n",
- "custom_metadata_fields.append(data_row_metadata_fields_number)\n"
- ],
+ "source": "# Final\ncustom_metadata_fields = []\n\n# Create the schema for the metadata\nnumber_schema = mdo.create_schema(name=\"numberMetadataCustom\",\n kind=DataRowMetadataKind.number)\n\n# Add fields to the metadata schema\ndata_row_metadata_fields_number = lb.DataRowMetadataField(\n name=number_schema.name, value=5.0)\n\ncustom_metadata_fields.append(data_row_metadata_fields_number)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Create the schema for an enum metadata\n",
- "custom_metadata_fields = []\n",
- "\n",
- "enum_schema = mdo.create_schema(\n",
- " name=\"enumMetadata\",\n",
- " kind=DataRowMetadataKind.enum,\n",
- " options=[\"option1\", \"option2\"]\n",
- ")\n",
- "\n",
- "# Add fields to the metadata schema\n",
- "data_row_metadata_fields_enum_1 = lb.DataRowMetadataField(\n",
- " name=enum_schema.name,\n",
- " value=\"option1\"\n",
- ")\n",
- "custom_metadata_fields.append(data_row_metadata_fields_enum_1)\n",
- "\n",
- "\n",
- "data_row_metadata_fields_enum_2 = lb.DataRowMetadataField(\n",
- " name=enum_schema.name,\n",
- " value=\"option2\"\n",
- ")\n",
- "custom_metadata_fields.append(data_row_metadata_fields_enum_2)\n",
- "\n"
- ],
+ "source": "# Create the schema for an enum metadata\ncustom_metadata_fields = []\n\nenum_schema = mdo.create_schema(\n name=\"enumMetadata\",\n kind=DataRowMetadataKind.enum,\n options=[\"option1\", \"option2\"],\n)\n\n# Add fields to the metadata schema\ndata_row_metadata_fields_enum_1 = lb.DataRowMetadataField(name=enum_schema.name,\n value=\"option1\")\ncustom_metadata_fields.append(data_row_metadata_fields_enum_1)\n\ndata_row_metadata_fields_enum_2 = lb.DataRowMetadataField(name=enum_schema.name,\n value=\"option2\")\ncustom_metadata_fields.append(data_row_metadata_fields_enum_2)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Inspect the newly created metadata schemas\n",
- "metadata_ontologies = mdo.fields_by_id\n",
- "pprint(metadata_ontologies, indent=2)"
- ],
+ "source": "# Inspect the newly created metadata schemas\nmetadata_ontologies = mdo.fields_by_id\npprint(metadata_ontologies, indent=2)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -328,20 +218,7 @@
},
{
"metadata": {},
- "source": [
- "# A simple example of uploading data rows with metadata\n",
- "dataset = client.create_dataset(name=\"Simple Data Rows import with metadata example\")\n",
- "global_key = \"s_basic.jpg\"\n",
- "data_row = {\"row_data\": \"https://storage.googleapis.com/labelbox-sample-datasets/Docs/basic.jpg\", \"global_key\": global_key}\n",
- "# This line works with dictionaries as well as schemas and fields created with DataRowMetadataField\n",
- "data_row['metadata_fields'] = custom_metadata_fields + [ split_metadata_field , capture_datetime_field_dict, tag_metadata_field ]\n",
- "\n",
- "\n",
- "task = dataset.create_data_rows([data_row])\n",
- "task.wait_till_done()\n",
- "result_task = task.result\n",
- "print(result_task)"
- ],
+ "source": "# A simple example of uploading data rows with metadata\ndataset = client.create_dataset(\n name=\"Simple Data Rows import with metadata example\")\nglobal_key = \"s_basic.jpg\"\ndata_row = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-sample-datasets/Docs/basic.jpg\",\n \"global_key\":\n global_key,\n}\n# This line works with dictionaries as well as schemas and fields created with DataRowMetadataField\ndata_row[\"metadata_fields\"] = custom_metadata_fields + [\n split_metadata_field,\n capture_datetime_field_dict,\n tag_metadata_field,\n]\n\ntask = dataset.create_data_rows([data_row])\ntask.wait_till_done()\nresult_task = task.result\nprint(result_task)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -355,25 +232,7 @@
},
{
"metadata": {},
- "source": [
- "# Get the data row that was uploaded in the previous cell\n",
- "num_schema = mdo.get_by_name(\"numberMetadataCustom\")\n",
- "\n",
- "# Update the metadata\n",
- "updated_metadata = lb.DataRowMetadataField(\n",
- " schema_id=num_schema.uid,\n",
- " value=10.2\n",
- ")\n",
- "\n",
- "# Create data row payload\n",
- "data_row_payload = lb.DataRowMetadata(\n",
- " global_key=global_key,\n",
- " fields=[updated_metadata]\n",
- ")\n",
- "\n",
- "# Upsert the fields with the update metadata for number-metadata\n",
- "mdo.bulk_upsert([data_row_payload])"
- ],
+ "source": "# Get the data row that was uploaded in the previous cell\nnum_schema = mdo.get_by_name(\"numberMetadataCustom\")\n\n# Update the metadata\nupdated_metadata = lb.DataRowMetadataField(schema_id=num_schema.uid, value=10.2)\n\n# Create data row payload\ndata_row_payload = lb.DataRowMetadata(global_key=global_key,\n fields=[updated_metadata])\n\n# Upsert the fields with the update metadata for number-metadata\nmdo.bulk_upsert([data_row_payload])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -387,17 +246,7 @@
},
{
"metadata": {},
- "source": [
- "# update a name\n",
- "number_schema = mdo.update_schema(name=\"numberMetadataCustom\", new_name=\"numberMetadataCustomNew\")\n",
- "\n",
- "# update an Enum metadata schema option's name, this only applies to Enum metadata schema.\n",
- "enum_schema = mdo.update_enum_option(\n",
- " name=\"enumMetadata\",\n",
- " option=\"option1\",\n",
- " new_option=\"option3\"\n",
- ")"
- ],
+ "source": "# update a name\nnumber_schema = mdo.update_schema(name=\"numberMetadataCustom\",\n new_name=\"numberMetadataCustomNew\")\n\n# update an Enum metadata schema option's name, this only applies to Enum metadata schema.\nenum_schema = mdo.update_enum_option(name=\"enumMetadata\",\n option=\"option1\",\n new_option=\"option3\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -413,11 +262,7 @@
},
{
"metadata": {},
- "source": [
- "data_row = next(dataset.data_rows())\n",
- "for metadata_field in data_row.metadata_fields:\n",
- " print(metadata_field['name'], \":\", metadata_field['value'])"
- ],
+ "source": "data_row = next(dataset.data_rows())\nfor metadata_field in data_row.metadata_fields:\n print(metadata_field[\"name\"], \":\", metadata_field[\"value\"])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -431,10 +276,7 @@
},
{
"metadata": {},
- "source": [
- "data_rows_metadata = mdo.bulk_export([data_row.uid])\n",
- "len(data_rows_metadata)"
- ],
+ "source": "data_rows_metadata = mdo.bulk_export([data_row.uid])\nlen(data_rows_metadata)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -449,9 +291,7 @@
},
{
"metadata": {},
- "source": [
- "#status = mdo.delete_schema(name=\"\")"
- ],
+ "source": "# status = mdo.delete_schema(name=\"\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/basics/data_rows.ipynb b/examples/basics/data_rows.ipynb
index 3de7b6933..46e758ee9 100644
--- a/examples/basics/data_rows.ipynb
+++ b/examples/basics/data_rows.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -54,20 +54,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install labelbox -q"
- ],
+ "source": "%pip install labelbox -q",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import uuid\n",
- "import json"
- ],
+ "source": "import labelbox as lb\nimport uuid\nimport json",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -82,11 +76,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your api key\n",
- "API_KEY = \"\"\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your api key\nAPI_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -100,15 +90,7 @@
},
{
"metadata": {},
- "source": [
- "# Pick a project with batches that have data rows with global keys\n",
- "PROJECT_ID = \"\"\n",
- "project = client.get_project(PROJECT_ID)\n",
- "batches = list(project.batches())\n",
- "print(batches)\n",
- "# This is the same as\n",
- "# -> dataset = client.get_dataset(dataset_id)"
- ],
+ "source": "# Pick a project with batches that have data rows with global keys\nPROJECT_ID = \"\"\nproject = client.get_project(PROJECT_ID)\nbatches = list(project.batches())\nprint(batches)\n# This is the same as\n# -> dataset = client.get_dataset(dataset_id)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -124,64 +106,21 @@
},
{
"metadata": {},
- "source": [
- "client.enable_experimental = True\n",
- "\n",
- "batch_ids = [batch.uid for batch in batches]\n",
- "\n",
- "export_params = {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"batch_ids\" : batch_ids # Include batch ids if you only want to export specific batches, otherwise,\n",
- " #you can export all the data without using this parameter\n",
- "}\n",
- "filters = {}\n",
- "\n",
- "# A task is returned, this provides additional information about the status of your task, such as\n",
- "# any errors encountered\n",
- "export_task = project.export(params=export_params, filters=filters)\n",
- "export_task.wait_till_done()"
- ],
+ "source": "client.enable_experimental = True\n\nbatch_ids = [batch.uid for batch in batches]\n\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"performance_details\": True,\n \"batch_ids\":\n batch_ids, # Include batch ids if you only want to export specific batches, otherwise,\n # you can export all the data without using this parameter\n}\nfilters = {}\n\n# A task is returned, this provides additional information about the status of your task, such as\n# any errors encountered\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "data_rows = []\n",
- "\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " data_row = json.loads(output.json_str)\n",
- " data_rows.append(data_row)\n",
- "\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)"
- ],
+ "source": "data_rows = []\n\n\ndef json_stream_handler(output: lb.JsonConverterOutput):\n data_row = json.loads(output.json_str)\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Get single data row\n",
- "data_row = data_rows[0]\n",
- "print(data_row)"
- ],
+ "source": "# Get single data row\ndata_row = data_rows[0]\nprint(data_row)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -195,10 +134,7 @@
},
{
"metadata": {},
- "source": [
- "print(\"Associated label(s)\", data_row[\"projects\"][project.uid][\"labels\"])\n",
- "print(\"Global key\", data_row[\"data_row\"][\"global_key\"])"
- ],
+ "source": "print(\"Associated label(s)\", data_row[\"projects\"][project.uid][\"labels\"])\nprint(\"Global key\", data_row[\"data_row\"][\"global_key\"])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -212,11 +148,7 @@
},
{
"metadata": {},
- "source": [
- "global_key = \"\"\n",
- "task = client.get_data_row_ids_for_global_keys([global_key])\n",
- "print(f\"Data row id: {task['results']}\")"
- ],
+ "source": "global_key = \"\"\ntask = client.get_data_row_ids_for_global_keys([global_key])\nprint(f\"Data row id: {task['results']}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -238,69 +170,14 @@
},
{
"metadata": {},
- "source": [
- "# Create a dataset\n",
- "dataset = client.create_dataset(name=\"data_rows_demo_dataset_6\")\n",
- "# You can also upload metadata along with your data row\n",
- "mdo = client.get_data_row_metadata_ontology()"
- ],
+ "source": "# Create a dataset\ndataset = client.create_dataset(name=\"data_rows_demo_dataset_6\")\n# You can also upload metadata along with your data row\nmdo = client.get_data_row_metadata_ontology()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "uploads = []\n",
- "# Generate data rows\n",
- "for i in range(1,8):\n",
- " uploads.append({\n",
- " \"row_data\": f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n",
- " \"global_key\": \"TEST-ID-%id\" % uuid.uuid1(),\n",
- " ## add metadata (optional)\n",
- " \"metadata_fields\": [\n",
- " lb.DataRowMetadataField(\n",
- " schema_id=mdo.reserved_by_name[\"tag\"].uid, # specify the schema id\n",
- " value=\"tag_string\", # typed inputs\n",
- " ),\n",
- " ],\n",
- " \"attachments\": [\n",
- " {\n",
- " \"type\": \"IMAGE_OVERLAY\",\n",
- " \"value\": \"https://storage.googleapis.com/labelbox-sample-datasets/Docs/disease_attachment.jpeg\"\n",
- " },\n",
- " {\n",
- " \"type\": \"RAW_TEXT\",\n",
- " \"value\": \"IOWA, Zone 2232, June 2022 [Text string]\"\n",
- " },\n",
- " {\n",
- " \"type\": \"TEXT_URL\",\n",
- " \"value\": \"https://storage.googleapis.com/labelbox-sample-datasets/Docs/text_attachment.txt\"\n",
- " },\n",
- " {\n",
- " \"type\": \"IMAGE\",\n",
- " \"value\": \"https://storage.googleapis.com/labelbox-sample-datasets/Docs/disease_attachment.jpeg\"\n",
- " },\n",
- " {\n",
- " \"type\": \"VIDEO\",\n",
- " \"value\": \"https://storage.googleapis.com/labelbox-sample-datasets/Docs/drone_video.mp4\"\n",
- " },\n",
- " {\n",
- " \"type\": \"HTML\",\n",
- " \"value\": \"https://storage.googleapis.com/labelbox-sample-datasets/Docs/windy.html\"\n",
- " },\n",
- " {\n",
- " \"type\": \"PDF_URL\",\n",
- " \"value\": \"https://storage.googleapis.com/labelbox-datasets/arxiv-pdf/data/99-word-token-pdfs/0801.3483.pdf\"\n",
- " }\n",
- " ]\n",
- " })\n",
- "\n",
- "task1 = dataset.upsert_data_rows(uploads)\n",
- "task1.wait_till_done()\n",
- "print(\"ERRORS: \" , task1.errors)\n",
- "print(\"RESULTS:\" , task1.result)"
- ],
+ "source": "uploads = []\n# Generate data rows\nfor i in range(1, 8):\n uploads.append({\n \"row_data\":\n f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n \"global_key\":\n \"TEST-ID-%id\" % uuid.uuid1(),\n ## add metadata (optional)\n \"metadata_fields\": [\n lb.DataRowMetadataField(\n schema_id=mdo.reserved_by_name[\"tag\"].\n uid, # specify the schema id\n value=\"tag_string\", # typed inputs\n ),\n ],\n \"attachments\": [\n {\n \"type\":\n \"IMAGE_OVERLAY\",\n \"value\":\n \"https://storage.googleapis.com/labelbox-sample-datasets/Docs/disease_attachment.jpeg\",\n },\n {\n \"type\": \"RAW_TEXT\",\n \"value\": \"IOWA, Zone 2232, June 2022 [Text string]\",\n },\n {\n \"type\":\n \"TEXT_URL\",\n \"value\":\n \"https://storage.googleapis.com/labelbox-sample-datasets/Docs/text_attachment.txt\",\n },\n {\n \"type\":\n \"IMAGE\",\n \"value\":\n \"https://storage.googleapis.com/labelbox-sample-datasets/Docs/disease_attachment.jpeg\",\n },\n {\n \"type\":\n \"VIDEO\",\n \"value\":\n \"https://storage.googleapis.com/labelbox-sample-datasets/Docs/drone_video.mp4\",\n },\n {\n \"type\":\n \"HTML\",\n \"value\":\n \"https://storage.googleapis.com/labelbox-sample-datasets/Docs/windy.html\",\n },\n {\n \"type\":\n \"PDF_URL\",\n \"value\":\n \"https://storage.googleapis.com/labelbox-datasets/arxiv-pdf/data/99-word-token-pdfs/0801.3483.pdf\",\n },\n ],\n })\n\ntask1 = dataset.upsert_data_rows(uploads)\ntask1.wait_till_done()\nprint(\"ERRORS: \", task1.errors)\nprint(\"RESULTS:\", task1.result)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -314,49 +191,14 @@
},
{
"metadata": {},
- "source": [
- "from PIL import Image\n",
- "\n",
- "# Create dummy empty jpeg file\n",
- "width = 400\n",
- "height = 300\n",
- "color = (255, 255, 255) # White color\n",
- "image = Image.new(\"RGB\", (width, height), color)\n",
- "\n",
- "# Save the image as a JPEG file\n",
- "image.save(\"dummy.jpg\")\n",
- "\n",
- "local_data_path = \"dummy.jpg\"\n",
- "\n",
- "data = {\n",
- " \"row_data\" : local_data_path,\n",
- " \"global_key\": str(uuid.uuid4())\n",
- "}\n",
- "\n",
- "task3 = dataset.upsert_data_rows([data])\n",
- "task3.wait_till_done()\n",
- "print(\"ERRORS: \" , task3.errors)\n",
- "print(\"RESULTS:\" , task3.result)"
- ],
+ "source": "from PIL import Image\n\n# Create dummy empty jpeg file\nwidth = 400\nheight = 300\ncolor = (255, 255, 255) # White color\nimage = Image.new(\"RGB\", (width, height), color)\n\n# Save the image as a JPEG file\nimage.save(\"dummy.jpg\")\n\nlocal_data_path = \"dummy.jpg\"\n\ndata = {\"row_data\": local_data_path, \"global_key\": str(uuid.uuid4())}\n\ntask3 = dataset.upsert_data_rows([data])\ntask3.wait_till_done()\nprint(\"ERRORS: \", task3.errors)\nprint(\"RESULTS:\", task3.result)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# You can mix local files with urls when creating data rows\n",
- "task4 = dataset.upsert_data_rows([{\n",
- " \"row_data\": \"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_0009.jpeg\",\n",
- " \"global_key\": str(uuid.uuid4())\n",
- " }, {\n",
- " \"row_data\": local_data_path,\n",
- " \"global_key\": str(uuid.uuid4())\n",
- " }])\n",
- "task4.wait_till_done()\n",
- "print(\"ERRORS: \" , task4.errors)\n",
- "print(\"RESULTS:\" , task4.result)"
- ],
+ "source": "# You can mix local files with urls when creating data rows\ntask4 = dataset.upsert_data_rows([\n {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_0009.jpeg\",\n \"global_key\":\n str(uuid.uuid4()),\n },\n {\n \"row_data\": local_data_path,\n \"global_key\": str(uuid.uuid4())\n },\n])\ntask4.wait_till_done()\nprint(\"ERRORS: \", task4.errors)\nprint(\"RESULTS:\", task4.result)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -370,36 +212,14 @@
},
{
"metadata": {},
- "source": [
- "dataset_2 = client.create_dataset(name=\"data_rows_demo_dataset_3\")"
- ],
+ "source": "dataset_2 = client.create_dataset(name=\"data_rows_demo_dataset_3\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "uploads = []\n",
- "# Generate data rows\n",
- "for i in range(1,9):\n",
- " uploads.append({\n",
- " \"row_data\": f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n",
- " \"global_key\": \"TEST-ID-%id\" % uuid.uuid1(),\n",
- " ## add metadata (optional)\n",
- " \"metadata_fields\": [\n",
- " lb.DataRowMetadataField(\n",
- " schema_id=mdo.reserved_by_name[\"tag\"].uid, # specify the schema id\n",
- " value=\"tag_string\", # typed inputs\n",
- " ),\n",
- " ]\n",
- " })\n",
- "\n",
- "task1_2 = dataset_2.create_data_rows(uploads)\n",
- "task1_2.wait_till_done()\n",
- "print(\"ERRORS: \" , task1_2.errors)\n",
- "print(\"RESULTS:\" , task1_2.result)"
- ],
+ "source": "uploads = []\n# Generate data rows\nfor i in range(1, 9):\n uploads.append({\n \"row_data\":\n f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n \"global_key\":\n \"TEST-ID-%id\" % uuid.uuid1(),\n ## add metadata (optional)\n \"metadata_fields\": [\n lb.DataRowMetadataField(\n schema_id=mdo.reserved_by_name[\"tag\"].\n uid, # specify the schema id\n value=\"tag_string\", # typed inputs\n ),\n ],\n })\n\ntask1_2 = dataset_2.create_data_rows(uploads)\ntask1_2.wait_till_done()\nprint(\"ERRORS: \", task1_2.errors)\nprint(\"RESULTS:\", task1_2.result)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -416,45 +236,14 @@
},
{
"metadata": {},
- "source": [
- "# Fetch a data row from the first dataset example\n",
- "ts = dataset.export()\n",
- "ts.wait_till_done()\n",
- "DATA_ROW_ID = [json.loads(output.json_str) for output in ts.get_stream()][0]['data_row']['id']\n",
- "GLOBAL_KEY = [json.loads(output.json_str) for output in ts.get_stream()][0]['data_row']['global_key']\n",
- "\n",
- "print(f\"Pick either a data row id : {DATA_ROW_ID} or global key: {GLOBAL_KEY}\")\n"
- ],
+ "source": "# Fetch a data row from the first dataset example\nts = dataset.export()\nts.wait_till_done()\nDATA_ROW_ID = [json.loads(output.json_str) for output in ts.get_stream()\n ][0][\"data_row\"][\"id\"]\nGLOBAL_KEY = [json.loads(output.json_str) for output in ts.get_stream()\n ][0][\"data_row\"][\"global_key\"]\n\nprint(f\"Pick either a data row id : {DATA_ROW_ID} or global key: {GLOBAL_KEY}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Update the global key assodicated with the DATAROW_ID or GLOBAL_KEY, and include a additional metadata\n",
- "data = {\n",
- " \"key\": lb.UniqueId(DATA_ROW_ID),\n",
- " \"global_key\": \"NEW-ID-%id\" % uuid.uuid1(),\n",
- " \"metadata_fields\": [\n",
- " # New metadata\n",
- " lb.DataRowMetadataField(\n",
- " schema_id=mdo.reserved_by_name['captureDateTime'].uid,\n",
- " value=\"2000-01-01 00:00:00\"\n",
- " ),\n",
- " # Include original metadata otherwise it will be removed\n",
- " lb.DataRowMetadataField(\n",
- " schema_id=mdo.reserved_by_name[\"tag\"].uid,\n",
- " value=\"tag_string\",\n",
- " ),\n",
- " ]\n",
- "}\n",
- "\n",
- "task5 = dataset_2.upsert_data_rows([data])\n",
- "task5.wait_till_done()\n",
- "print(\"ERRORS: \" , task5.errors)\n",
- "print(\"RESULTS:\" , task5.result)"
- ],
+ "source": "# Update the global key assodicated with the DATAROW_ID or GLOBAL_KEY, and include a additional metadata\ndata = {\n \"key\":\n lb.UniqueId(DATA_ROW_ID),\n \"global_key\":\n \"NEW-ID-%id\" % uuid.uuid1(),\n \"metadata_fields\": [\n # New metadata\n lb.DataRowMetadataField(\n schema_id=mdo.reserved_by_name[\"captureDateTime\"].uid,\n value=\"2000-01-01 00:00:00\",\n ),\n # Include original metadata otherwise it will be removed\n lb.DataRowMetadataField(\n schema_id=mdo.reserved_by_name[\"tag\"].uid,\n value=\"tag_string\",\n ),\n ],\n}\n\ntask5 = dataset_2.upsert_data_rows([data])\ntask5.wait_till_done()\nprint(\"ERRORS: \", task5.errors)\nprint(\"RESULTS:\", task5.result)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -468,13 +257,7 @@
},
{
"metadata": {},
- "source": [
- "# You can only create one attachment at the time.\n",
- "DATA_ROW_ID = \"\"\n",
- "data_row = client.get_data_row(DATA_ROW_ID)\n",
- "attachment = data_row.create_attachment(attachment_type=\"RAW_TEXT\",\n",
- " attachment_value=\"LABELERS WILL SEE THIS\")"
- ],
+ "source": "# You can only create one attachment at the time.\nDATA_ROW_ID = \"\"\ndata_row = client.get_data_row(DATA_ROW_ID)\nattachment = data_row.create_attachment(\n attachment_type=\"RAW_TEXT\", attachment_value=\"LABELERS WILL SEE THIS\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -488,9 +271,7 @@
},
{
"metadata": {},
- "source": [
- "attachment.update(type= \"RAW_TEXT\", value=\"NEW RAW TEXT\")"
- ],
+ "source": "attachment.update(type=\"RAW_TEXT\", value=\"NEW RAW TEXT\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -511,11 +292,7 @@
},
{
"metadata": {},
- "source": [
- "DATAROW_ID_TO_DELETE = \"\"\n",
- "data_row = client.get_data_row(DATAROW_ID_TO_DELETE)\n",
- "data_row.delete()"
- ],
+ "source": "DATAROW_ID_TO_DELETE = \"\"\ndata_row = client.get_data_row(DATAROW_ID_TO_DELETE)\ndata_row.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -529,10 +306,7 @@
},
{
"metadata": {},
- "source": [
- "# Bulk delete a list of data_rows ( limit: 4K data rows per call)\n",
- "lb.DataRow.bulk_delete(list(dataset.data_rows()))"
- ],
+ "source": "# Bulk delete a list of data_rows ( limit: 4K data rows per call)\nlb.DataRow.bulk_delete(list(dataset.data_rows()))",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/basics/export_v1_migration_support.ipynb b/examples/basics/export_v1_migration_support.ipynb
deleted file mode 100644
index 3ad1062ea..000000000
--- a/examples/basics/export_v1_migration_support.ipynb
+++ /dev/null
@@ -1,1031 +0,0 @@
-{
- "nbformat": 4,
- "nbformat_minor": 5,
- "metadata": {},
- "cells": [
- {
- "metadata": {},
- "source": [
- "\n",
- " \n",
- " | "
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "\n",
- "\n",
- "\n",
- " \n",
- " | \n",
- "\n",
- "\n",
- "\n",
- " \n",
- " | "
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "# Export V1 to V2 migration "
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "**Export V1 will no longer be available in any version of the SDK starting on April 2024**. We recommend users to plan accordingly. \n",
- "\n",
- "This notebook is designed to help users identify alternative V2 export methods that can serve as replacements for V1 methods."
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "### Key changes included in export V2 methods ( ``export()`` and ``export_v2()``):\n",
- "1. Added flexibility to only export the data that is needed. The new methods include parameters and filters to give you more granular control over your exports.\n",
- "2. Added functionality to stream an **unlimited** number of data rows using ``export()`` (available on SDK >=3.56). Upgrading to `export()` is recommended as it is a more scalable solution.\n",
- "\n",
- "For complete details on how to use export V2 methods please see the [Export V2 methods](https://docs.labelbox.com/reference/label-export#export-v2-methods) documentation."
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "### Export V1 deprecated methods: \n",
- "Project methods : \n",
- "1. ```project.export_labels()```\n",
- "2. ```project.label_generator()```\n",
- "3. ```project.export_queued_data_rows()```\n",
- "\n",
- "Dataset methods: \n",
- "1. ```dataset.export_data_rows()```\n",
- "\n",
- "Batch methods: \n",
- "1. ```batch.export_data_rows()```\n",
- "\n",
- "Model methods :\n",
- "1. ```model_run.export_labels()```\n",
- "\n"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "# Imports"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import pprint\n",
- "pp = pprint.PrettyPrinter(width=30, compact=True)\n"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "## API Key and Client\n",
- "See the developer guide for [creating an API key](https://docs.labelbox.com/reference/create-api-key)."
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "API_KEY = \"\"\n",
- "client = lb.Client(api_key=API_KEY)\n",
- "client.enable_experimental = True ## This is required if using the export() streamable method"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "# Exports V1 to V2 guidelines\n",
- "The follow sections will demonstrate how to use the export V2 methods to fetch data from your projects, datasets, batches and model runs. "
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "## Export labels from a project\n"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "PROJECT_ID = \"\"\n",
- "project = client.get_project(PROJECT_ID)"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "##### Export V1 (deprecated) \n",
- "1. ```project.export_labels()``` \n",
- " - Parameters: \n",
- " - ```download: bool = False```\n",
- " - ```timeout_seconds: int = 1800```\n",
- " - Output : (str | List[Dict[Any, Any]] | None)"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "For a comprehensive example of Export V1 ``project.export_labels()`` output, please refer to our documentation: [Export V1 sample export](https://docs.labelbox.com/reference/export-image-annotations#sample-project-export)"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "2. ```project.label_generator()```\n",
- " - Parameters: \n",
- " - ```timeout_seconds: int = 600```\n",
- " - Output: LabelGenerator"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "# Single entry from the output of project.label_generator() (deprecated)\n",
- "# Label objects will not be deprecated.\n",
- "single_output_from_generator = \"\"\"\n",
- "\n",
- "Label(\n",
- " uid='clrf5csho2ihx07ilffgp2fzj',\n",
- " data=ImageData(\n",
- " im_bytes=None,\n",
- " file_path=None,\n",
- " url='https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg',\n",
- " arr=None\n",
- " ),\n",
- " annotations=[\n",
- " ObjectAnnotation(\n",
- " confidence=None,\n",
- " name='bounding_box',\n",
- " feature_schema_id='clrf5ck4a0b9b071paa9ncu15',\n",
- " extra={\n",
- " 'instanceURI': 'https://api.labelbox.com/masks/feature/clrf5csvi6ofm07lsf9pygwvi?token='\n",
- " 'color': '#ff0000',\n",
- " 'feature_id': 'clrf5csvi6ofm07lsf9pygwvi',\n",
- " 'value': 'bounding_box',\n",
- " 'page': None,\n",
- " 'unit': None\n",
- " },\n",
- " value=Rectangle(\n",
- " extra={},\n",
- " start=Point(extra={}, x=2096.0, y=1264.0),\n",
- " end=Point(extra={}, x=2240.0, y=1689.0)\n",
- " ),\n",
- " classifications=[]\n",
- " ),\n",
- " # Add more annotations as needed\n",
- " # ...\n",
- " ],\n",
- " extra={\n",
- " 'Created By': 'aovalle@labelbox.com',\n",
- " 'Project Name': 'Image Annotation Import Demo',\n",
- " 'Created At': '2024-01-15T16:35:59.000Z',\n",
- " 'Updated At': '2024-01-15T16:51:56.000Z',\n",
- " 'Seconds to Label': 66.0,\n",
- " 'Agreement': -1.0,\n",
- " 'Benchmark Agreement': -1.0,\n",
- " 'Benchmark ID': None,\n",
- " 'Dataset Name': 'image-demo-dataset',\n",
- " 'Reviews': [],\n",
- " 'View Label': 'https://editor.labelbox.com?project=clrf5ckex09m9070x1te223u5&label=clrf5csho2ihx07ilffgp2fzj',\n",
- " 'Has Open Issues': 0.0,\n",
- " 'Skipped': False,\n",
- " 'media_type': 'image',\n",
- " 'Data Split': None,\n",
- " 'Global Key': '2560px-Kitano_Street_Kobe01s5s41102.jpeg'\n",
- " }\n",
- ")\n",
- "\n",
- "\"\"\""
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "##### Export V2 \n",
- "\n",
- "For complete details on the supported filters abd parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n",
- "\n",
- "1. ```project.export()``` : Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n",
- "\n",
- " - Parameters: \n",
- " - ```\"label_details\": True```\n",
- " - ```\"attachments\": True```\n",
- " - ```\"data_row_details\": True```\n",
- " - ```\"project_details\": True```\n",
- " - ```\"label_details\": True```\n",
- " - ```\"performance_details\": True```\n",
- " - Output: \n",
- " - ```ExportTask```\n",
- " - `ExportTask.has_result()` return type: bool \n",
- " - `ExportTask.has_errors()` return type: bool\n",
- " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "## Set the export parameters to only export labels\n",
- "export_params= {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"label_details\": True,\n",
- " \"performance_details\": True\n",
- "}\n",
- "# You also have the option to include additional filtering to narrow down the list of labels\n",
- "filters = {}\n",
- "\n",
- "export_task = project.export(params=export_params, filters=filters)\n",
- "export_task.wait_till_done()"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "# Provide results with JSON converter\n",
- "# Returns streamed JSON output strings from export task results/errors, one by one\n",
- "\n",
- "# Callback used for JSON Converter\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " print(output.json_str)\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)\n",
- "\n",
- "print(\"file size: \", export_task.get_total_file_size(stream_type=lb.StreamType.RESULT))\n",
- "print(\"line count: \", export_task.get_total_lines(stream_type=lb.StreamType.RESULT))\n"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "## Export queued (\"To Label\") data rows from a project"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "##### Export V1 (deprecated): \n",
- "1. ``project.export_queued_data_rows()`` :\n",
- " - Parameters: \n",
- " - ``timeout_seconds: int = 120``\n",
- " - ``include_metadata: bool = False``\n",
- " - Output: List[Dict[str, str]]"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "# Single entry from the output of project.export_queued_data_rows() (deprecated)\n",
- "single_output_example = \"\"\"\n",
- "[\n",
- " {'id': 'clpouak6nap2g0783ajd1d6pf',\n",
- " 'createdAt': '2023-12-03T02:04:34.062Z',\n",
- " 'updatedAt': '2023-12-03T02:05:33.797Z',\n",
- " 'externalId': None,\n",
- " 'globalKey': 'b57c9ab2-304f-4c17-ba5f-c536f39a6a46',\n",
- " 'metadataFields': [],\n",
- " 'customMetadata': [],\n",
- " 'rowData': 'https://storage.googleapis.com/labelbox-developer-testing-assets/image/data_files/santa.jpeg',\n",
- " 'mediaAttributes': {'assetType': 'image',\n",
- " 'contentLength': 305973,\n",
- " 'height': 1333,\n",
- " 'mimeType': 'image/jpeg',\n",
- " 'subType': 'jpeg',\n",
- " 'superType': 'image',\n",
- " 'width': 2000}}\n",
- "]\n",
- "\n",
- "\"\"\""
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "##### Export V2\n",
- "For complete details on the supported filters and parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n",
- "\n",
- "1. ```project.export()``` : Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n",
- "\n",
- " - Parameters (Minimum required parameters): \n",
- " - ```\"data_row_details\": True```\n",
- " - ```\"project_details\": True```\n",
- " - Required filters: \n",
- " - ``` \"workflow_status\": \"ToLabel\"```\n",
- " - Output: \n",
- " - ```ExportTask```\n",
- " - `ExportTask.has_result()` return type: bool \n",
- " - `ExportTask.has_errors()` return type: bool\n",
- " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "export_params= {\n",
- " \"attachments\": True, # Set to true if you want to export attachments\n",
- " \"metadata_fields\": True, # Set to true if you want to export metadata\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True\n",
- "}\n",
- "filters = {\n",
- " \"workflow_status\": \"ToLabel\" ## Using this filter will only export queued data rows\n",
- "}\n",
- "\n",
- "# An ExportTask is returned, this provides additional information about the status of your task, such as\n",
- "# any errors encountered and includes additional methods to stream your data\n",
- "\n",
- "\n",
- "export_task = project.export(params=export_params, filters=filters)\n",
- "export_task.wait_till_done()\n"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "# Provide results with JSON converter\n",
- "# Returns streamed JSON output strings from export task results/errors, one by one\n",
- "\n",
- "# Callback used for JSON Converter\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " print(output.json_str)\n",
- "\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- "\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)\n",
- "\n",
- "print(\"file size: \", export_task.get_total_file_size(stream_type=lb.StreamType.RESULT))\n",
- "print(\"line count: \", export_task.get_total_lines(stream_type=lb.StreamType.RESULT))"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "## Export data rows from a Dataset "
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "DATASET_ID = \"\"\n",
- "dataset = client.get_dataset(DATASET_ID)"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "#### Export V1 (deprecated): \n",
- "\n",
- "1. ```dataset.export_data_rows()```\n",
- " - Parameters: \n",
- " - ``timeout_seconds=120``\n",
- " - ``include_metadata: bool = True``\n",
- " - Output: \n",
- " - Data row object generator\n"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "# Single entry from the output of dataset.export_data_rows() (deprecated)\n",
- "# Data row objects will not be deprecated.\n",
- "\n",
- "single_output_from_data_row_generator = \"\"\"\n",
- "\n",
- "\"\"\""
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "#### Export V2\n",
- "For complete details on the supported filters and parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n",
- "\n",
- "1. ```project.export()``` : Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n",
- "\n",
- " - Parameters (minimum required parameters): \n",
- " - ``\"data_row_details\": True``\n",
- " - Output: \n",
- " - ```ExportTask```\n",
- " - `ExportTask.has_result()` return type: bool \n",
- " - `ExportTask.has_errors()` return type: bool\n",
- " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "export_params = {\n",
- " \"attachments\": True, # Set to true if you want to export attachments\n",
- " \"metadata_fields\": True, # Set to true if you want to export metadata\n",
- " \"data_row_details\": True,\n",
- "}\n",
- "filters = {}\n",
- "\n",
- "# A task is returned, this provides additional information about the status of your task, such as\n",
- "# any errors encountered\n",
- "export_task = dataset.export(params=export_params, filters=filters)\n",
- "export_task.wait_till_done()"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "# Provide results with JSON converter\n",
- "# Returns streamed JSON output strings from export task results/errors, one by one\n",
- "\n",
- "# Callback used for JSON Converter\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " print(output.json_str)\n",
- "\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- "\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)\n",
- "\n",
- "print(\"file size: \", export_task.get_total_file_size(stream_type=lb.StreamType.RESULT))\n",
- "print(\"line count: \", export_task.get_total_lines(stream_type=lb.StreamType.RESULT))"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "## Export data rows from a batch"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "#### Export V1 (deprecated): \n",
- "1. ```batch.export_data_rows()```\n",
- " - Parameters: \n",
- " - ``timeout_seconds=120``\n",
- " - ``include_metadata: bool = True``\n",
- " - Output: \n",
- " - Data row object generator"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "# Single output from batch.export_data_rows() method (deprecated)\n",
- "# Data row objects will not be deprecated\n",
- "\n",
- "single_output_from_data_row_generator = \"\"\"\n",
- "\n",
- "\"\"\""
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "#### Export V2\n",
- "For complete details on the supported filters and parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n",
- "\n",
- "1. ```project.export()``` : Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n",
- "\n",
- " - Required parameters: \n",
- " - ```\"data_row_details\": True```,\n",
- " - ```\"batch_ids\": [] ```\n",
- " - Output: \n",
- " - ```ExportTask```\n",
- " - `ExportTask.has_result()` return type: bool \n",
- " - `ExportTask.has_errors()` return type: bool\n",
- " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "# Find the batch ID by navigating to \"Batches\" --> \"Manage batches\" --> \"Copy Batch ID\"\n",
- "BATCH_ID = \"\""
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "export_params = {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"batch_ids\" : [BATCH_ID] # Include batch ids if you only want to export specific batches, otherwise,\n",
- " #you can export all the data without using this parameter\n",
- "}\n",
- "filters = {}\n",
- "\n",
- "# A task is returned, this provides additional information about the status of your task, such as\n",
- "# any errors encountered\n",
- "export_task = project.export(params=export_params, filters=filters)\n",
- "export_task.wait_till_done()"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "# Provide results with JSON converter\n",
- "# Returns streamed JSON output strings from export task results/errors, one by one\n",
- "\n",
- "# Callback used for JSON Converter\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " print(output.json_str)\n",
- "\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- "\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)\n",
- "\n",
- "print(\"file size: \", export_task.get_total_file_size(stream_type=lb.StreamType.RESULT))\n",
- "print(\"line count: \", export_task.get_total_lines(stream_type=lb.StreamType.RESULT))"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "## Export data rows from a Model "
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "#### Export V1 (deprecated): \n",
- "1. ```model_run.export_labels(downlaod=True)```\n",
- " - Parameters: \n",
- " - ```download: bool = False```\n",
- " - ```timeout_seconds: int = 1800```\n",
- " - Output : (str | List[Dict[Any, Any]] | None)"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "# Single output from model_run.export_labels()\n",
- "single_output_example = \"\"\"\n",
- "[\n",
- " {'ID': '1c48a7a0-3016-48e0-b0e3-47430f974869',\n",
- " 'Data Split': 'training',\n",
- " 'DataRow ID': 'clpqdyf650xd40712pycshy6a',\n",
- " 'External ID': './resume/BANKING/99124477.pdf',\n",
- " 'Labeled Data': 'https://storage.labelbox.com/cl5bn8qvq1av907xtb3bp8q60%2F8c6afc38-42a4-b2e1-a2e3-1e3b0c2998fc-99124477.pdf?Expires=1706637969726&KeyName=labelbox-assets-key-3&Signature=2nVt3sJ21CbjGS9I64yFquUELRw',\n",
- " 'Media Attributes': {'assetType': 'pdf',\n",
- " 'contentLength': 42535,\n",
- " 'mimeType': 'application/pdf',\n",
- " 'pageCount': 3,\n",
- " 'subType': 'pdf',\n",
- " 'superType': 'application'},\n",
- " 'Label': {'objects': [{'featureId': 'b9f3b584-0f45-050a-88d4-39c2a169c8e1',\n",
- " 'schemaId': 'clq1ckwbd08jp07z91q9mch5j',\n",
- " 'title': 'Test',\n",
- " 'value': 'test',\n",
- " 'color': '#1CE6FF',\n",
- " 'data': {'location': [{'text-bbox': {'page': 1,\n",
- " 'top': 158.44,\n",
- " 'left': 58.765,\n",
- " 'height': 13.691,\n",
- " 'width': 78.261}}],\n",
- " 'unit': 'POINTS'}}],\n",
- " 'classifications': [],\n",
- " 'relationships': []}}\n",
- " ]\n",
- " \"\"\"\n"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "#### Export V2\n",
- "For complete details on the supported filters and parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n",
- "\n",
- "1. ```model_run.export()```: Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n",
- "\n",
- " - Required parameters: \n",
- " - ```\"data_row_details\": True```\n",
- " - ```\"project_details\": True```\n",
- " - ```\"label_details\": True```\n",
- " - Required filters: \n",
- " - N/A -> Filters not supported\n",
- " - Output: \n",
- " - ```ExportTask```\n",
- " - `ExportTask.has_result()` return type: bool \n",
- " - `ExportTask.has_errors()` return type: bool\n",
- " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "MODEL_RUN_ID = \"\"\n",
- "model_run = client.get_model_run(MODEL_RUN_ID)"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "export_params = {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"performance_details\": True\n",
- "}\n",
- "\n",
- "export_task = model_run.export(params=export_params)\n",
- "export_task.wait_till_done()\n"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "# Provide results with JSON converter\n",
- "# Returns streamed JSON output strings from export task results/errors, one by one\n",
- "\n",
- "# Callback used for JSON Converter\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " print(output.json_str)\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)\n",
- "\n",
- "print(\"file size: \", export_task.get_total_file_size(stream_type=lb.StreamType.RESULT))\n",
- "print(\"line count: \", export_task.get_total_lines(stream_type=lb.StreamType.RESULT))"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "## Export data rows from a video project\n",
- "Video projects include additional fields. Please refer to the example below to extract specific fields from video exports.\n"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "##### Export V1 (deprecated) \n",
- "1. ```project.export_labels()``` \n",
- " - Parameters: \n",
- " - ```download: bool = False```\n",
- " - ```timeout_seconds: int = 1800```\n",
- " - Output : (str | List[Dict[Any, Any]] | None)"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "For a comprehensive example of Export V1 ``project.export_labels()`` output, please refer to our documentation: [Export V1 sample export](https://docs.labelbox.com/reference/export-image-annotations#sample-project-export)"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "2. ```project.video_label_generator()```\n",
- " - Parameters: \n",
- " - ```timeout_seconds: int = 600```\n",
- " - Output: LabelGenerator"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "##### Export V2\n",
- "\n",
- "For complete details on the supported filters and parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n",
- "\n",
- "1. ```project.export()```: Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n",
- "\n",
- " - Required parameters: \n",
- " - ```\"attachments\": True```\n",
- " - ```\"data_row_details\": True```\n",
- " - ```\"project_details\": True```\n",
- " - ```\"label_details\": True```\n",
- " - ```\"performance_details\": True```\n",
- " - Output: \n",
- " - ```ExportTask```\n",
- " - `ExportTask.has_result()` return type: bool \n",
- " - `ExportTask.has_errors()` return type: bool\n",
- " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "VIDEO_PROJECT_ID = \"\"\n",
- "project = client.get_project(VIDEO_PROJECT_ID)"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "export_params = {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"label_details\": True,\n",
- " \"interpolated_frames\": True # For additional information on interpolated frames please visit our documentation https://docs.labelbox.com/docs/video-annotations#video-editor-components\n",
- "}\n",
- "filters = {}\n",
- "\n",
- "# A task is returned, this provides additional information about the status of your task, such as\n",
- "# any errors encountered\n",
- "export_task = project.export(params=export_params, filters=filters)\n",
- "export_task.wait_till_done()"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "Fetch frame specific objects and frame or global classifications"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "import json\n",
- "import pprint as pp # Assuming pp is imported from pprint module\n",
- "\n",
- "frames_objects_class_list = []\n",
- "global_class_list = []\n",
- "\n",
- "stream = export_task.get_stream()\n",
- "for output in stream:\n",
- " output_json = json.loads(output.json_str)\n",
- " for dr in output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]:\n",
- " frames_data = dr[\"annotations\"][\"frames\"]\n",
- " for k, v in frames_data.items():\n",
- " frames_objects_class_list.append({k: v})\n",
- " global_class_list.extend(dr[\"annotations\"][\"classifications\"])\n",
- "\n",
- " print(\"------- Frame specific classifications and objects -------\")\n",
- " pp.pprint(frames_objects_class_list)\n",
- "\n",
- " print(\"------ Global classifications -------\")\n",
- " pp.pprint(global_class_list)\n",
- "\n",
- "\n"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "Fetch key frame feature map "
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "keyframe_map = []\n",
- "\n",
- "stream = export_task.get_stream()\n",
- "for output in stream:\n",
- " output_json = json.loads(output.json_str)\n",
- " labels = output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]\n",
- " for label in labels:\n",
- " annotations = label[\"annotations\"][\"key_frame_feature_map\"]\n",
- " for key, value in annotations.items():\n",
- " keyframe_map.append({key: value})\n",
- "\n",
- "print(\"----- Keyframe Feature Map -----\")\n",
- "pp.pprint(keyframe_map)"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "Fetch segments "
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "segments_map = []\n",
- "stream = export_task.get_stream()\n",
- "for output in stream:\n",
- " output_json = json.loads(output.json_str)\n",
- " labels = output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]\n",
- " for label in labels:\n",
- " annotations = label[\"annotations\"][\"segments\"]\n",
- " for key, value in annotations.items():\n",
- " segments_map.append({key: value})\n",
- "\n",
- "print(\"----- Segments Feature Map -----\")\n",
- "pp.pprint(segments_map)"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- }
- ]
-}
\ No newline at end of file
diff --git a/examples/basics/ontologies.ipynb b/examples/basics/ontologies.ipynb
index c4ed8806e..0058424fd 100644
--- a/examples/basics/ontologies.ipynb
+++ b/examples/basics/ontologies.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -42,19 +42,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install labelbox -q"
- ],
+ "source": "%pip install labelbox -q",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import json"
- ],
+ "source": "import labelbox as lb\nimport json",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -69,11 +64,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your api key\n",
- "API_KEY = \"\"\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your api key\nAPI_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -100,23 +91,7 @@
},
{
"metadata": {},
- "source": [
- "# This will automatically create new feature schema\n",
- "ontology_name = \"sdk-ontology\"\n",
- "feature_schema_cat_normalized = {\n",
- " 'tool': 'polygon',\n",
- " 'name': 'cat',\n",
- " 'color': 'black'\n",
- "}\n",
- "\n",
- "ontology_normalized_json = {\n",
- " \"tools\": [feature_schema_cat_normalized],\n",
- " \"classifications\": []\n",
- "}\n",
- "ontology = client.create_ontology(name=ontology_name,\n",
- " normalized=ontology_normalized_json)\n",
- "print(ontology)"
- ],
+ "source": "# This will automatically create new feature schema\nontology_name = \"sdk-ontology\"\nfeature_schema_cat_normalized = {\n \"tool\": \"polygon\",\n \"name\": \"cat\",\n \"color\": \"black\",\n}\n\nontology_normalized_json = {\n \"tools\": [feature_schema_cat_normalized],\n \"classifications\": [],\n}\nontology = client.create_ontology(name=ontology_name,\n normalized=ontology_normalized_json)\nprint(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -132,14 +107,7 @@
},
{
"metadata": {},
- "source": [
- "# First create the feature schema\n",
- "feature_schema_cat = client.create_feature_schema(feature_schema_cat_normalized)\n",
- "# When we create the ontology it will not re-create the feature schema\n",
- "print(feature_schema_cat.uid)\n",
- "ontology = client.create_ontology_from_feature_schemas(ontology_name,\n",
- " [feature_schema_cat.uid])"
- ],
+ "source": "# First create the feature schema\nfeature_schema_cat = client.create_feature_schema(feature_schema_cat_normalized)\n# When we create the ontology it will not re-create the feature schema\nprint(feature_schema_cat.uid)\nontology = client.create_ontology_from_feature_schemas(ontology_name,\n [feature_schema_cat.uid])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -156,20 +124,7 @@
},
{
"metadata": {},
- "source": [
- "# Create new dog schema id\n",
- "feature_schema_dog_normalized = {\n",
- " 'tool': 'polygon',\n",
- " 'name': 'dog',\n",
- " 'color': 'black',\n",
- " 'classifications': [],\n",
- "}\n",
- "feature_schema_dog = client.create_feature_schema(feature_schema_dog_normalized)\n",
- "# The cat is shared between this new ontology and the one we created previously\n",
- "# (ie. the cat feature schema will not be re-created)\n",
- "ontology = client.create_ontology_from_feature_schemas(\n",
- " ontology_name, [feature_schema_cat.uid, feature_schema_dog.uid])"
- ],
+ "source": "# Create new dog schema id\nfeature_schema_dog_normalized = {\n \"tool\": \"polygon\",\n \"name\": \"dog\",\n \"color\": \"black\",\n \"classifications\": [],\n}\nfeature_schema_dog = client.create_feature_schema(feature_schema_dog_normalized)\n# The cat is shared between this new ontology and the one we created previously\n# (ie. the cat feature schema will not be re-created)\nontology = client.create_ontology_from_feature_schemas(\n ontology_name, [feature_schema_cat.uid, feature_schema_dog.uid])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -185,26 +140,14 @@
},
{
"metadata": {},
- "source": [
- "#### Fetch by ID\n",
- "feature_schema = client.get_feature_schema(feature_schema_cat.uid)\n",
- "ontology = client.get_ontology(ontology.uid)\n",
- "print(feature_schema)\n",
- "print(ontology)"
- ],
+ "source": "#### Fetch by ID\nfeature_schema = client.get_feature_schema(feature_schema_cat.uid)\nontology = client.get_ontology(ontology.uid)\nprint(feature_schema)\nprint(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "#### Search by name\n",
- "feature_schema = next(client.get_feature_schemas(\"cat\"))\n",
- "ontology = next(client.get_ontologies(ontology_name))\n",
- "print(feature_schema)\n",
- "print(ontology)"
- ],
+ "source": "#### Search by name\nfeature_schema = next(client.get_feature_schemas(\"cat\"))\nontology = next(client.get_ontologies(ontology_name))\nprint(feature_schema)\nprint(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -218,49 +161,28 @@
},
{
"metadata": {},
- "source": [
- "# Check if feature is archived\n",
- "feature_schema = next(client.get_feature_schemas(\"cat\"))\n",
- "client.is_feature_schema_archived(ontology_id=ontology.uid, feature_schema_id=feature_schema.uid)"
- ],
+ "source": "# Check if feature is archived\nfeature_schema = next(client.get_feature_schemas(\"cat\"))\nclient.is_feature_schema_archived(ontology_id=ontology.uid,\n feature_schema_id=feature_schema.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Update a feature's title\n",
- "client.update_feature_schema_title(feature_schema_id=feature_schema.uid, title=\"cat-2\")\n",
- "feature = client.get_feature_schema(feature_schema_id=feature_schema.uid)\n",
- "print(\"Feature: \", feature)"
- ],
+ "source": "# Update a feature's title\nclient.update_feature_schema_title(feature_schema_id=feature_schema.uid,\n title=\"cat-2\")\nfeature = client.get_feature_schema(feature_schema_id=feature_schema.uid)\nprint(\"Feature: \", feature)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Replace a feature\n",
- "tool = lb.Tool(feature_schema_id=feature_schema.uid, name=\"tool-cat-upserted\", tool=lb.Tool.Type.BBOX, color=\"#FF0000\")\n",
- "upserted_feature_schema_id = client.upsert_feature_schema(tool.asdict()).uid\n",
- "feature = client.get_feature_schema(feature_schema_id=upserted_feature_schema_id)\n",
- "print(\"Updated feature: \", feature)"
- ],
+ "source": "# Replace a feature\ntool = lb.Tool(\n feature_schema_id=feature_schema.uid,\n name=\"tool-cat-upserted\",\n tool=lb.Tool.Type.BBOX,\n color=\"#FF0000\",\n)\nupserted_feature_schema_id = client.upsert_feature_schema(tool.asdict()).uid\nfeature = client.get_feature_schema(\n feature_schema_id=upserted_feature_schema_id)\nprint(\"Updated feature: \", feature)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Insert a new feature\n",
- "tool = lb.Tool(name=\"tool-cat-2\", tool=lb.Tool.Type.RASTER_SEGMENTATION)\n",
- "feature_schema_id_new = client.create_feature_schema(tool.asdict()).uid\n",
- "client.insert_feature_schema_into_ontology(feature_schema_id=feature_schema_id_new, ontology_id=ontology.uid , position=2)\n",
- "print(\"Updated ontology: \", client.get_ontology(ontology_id=ontology.uid))"
- ],
+ "source": "# Insert a new feature\ntool = lb.Tool(name=\"tool-cat-2\", tool=lb.Tool.Type.RASTER_SEGMENTATION)\nfeature_schema_id_new = client.create_feature_schema(tool.asdict()).uid\nclient.insert_feature_schema_into_ontology(\n feature_schema_id=feature_schema_id_new,\n ontology_id=ontology.uid,\n position=2,\n)\nprint(\"Updated ontology: \", client.get_ontology(ontology_id=ontology.uid))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -278,21 +200,14 @@
},
{
"metadata": {},
- "source": [
- "client.delete_feature_schema_from_ontology(ontology_id=ontology.uid, feature_schema_id=feature_schema_id_new)"
- ],
+ "source": "client.delete_feature_schema_from_ontology(\n ontology_id=ontology.uid, feature_schema_id=feature_schema_id_new)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Only features with annotations will be archived, features without annotations will be deleted.\n",
- "feature_schema_id_with_annotations = \"\"\n",
- "ontology_id = \"\"\n",
- "client.unarchive_feature_schema_node(ontology_id=ontology_id, root_feature_schema_id=feature_schema_id_with_annotations)"
- ],
+ "source": "# Only features with annotations will be archived, features without annotations will be deleted.\nfeature_schema_id_with_annotations = \"\"\nontology_id = \"\"\nclient.unarchive_feature_schema_node(\n ontology_id=ontology_id,\n root_feature_schema_id=feature_schema_id_with_annotations,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -307,17 +222,7 @@
},
{
"metadata": {},
- "source": [
- "# Create normalized json with a bounding box and segmentation tool\n",
- "ontology_builder = lb.OntologyBuilder(tools=[\n",
- " lb.Tool(tool=lb.Tool.Type.BBOX, name=\"dog\"),\n",
- " lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=\"cat\"),\n",
- "])\n",
- "# Creating an ontology from this is easy\n",
- "ontology = client.create_ontology(\"ontology-builder-ontology\",\n",
- " ontology_builder.asdict())\n",
- "print(json.dumps(ontology.normalized, indent=2))"
- ],
+ "source": "# Create normalized json with a bounding box and segmentation tool\nontology_builder = lb.OntologyBuilder(tools=[\n lb.Tool(tool=lb.Tool.Type.BBOX, name=\"dog\"),\n lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=\"cat\"),\n])\n# Creating an ontology from this is easy\nontology = client.create_ontology(\"ontology-builder-ontology\",\n ontology_builder.asdict())\nprint(json.dumps(ontology.normalized, indent=2))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -331,18 +236,7 @@
},
{
"metadata": {},
- "source": [
- "# Create\n",
- "ontology_builder = lb.OntologyBuilder()\n",
- "# Append tools\n",
- "tool_dog = lb.Tool(tool=lb.Tool.Type.BBOX, name=\"dog\")\n",
- "tool_cat = lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=\"cat\")\n",
- "ontology_builder.add_tool(tool_dog)\n",
- "ontology_builder.add_tool(tool_cat)\n",
- "ontology = client.create_ontology(\"ontology-builder-ontology\",\n",
- " ontology_builder.asdict())\n",
- "print(json.dumps(ontology.normalized, indent=2))"
- ],
+ "source": "# Create\nontology_builder = lb.OntologyBuilder()\n# Append tools\ntool_dog = lb.Tool(tool=lb.Tool.Type.BBOX, name=\"dog\")\ntool_cat = lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=\"cat\")\nontology_builder.add_tool(tool_dog)\nontology_builder.add_tool(tool_cat)\nontology = client.create_ontology(\"ontology-builder-ontology\",\n ontology_builder.asdict())\nprint(json.dumps(ontology.normalized, indent=2))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -356,25 +250,7 @@
},
{
"metadata": {},
- "source": [
- "ontology_builder = lb.OntologyBuilder(\n",
- " tools=[\n",
- " lb.Tool(tool=lb.Tool.Type.BBOX, name=\"dog\"),\n",
- " lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION,\n",
- " name=\"cat\",\n",
- " classifications=[\n",
- " lb.Classification(class_type=lb.Classification.Type.TEXT,\n",
- " name=\"name\")\n",
- " ])\n",
- " ],\n",
- " classifications=[\n",
- " lb.Classification(class_type=lb.Classification.Type.RADIO,\n",
- " name=\"image_quality\",\n",
- " options=[lb.Option(value=\"clear\"),\n",
- " lb.Option(value=\"blurry\")])\n",
- " ])\n",
- "print(json.dumps(ontology_builder.asdict(), indent=2))"
- ],
+ "source": "ontology_builder = lb.OntologyBuilder(\n tools=[\n lb.Tool(tool=lb.Tool.Type.BBOX, name=\"dog\"),\n lb.Tool(\n tool=lb.Tool.Type.RASTER_SEGMENTATION,\n name=\"cat\",\n classifications=[\n lb.Classification(class_type=lb.Classification.Type.TEXT,\n name=\"name\")\n ],\n ),\n ],\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"image_quality\",\n options=[lb.Option(value=\"clear\"),\n lb.Option(value=\"blurry\")],\n )\n ],\n)\nprint(json.dumps(ontology_builder.asdict(), indent=2))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -388,22 +264,7 @@
},
{
"metadata": {},
- "source": [
- "# We will use add_classification to add this classification to a previously built ontology_builder or you can create new ontology_builder = OntologyBuilder()\n",
- "radio_classification = lb.Classification(class_type=lb.Classification.Type.RADIO,\n",
- " name=\"Global classification\",\n",
- " options=[lb.Option(\"1st option\", options=[lb.Classification(class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"Inside 1st option\",\n",
- " options=[lb.Option(\"Option A\"), lb.Option(\"Option B\")])]), lb.Option(\"2nd option\", options=[lb.Classification(class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"Inside 2nd option\",\n",
- " options=[lb.Option(\"Option A\"), lb.Option(\"Option B\")])])])\n",
- "\n",
- "ontology_builder.add_classification(radio_classification)\n",
- "\n",
- "ontology = client.create_ontology(\"example of nested classification\",\n",
- " ontology_builder.asdict())\n",
- "print(json.dumps(ontology.normalized, indent=2))"
- ],
+ "source": "# We will use add_classification to add this classification to a previously built ontology_builder or you can create new ontology_builder = OntologyBuilder()\nradio_classification = lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"Global classification\",\n options=[\n lb.Option(\n \"1st option\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Inside 1st option\",\n options=[lb.Option(\"Option A\"),\n lb.Option(\"Option B\")],\n )\n ],\n ),\n lb.Option(\n \"2nd option\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Inside 2nd option\",\n options=[lb.Option(\"Option A\"),\n lb.Option(\"Option B\")],\n )\n ],\n ),\n ],\n)\n\nontology_builder.add_classification(radio_classification)\n\nontology = client.create_ontology(\"example of nested classification\",\n ontology_builder.asdict())\nprint(json.dumps(ontology.normalized, indent=2))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -417,15 +278,7 @@
},
{
"metadata": {},
- "source": [
- "bbox_tool = lb.Tool(tool=lb.Tool.Type.BBOX, name=\"dog_box\")\n",
- "poly_tool = lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"dog_poly\")\n",
- "seg_tool = lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=\"dog_seg\")\n",
- "point_tool = lb.Tool(tool=lb.Tool.Type.POINT, name=\"dog_center\")\n",
- "line_tool = lb.Tool(tool=lb.Tool.Type.LINE, name=\"dog_orientation\")\n",
- "ner_tool = lb.Tool(tool=lb.Tool.Type.NER, name=\"dog_reference\")\n",
- "relationship_tool = lb.Tool(tool=lb.Tool.Type.RELATIONSHIP, name=\"relationship\")"
- ],
+ "source": "bbox_tool = lb.Tool(tool=lb.Tool.Type.BBOX, name=\"dog_box\")\npoly_tool = lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"dog_poly\")\nseg_tool = lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=\"dog_seg\")\npoint_tool = lb.Tool(tool=lb.Tool.Type.POINT, name=\"dog_center\")\nline_tool = lb.Tool(tool=lb.Tool.Type.LINE, name=\"dog_orientation\")\nner_tool = lb.Tool(tool=lb.Tool.Type.NER, name=\"dog_reference\")\nrelationship_tool = lb.Tool(tool=lb.Tool.Type.RELATIONSHIP, name=\"relationship\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -440,17 +293,7 @@
},
{
"metadata": {},
- "source": [
- "text_classification = lb.Classification(class_type=lb.Classification.Type.TEXT,\n",
- " name=\"dog_name\")\n",
- "radio_classification = lb.Classification(class_type=lb.Classification.Type.RADIO,\n",
- " name=\"dog_breed\",\n",
- " options=[lb.Option(\"poodle\")])\n",
- "checklist_classification = lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"background\",\n",
- " options=[lb.Option(\"at_park\"), lb.Option(\"has_leash\")])"
- ],
+ "source": "text_classification = lb.Classification(class_type=lb.Classification.Type.TEXT,\n name=\"dog_name\")\nradio_classification = lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"dog_breed\",\n options=[lb.Option(\"poodle\")],\n)\nchecklist_classification = lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"background\",\n options=[lb.Option(\"at_park\"), lb.Option(\"has_leash\")],\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/basics/projects.ipynb b/examples/basics/projects.ipynb
index d188399a0..3bc3d8cb9 100644
--- a/examples/basics/projects.ipynb
+++ b/examples/basics/projects.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -47,21 +47,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import labelbox.types as lb_types\n",
- "from labelbox.schema.conflict_resolution_strategy import ConflictResolutionStrategy\n",
- "import uuid"
- ],
+ "source": "import labelbox as lb\nimport labelbox.types as lb_types\nfrom labelbox.schema.conflict_resolution_strategy import (\n ConflictResolutionStrategy,)\nimport uuid",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -76,12 +69,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your API key\n",
- "API_KEY = \"\"\n",
- "# To get your API key go to: Workspace settings -> API -> Create API Key\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your API key\nAPI_KEY = \"\"\n# To get your API key go to: Workspace settings -> API -> Create API Key\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -95,12 +83,7 @@
},
{
"metadata": {},
- "source": [
- "# Creates an empty project\n",
- "project = client.create_project(name=\"my-test-project\",\n",
- " description=\"a description\",\n",
- " media_type=lb.MediaType.Image)"
- ],
+ "source": "# Creates an empty project\nproject = client.create_project(\n name=\"my-test-project\",\n description=\"a description\",\n media_type=lb.MediaType.Image,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -114,24 +97,7 @@
},
{
"metadata": {},
- "source": [
- "dataset = client.create_dataset(name=\"project-demo-dataset\")\n",
- "global_keys = []\n",
- "uploads = []\n",
- "# Generate data rows\n",
- "for i in range(1,9):\n",
- " gb_key = \"TEST-ID-%id\" % uuid.uuid1()\n",
- " uploads.append({\n",
- " 'row_data': f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n",
- " \"global_key\": gb_key,\n",
- " })\n",
- " global_keys.append(gb_key)\n",
- "\n",
- "task = dataset.create_data_rows(uploads)\n",
- "task.wait_till_done()\n",
- "print(\"ERRORS: \" , task.errors)\n",
- "print(\"RESULT URL: \", task.result_url)"
- ],
+ "source": "dataset = client.create_dataset(name=\"project-demo-dataset\")\nglobal_keys = []\nuploads = []\n# Generate data rows\nfor i in range(1, 9):\n gb_key = \"TEST-ID-%id\" % uuid.uuid1()\n uploads.append({\n \"row_data\":\n f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n \"global_key\":\n gb_key,\n })\n global_keys.append(gb_key)\n\ntask = dataset.create_data_rows(uploads)\ntask.wait_till_done()\nprint(\"ERRORS: \", task.errors)\nprint(\"RESULT URL: \", task.result_url)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -145,13 +111,7 @@
},
{
"metadata": {},
- "source": [
- "project.create_batch(\n",
- " \"project-demo\", # each batch in a project must have a unique name\n",
- " global_keys=global_keys, # paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=1 # priority between 1(highest) - 5(lowest)\n",
- ")"
- ],
+ "source": "project.create_batch(\n \"project-demo\", # each batch in a project must have a unique name\n global_keys=\n global_keys, # paginated collection of data row objects, list of data row ids or global keys\n priority=1, # priority between 1(highest) - 5(lowest)\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -173,17 +133,7 @@
},
{
"metadata": {},
- "source": [
- "# Get the organization\n",
- "organization = client.get_organization()\n",
- "\n",
- "tag = organization.create_resource_tag(\n",
- " {\n",
- " \"text\": \"new-tag-name\",\n",
- " \"color\": \"4ed2f9\"\n",
- " }\n",
- ")"
- ],
+ "source": "# Get the organization\norganization = client.get_organization()\n\ntag = organization.create_resource_tag({\n \"text\": \"new-tag-name\",\n \"color\": \"4ed2f9\"\n})",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -197,9 +147,7 @@
},
{
"metadata": {},
- "source": [
- "tags = project.update_project_resource_tags([tag.uid])"
- ],
+ "source": "tags = project.update_project_resource_tags([tag.uid])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -213,9 +161,7 @@
},
{
"metadata": {},
- "source": [
- "tags = project.get_resource_tags()"
- ],
+ "source": "tags = project.get_resource_tags()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -238,20 +184,7 @@
},
{
"metadata": {},
- "source": [
- "# Create normalized json with a radio classification\n",
- "ontology_builder = lb.OntologyBuilder(classifications=[ # List of Classification objects\n",
- " lb.Classification(class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\"),\n",
- " lb.Option(value=\"second_radio_answer\")\n",
- " ]),\n",
- "])\n",
- "# Creating an ontology\n",
- "ontology = client.create_ontology(\"test-ontology\",\n",
- " ontology_builder.asdict())"
- ],
+ "source": "# Create normalized json with a radio classification\nontology_builder = lb.OntologyBuilder(\n classifications=[ # List of Classification objects\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_question\",\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n ])\n# Creating an ontology\nontology = client.create_ontology(\"test-ontology\", ontology_builder.asdict())",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -265,9 +198,7 @@
},
{
"metadata": {},
- "source": [
- "project.setup_editor(ontology)"
- ],
+ "source": "project.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -281,30 +212,7 @@
},
{
"metadata": {},
- "source": [
- "# Create labels\n",
- "labels = []\n",
- "for global_key in global_keys:\n",
- " labels.append(lb_types.Label(data={\"global_key\":global_key},\n",
- " annotations=[\n",
- " # Create radio classification annotation for labels\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question\",\n",
- " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n",
- " name=\"second_radio_answer\")))\n",
- " ]))\n",
- "\n",
- "# Upload labels for the data rows in project\n",
- "upload_job = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"label_import_job\"+str(uuid.uuid4()),\n",
- " labels=labels)\n",
- "\n",
- "upload_job.wait_until_done()\n",
- "\n",
- "print(f\"Errors: {upload_job.errors}\")"
- ],
+ "source": "# Create labels\nlabels = []\nfor global_key in global_keys:\n labels.append(\n lb_types.Label(\n data={\"global_key\": global_key},\n annotations=[\n # Create radio classification annotation for labels\n lb_types.ClassificationAnnotation(\n name=\"radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"second_radio_answer\")),\n )\n ],\n ))\n\n# Upload labels for the data rows in project\nupload_job = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"label_import_job\" + str(uuid.uuid4()),\n labels=labels,\n)\n\nupload_job.wait_until_done()\n\nprint(f\"Errors: {upload_job.errors}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -318,24 +226,14 @@
},
{
"metadata": {},
- "source": [
- "# Get list of task queues for project\n",
- "task_queues = project.task_queues()\n",
- "\n",
- "for task_queue in task_queues:\n",
- " print(task_queue)"
- ],
+ "source": "# Get list of task queues for project\ntask_queues = project.task_queues()\n\nfor task_queue in task_queues:\n print(task_queue)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "project.move_data_rows_to_task_queue(data_row_ids=lb.GlobalKeys(global_keys), #Provide a list of global keys\n",
- " task_queue_id=task_queues[2].uid #Passing None moves data rows to \"Done\" task queue\n",
- " )"
- ],
+ "source": "project.move_data_rows_to_task_queue(\n data_row_ids=lb.GlobalKeys(global_keys), # Provide a list of global keys\n task_queue_id=task_queues[2].\n uid, # Passing None moves data rows to \"Done\" task queue\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -349,16 +247,7 @@
},
{
"metadata": {},
- "source": [
- "# Note the project is not fully setup many of the fields will be empty.\n",
- "print(\"Project is not setup yet:\", project.setup_complete is None)\n",
- "print(\"Project name:\", project.name)\n",
- "print(\"Project description:\", project.description)\n",
- "print(\"Media Type:\", project.media_type)\n",
- "batches = [b for b in project.batches()]\n",
- "print(\"Project Batches\", batches)\n",
- "print(\"Ontology:\", project.ontology())"
- ],
+ "source": "# Note the project is not fully setup many of the fields will be empty.\nprint(\"Project is not setup yet:\", project.setup_complete is None)\nprint(\"Project name:\", project.name)\nprint(\"Project description:\", project.description)\nprint(\"Media Type:\", project.media_type)\nbatches = [b for b in project.batches()]\nprint(\"Project Batches\", batches)\nprint(\"Ontology:\", project.ontology())",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -372,9 +261,7 @@
},
{
"metadata": {},
- "source": [
- "print(\"Number of labels:\", project.get_label_count())"
- ],
+ "source": "print(\"Number of labels:\", project.get_label_count())",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -389,27 +276,7 @@
},
{
"metadata": {},
- "source": [
- "# Create an empty destination project\n",
- "destination_project = client.create_project(name=\"destination-test-project\",\n",
- " description=\"a description\",\n",
- " media_type=lb.MediaType.Image)\n",
- "\n",
- "# Create ontology and attach to destination project\n",
- "destination_ontology_builder = lb.OntologyBuilder(classifications=[ # List of Classification objects\n",
- " lb.Classification(class_type=lb.Classification.Type.RADIO,\n",
- " name=\"destination_radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"destination_first_radio_answer\"),\n",
- " lb.Option(value=\"destination_second_radio_answer\")\n",
- " ]),\n",
- "])\n",
- "\n",
- "destination_ontology = client.create_ontology(\"dest-test-ontology\",\n",
- " ontology_builder.asdict())\n",
- "\n",
- "destination_project.setup_editor(destination_ontology)"
- ],
+ "source": "# Create an empty destination project\ndestination_project = client.create_project(\n name=\"destination-test-project\",\n description=\"a description\",\n media_type=lb.MediaType.Image,\n)\n\n# Create ontology and attach to destination project\ndestination_ontology_builder = lb.OntologyBuilder(\n classifications=[ # List of Classification objects\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"destination_radio_question\",\n options=[\n lb.Option(value=\"destination_first_radio_answer\"),\n lb.Option(value=\"destination_second_radio_answer\"),\n ],\n ),\n ])\n\ndestination_ontology = client.create_ontology(\"dest-test-ontology\",\n ontology_builder.asdict())\n\ndestination_project.setup_editor(destination_ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -444,49 +311,14 @@
},
{
"metadata": {},
- "source": [
- "# Get ontology dictionary to obtain featureSchemaIds\n",
- "source_ontology_normalized = ontology.normalized\n",
- "destination_ontology_normalized = destination_ontology.normalized\n",
- "\n",
- "ANNOTATION_ONTOLOGY_MAPPING = {\n",
- " source_ontology_normalized[\"classifications\"][0][\"featureSchemaId\"]:destination_ontology_normalized[\"classifications\"][0][\"featureSchemaId\"], # Classification featureSchemaID\n",
- " source_ontology_normalized[\"classifications\"][0][\"options\"][0][\"featureSchemaId\"]:destination_ontology_normalized[\"classifications\"][0][\"options\"][0][\"featureSchemaId\"], # Different Classification Answer featureSchemaIDs\n",
- " source_ontology_normalized[\"classifications\"][0][\"options\"][1][\"featureSchemaId\"]:destination_ontology_normalized[\"classifications\"][0][\"options\"][1][\"featureSchemaId\"]\n",
- "}"
- ],
+ "source": "# Get ontology dictionary to obtain featureSchemaIds\nsource_ontology_normalized = ontology.normalized\ndestination_ontology_normalized = destination_ontology.normalized\n\nANNOTATION_ONTOLOGY_MAPPING = {\n source_ontology_normalized[\"classifications\"][0][\"featureSchemaId\"]:\n destination_ontology_normalized[\"classifications\"][0]\n [\"featureSchemaId\"], # Classification featureSchemaID\n source_ontology_normalized[\"classifications\"][0][\"options\"][0][\"featureSchemaId\"]:\n destination_ontology_normalized[\"classifications\"][0][\"options\"][0]\n [\"featureSchemaId\"], # Different Classification Answer featureSchemaIDs\n source_ontology_normalized[\"classifications\"][0][\"options\"][1][\"featureSchemaId\"]:\n destination_ontology_normalized[\"classifications\"][0][\"options\"][1]\n [\"featureSchemaId\"],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "send_to_annotate_params = {\n",
- " \"source_project_id\": project.uid,\n",
- " \"annotations_ontology_mapping\": ANNOTATION_ONTOLOGY_MAPPING,\n",
- " \"exclude_data_rows_in_project\": False,\n",
- " \"override_existing_annotations_rule\": ConflictResolutionStrategy.OverrideWithPredictions,\n",
- " \"batch_priority\": 5,\n",
- "}\n",
- "\n",
- "# Get task id to workflow you want to send data rows. If sent to initial labeling queue, labels will be pre-labels. \n",
- "queue_id = [queue.uid for queue in destination_project.task_queues() if queue.queue_type == \"MANUAL_REVIEW_QUEUE\" ][0]\n",
- "\n",
- "task = client.send_to_annotate_from_catalog(\n",
- " destination_project_id=destination_project.uid,\n",
- " task_queue_id=queue_id, # ID of workflow task, set ID to None if you want to send data rows with labels to the Done queue.\n",
- " batch_name=\"Prediction Import Demo Batch\",\n",
- " data_rows=lb.GlobalKeys(\n",
- " global_keys # Provide a list of global keys from source project\n",
- " ),\n",
- " params=send_to_annotate_params\n",
- " )\n",
- "\n",
- "task.wait_till_done()\n",
- "\n",
- "print(f\"Errors: {task.errors}\")"
- ],
+ "source": "send_to_annotate_params = {\n \"source_project_id\":\n project.uid,\n \"annotations_ontology_mapping\":\n ANNOTATION_ONTOLOGY_MAPPING,\n \"exclude_data_rows_in_project\":\n False,\n \"override_existing_annotations_rule\":\n ConflictResolutionStrategy.OverrideWithPredictions,\n \"batch_priority\":\n 5,\n}\n\n# Get task id to workflow you want to send data rows. If sent to initial labeling queue, labels will be pre-labels.\nqueue_id = [\n queue.uid\n for queue in destination_project.task_queues()\n if queue.queue_type == \"MANUAL_REVIEW_QUEUE\"\n][0]\n\ntask = client.send_to_annotate_from_catalog(\n destination_project_id=destination_project.uid,\n task_queue_id=\n queue_id, # ID of workflow task, set ID to None if you want to send data rows with labels to the Done queue.\n batch_name=\"Prediction Import Demo Batch\",\n data_rows=lb.GlobalKeys(\n global_keys # Provide a list of global keys from source project\n ),\n params=send_to_annotate_params,\n)\n\ntask.wait_till_done()\n\nprint(f\"Errors: {task.errors}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -500,13 +332,7 @@
},
{
"metadata": {},
- "source": [
- "# project.delete()\n",
- "# destination_project.delete()\n",
- "# dataset.delete()\n",
- "# client.delete_unused_ontology(destination_ontology.uid)\n",
- "# client.delete_unused_ontology(ontology.uid)"
- ],
+ "source": "# project.delete()\n# destination_project.delete()\n# dataset.delete()\n# client.delete_unused_ontology(destination_ontology.uid)\n# client.delete_unused_ontology(ontology.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/basics/user_management.ipynb b/examples/basics/user_management.ipynb
index 4772c1529..ffe656406 100644
--- a/examples/basics/user_management.ipynb
+++ b/examples/basics/user_management.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -43,19 +43,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install labelbox"
- ],
+ "source": "%pip install \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import os"
- ],
+ "source": "import labelbox as lb\nimport os",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -79,26 +74,14 @@
},
{
"metadata": {},
- "source": [
- "# Add your api key\n",
- "API_KEY = None\n",
- "client = lb.Client(api_key=API_KEY, enable_experimental=True)\n",
- "organization = client.get_organization()"
- ],
+ "source": "# Add your api key\nAPI_KEY = None\nclient = lb.Client(api_key=API_KEY, enable_experimental=True)\norganization = client.get_organization()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Please provide a dummy email here:\n",
- "# Preferrably one you can access. If you have a google account you can do email+1@.com\n",
- "DUMMY_EMAIL = \"SET THIS\"\n",
- "# This should be set to an account that you wan't to change the permissions for.\n",
- "# You could invite a new user, accept the invite and use that account if you don't want to effect any active users\n",
- "DUMMY_USER_ACCOUNT_ID = \"ckneh4n8c9qvq0706uwwg5i16\""
- ],
+ "source": "# Please provide a dummy email here:\n# Preferrably one you can access. If you have a google account you can do email+1@.com\nDUMMY_EMAIL = \"SET THIS\"\n# This should be set to an account that you wan't to change the permissions for.\n# You could invite a new user, accept the invite and use that account if you don't want to effect any active users\nDUMMY_USER_ACCOUNT_ID = \"ckneh4n8c9qvq0706uwwg5i16\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -114,11 +97,7 @@
},
{
"metadata": {},
- "source": [
- "roles = client.get_roles()\n",
- "for name, role in roles.items():\n",
- " print(role.name, \":\", role.uid)"
- ],
+ "source": "roles = client.get_roles()\nfor name, role in roles.items():\n print(role.name, \":\", role.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -150,30 +129,21 @@
},
{
"metadata": {},
- "source": [
- "# First make sure that you have enough seats:\n",
- "organization.invite_limit()"
- ],
+ "source": "# First make sure that you have enough seats:\norganization.invite_limit()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "invite = organization.invite_user(DUMMY_EMAIL, roles[\"LABELER\"])"
- ],
+ "source": "invite = organization.invite_user(DUMMY_EMAIL, roles[\"LABELER\"])",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "print(invite.created_at)\n",
- "print(invite.organization_role_name)\n",
- "print(invite.email)"
- ],
+ "source": "print(invite.created_at)\nprint(invite.organization_role_name)\nprint(invite.email)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -189,13 +159,7 @@
},
{
"metadata": {},
- "source": [
- "project = client.create_project(name=\"test_user_management\", media_type=lb.MediaType.Image)\n",
- "project_role = lb.ProjectRole(project=project, role=roles[\"REVIEWER\"])\n",
- "invite = organization.invite_user(DUMMY_EMAIL,\n",
- " roles[\"NONE\"],\n",
- " project_roles=[project_role])"
- ],
+ "source": "project = client.create_project(name=\"test_user_management\",\n media_type=lb.MediaType.Image)\nproject_role = lb.ProjectRole(project=project, role=roles[\"REVIEWER\"])\ninvite = organization.invite_user(DUMMY_EMAIL,\n roles[\"NONE\"],\n project_roles=[project_role])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -211,10 +175,7 @@
},
{
"metadata": {},
- "source": [
- "users = list(organization.users())\n",
- "print(users[0])"
- ],
+ "source": "users = list(organization.users())\nprint(users[0])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -230,29 +191,14 @@
},
{
"metadata": {},
- "source": [
- "user = client._get_single(lb.User, DUMMY_USER_ACCOUNT_ID)\n",
- "\n",
- "# Give the user organization level permissions\n",
- "user.update_org_role(roles[\"LABELER\"])\n",
- "print(user.org_role())\n",
- "# Restore project level permissions\n",
- "user.update_org_role(roles[\"NONE\"])\n",
- "print(user.org_role())\n",
- "# Make the user a labeler for the current project\n",
- "user.upsert_project_role(project, roles[\"LABELER\"])\n",
- "print(user.org_role())"
- ],
+ "source": "user = client._get_single(lb.User, DUMMY_USER_ACCOUNT_ID)\n\n# Give the user organization level permissions\nuser.update_org_role(roles[\"LABELER\"])\nprint(user.org_role())\n# Restore project level permissions\nuser.update_org_role(roles[\"NONE\"])\nprint(user.org_role())\n# Make the user a labeler for the current project\nuser.upsert_project_role(project, roles[\"LABELER\"])\nprint(user.org_role())",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Remove the user from a project (Same as setting the project role to `roles.NONE`)\n",
- "user.remove_from_project(project)"
- ],
+ "source": "# Remove the user from a project (Same as setting the project role to `roles.NONE`)\nuser.remove_from_project(project)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -291,9 +237,7 @@
},
{
"metadata": {},
- "source": [
- "project.delete()"
- ],
+ "source": "project.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/exports/composite_mask_export.ipynb b/examples/exports/composite_mask_export.ipynb
index 7d70a3922..ced50a4ea 100644
--- a/examples/exports/composite_mask_export.ipynb
+++ b/examples/exports/composite_mask_export.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -48,21 +48,14 @@
},
{
"metadata": {},
- "source": [
- "%pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import urllib.request\n",
- "from PIL import Image\n",
- "import json\n"
- ],
+ "source": "import labelbox as lb\nimport urllib.request\nfrom PIL import Image\nimport json",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -77,11 +70,7 @@
},
{
"metadata": {},
- "source": [
- "API_KEY = \"\"\n",
- "client = lb.Client(api_key=API_KEY)\n",
- "client.enable_experimental = True ## This is required if using the export() streamable method"
- ],
+ "source": "API_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)\nclient.enable_experimental = (\n True ## This is required if using the export() streamable method\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -133,21 +122,7 @@
},
{
"metadata": {},
- "source": [
- "# Example on how to fetch a composite mask\n",
- "# The mask here shows all the mask instances associated with a label\n",
- "task_id = \"\"\n",
- "composite_mask_id = \"\"\n",
- "\n",
- "mask_url = f'https://api.labelbox.com/api/v1/tasks/{task_id}/masks/{composite_mask_id}/index/1'\n",
- "req = urllib.request.Request(mask_url, headers=client.headers)\n",
- "image = Image.open(urllib.request.urlopen(req))\n",
- "w, h = image.size\n",
- "new_w = w // 4\n",
- "new_h = h // 4\n",
- "\n",
- "image.resize((new_w, new_h), Image.BICUBIC)"
- ],
+ "source": "# Example on how to fetch a composite mask\n# The mask here shows all the mask instances associated with a label\ntask_id = \"\"\ncomposite_mask_id = \"\"\n\nmask_url = f\"https://api.labelbox.com/api/v1/tasks/{task_id}/masks/{composite_mask_id}/index/1\"\nreq = urllib.request.Request(mask_url, headers=client.headers)\nimage = Image.open(urllib.request.urlopen(req))\nw, h = image.size\nnew_w = w // 4\nnew_h = h // 4\n\nimage.resize((new_w, new_h), Image.BICUBIC)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -215,39 +190,14 @@
},
{
"metadata": {},
- "source": [
- "# Insert the project ID of the project from which you wish to export data rows.\n",
- "PROJECT_ID = \"\"\n",
- "project = client.get_project(PROJECT_ID)"
- ],
+ "source": "# Insert the project ID of the project from which you wish to export data rows.\nPROJECT_ID = \"\"\nproject = client.get_project(PROJECT_ID)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "export_params= {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"label_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"interpolated_frames\": True\n",
- "}\n",
- "\n",
- "filters= {}\n",
- "\n",
- "# export() is the streamable option of exports V2, for more information please visit our documentation:\n",
- "# https://docs.labelbox.com/reference/label-export#export-v2-methods\n",
- "\n",
- "export_task = project.export(params=export_params, filters=filters)\n",
- "export_task.wait_till_done()\n",
- "\n",
- "if export_task.has_result():\n",
- " print(export_task.result)"
- ],
+ "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n}\n\nfilters = {}\n\n# export() is the streamable option of exports V2, for more information please visit our documentation:\n# https://docs.labelbox.com/reference/label-export#export-v2-methods\n\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()\n\nif export_task.has_result():\n print(export_task.result)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -261,32 +211,7 @@
},
{
"metadata": {},
- "source": [
- "stream = export_task.get_stream()\n",
- "\n",
- "mask_tool_rgb_mapping = {}\n",
- "\n",
- "for output in stream:\n",
- " # Parse the JSON string from the output\n",
- " output_json = json.loads(output.json_str)\n",
- "\n",
- " # Get the labels for the specified project ID or an empty list if the project ID is not found\n",
- " project_labels = output_json['projects'].get(PROJECT_ID, {}).get('labels', [])\n",
- "\n",
- " # Iterate through each label\n",
- " for label in project_labels:\n",
- " # Get the list of annotations (objects) for the label\n",
- " annotations = label['annotations'].get('objects', [])\n",
- "\n",
- " # Iterate through each annotation\n",
- " for annotation in annotations:\n",
- " # Check if the annotation is of type \"ImageSegmentationMask\"\n",
- " if annotation.get('annotation_kind') == \"ImageSegmentationMask\":\n",
- " # Add the color RGB information to the mapping dictionary\n",
- " mask_tool_rgb_mapping.setdefault(annotation['name'], []).append(annotation['composite_mask']['color_rgb'])\n",
- "\n",
- "print(mask_tool_rgb_mapping)"
- ],
+ "source": "stream = export_task.get_stream()\n\nmask_tool_rgb_mapping = {}\n\nfor output in stream:\n # Parse the JSON string from the output\n output_json = json.loads(output.json_str)\n\n # Get the labels for the specified project ID or an empty list if the project ID is not found\n project_labels = (output_json[\"projects\"].get(PROJECT_ID,\n {}).get(\"labels\", []))\n\n # Iterate through each label\n for label in project_labels:\n # Get the list of annotations (objects) for the label\n annotations = label[\"annotations\"].get(\"objects\", [])\n\n # Iterate through each annotation\n for annotation in annotations:\n # Check if the annotation is of type \"ImageSegmentationMask\"\n if annotation.get(\"annotation_kind\") == \"ImageSegmentationMask\":\n # Add the color RGB information to the mapping dictionary\n mask_tool_rgb_mapping.setdefault(annotation[\"name\"], []).append(\n annotation[\"composite_mask\"][\"color_rgb\"])\n\nprint(mask_tool_rgb_mapping)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -300,38 +225,14 @@
},
{
"metadata": {},
- "source": [
- "VIDEO_PROJECT_ID = \"\"\n",
- "project_video = client.get_project(VIDEO_PROJECT_ID)"
- ],
+ "source": "VIDEO_PROJECT_ID = \"\"\nproject_video = client.get_project(VIDEO_PROJECT_ID)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "export_params= {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"label_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"interpolated_frames\": True\n",
- "}\n",
- "\n",
- "filters= {}\n",
- "\n",
- "# export() is the streamable option of exports V2, for more information please visit our documentation:\n",
- "# https://docs.labelbox.com/reference/label-export#export-v2-methods\n",
- "\n",
- "export_task_video = project_video.export(params=export_params, filters=filters)\n",
- "export_task_video.wait_till_done()\n",
- "\n",
- "if export_task_video.has_result():\n",
- " print(export_task_video.result)\n"
- ],
+ "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n}\n\nfilters = {}\n\n# export() is the streamable option of exports V2, for more information please visit our documentation:\n# https://docs.labelbox.com/reference/label-export#export-v2-methods\n\nexport_task_video = project_video.export(params=export_params, filters=filters)\nexport_task_video.wait_till_done()\n\nif export_task_video.has_result():\n print(export_task_video.result)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -345,33 +246,7 @@
},
{
"metadata": {},
- "source": [
- "tools_frames_color = {}\n",
- "stream = export_task_video.get_stream()\n",
- "\n",
- "# Iterate over each output in the stream\n",
- "for output in stream:\n",
- " output_json = json.loads(output.json_str)\n",
- "\n",
- " # Iterate over the labels in the specific project\n",
- " for dr in output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]:\n",
- " frames_data = dr[\"annotations\"][\"frames\"]\n",
- "\n",
- " # Iterate over each frame in the frames data\n",
- " for frame_key, frame_value in frames_data.items():\n",
- "\n",
- " # Iterate over each annotation in the frame\n",
- " for annotation_key, annotation_value in frame_value.items():\n",
- " if 'objects' in annotation_key and annotation_value.values():\n",
- "\n",
- " # Iterate over each object in the annotation\n",
- " for object_key, object_value in annotation_value.items():\n",
- " if object_value['annotation_kind'] == 'VideoSegmentationMask':\n",
- " # Update tools_frames_color with object information\n",
- " tools_frames_color.setdefault(object_value['name'], []).append({frame_key: object_value['composite_mask']['color_rgb']})\n",
- "\n",
- "print(tools_frames_color)"
- ],
+ "source": "tools_frames_color = {}\nstream = export_task_video.get_stream()\n\n# Iterate over each output in the stream\nfor output in stream:\n output_json = json.loads(output.json_str)\n\n # Iterate over the labels in the specific project\n for dr in output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]:\n frames_data = dr[\"annotations\"][\"frames\"]\n\n # Iterate over each frame in the frames data\n for frame_key, frame_value in frames_data.items():\n\n # Iterate over each annotation in the frame\n for annotation_key, annotation_value in frame_value.items():\n if \"objects\" in annotation_key and annotation_value.values():\n\n # Iterate over each object in the annotation\n for object_key, object_value in annotation_value.items():\n if (object_value[\"annotation_kind\"] ==\n \"VideoSegmentationMask\"):\n # Update tools_frames_color with object information\n tools_frames_color.setdefault(\n object_value[\"name\"], []).append({\n frame_key:\n object_value[\"composite_mask\"]\n [\"color_rgb\"]\n })\n\nprint(tools_frames_color)",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/exports/export_data.ipynb b/examples/exports/export_data.ipynb
index 0d9f39b55..e0fa8f728 100644
--- a/examples/exports/export_data.ipynb
+++ b/examples/exports/export_data.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -39,22 +39,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\"\n",
- "!pip install -q urllib3"
- ],
+ "source": "%pip install -q \"labelbox[data]\"\n%pip install -q urllib3",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import urllib.request\n",
- "from PIL import Image\n",
- "import time"
- ],
+ "source": "import labelbox as lb\nimport urllib.request\nfrom PIL import Image\nimport time",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -69,10 +61,7 @@
},
{
"metadata": {},
- "source": [
- "API_KEY = \"\"\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "API_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -128,11 +117,7 @@
},
{
"metadata": {},
- "source": [
- "# Insert the project ID of the project from which you wish to export data rows.\n",
- "PROJECT_ID = \"\"\n",
- "project = client.get_project(PROJECT_ID)"
- ],
+ "source": "# Insert the project ID of the project from which you wish to export data rows.\nPROJECT_ID = \"\"\nproject = client.get_project(PROJECT_ID)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -146,38 +131,7 @@
},
{
"metadata": {},
- "source": [
- "# Set the export params to include/exclude certain fields.\n",
- "export_params= {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"label_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"interpolated_frames\": True,\n",
- " \"embeddings\": True\n",
- "}\n",
- "\n",
- "# Note: Filters follow AND logic, so typically using one filter is sufficient.\n",
- "filters= {\n",
- " \"last_activity_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n",
- " \"label_created_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n",
- " # \"global_keys\": [\"\", \"\"],\n",
- " # \"data_row_ids\": [\"\", \"\"],\n",
- " # \"batch_ids\": [\"\", \"\"],\n",
- " # \"workflow_status\": \"\"\n",
- "}\n",
- "\n",
- "export_task = project.export_v2(params=export_params, filters=filters)\n",
- "export_task.wait_till_done()\n",
- "\n",
- "if export_task.errors:\n",
- " print(export_task.errors)\n",
- "\n",
- "export_json = export_task.result\n",
- "print(\"results: \", export_json)"
- ],
+ "source": "# Set the export params to include/exclude certain fields.\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n \"embeddings\": True,\n}\n\n# Note: Filters follow AND logic, so typically using one filter is sufficient.\nfilters = {\n \"last_activity_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n \"label_created_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n # \"global_keys\": [\"\", \"\"],\n # \"data_row_ids\": [\"\", \"\"],\n # \"batch_ids\": [\"\", \"\"],\n # \"workflow_status\": \"\"\n}\n\nexport_task = project.export_v2(params=export_params, filters=filters)\nexport_task.wait_till_done()\n\nif export_task.errors:\n print(export_task.errors)\n\nexport_json = export_task.result\nprint(\"results: \", export_json)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -193,89 +147,21 @@
},
{
"metadata": {},
- "source": [
- "# Set the export params to include/exclude certain fields.\n",
- "export_params= {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"label_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"interpolated_frames\": True,\n",
- " \"embeddings\": True\n",
- "\n",
- "}\n",
- "\n",
- "# Note: Filters follow AND logic, so typically using one filter is sufficient.\n",
- "filters= {\n",
- " \"last_activity_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n",
- " \"label_created_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n",
- " # \"global_keys\": [\"\", \"\"],\n",
- " # \"data_row_ids\": [\"\", \"\"],\n",
- " # \"batch_ids\": [\"\", \"\"],\n",
- " # \"workflow_status\": \"\"\n",
- "}\n",
- "\n",
- "client.enable_experimental = True\n",
- "\n",
- "export_task = project.export(params=export_params, filters=filters)\n",
- "export_task.wait_till_done()"
- ],
+ "source": "# Set the export params to include/exclude certain fields.\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n \"embeddings\": True,\n}\n\n# Note: Filters follow AND logic, so typically using one filter is sufficient.\nfilters = {\n \"last_activity_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n \"label_created_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n # \"global_keys\": [\"\", \"\"],\n # \"data_row_ids\": [\"\", \"\"],\n # \"batch_ids\": [\"\", \"\"],\n # \"workflow_status\": \"\"\n}\n\nclient.enable_experimental = True\n\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Provide results with JSON converter\n",
- "# Returns streamed JSON output strings from export task results/errors, one by one\n",
- "\n",
- "# Callback used for JSON Converter\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " print(output.json_str)\n",
- "\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- "\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)\n",
- "\n",
- "print(\"file size: \", export_task.get_total_file_size(stream_type=lb.StreamType.RESULT))\n",
- "print(\"line count: \", export_task.get_total_lines(stream_type=lb.StreamType.RESULT))"
- ],
+ "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Uncomment to get stream results as a written file\n",
- "\n",
- "# Provide results with file converter\n",
- "\n",
- "# if export_task.has_errors():\n",
- "# export_task.get_stream(\n",
- "# converter=lb.FileConverter(file_path=\"./errors.txt\"),\n",
- "# stream_type=lb.StreamType.ERRORS\n",
- "# ).start()\n",
- "\n",
- "# if export_task.has_result():\n",
- "# export_task.get_stream(\n",
- "# converter=lb.FileConverter(file_path=\"./result.txt\"),\n",
- "# stream_type=lb.StreamType.RESULT\n",
- "# ).start()"
- ],
+ "source": "# Uncomment to get stream results as a written file\n\n# Provide results with file converter\n\n# if export_task.has_errors():\n# export_task.get_stream(\n# converter=lb.FileConverter(file_path=\"./errors.txt\"),\n# stream_type=lb.StreamType.ERRORS\n# ).start()\n\n# if export_task.has_result():\n# export_task.get_stream(\n# converter=lb.FileConverter(file_path=\"./result.txt\"),\n# stream_type=lb.StreamType.RESULT\n# ).start()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -314,11 +200,7 @@
},
{
"metadata": {},
- "source": [
- "# Insert the dataset ID of the dataset from which you wish to export data rows.\n",
- "DATASET_ID = \"\"\n",
- "dataset = client.get_dataset(DATASET_ID)"
- ],
+ "source": "# Insert the dataset ID of the dataset from which you wish to export data rows.\nDATASET_ID = \"\"\ndataset = client.get_dataset(DATASET_ID)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -332,38 +214,7 @@
},
{
"metadata": {},
- "source": [
- "# Set the export params to include/exclude certain fields.\n",
- "export_params= {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"label_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"interpolated_frames\": True,\n",
- " \"embeddings\": True,\n",
- " # \"project_ids\": [\"\", \"\"],\n",
- " # \"model_run_ids\": [\"\", \"\"]\n",
- "}\n",
- "\n",
- "# Note: Filters follow AND logic, so typically using one filter is sufficient.\n",
- "filters= {\n",
- " \"last_activity_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n",
- " # \"label_created_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n",
- " # \"global_keys\": [\"\", \"\"],\n",
- " # \"data_row_ids\": [\"\", \"\"],\n",
- "}\n",
- "\n",
- "export_task = dataset.export_v2(params=export_params, filters=filters)\n",
- "export_task.wait_till_done()\n",
- "\n",
- "if export_task.errors:\n",
- " print(export_task.errors)\n",
- "\n",
- "export_json = export_task.result\n",
- "print(\"results: \", export_json)"
- ],
+ "source": "# Set the export params to include/exclude certain fields.\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n \"embeddings\": True,\n # \"project_ids\": [\"\", \"\"],\n # \"model_run_ids\": [\"\", \"\"]\n}\n\n# Note: Filters follow AND logic, so typically using one filter is sufficient.\nfilters = {\n \"last_activity_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n # \"label_created_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n # \"global_keys\": [\"\", \"\"],\n # \"data_row_ids\": [\"\", \"\"],\n}\n\nexport_task = dataset.export_v2(params=export_params, filters=filters)\nexport_task.wait_till_done()\n\nif export_task.errors:\n print(export_task.errors)\n\nexport_json = export_task.result\nprint(\"results: \", export_json)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -379,64 +230,14 @@
},
{
"metadata": {},
- "source": [
- "# Set the export params to include/exclude certain fields.\n",
- "export_params= {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"label_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"interpolated_frames\": True,\n",
- " \"embeddings\": True,\n",
- " # \"project_ids\": [\"\", \"\"],\n",
- " # \"model_run_ids\": [\"\", \"\"]\n",
- "}\n",
- "\n",
- "# Note: Filters follow AND logic, so typically using one filter is sufficient.\n",
- "filters= {\n",
- " \"last_activity_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n",
- " # \"label_created_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n",
- " # \"global_keys\": [\"\", \"\"],\n",
- " # \"data_row_ids\": [\"\", \"\"],\n",
- "}\n",
- "\n",
- "client.enable_experimental = True\n",
- "\n",
- "export_task = dataset.export(params=export_params, filters=filters)\n",
- "export_task.wait_till_done()"
- ],
+ "source": "# Set the export params to include/exclude certain fields.\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n \"embeddings\": True,\n # \"project_ids\": [\"\", \"\"],\n # \"model_run_ids\": [\"\", \"\"]\n}\n\n# Note: Filters follow AND logic, so typically using one filter is sufficient.\nfilters = {\n \"last_activity_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n # \"label_created_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n # \"global_keys\": [\"\", \"\"],\n # \"data_row_ids\": [\"\", \"\"],\n}\n\nclient.enable_experimental = True\n\nexport_task = dataset.export(params=export_params, filters=filters)\nexport_task.wait_till_done()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Provide results with JSON converter\n",
- "# Returns streamed JSON output strings from export task results/errors, one by one\n",
- "\n",
- "# Callback used for JSON Converter\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " print(output.json_str)\n",
- "\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)\n",
- "\n",
- "print(\"file size: \", export_task.get_total_file_size(stream_type=lb.StreamType.RESULT))\n",
- "print(\"line count: \", export_task.get_total_lines(stream_type=lb.StreamType.RESULT))"
- ],
+ "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -457,46 +258,14 @@
},
{
"metadata": {},
- "source": [
- "catalog = client.get_catalog()"
- ],
+ "source": "catalog = client.get_catalog()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "\n",
- "export_params= {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"label_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"interpolated_frames\": True,\n",
- " \"embeddings\": True,\n",
- " # \"project_ids\": [\"\",\"\"],\n",
- " # \"model_run_ids\": [\"\", \"\"]\n",
- "}\n",
- "\n",
- "filters = {\n",
- " \"last_activity_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n",
- " # \"label_created_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n",
- " # \"global_keys\": [\"\", \"\"],\n",
- " # \"data_row_ids\": [\"\", \"\"]\n",
- "\n",
- "}\n",
- "export_task = catalog.export_v2(params=export_params,filters=filters)\n",
- "export_task.wait_till_done()\n",
- "\n",
- "if export_task.errors:\n",
- " print(export_task.errors)\n",
- "\n",
- "export_json = export_task.result\n",
- "print(\"results: \", export_json)"
- ],
+ "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n \"embeddings\": True,\n # \"project_ids\": [\"\",\"\"],\n # \"model_run_ids\": [\"\", \"\"]\n}\n\nfilters = {\n \"last_activity_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n # \"label_created_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n # \"global_keys\": [\"\", \"\"],\n # \"data_row_ids\": [\"\", \"\"]\n}\nexport_task = catalog.export_v2(params=export_params, filters=filters)\nexport_task.wait_till_done()\n\nif export_task.errors:\n print(export_task.errors)\n\nexport_json = export_task.result\nprint(\"results: \", export_json)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -512,57 +281,14 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "export_params = {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"label_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"interpolated_frames\": True,\n",
- " \"embeddings\": True,\n",
- " # \"project_ids\": [\"\",\"\"],\n",
- " # \"model_run_ids\": [\"\", \"\"]\n",
- "}\n",
- "\n",
- "filters = {\n",
- " \"last_activity_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n",
- " # \"label_created_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n",
- " # \"global_keys\": [\"\", \"\"],\n",
- " # \"data_row_ids\": [\"\", \"\"]\n",
- "}\n",
- "\n",
- "client.enable_experimental = True\n",
- "export_task = catalog.export(params=export_params)\n",
- "export_task.wait_till_done()"
- ],
+ "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n \"embeddings\": True,\n # \"project_ids\": [\"\",\"\"],\n # \"model_run_ids\": [\"\", \"\"]\n}\n\nfilters = {\n \"last_activity_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n # \"label_created_at\": [\"2000-01-01 00:00:00\", \"2050-01-01 00:00:00\"],\n # \"global_keys\": [\"\", \"\"],\n # \"data_row_ids\": [\"\", \"\"]\n}\n\nclient.enable_experimental = True\nexport_task = catalog.export(params=export_params)\nexport_task.wait_till_done()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " print(output.json_str)\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)\n",
- "\n",
- "print(\"file size: \", export_task.get_total_file_size(stream_type=lb.StreamType.RESULT))\n",
- "print(\"line count: \", export_task.get_total_lines(stream_type=lb.StreamType.RESULT))"
- ],
+ "source": "def json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -583,11 +309,7 @@
},
{
"metadata": {},
- "source": [
- "# Insert the Catalog slice ID of the slice from which you wish to export data rows.\n",
- "CATALOG_SLICE_ID = \"\"\n",
- "catalog_slice = client.get_catalog_slice(CATALOG_SLICE_ID)"
- ],
+ "source": "# Insert the Catalog slice ID of the slice from which you wish to export data rows.\nCATALOG_SLICE_ID = \"\"\ncatalog_slice = client.get_catalog_slice(CATALOG_SLICE_ID)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -601,30 +323,7 @@
},
{
"metadata": {},
- "source": [
- "# Set the export params to include/exclude certain fields.\n",
- "export_params = {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"label_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"interpolated_frames\": True,\n",
- " \"embeddings\": True,\n",
- " # \"project_ids\": [\"\", \"\"],\n",
- " # \"model_run_ids\": [\"\", \"\"]\n",
- "}\n",
- "\n",
- "export_task = catalog_slice.export_v2(params=export_params)\n",
- "export_task.wait_till_done()\n",
- "\n",
- "if export_task.errors:\n",
- " print(export_task.errors)\n",
- "\n",
- "export_json = export_task.result\n",
- "print(\"results: \", export_json)"
- ],
+ "source": "# Set the export params to include/exclude certain fields.\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n \"embeddings\": True,\n # \"project_ids\": [\"\", \"\"],\n # \"model_run_ids\": [\"\", \"\"]\n}\n\nexport_task = catalog_slice.export_v2(params=export_params)\nexport_task.wait_till_done()\n\nif export_task.errors:\n print(export_task.errors)\n\nexport_json = export_task.result\nprint(\"results: \", export_json)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -640,56 +339,14 @@
},
{
"metadata": {},
- "source": [
- "# Set the export params to include/exclude certain fields.\n",
- "export_params = {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"label_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"interpolated_frames\": True,\n",
- " \"embeddings\": True,\n",
- " # \"project_ids\": [\"\", \"\"],\n",
- " # \"model_run_ids\": [\"\", \"\"]\n",
- "}\n",
- "\n",
- "\n",
- "client.enable_experimental = True\n",
- "\n",
- "export_task = catalog_slice.export(params=export_params)\n",
- "export_task.wait_till_done()"
- ],
+ "source": "# Set the export params to include/exclude certain fields.\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n \"embeddings\": True,\n # \"project_ids\": [\"\", \"\"],\n # \"model_run_ids\": [\"\", \"\"]\n}\n\nclient.enable_experimental = True\n\nexport_task = catalog_slice.export(params=export_params)\nexport_task.wait_till_done()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Provide results with JSON converter\n",
- "# Returns streamed JSON output strings from export task results/errors, one by one\n",
- "\n",
- "# Callback used for JSON Converter\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " print(output.json_str)\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)\n",
- "\n",
- "print(\"file size: \", export_task.get_total_file_size(stream_type=lb.StreamType.RESULT))\n",
- "print(\"line count: \", export_task.get_total_lines(stream_type=lb.StreamType.RESULT))"
- ],
+ "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -716,11 +373,7 @@
},
{
"metadata": {},
- "source": [
- "# Insert the model run ID of the model run from which you wish to export data rows.\n",
- "MODEL_RUN_ID = \"\"\n",
- "model_run = client.get_model_run(MODEL_RUN_ID)"
- ],
+ "source": "# Insert the model run ID of the model run from which you wish to export data rows.\nMODEL_RUN_ID = \"\"\nmodel_run = client.get_model_run(MODEL_RUN_ID)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -734,26 +387,7 @@
},
{
"metadata": {},
- "source": [
- "# Set the export params to include/exclude certain fields.\n",
- "export_params = {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"interpolated_frames\": True,\n",
- " \"predictions\": True,\n",
- " \"embeddings\": True\n",
- "}\n",
- "\n",
- "export_task = model_run.export_v2(params=export_params)\n",
- "export_task.wait_till_done()\n",
- "\n",
- "if export_task.errors:\n",
- " print(export_task.errors)\n",
- "\n",
- "export_json = export_task.result\n",
- "print(\"results: \", export_json)"
- ],
+ "source": "# Set the export params to include/exclude certain fields.\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"interpolated_frames\": True,\n \"predictions\": True,\n \"embeddings\": True,\n}\n\nexport_task = model_run.export_v2(params=export_params)\nexport_task.wait_till_done()\n\nif export_task.errors:\n print(export_task.errors)\n\nexport_json = export_task.result\nprint(\"results: \", export_json)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -769,51 +403,14 @@
},
{
"metadata": {},
- "source": [
- "# Set the export params to include/exclude certain fields.\n",
- "export_params = {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"interpolated_frames\": True,\n",
- " \"predictions\": True,\n",
- " \"embeddings\": True\n",
- "}\n",
- "\n",
- "client.enable_experimental = True\n",
- "\n",
- "export_task = model_run.export(params=export_params)\n",
- "export_task.wait_till_done()"
- ],
+ "source": "# Set the export params to include/exclude certain fields.\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"interpolated_frames\": True,\n \"predictions\": True,\n \"embeddings\": True,\n}\n\nclient.enable_experimental = True\n\nexport_task = model_run.export(params=export_params)\nexport_task.wait_till_done()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Provide results with JSON converter\n",
- "# Returns streamed JSON output strings from export task results/errors, one by one\n",
- "\n",
- "# Callback used for JSON Converter\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " print(output.json_str)\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)\n",
- "\n",
- "print(\"file size: \", export_task.get_total_file_size(stream_type=lb.StreamType.RESULT))\n",
- "print(\"line count: \", export_task.get_total_lines(stream_type=lb.StreamType.RESULT))"
- ],
+ "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -834,10 +431,7 @@
},
{
"metadata": {},
- "source": [
- "# Insert the global key of the data row you wish to export\n",
- "DATA_ROW_GLOBAL_KEY = \"\""
- ],
+ "source": "# Insert the global key of the data row you wish to export\nDATA_ROW_GLOBAL_KEY = \"\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -851,29 +445,7 @@
},
{
"metadata": {},
- "source": [
- "# Set the export params to include/exclude certain fields.\n",
- "export_params= {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"label_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"interpolated_frames\": True,\n",
- " \"embeddings\": True\n",
- "}\n",
- "\n",
- "# Provide a list of data row global keys\n",
- "export_task = lb.DataRow.export_v2(client=client, global_keys=[DATA_ROW_GLOBAL_KEY], params=export_params)\n",
- "export_task.wait_till_done()\n",
- "\n",
- "if export_task.errors:\n",
- " print(export_task.errors)\n",
- "\n",
- "export_json = export_task.result\n",
- "print(\"results: \", export_json)"
- ],
+ "source": "# Set the export params to include/exclude certain fields.\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n \"embeddings\": True,\n}\n\n# Provide a list of data row global keys\nexport_task = lb.DataRow.export_v2(client=client,\n global_keys=[DATA_ROW_GLOBAL_KEY],\n params=export_params)\nexport_task.wait_till_done()\n\nif export_task.errors:\n print(export_task.errors)\n\nexport_json = export_task.result\nprint(\"results: \", export_json)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -889,54 +461,14 @@
},
{
"metadata": {},
- "source": [
- "# Set the export params to include/exclude certain fields.\n",
- "export_params= {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"label_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"interpolated_frames\": True,\n",
- " \"embeddings\": True\n",
- "}\n",
- "\n",
- "client.enable_experimental = True\n",
- "\n",
- "# Provide a list of data row global keys\n",
- "export_task = lb.DataRow.export(client=client, global_keys=[DATA_ROW_GLOBAL_KEY], params=export_params)\n",
- "export_task.wait_till_done()"
- ],
+ "source": "# Set the export params to include/exclude certain fields.\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n \"embeddings\": True,\n}\n\nclient.enable_experimental = True\n\n# Provide a list of data row global keys\nexport_task = lb.DataRow.export(client=client,\n global_keys=[DATA_ROW_GLOBAL_KEY],\n params=export_params)\nexport_task.wait_till_done()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Provide results with JSON converter\n",
- "# Returns streamed JSON output strings from export task results/errors, one by one\n",
- "\n",
- "# Callback used for JSON Converter\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " print(output.json_str)\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(),\n",
- " stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)\n",
- "\n",
- "print(\"file size: \", export_task.get_total_file_size(stream_type=lb.StreamType.RESULT))\n",
- "print(\"line count: \", export_task.get_total_lines(stream_type=lb.StreamType.RESULT))"
- ],
+ "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/exports/export_v1_to_v2_migration_support.ipynb b/examples/exports/export_v1_to_v2_migration_support.ipynb
new file mode 100644
index 000000000..2434c7369
--- /dev/null
+++ b/examples/exports/export_v1_to_v2_migration_support.ipynb
@@ -0,0 +1,591 @@
+{
+ "nbformat": 4,
+ "nbformat_minor": 5,
+ "metadata": {},
+ "cells": [
+ {
+ "metadata": {},
+ "source": [
+ "",
+ " ",
+ " | \n"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "\n",
+ " \n",
+ " | \n",
+ "\n",
+ "\n",
+ " \n",
+ " | "
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "# Export V1 to V2 migration "
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "**Export V1 will no longer be available in any version of the SDK starting on April 2024**. We recommend users to plan accordingly. \n",
+ "\n",
+ "This notebook is designed to help users identify alternative V2 export methods that can serve as replacements for V1 methods."
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "### Key changes included in export V2 methods ( ``export()`` and ``export_v2()``):\n",
+ "1. Added flexibility to only export the data that is needed. The new methods include parameters and filters to give you more granular control over your exports.\n",
+ "2. Added functionality to stream an **unlimited** number of data rows using ``export()`` (available on SDK >=3.56). Upgrading to `export()` is recommended as it is a more scalable solution.\n",
+ "\n",
+ "For complete details on how to use export V2 methods please see the [Export V2 methods](https://docs.labelbox.com/reference/label-export#export-v2-methods) documentation."
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "### Export V1 deprecated methods: \n",
+ "Project methods : \n",
+ "1. ```project.export_labels()```\n",
+ "2. ```project.label_generator()```\n",
+ "3. ```project.export_queued_data_rows()```\n",
+ "\n",
+ "Dataset methods: \n",
+ "1. ```dataset.export_data_rows()```\n",
+ "\n",
+ "Batch methods: \n",
+ "1. ```batch.export_data_rows()```\n",
+ "\n",
+ "Model methods :\n",
+ "1. ```model_run.export_labels()```\n",
+ "\n"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "# Imports"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "%pip install -q \"labelbox[data]\"",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": "import labelbox as lb\nimport pprint\n\npp = pprint.PrettyPrinter(width=30, compact=True)",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "## API Key and Client\n",
+ "See the developer guide for [creating an API key](https://docs.labelbox.com/reference/create-api-key)."
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "API_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)\nclient.enable_experimental = (\n True ## This is required if using the export() streamable method\n)",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "# Exports V1 to V2 guidelines\n",
+ "The follow sections will demonstrate how to use the export V2 methods to fetch data from your projects, datasets, batches and model runs. "
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "## Export labels from a project\n"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "PROJECT_ID = \"\"\nproject = client.get_project(PROJECT_ID)",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "##### Export V1 (deprecated) \n",
+ "1. ```project.export_labels()``` \n",
+ " - Parameters: \n",
+ " - ```download: bool = False```\n",
+ " - ```timeout_seconds: int = 1800```\n",
+ " - Output : (str | List[Dict[Any, Any]] | None)"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "For a comprehensive example of Export V1 ``project.export_labels()`` output, please refer to our documentation: [Export V1 sample export](https://docs.labelbox.com/reference/export-image-annotations#sample-project-export)"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "2. ```project.label_generator()```\n",
+ " - Parameters: \n",
+ " - ```timeout_seconds: int = 600```\n",
+ " - Output: LabelGenerator"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "# Single entry from the output of project.label_generator() (deprecated)\n# Label objects will not be deprecated.\nsingle_output_from_generator = \"\"\"\n\nLabel(\n uid='clrf5csho2ihx07ilffgp2fzj',\n data=ImageData(\n im_bytes=None,\n file_path=None,\n url='https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg',\n arr=None\n ),\n annotations=[\n ObjectAnnotation(\n confidence=None,\n name='bounding_box',\n feature_schema_id='clrf5ck4a0b9b071paa9ncu15',\n extra={\n 'instanceURI': 'https://api.labelbox.com/masks/feature/clrf5csvi6ofm07lsf9pygwvi?token='\n 'color': '#ff0000',\n 'feature_id': 'clrf5csvi6ofm07lsf9pygwvi',\n 'value': 'bounding_box',\n 'page': None,\n 'unit': None\n },\n value=Rectangle(\n extra={},\n start=Point(extra={}, x=2096.0, y=1264.0),\n end=Point(extra={}, x=2240.0, y=1689.0)\n ),\n classifications=[]\n ),\n # Add more annotations as needed\n # ...\n ],\n extra={\n 'Created By': 'aovalle@labelbox.com',\n 'Project Name': 'Image Annotation Import Demo',\n 'Created At': '2024-01-15T16:35:59.000Z',\n 'Updated At': '2024-01-15T16:51:56.000Z',\n 'Seconds to Label': 66.0,\n 'Agreement': -1.0,\n 'Benchmark Agreement': -1.0,\n 'Benchmark ID': None,\n 'Dataset Name': 'image-demo-dataset',\n 'Reviews': [],\n 'View Label': 'https://editor.labelbox.com?project=clrf5ckex09m9070x1te223u5&label=clrf5csho2ihx07ilffgp2fzj',\n 'Has Open Issues': 0.0,\n 'Skipped': False,\n 'media_type': 'image',\n 'Data Split': None,\n 'Global Key': '2560px-Kitano_Street_Kobe01s5s41102.jpeg'\n }\n)\n\n\"\"\"",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "##### Export V2 \n",
+ "\n",
+ "For complete details on the supported filters abd parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n",
+ "\n",
+ "1. ```project.export()``` : Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n",
+ "\n",
+ " - Parameters: \n",
+ " - ```\"label_details\": True```\n",
+ " - ```\"attachments\": True```\n",
+ " - ```\"data_row_details\": True```\n",
+ " - ```\"project_details\": True```\n",
+ " - ```\"label_details\": True```\n",
+ " - ```\"performance_details\": True```\n",
+ " - Output: \n",
+ " - ```ExportTask```\n",
+ " - `ExportTask.has_result()` return type: bool \n",
+ " - `ExportTask.has_errors()` return type: bool\n",
+ " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "## Set the export parameters to only export labels\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n}\n# You also have the option to include additional filtering to narrow down the list of labels\nfilters = {}\n\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "## Export queued (\"To Label\") data rows from a project"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "##### Export V1 (deprecated): \n",
+ "1. ``project.export_queued_data_rows()`` :\n",
+ " - Parameters: \n",
+ " - ``timeout_seconds: int = 120``\n",
+ " - ``include_metadata: bool = False``\n",
+ " - Output: List[Dict[str, str]]"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "# Single entry from the output of project.export_queued_data_rows() (deprecated)\nsingle_output_example = \"\"\"\n[\n {'id': 'clpouak6nap2g0783ajd1d6pf',\n 'createdAt': '2023-12-03T02:04:34.062Z',\n 'updatedAt': '2023-12-03T02:05:33.797Z',\n 'externalId': None,\n 'globalKey': 'b57c9ab2-304f-4c17-ba5f-c536f39a6a46',\n 'metadataFields': [],\n 'customMetadata': [],\n 'rowData': 'https://storage.googleapis.com/labelbox-developer-testing-assets/image/data_files/santa.jpeg',\n 'mediaAttributes': {'assetType': 'image',\n 'contentLength': 305973,\n 'height': 1333,\n 'mimeType': 'image/jpeg',\n 'subType': 'jpeg',\n 'superType': 'image',\n 'width': 2000}}\n]\n\n\"\"\"",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "##### Export V2\n",
+ "For complete details on the supported filters and parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n",
+ "\n",
+ "1. ```project.export()``` : Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n",
+ "\n",
+ " - Parameters (Minimum required parameters): \n",
+ " - ```\"data_row_details\": True```\n",
+ " - ```\"project_details\": True```\n",
+ " - Required filters: \n",
+ " - ``` \"workflow_status\": \"ToLabel\"```\n",
+ " - Output: \n",
+ " - ```ExportTask```\n",
+ " - `ExportTask.has_result()` return type: bool \n",
+ " - `ExportTask.has_errors()` return type: bool\n",
+ " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "export_params = {\n \"attachments\": True, # Set to true if you want to export attachments\n \"metadata_fields\": True, # Set to true if you want to export metadata\n \"data_row_details\": True,\n \"project_details\": True,\n}\nfilters = {\n \"workflow_status\":\n \"ToLabel\" ## Using this filter will only export queued data rows\n}\n\n# An ExportTask is returned, this provides additional information about the status of your task, such as\n# any errors encountered and includes additional methods to stream your data\n\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "## Export data rows from a Dataset "
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "DATASET_ID = \"\"\ndataset = client.get_dataset(DATASET_ID)",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "#### Export V1 (deprecated): \n",
+ "\n",
+ "1. ```dataset.export_data_rows()```\n",
+ " - Parameters: \n",
+ " - ``timeout_seconds=120``\n",
+ " - ``include_metadata: bool = True``\n",
+ " - Output: \n",
+ " - Data row object generator\n"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "# Single entry from the output of dataset.export_data_rows() (deprecated)\n# Data row objects will not be deprecated.\n\nsingle_output_from_data_row_generator = \"\"\"\n\n\"\"\"",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "#### Export V2\n",
+ "For complete details on the supported filters and parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n",
+ "\n",
+ "1. ```project.export()``` : Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n",
+ "\n",
+ " - Parameters (minimum required parameters): \n",
+ " - ``\"data_row_details\": True``\n",
+ " - Output: \n",
+ " - ```ExportTask```\n",
+ " - `ExportTask.has_result()` return type: bool \n",
+ " - `ExportTask.has_errors()` return type: bool\n",
+ " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "export_params = {\n \"attachments\": True, # Set to true if you want to export attachments\n \"metadata_fields\": True, # Set to true if you want to export metadata\n \"data_row_details\": True,\n}\nfilters = {}\n\n# A task is returned, this provides additional information about the status of your task, such as\n# any errors encountered\nexport_task = dataset.export(params=export_params, filters=filters)\nexport_task.wait_till_done()",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "## Export data rows from a batch"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "#### Export V1 (deprecated): \n",
+ "1. ```batch.export_data_rows()```\n",
+ " - Parameters: \n",
+ " - ``timeout_seconds=120``\n",
+ " - ``include_metadata: bool = True``\n",
+ " - Output: \n",
+ " - Data row object generator"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "# Single output from batch.export_data_rows() method (deprecated)\n# Data row objects will not be deprecated\n\nsingle_output_from_data_row_generator = \"\"\"\n\n\"\"\"",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "#### Export V2\n",
+ "For complete details on the supported filters and parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n",
+ "\n",
+ "1. ```project.export()``` : Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n",
+ "\n",
+ " - Required parameters: \n",
+ " - ```\"data_row_details\": True```,\n",
+ " - ```\"batch_ids\": [] ```\n",
+ " - Output: \n",
+ " - ```ExportTask```\n",
+ " - `ExportTask.has_result()` return type: bool \n",
+ " - `ExportTask.has_errors()` return type: bool\n",
+ " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "# Find the batch ID by navigating to \"Batches\" --> \"Manage batches\" --> \"Copy Batch ID\"\nBATCH_ID = \"\"",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"performance_details\": True,\n \"batch_ids\": [\n BATCH_ID\n ], # Include batch ids if you only want to export specific batches, otherwise,\n # you can export all the data without using this parameter\n}\nfilters = {}\n\n# A task is returned, this provides additional information about the status of your task, such as\n# any errors encountered\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "## Export data rows from a Model "
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "#### Export V1 (deprecated): \n",
+ "1. ```model_run.export_labels(downlaod=True)```\n",
+ " - Parameters: \n",
+ " - ```download: bool = False```\n",
+ " - ```timeout_seconds: int = 1800```\n",
+ " - Output : (str | List[Dict[Any, Any]] | None)"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "# Single output from model_run.export_labels()\nsingle_output_example = \"\"\"\n[\n {'ID': '1c48a7a0-3016-48e0-b0e3-47430f974869',\n 'Data Split': 'training',\n 'DataRow ID': 'clpqdyf650xd40712pycshy6a',\n 'External ID': './resume/BANKING/99124477.pdf',\n 'Labeled Data': 'https://storage.labelbox.com/cl5bn8qvq1av907xtb3bp8q60%2F8c6afc38-42a4-b2e1-a2e3-1e3b0c2998fc-99124477.pdf?Expires=1706637969726&KeyName=labelbox-assets-key-3&Signature=2nVt3sJ21CbjGS9I64yFquUELRw',\n 'Media Attributes': {'assetType': 'pdf',\n 'contentLength': 42535,\n 'mimeType': 'application/pdf',\n 'pageCount': 3,\n 'subType': 'pdf',\n 'superType': 'application'},\n 'Label': {'objects': [{'featureId': 'b9f3b584-0f45-050a-88d4-39c2a169c8e1',\n 'schemaId': 'clq1ckwbd08jp07z91q9mch5j',\n 'title': 'Test',\n 'value': 'test',\n 'color': '#1CE6FF',\n 'data': {'location': [{'text-bbox': {'page': 1,\n 'top': 158.44,\n 'left': 58.765,\n 'height': 13.691,\n 'width': 78.261}}],\n 'unit': 'POINTS'}}],\n 'classifications': [],\n 'relationships': []}}\n ]\n \"\"\"",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "#### Export V2\n",
+ "For complete details on the supported filters and parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n",
+ "\n",
+ "1. ```model_run.export()```: Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n",
+ "\n",
+ " - Required parameters: \n",
+ " - ```\"data_row_details\": True```\n",
+ " - ```\"project_details\": True```\n",
+ " - ```\"label_details\": True```\n",
+ " - Required filters: \n",
+ " - N/A -> Filters not supported\n",
+ " - Output: \n",
+ " - ```ExportTask```\n",
+ " - `ExportTask.has_result()` return type: bool \n",
+ " - `ExportTask.has_errors()` return type: bool\n",
+ " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "MODEL_RUN_ID = \"\"\nmodel_run = client.get_model_run(MODEL_RUN_ID)",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"performance_details\": True,\n}\n\nexport_task = model_run.export(params=export_params)\nexport_task.wait_till_done()",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.JsonConverterOutput):\n print(output.json_str)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "## Export data rows from a video project\n",
+ "Video projects include additional fields. Please refer to the example below to extract specific fields from video exports.\n"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "##### Export V1 (deprecated) \n",
+ "1. ```project.export_labels()``` \n",
+ " - Parameters: \n",
+ " - ```download: bool = False```\n",
+ " - ```timeout_seconds: int = 1800```\n",
+ " - Output : (str | List[Dict[Any, Any]] | None)"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "For a comprehensive example of Export V1 ``project.export_labels()`` output, please refer to our documentation: [Export V1 sample export](https://docs.labelbox.com/reference/export-image-annotations#sample-project-export)"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "2. ```project.video_label_generator()```\n",
+ " - Parameters: \n",
+ " - ```timeout_seconds: int = 600```\n",
+ " - Output: LabelGenerator"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "##### Export V2\n",
+ "\n",
+ "For complete details on the supported filters and parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n",
+ "\n",
+ "1. ```project.export()```: Starting from SDK version 3.56, a streamable method is available, this method allows you to stream unlimited number of data rows. However, if you are using an earlier version, you can still utilize the ```export_v2()``` function with identical parameters. It's important to note that the output task type differs, and streaming data methods are not included in `export_v2()`.\n",
+ "\n",
+ " - Required parameters: \n",
+ " - ```\"attachments\": True```\n",
+ " - ```\"data_row_details\": True```\n",
+ " - ```\"project_details\": True```\n",
+ " - ```\"label_details\": True```\n",
+ " - ```\"performance_details\": True```\n",
+ " - Output: \n",
+ " - ```ExportTask```\n",
+ " - `ExportTask.has_result()` return type: bool \n",
+ " - `ExportTask.has_errors()` return type: bool\n",
+ " - `ExportTask.get_stream()` return type: Stream[JsonConverterOutput]"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "VIDEO_PROJECT_ID = \"\"\nproject = client.get_project(VIDEO_PROJECT_ID)",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"performance_details\": True,\n \"label_details\": True,\n \"interpolated_frames\":\n True, # For additional information on interpolated frames please visit our documentation https://docs.labelbox.com/docs/video-annotations#video-editor-components\n}\nfilters = {}\n\n# A task is returned, this provides additional information about the status of your task, such as\n# any errors encountered\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "Fetch frame specific objects and frame or global classifications"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "import json\nimport pprint as pp # Assuming pp is imported from pprint module\n\nframes_objects_class_list = []\nglobal_class_list = []\n\nstream = export_task.get_stream()\nfor output in stream:\n output_json = json.loads(output.json_str)\n for dr in output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]:\n frames_data = dr[\"annotations\"][\"frames\"]\n for k, v in frames_data.items():\n frames_objects_class_list.append({k: v})\n global_class_list.extend(dr[\"annotations\"][\"classifications\"])\n\n print(\"------- Frame specific classifications and objects -------\")\n pp.pprint(frames_objects_class_list)\n\n print(\"------ Global classifications -------\")\n pp.pprint(global_class_list)",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "Fetch key frame feature map "
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "keyframe_map = []\n\nstream = export_task.get_stream()\nfor output in stream:\n output_json = json.loads(output.json_str)\n labels = output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]\n for label in labels:\n annotations = label[\"annotations\"][\"key_frame_feature_map\"]\n for key, value in annotations.items():\n keyframe_map.append({key: value})\n\nprint(\"----- Keyframe Feature Map -----\")\npp.pprint(keyframe_map)",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "Fetch segments "
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "segments_map = []\nstream = export_task.get_stream()\nfor output in stream:\n output_json = json.loads(output.json_str)\n labels = output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]\n for label in labels:\n annotations = label[\"annotations\"][\"segments\"]\n for key, value in annotations.items():\n segments_map.append({key: value})\n\nprint(\"----- Segments Feature Map -----\")\npp.pprint(segments_map)",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ }
+ ]
+}
\ No newline at end of file
diff --git a/examples/extras/classification_confusion_matrix.ipynb b/examples/extras/classification_confusion_matrix.ipynb
deleted file mode 100644
index 0c45acf52..000000000
--- a/examples/extras/classification_confusion_matrix.ipynb
+++ /dev/null
@@ -1,228 +0,0 @@
-{
- "nbformat": 4,
- "nbformat_minor": 5,
- "metadata": {},
- "cells": [
- {
- "metadata": {},
- "source": [
- "\n",
- " \n",
- " | "
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "\n",
- " \n",
- " | \n",
- "\n",
- "\n",
- " \n",
- " | "
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "# Classification Confusion matrix\n",
- "\n",
- "This notebook plots a confusion matrix for a multi-class, single label classification.\n",
- "\n",
- "It assumes that your project has a number of labels from multiple labelers, where the Annotation Type is Radio.\n",
- "\n",
- "## Installs"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "!pip install -q 'labelbox[data]' scikit-learn matplotlib ipywidgets"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "## Imports"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "# Imports and etc\n",
- "\n",
- "from sklearn.metrics import ConfusionMatrixDisplay\n",
- "from sklearn.metrics import classification_report\n",
- "import matplotlib.pyplot as plt\n",
- "import ipywidgets as widgets\n",
- "import labelbox as lb\n",
- "\n",
- "def get_labelers():\n",
- " labels = project.label_generator()\n",
- " labelers = []\n",
- "\n",
- " for l in labels:\n",
- " if not l.extra['Created By'] in labelers:\n",
- " labelers.append(l.extra['Created By'])\n",
- "\n",
- " return labelers\n",
- "\n",
- "\n",
- "def get_paired_labels(labeler1, labeler2):\n",
- " labels = project.label_generator()\n",
- " l1 = []\n",
- " l2 = []\n",
- " label_dict = {}\n",
- "\n",
- " for l in labels:\n",
- " if not l.data.uid in label_dict:\n",
- " label_dict[l.data.uid] = {}\n",
- "\n",
- " # Check if benchmark\n",
- " if l.extra['Benchmark ID']:\n",
- " label_dict[l.data.uid]['Benchmarks'] = l.annotations[0].value.answer.name\n",
- "\n",
- " # Skip labels not created by either of our labelers\n",
- " if l.extra['Created By'] != labeler1 and l.extra[\n",
- " 'Created By'] != labeler2:\n",
- " continue\n",
- "\n",
- " label_dict[l.data.uid][l.extra['Created By']] = \\\n",
- " l.annotations[0].value.answer.name\n",
- "\n",
- " for uid in label_dict.keys():\n",
- " if labeler1 in label_dict[uid] and labeler2 in label_dict[uid]:\n",
- " l1.append(label_dict[uid][labeler1])\n",
- " l2.append(label_dict[uid][labeler2])\n",
- "\n",
- " return l1, l2\n",
- "\n",
- "\n",
- "def get_label_dict():\n",
- " labels = project.label_generator()\n",
- " labelers = []\n",
- " label_dict = {}\n",
- "\n",
- " for l in labels:\n",
- " if not l.data.uid in label_dict:\n",
- " label_dict[l.data.uid] = {}\n",
- "\n",
- " label_dict[l.data.uid][l.extra['Created By']] = \\\n",
- " l.annotations[0].value.answer.name\n",
- "\n",
- " if not l.extra['Created By'] in labelers:\n",
- " labelers.append(l.extra['Created By'])\n",
- "\n",
- " print(labelers)\n",
- " return label_dict, labelers"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "# Labelbox API + project and dataset\n",
- "\n",
- "# Add your api key\n",
- "API_KEY = None\n",
- "lb = lb.Client(api_key=API_KEY)\n",
- "\n",
- "# Add your project and dataset uids here\n",
- "project = lb.get_project('xxx')\n",
- "dataset = lb.get_dataset('xxx')"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "## Labeler Selection"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "# Selectors\n",
- "\n",
- "labelers = get_labelers()\n",
- "\n",
- "items = [\n",
- " widgets.Dropdown(\n",
- " options=['Benchmarks'] + labelers,\n",
- " description='Compare this:',\n",
- " disabled=False,\n",
- " ),\n",
- " widgets.Dropdown(\n",
- " options=labelers,\n",
- " description='Against this:',\n",
- " disabled=False,\n",
- " )]\n",
- "\n",
- "\n",
- "widgets.VBox(items)"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [
- "## Confusion Matrix"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "# Plot Matrix\n",
- "\n",
- "l1, l2 = get_paired_labels(items[0].value, items[1].value)\n",
- "\n",
- "fig, ax = plt.subplots(figsize=(15,15))\n",
- "c = ConfusionMatrixDisplay.from_predictions(l1, l2,\n",
- " labels=list(set(l1)), sample_weight=None,\n",
- " normalize=None, display_labels=None, include_values=True,\n",
- " xticks_rotation='vertical', values_format=None,\n",
- " cmap='Blues', ax=ax, colorbar=False)\n",
- "\n",
- "_ = c.ax_.set_xlabel(items[1].value), c.ax_.set_ylabel(items[0].value)\n",
- "\n",
- "cr = classification_report(\n",
- " l1,\n",
- " l2,\n",
- " output_dict=False,\n",
- " target_names=list(set(l1)),\n",
- " zero_division=1\n",
- ")\n",
- "\n",
- "print(cr)"
- ],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- },
- {
- "metadata": {},
- "source": [],
- "cell_type": "code",
- "outputs": [],
- "execution_count": null
- }
- ]
-}
\ No newline at end of file
diff --git a/examples/foundry/object_detection.ipynb b/examples/foundry/object_detection.ipynb
index a7de826db..5cf092bca 100644
--- a/examples/foundry/object_detection.ipynb
+++ b/examples/foundry/object_detection.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -51,20 +51,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q labelbox"
- ],
+ "source": "%pip install -q labelbox",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "from labelbox.schema.conflict_resolution_strategy import ConflictResolutionStrategy\n",
- "import uuid"
- ],
+ "source": "import labelbox as lb\nfrom labelbox.schema.conflict_resolution_strategy import (\n ConflictResolutionStrategy,)\nimport uuid",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -80,12 +74,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your API key\n",
- "API_KEY = \"\"\n",
- "# To get your API key go to: Workspace settings -> API -> Create API Key\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your API key\nAPI_KEY = \"\"\n# To get your API key go to: Workspace settings -> API -> Create API Key\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -106,24 +95,7 @@
},
{
"metadata": {},
- "source": [
- "# send a sample image as data row for a dataset\n",
- "global_key = str(uuid.uuid4())\n",
- "\n",
- "test_img_url = {\n",
- " \"row_data\":\n",
- " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n",
- " \"global_key\":\n",
- " global_key\n",
- "}\n",
- "\n",
- "dataset = client.create_dataset(name=\"foundry-demo-dataset\")\n",
- "task = dataset.create_data_rows([test_img_url])\n",
- "task.wait_till_done()\n",
- "\n",
- "print(f\"Errors: {task.errors}\")\n",
- "print(f\"Failed data rows: {task.failed_data_rows}\")"
- ],
+ "source": "# send a sample image as data row for a dataset\nglobal_key = str(uuid.uuid4())\n\ntest_img_url = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n}\n\ndataset = client.create_dataset(name=\"foundry-demo-dataset\")\ntask = dataset.create_data_rows([test_img_url])\ntask.wait_till_done()\n\nprint(f\"Errors: {task.errors}\")\nprint(f\"Failed data rows: {task.failed_data_rows}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -143,20 +115,7 @@
},
{
"metadata": {},
- "source": [
- "# Create ontology with two bounding boxes that is included with Amazon Rekognition: Car and Person\n",
- "ontology_builder = lb.OntologyBuilder(\n",
- " classifications=[],\n",
- " tools=[\n",
- " lb.Tool(tool=lb.Tool.Type.BBOX, name=\"Car\"),\n",
- " lb.Tool(tool=lb.Tool.Type.BBOX, name=\"Person\")\n",
- " ]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Image Bounding Box Annotation Demo Foundry\",\n",
- " ontology_builder.asdict(),\n",
- " media_type=lb.MediaType.Image)"
- ],
+ "source": "# Create ontology with two bounding boxes that is included with Amazon Rekognition: Car and Person\nontology_builder = lb.OntologyBuilder(\n classifications=[],\n tools=[\n lb.Tool(tool=lb.Tool.Type.BBOX, name=\"Car\"),\n lb.Tool(tool=lb.Tool.Type.BBOX, name=\"Person\"),\n ],\n)\n\nontology = client.create_ontology(\n \"Image Bounding Box Annotation Demo Foundry\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -172,12 +131,7 @@
},
{
"metadata": {},
- "source": [
- "project = client.create_project(name=\"Foundry Image Demo\",\n",
- " media_type=lb.MediaType.Image)\n",
- "\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "project = client.create_project(name=\"Foundry Image Demo\",\n media_type=lb.MediaType.Image)\n\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -200,10 +154,7 @@
},
{
"metadata": {},
- "source": [
- "#Select your foundry application inside the UI and copy the APP ID from the top right corner\n",
- "AMAZON_REKOGNITION_APP_ID = \"\""
- ],
+ "source": "# Select your foundry application inside the UI and copy the APP ID from the top right corner\nAMAZON_REKOGNITION_APP_ID = \"\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -219,20 +170,7 @@
},
{
"metadata": {},
- "source": [
- "task = client.run_foundry_app(model_run_name=f\"Amazon-{str(uuid.uuid4())}\",\n",
- " data_rows=lb.GlobalKeys(\n",
- " [global_key] # Provide a list of global keys\n",
- " ),\n",
- " app_id=AMAZON_REKOGNITION_APP_ID)\n",
- "\n",
- "task.wait_till_done()\n",
- "\n",
- "print(f\"Errors: {task.errors}\")\n",
- "\n",
- "#Obtain model run ID from task\n",
- "MODEL_RUN_ID = task.metadata[\"modelRunId\"]"
- ],
+ "source": "task = client.run_foundry_app(\n model_run_name=f\"Amazon-{str(uuid.uuid4())}\",\n data_rows=lb.GlobalKeys([global_key]), # Provide a list of global keys\n app_id=AMAZON_REKOGNITION_APP_ID,\n)\n\ntask.wait_till_done()\n\nprint(f\"Errors: {task.errors}\")\n\n# Obtain model run ID from task\nMODEL_RUN_ID = task.metadata[\"modelRunId\"]",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -260,10 +198,7 @@
},
{
"metadata": {},
- "source": [
- "# Copy map ontology through the UI then paste JSON file here\n",
- "PREDICTIONS_ONTOLOGY_MAPPING = {}"
- ],
+ "source": "# Copy map ontology through the UI then paste JSON file here\nPREDICTIONS_ONTOLOGY_MAPPING = {}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -295,31 +230,7 @@
},
{
"metadata": {},
- "source": [
- "model_run = client.get_model_run(MODEL_RUN_ID)\n",
- "\n",
- "send_to_annotations_params = {\n",
- " \"predictions_ontology_mapping\": PREDICTIONS_ONTOLOGY_MAPPING,\n",
- " \"exclude_data_rows_in_project\": False,\n",
- " \"override_existing_annotations_rule\": ConflictResolutionStrategy.OverrideWithPredictions,\n",
- " \"batch_priority\": 5,\n",
- "}\n",
- "\n",
- "\n",
- "task = model_run.send_to_annotate_from_model(\n",
- " destination_project_id=project.uid,\n",
- " task_queue_id=None, #ID of workflow task, set ID to None if you want to convert pre-labels to ground truths or obtain task queue id through project.task_queues().\n",
- " batch_name=\"Foundry Demo Batch\",\n",
- " data_rows=lb.GlobalKeys(\n",
- " [global_key] # Provide a list of global keys from foundry app task\n",
- " ),\n",
- " params=send_to_annotations_params\n",
- " )\n",
- "\n",
- "task.wait_till_done()\n",
- "\n",
- "print(f\"Errors: {task.errors}\")"
- ],
+ "source": "model_run = client.get_model_run(MODEL_RUN_ID)\n\nsend_to_annotations_params = {\n \"predictions_ontology_mapping\":\n PREDICTIONS_ONTOLOGY_MAPPING,\n \"exclude_data_rows_in_project\":\n False,\n \"override_existing_annotations_rule\":\n ConflictResolutionStrategy.OverrideWithPredictions,\n \"batch_priority\":\n 5,\n}\n\ntask = model_run.send_to_annotate_from_model(\n destination_project_id=project.uid,\n task_queue_id=\n None, # ID of workflow task, set ID to None if you want to convert pre-labels to ground truths or obtain task queue id through project.task_queues().\n batch_name=\"Foundry Demo Batch\",\n data_rows=lb.GlobalKeys(\n [global_key] # Provide a list of global keys from foundry app task\n ),\n params=send_to_annotations_params,\n)\n\ntask.wait_till_done()\n\nprint(f\"Errors: {task.errors}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -333,11 +244,7 @@
},
{
"metadata": {},
- "source": [
- "# project.delete()\n",
- "# dataset.delete()\n",
- "# model_run.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()\n# model_run.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/integrations/huggingface/huggingface_custom_embeddings.ipynb b/examples/integrations/huggingface/huggingface_custom_embeddings.ipynb
index 6e3929b12..e86fe85b9 100644
--- a/examples/integrations/huggingface/huggingface_custom_embeddings.ipynb
+++ b/examples/integrations/huggingface/huggingface_custom_embeddings.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -16,12 +16,12 @@
"metadata": {},
"source": [
"\n",
- "![]() \n",
" | \n",
"\n",
"\n",
- "![]() \n",
" | "
],
@@ -36,10 +36,7 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox\"\n",
- "!pip install -q transformers"
- ],
+ "source": "%pip install -q \"labelbox[data]\"\n%pip install -q transformers",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -53,17 +50,7 @@
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import transformers\n",
- "transformers.logging.set_verbosity(50)\n",
- "import torch\n",
- "import torch.nn.functional as F\n",
- "from PIL import Image\n",
- "import requests\n",
- "from tqdm import tqdm\n",
- "import numpy as np"
- ],
+ "source": "import labelbox as lb\nimport transformers\n\ntransformers.logging.set_verbosity(50)\nimport torch\nimport torch.nn.functional as F\nfrom PIL import Image\nimport requests\nfrom tqdm import tqdm\nimport numpy as np",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -77,11 +64,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your API key\n",
- "API_KEY = \"\"\n",
- "client = lb.Client(API_KEY)"
- ],
+ "source": "# Add your API key\nAPI_KEY = \"\"\nclient = lb.Client(API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -95,36 +78,21 @@
},
{
"metadata": {},
- "source": [
- "# Get images from a Labelbox dataset,\n",
- "# Ensure the images are available by obtaining a token from your cloud provider if necessary\n",
- "DATASET_ID = \"\""
- ],
+ "source": "# Get images from a Labelbox dataset,\n# Ensure the images are available by obtaining a token from your cloud provider if necessary\nDATASET_ID = \"\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "dataset = client.get_dataset(DATASET_ID)"
- ],
+ "source": "dataset = client.get_dataset(DATASET_ID)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "export_task = dataset.export_v2()\n",
- "\n",
- "export_task.wait_till_done()\n",
- "if export_task.errors:\n",
- "\tprint(export_task.errors)\n",
- "export_json = export_task.result\n",
- "\n",
- "data_row_urls = [dr_url['data_row']['row_data'] for dr_url in export_json]"
- ],
+ "source": "export_task = dataset.export_v2()\n\nexport_task.wait_till_done()\nif export_task.errors:\n print(export_task.errors)\nexport_json = export_task.result\n\ndata_row_urls = [dr_url[\"data_row\"][\"row_data\"] for dr_url in export_json]",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -138,11 +106,7 @@
},
{
"metadata": {},
- "source": [
- "# Get ResNet-50 from HuggingFace\n",
- "image_processor = transformers.AutoImageProcessor.from_pretrained(\"microsoft/resnet-50\")\n",
- "model = transformers.ResNetModel.from_pretrained(\"microsoft/resnet-50\")"
- ],
+ "source": "# Get ResNet-50 from HuggingFace\nimage_processor = transformers.AutoImageProcessor.from_pretrained(\n \"microsoft/resnet-50\")\nmodel = transformers.ResNetModel.from_pretrained(\"microsoft/resnet-50\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -156,13 +120,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a new embedding in your workspace, use the right dimensions to your use case, here we use 2048 for ResNet-50\n",
- "new_custom_embedding_id = client.create_embedding(name=\"My new awesome embedding\", dims=2048).id\n",
- "\n",
- "# Or use an existing embedding from your workspace\n",
- "# existing_embedding_id = client.get_embedding_by_name(name=\"ResNet img 2048\").id"
- ],
+ "source": "# Create a new embedding in your workspace, use the right dimensions to your use case, here we use 2048 for ResNet-50\nnew_custom_embedding_id = client.create_embedding(\n name=\"My new awesome embedding\", dims=2048).id\n\n# Or use an existing embedding from your workspace\n# existing_embedding_id = client.get_embedding_by_name(name=\"ResNet img 2048\").id",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -176,52 +134,14 @@
},
{
"metadata": {},
- "source": [
- "img_emb = []\n",
- "\n",
- "for url in tqdm(data_row_urls):\n",
- " try:\n",
- " response = requests.get(url, stream=True)\n",
- " if response.status_code == 200:\n",
- " # Open the image, convert to RGB, and resize to 224x224\n",
- " image = Image.open(response.raw).convert('RGB').resize((224, 224))\n",
- "\n",
- " # Preprocess the image for model input\n",
- " img_hf = image_processor(image, return_tensors=\"pt\")\n",
- "\n",
- " # Pass the image through the model to get embeddings\n",
- " with torch.no_grad():\n",
- " last_layer = model(**img_hf, output_hidden_states=True).last_hidden_state\n",
- " resnet_embeddings = F.adaptive_avg_pool2d(last_layer, (1, 1))\n",
- " resnet_embeddings = torch.flatten(resnet_embeddings, start_dim=1, end_dim=3)\n",
- " img_emb.append(resnet_embeddings.cpu().numpy())\n",
- " else:\n",
- " continue\n",
- " except Exception as e:\n",
- " print(f\"Error processing URL: {url}. Exception: {e}\")\n",
- " continue\n",
- "\n",
- "data_rows = []\n",
- " \n",
- "# Create data rows payload to send to a dataset\n",
- "for url, embedding in tqdm(zip(data_row_urls, img_emb)):\n",
- " data_rows.append({\n",
- " \"row_data\": url,\n",
- " \"embeddings\": [{\"embedding_id\": new_custom_embedding_id, \"vector\": embedding[0].tolist()}]\n",
- " })"
- ],
+ "source": "img_emb = []\n\nfor url in tqdm(data_row_urls):\n try:\n response = requests.get(url, stream=True)\n if response.status_code == 200:\n # Open the image, convert to RGB, and resize to 224x224\n image = Image.open(response.raw).convert(\"RGB\").resize((224, 224))\n\n # Preprocess the image for model input\n img_hf = image_processor(image, return_tensors=\"pt\")\n\n # Pass the image through the model to get embeddings\n with torch.no_grad():\n last_layer = model(**img_hf,\n output_hidden_states=True).last_hidden_state\n resnet_embeddings = F.adaptive_avg_pool2d(last_layer, (1, 1))\n resnet_embeddings = torch.flatten(resnet_embeddings,\n start_dim=1,\n end_dim=3)\n img_emb.append(resnet_embeddings.cpu().numpy())\n else:\n continue\n except Exception as e:\n print(f\"Error processing URL: {url}. Exception: {e}\")\n continue\n\ndata_rows = []\n\n# Create data rows payload to send to a dataset\nfor url, embedding in tqdm(zip(data_row_urls, img_emb)):\n data_rows.append({\n \"row_data\":\n url,\n \"embeddings\": [{\n \"embedding_id\": new_custom_embedding_id,\n \"vector\": embedding[0].tolist(),\n }],\n })",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Upload to a new dataset\n",
- "dataset = client.create_dataset(name='image_custom_embedding_resnet', iam_integration=None)\n",
- "task = dataset.create_data_rows(data_rows)\n",
- "print(task.errors)"
- ],
+ "source": "# Upload to a new dataset\ndataset = client.create_dataset(name=\"image_custom_embedding_resnet\",\n iam_integration=None)\ntask = dataset.create_data_rows(data_rows)\nprint(task.errors)",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/integrations/langchain/langchain.ipynb b/examples/integrations/langchain/langchain.ipynb
index 17c54110b..f6653d001 100644
--- a/examples/integrations/langchain/langchain.ipynb
+++ b/examples/integrations/langchain/langchain.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -37,39 +37,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install --upgrade --quiet langchain langsmith langchainhub\n",
- "!pip install --upgrade --quiet langchain-openai tiktoken pandas duckduckgo-search\n",
- "!pip install --upgrade --quiet \"labelbox[data]\""
- ],
+ "source": "%pip install --upgrade --quiet langchain langsmith langchainhub\n%pip install --upgrade --quiet langchain-openai tiktoken pandas duckduckgo-search\n%pip install --upgrade --quiet \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "from uuid import uuid4\n",
- "import os\n",
- "import functools\n",
- "\n",
- "# LangSmith Imports\n",
- "from langsmith.client import Client\n",
- "from langchain import hub\n",
- "from langchain.agents import AgentExecutor\n",
- "from langchain.agents.format_scratchpad.openai_tools import (\n",
- " format_to_openai_tool_messages,\n",
- ")\n",
- "from langchain.agents.output_parsers.openai_tools import OpenAIToolsAgentOutputParser\n",
- "from langchain_community.tools import DuckDuckGoSearchResults\n",
- "from langchain_openai import ChatOpenAI\n",
- "from langsmith.evaluation import EvaluationResult\n",
- "from langsmith.schemas import Example, Run, DataType\n",
- "from langchain.smith import run_on_dataset\n",
- "from langchain.evaluation import EvaluatorType\n",
- "from langchain.smith import RunEvalConfig\n"
- ],
+ "source": "import labelbox as lb\nfrom uuid import uuid4\nimport os\nimport functools\n\n# LangSmith Imports\nfrom langsmith.client import Client\nfrom langchain import hub\nfrom langchain.agents import AgentExecutor\nfrom langchain.agents.format_scratchpad.openai_tools import (\n format_to_openai_tool_messages,)\nfrom langchain.agents.output_parsers.openai_tools import (\n OpenAIToolsAgentOutputParser,)\nfrom langchain_community.tools import DuckDuckGoSearchResults\nfrom langchain_openai import ChatOpenAI\nfrom langsmith.evaluation import EvaluationResult\nfrom langsmith.schemas import Example, Run, DataType\nfrom langchain.smith import run_on_dataset\nfrom langchain.evaluation import EvaluatorType\nfrom langchain.smith import RunEvalConfig",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -84,23 +59,7 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "LB_API_KEY = \"\"\n",
- "LS_API_KEY = \"\"\n",
- "OPENAI_API_KEY = \"\"\n",
- "\n",
- "unique_id = uuid4().hex[0:8]\n",
- "os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n",
- "os.environ[\"LANGCHAIN_PROJECT\"] = f\"Tracing Walkthrough - {unique_id}\"\n",
- "os.environ[\"LANGCHAIN_ENDPOINT\"] = \"https://api.smith.langchain.com\"\n",
- "os.environ[\"LANGCHAIN_API_KEY\"] = LS_API_KEY\n",
- "\n",
- "os.environ[\"OPENAI_API_KEY\"] = OPENAI_API_KEY\n",
- "\n",
- "lb_client = lb.Client(LB_API_KEY)\n",
- "client = Client()"
- ],
+ "source": "LB_API_KEY = \"\"\nLS_API_KEY = \"\"\nOPENAI_API_KEY = \"\"\n\nunique_id = uuid4().hex[0:8]\nos.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\nos.environ[\"LANGCHAIN_PROJECT\"] = f\"Tracing Walkthrough - {unique_id}\"\nos.environ[\"LANGCHAIN_ENDPOINT\"] = \"https://api.smith.langchain.com\"\nos.environ[\"LANGCHAIN_API_KEY\"] = LS_API_KEY\n\nos.environ[\"OPENAI_API_KEY\"] = OPENAI_API_KEY\n\nlb_client = lb.Client(LB_API_KEY)\nclient = Client()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -115,15 +74,7 @@
},
{
"metadata": {},
- "source": [
- "dataset_name = f\"Sample Dataset - {str(uuid4())}\"\n",
- "dataset = client.create_dataset(dataset_name, description=\"A sample dataset in LangSmith.\", data_type=DataType.chat)\n",
- "client.create_chat_example(\n",
- " messages=[{\"type\": \"ai\", \"data\": {\"content\": \"hi how are you\"}}, {\"type\": \"human\", \"data\": {\"content\": \"Im doing great how about you\"}}],\n",
- " generations={\"type\": \"ai\", \"data\": {\"content\": \"Im doing great\"}}, # Custom model output\n",
- " dataset_id=dataset.id,\n",
- ")"
- ],
+ "source": "dataset_name = f\"Sample Dataset - {str(uuid4())}\"\ndataset = client.create_dataset(\n dataset_name,\n description=\"A sample dataset in LangSmith.\",\n data_type=DataType.chat,\n)\nclient.create_chat_example(\n messages=[\n {\n \"type\": \"ai\",\n \"data\": {\n \"content\": \"hi how are you\"\n }\n },\n {\n \"type\": \"human\",\n \"data\": {\n \"content\": \"Im doing great how about you\"\n }\n },\n ],\n generations={\n \"type\": \"ai\",\n \"data\": {\n \"content\": \"Im doing great\"\n },\n }, # Custom model output\n dataset_id=dataset.id,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -138,128 +89,28 @@
},
{
"metadata": {},
- "source": [
- "tools = [\n",
- " DuckDuckGoSearchResults(\n",
- " name=\"duck_duck_go\"\n",
- " ), # General internet search using DuckDuckGo\n",
- "]\n",
- "\n",
- "llm = ChatOpenAI(\n",
- " model=\"gpt-3.5-turbo-16k\",\n",
- " temperature=0,\n",
- ")\n",
- "\n",
- "# Since chains can be stateful (e.g. they can have memory), we provide\n",
- "# a way to initialize a new chain for each row in the dataset. This is done\n",
- "# by passing in a factory function that returns a new chain for each row.\n",
- "def create_agent(prompt, llm_with_tools):\n",
- " runnable_agent = (\n",
- " {\n",
- " \"input\": lambda x: x[\"input\"],\n",
- " \"agent_scratchpad\": lambda x: format_to_openai_tool_messages(\n",
- " x[\"intermediate_steps\"]\n",
- " ),\n",
- " }\n",
- " | prompt\n",
- " | llm_with_tools\n",
- " | OpenAIToolsAgentOutputParser()\n",
- " )\n",
- " return AgentExecutor(agent=runnable_agent, tools=tools, handle_parsing_errors=True)"
- ],
+ "source": "tools = [\n DuckDuckGoSearchResults(\n name=\"duck_duck_go\"), # General internet search using DuckDuckGo\n]\n\nllm = ChatOpenAI(\n model=\"gpt-3.5-turbo-16k\",\n temperature=0,\n)\n\n\n# Since chains can be stateful (e.g. they can have memory), we provide\n# a way to initialize a new chain for each row in the dataset. This is done\n# by passing in a factory function that returns a new chain for each row.\ndef create_agent(prompt, llm_with_tools):\n runnable_agent = ({\n \"input\":\n lambda x: x[\"input\"],\n \"agent_scratchpad\":\n lambda x: format_to_openai_tool_messages(x[\"intermediate_steps\"]),\n } | prompt | llm_with_tools | OpenAIToolsAgentOutputParser())\n return AgentExecutor(agent=runnable_agent,\n tools=tools,\n handle_parsing_errors=True)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "def max_pred_length(runs, examples):\n",
- " predictions = [len(run.outputs[\"output\"]) for run in runs]\n",
- " return EvaluationResult(key=\"max_pred_length\", score=max(predictions))"
- ],
+ "source": "def max_pred_length(runs, examples):\n predictions = [len(run.outputs[\"output\"]) for run in runs]\n return EvaluationResult(key=\"max_pred_length\", score=max(predictions))",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "def check_not_idk(run: Run, example: Example):\n",
- " \"\"\"Illustration of a custom evaluator.\"\"\"\n",
- " agent_response = run.outputs[\"output\"]\n",
- " if \"don't know\" in agent_response or \"not sure\" in agent_response:\n",
- " score = 0\n",
- " else:\n",
- " score = 1\n",
- " # You can access the dataset labels in example.outputs[key]\n",
- " # You can also access the model inputs in run.inputs[key]\n",
- " return EvaluationResult(\n",
- " key=\"not_uncertain\",\n",
- " score=score,\n",
- " )"
- ],
+ "source": "def check_not_idk(run: Run, example: Example):\n \"\"\"Illustration of a custom evaluator.\"\"\"\n agent_response = run.outputs[\"output\"]\n if \"don't know\" in agent_response or \"not sure\" in agent_response:\n score = 0\n else:\n score = 1\n # You can access the dataset labels in example.outputs[key]\n # You can also access the model inputs in run.inputs[key]\n return EvaluationResult(\n key=\"not_uncertain\",\n score=score,\n )",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "evaluation_config = RunEvalConfig(\n",
- " # Evaluators can either be an evaluator type (e.g., \"qa\", \"criteria\", \"embedding_distance\", etc.) or a configuration for that evaluator\n",
- " evaluators=[\n",
- " check_not_idk,\n",
- " # Measures whether a QA response is \"Correct\", based on a reference answer\n",
- " # You can also select via the raw string \"qa\"\n",
- " EvaluatorType.QA,\n",
- " # Measure the embedding distance between the output and the reference answer\n",
- " # Equivalent to: EvalConfig.EmbeddingDistance(embeddings=OpenAIEmbeddings())\n",
- " EvaluatorType.EMBEDDING_DISTANCE,\n",
- " # Grade whether the output satisfies the stated criteria.\n",
- " # You can select a default one such as \"helpfulness\" or provide your own.\n",
- " RunEvalConfig.LabeledCriteria(\"helpfulness\"),\n",
- " # The LabeledScoreString evaluator outputs a score on a scale from 1-10.\n",
- " # You can use default criteria or write our own rubric\n",
- " RunEvalConfig.LabeledScoreString(\n",
- " {\n",
- " \"accuracy\": \"\"\"\n",
- "Score 1: The answer is completely unrelated to the reference.\n",
- "Score 3: The answer has minor relevance but does not align with the reference.\n",
- "Score 5: The answer has moderate relevance but contains inaccuracies.\n",
- "Score 7: The answer aligns with the reference but has minor errors or omissions.\n",
- "Score 10: The answer is completely accurate and aligns perfectly with the reference.\"\"\"\n",
- " },\n",
- " normalize_by=10,\n",
- " ),\n",
- " ],\n",
- " batch_evaluators=[max_pred_length],\n",
- ")\n",
- "\n",
- "llm_with_tools = llm.bind_tools(tools)\n",
- "prompt = hub.pull(\"gabe/labelboxtutorialdemo\") # Change prompt in LangSmith hub to reflect example run\n",
- "\n",
- "chain_results = run_on_dataset(\n",
- " dataset_name=dataset_name,\n",
- " llm_or_chain_factory=functools.partial(\n",
- " create_agent, prompt=prompt, llm_with_tools=llm_with_tools\n",
- " ),\n",
- " evaluation=evaluation_config,\n",
- " verbose=True,\n",
- " client=client,\n",
- " project_name=f\"tools-agent-test-5d466cbc-{unique_id}\",\n",
- " # Project metadata communicates the experiment parameters,\n",
- " # Useful for reviewing the test results\n",
- " project_metadata={\n",
- " \"env\": \"testing-notebook\",\n",
- " \"model\": \"gpt-3.5-turbo\",\n",
- " \"prompt\": \"5d466cbc\",\n",
- " },\n",
- ")\n",
- "\n",
- "# Sometimes, the agent will error due to parsing issues, incompatible tool inputs, etc.\n",
- "# These are logged as warnings here and captured as errors in the tracing UI."
- ],
+ "source": "evaluation_config = RunEvalConfig(\n # Evaluators can either be an evaluator type (e.g., \"qa\", \"criteria\", \"embedding_distance\", etc.) or a configuration for that evaluator\n evaluators=[\n check_not_idk,\n # Measures whether a QA response is \"Correct\", based on a reference answer\n # You can also select via the raw string \"qa\"\n EvaluatorType.QA,\n # Measure the embedding distance between the output and the reference answer\n # Equivalent to: EvalConfig.EmbeddingDistance(embeddings=OpenAIEmbeddings())\n EvaluatorType.EMBEDDING_DISTANCE,\n # Grade whether the output satisfies the stated criteria.\n # You can select a default one such as \"helpfulness\" or provide your own.\n RunEvalConfig.LabeledCriteria(\"helpfulness\"),\n # The LabeledScoreString evaluator outputs a score on a scale from 1-10.\n # You can use default criteria or write our own rubric\n RunEvalConfig.LabeledScoreString(\n {\n \"accuracy\":\n \"\"\"\nScore 1: The answer is completely unrelated to the reference.\nScore 3: The answer has minor relevance but does not align with the reference.\nScore 5: The answer has moderate relevance but contains inaccuracies.\nScore 7: The answer aligns with the reference but has minor errors or omissions.\nScore 10: The answer is completely accurate and aligns perfectly with the reference.\"\"\"\n },\n normalize_by=10,\n ),\n ],\n batch_evaluators=[max_pred_length],\n)\n\nllm_with_tools = llm.bind_tools(tools)\nprompt = hub.pull(\"gabe/labelboxtutorialdemo\"\n ) # Change prompt in LangSmith hub to reflect example run\n\nchain_results = run_on_dataset(\n dataset_name=dataset_name,\n llm_or_chain_factory=functools.partial(create_agent,\n prompt=prompt,\n llm_with_tools=llm_with_tools),\n evaluation=evaluation_config,\n verbose=True,\n client=client,\n project_name=f\"tools-agent-test-5d466cbc-{unique_id}\",\n # Project metadata communicates the experiment parameters,\n # Useful for reviewing the test results\n project_metadata={\n \"env\": \"testing-notebook\",\n \"model\": \"gpt-3.5-turbo\",\n \"prompt\": \"5d466cbc\",\n },\n)\n\n# Sometimes, the agent will error due to parsing issues, incompatible tool inputs, etc.\n# These are logged as warnings here and captured as errors in the tracing UI.",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -274,65 +125,7 @@
},
{
"metadata": {},
- "source": [
- "def import_conversational (chain_results: dict[str:str], user_id_dict: dict[str:dict[str:str]]) -> dict[str:str]:\n",
- " '''Converts LangSmith chain_results from model invocation to Labelbox conversation data for model response comparison. Output is based on popular model response and custom model response towards prompts.\n",
- "\n",
- " Args:\n",
- " chain_results(dict[str:str]): Results from LangSmith model invocation against example dataset runs.\n",
- " user_id_dict(dict[str:dict[str:str]]): Dictionary mapping of LangSmith example run type to Labelbox chat names and alignment.\n",
- "\n",
- " Returns:\n",
- " dict[str:str]: Labelbox conversation text format\n",
- " '''\n",
- " lb_conversations = []\n",
- " for key, conversational in chain_results[\"results\"].items():\n",
- " lb_conversation = {\n",
- " \"row_data\": {\n",
- " \"type\": \"application/vnd.labelbox.conversational\",\n",
- " \"version\": 1,\n",
- " \"messages\": [],\n",
- " \"modelOutputs\": []\n",
- " },\n",
- " \"global_key\": key,\n",
- " \"media_type\": \"CONVERSATIONAL\",\n",
- " }\n",
- " if \"input\" in conversational[\"output\"]:\n",
- " for i, input in enumerate(conversational[\"output\"][\"input\"]):\n",
- " lb_conversation[\"row_data\"][\"messages\"].append({\n",
- " \"content\": input[\"data\"][\"content\"],\n",
- " \"timestampUsec\": i + 1,\n",
- " \"user\": {\n",
- " \"userId\": user_id_dict[input[\"type\"]][\"id\"],\n",
- " \"name\": input[\"type\"]\n",
- " },\n",
- " \"canLabel\": True,\n",
- " \"align\": user_id_dict[input[\"type\"]][\"align\"],\n",
- " \"messageId\": str(uuid4())\n",
- " })\n",
- "\n",
- " # Custom model output\n",
- " if \"reference\" in conversational:\n",
- " reference = conversational[\"reference\"][\"output\"]\n",
- " lb_conversation[\"row_data\"][\"modelOutputs\"].append({\n",
- " \"title\": \"Custom Model Response\",\n",
- " \"content\": reference[\"data\"][\"content\"],\n",
- " \"modelConfigName\": \"Custom Model - Example Config\"\n",
- " })\n",
- "\n",
- " # Popular model output\n",
- " if \"output\" in conversational[\"output\"]:\n",
- " output = conversational[\"output\"][\"output\"]\n",
- " lb_conversation[\"row_data\"][\"modelOutputs\"].append({\n",
- " \"title\": \"Popular LLM Response\",\n",
- " \"content\": output,\n",
- " \"modelConfigName\": \"GPT-3.5 - Example Config\"\n",
- " })\n",
- "\n",
- "\n",
- " lb_conversations.append(lb_conversation)\n",
- " return lb_conversations"
- ],
+ "source": "def import_conversational(\n chain_results: dict[str:str],\n user_id_dict: dict[str:dict[str:str]]) -> dict[str:str]:\n \"\"\"Converts LangSmith chain_results from model invocation to Labelbox conversation data for model response comparison. Output is based on popular model response and custom model response towards prompts.\n\n Args:\n chain_results(dict[str:str]): Results from LangSmith model invocation against example dataset runs.\n user_id_dict(dict[str:dict[str:str]]): Dictionary mapping of LangSmith example run type to Labelbox chat names and alignment.\n\n Returns:\n dict[str:str]: Labelbox conversation text format\n \"\"\"\n lb_conversations = []\n for key, conversational in chain_results[\"results\"].items():\n lb_conversation = {\n \"row_data\": {\n \"type\": \"application/vnd.labelbox.conversational\",\n \"version\": 1,\n \"messages\": [],\n \"modelOutputs\": [],\n },\n \"global_key\": key,\n \"media_type\": \"CONVERSATIONAL\",\n }\n if \"input\" in conversational[\"output\"]:\n for i, input in enumerate(conversational[\"output\"][\"input\"]):\n lb_conversation[\"row_data\"][\"messages\"].append({\n \"content\": input[\"data\"][\"content\"],\n \"timestampUsec\": i + 1,\n \"user\": {\n \"userId\": user_id_dict[input[\"type\"]][\"id\"],\n \"name\": input[\"type\"],\n },\n \"canLabel\": True,\n \"align\": user_id_dict[input[\"type\"]][\"align\"],\n \"messageId\": str(uuid4()),\n })\n\n # Custom model output\n if \"reference\" in conversational:\n reference = conversational[\"reference\"][\"output\"]\n lb_conversation[\"row_data\"][\"modelOutputs\"].append({\n \"title\": \"Custom Model Response\",\n \"content\": reference[\"data\"][\"content\"],\n \"modelConfigName\": \"Custom Model - Example Config\",\n })\n\n # Popular model output\n if \"output\" in conversational[\"output\"]:\n output = conversational[\"output\"][\"output\"]\n lb_conversation[\"row_data\"][\"modelOutputs\"].append({\n \"title\": \"Popular LLM Response\",\n \"content\": output,\n \"modelConfigName\": \"GPT-3.5 - Example Config\",\n })\n\n lb_conversations.append(lb_conversation)\n return lb_conversations",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -346,9 +139,7 @@
},
{
"metadata": {},
- "source": [
- "dataset = lb_client.create_dataset(name=\"demo_langchain\")"
- ],
+ "source": "dataset = lb_client.create_dataset(name=\"demo_langchain\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -362,12 +153,7 @@
},
{
"metadata": {},
- "source": [
- "task = dataset.create_data_rows(import_conversational(chain_results, {\"human\": {\"id\":\"human\",\"align\": \"right\"}, \"ai\":{\"id\":\"ai\", \"align\": \"left\"}}))\n",
- "task.wait_till_done()\n",
- "\n",
- "print(task.errors)"
- ],
+ "source": "task = dataset.create_data_rows(\n import_conversational(\n chain_results,\n {\n \"human\": {\n \"id\": \"human\",\n \"align\": \"right\"\n },\n \"ai\": {\n \"id\": \"ai\",\n \"align\": \"left\"\n },\n },\n ))\ntask.wait_till_done()\n\nprint(task.errors)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -381,9 +167,7 @@
},
{
"metadata": {},
- "source": [
- "# dataset.delete()"
- ],
+ "source": "# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/integrations/sam/meta_sam.ipynb b/examples/integrations/sam/meta_sam.ipynb
index 07d671dc4..4802f7603 100644
--- a/examples/integrations/sam/meta_sam.ipynb
+++ b/examples/integrations/sam/meta_sam.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -16,12 +16,12 @@
"metadata": {},
"source": [
"\n",
- "![]() \n",
" | \n",
"\n",
"\n",
- "![]() \n",
" | "
],
@@ -37,57 +37,21 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\"\n",
- "!pip install -q ultralytics==8.0.20\n",
- "!pip install -q 'git+https://github.com/facebookresearch/segment-anything.git'"
- ],
+ "source": "%pip install -q \"labelbox[data]\"\n%pip install -q ultralytics==8.0.20\n%pip install -q \"git+https://github.com/facebookresearch/segment-anything.git\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Check if in google colab\n",
- "try:\n",
- " import google.colab\n",
- " IN_COLAB = True\n",
- "except:\n",
- " IN_COLAB = False"
- ],
+ "source": "# Check if in google colab\ntry:\n import google.colab\n\n IN_COLAB = True\nexcept:\n IN_COLAB = False",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "from IPython import display\n",
- "display.clear_output()\n",
- "\n",
- "import ultralytics\n",
- "ultralytics.checks()\n",
- "\n",
- "import cv2\n",
- "import numpy as np\n",
- "from ultralytics import YOLO\n",
- "from IPython.display import display, Image\n",
- "import torch\n",
- "import matplotlib.pyplot as plt\n",
- "from segment_anything import sam_model_registry, SamAutomaticMaskGenerator, SamPredictor\n",
- "import os\n",
- "import urllib.request\n",
- "import uuid\n",
- "\n",
- "import labelbox as lb\n",
- "import labelbox.types as lb_types\n",
- "\n",
- "HOME = os.getcwd()\n",
- "\n",
- "if IN_COLAB:\n",
- " from google.colab.patches import cv2_imshow"
- ],
+ "source": "from IPython import display\n\ndisplay.clear_output()\n\nimport ultralytics\n\nultralytics.checks()\n\nimport cv2\nimport numpy as np\nfrom ultralytics import YOLO\nfrom IPython.display import display, Image\nimport torch\nimport matplotlib.pyplot as plt\nfrom segment_anything import (\n sam_model_registry,\n SamAutomaticMaskGenerator,\n SamPredictor,\n)\nimport os\nimport urllib.request\nimport uuid\n\nimport labelbox as lb\nimport labelbox.types as lb_types\n\nHOME = os.getcwd()\n\nif IN_COLAB:\n from google.colab.patches import cv2_imshow",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -102,12 +66,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your api key\n",
- "API_KEY=\"\"\n",
- "# To get your API key go to: Workspace settings -> API -> Create API Key\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your api key\nAPI_KEY = \"\"\n# To get your API key go to: Workspace settings -> API -> Create API Key\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -139,30 +98,14 @@
},
{
"metadata": {},
- "source": [
- "# You can also use the Labelbox Client API to get specific images or an entire\n",
- "# dataset from your Catalog. Refer to these docs:\n",
- "# https://labelbox-python.readthedocs.io/en/latest/#labelbox.client.Client.get_data_row\n",
- "\n",
- "IMAGE_PATH = \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/chairs.jpeg\""
- ],
+ "source": "# You can also use the Labelbox Client API to get specific images or an entire\n# dataset from your Catalog. Refer to these docs:\n# https://labelbox-python.readthedocs.io/en/latest/#labelbox.client.Client.get_data_row\n\nIMAGE_PATH = \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/chairs.jpeg\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "model = YOLO(f'{HOME}/yolov8n.pt')\n",
- "results = model.predict(source=IMAGE_PATH, conf=0.25)\n",
- "\n",
- "# print(results[0].boxes.xyxy) # print bounding box coordinates\n",
- "\n",
- "# print(results[0].boxes.conf) # print confidence scores\n",
- "\n",
- "#for c in results[0].boxes.cls:\n",
- "# print(model.names[int(c)]) # print predicted classes"
- ],
+ "source": "model = YOLO(f\"{HOME}/yolov8n.pt\")\nresults = model.predict(source=IMAGE_PATH, conf=0.25)\n\n# print(results[0].boxes.xyxy) # print bounding box coordinates\n\n# print(results[0].boxes.conf) # print confidence scores\n\n# for c in results[0].boxes.cls:\n# print(model.names[int(c)]) # print predicted classes",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -176,18 +119,7 @@
},
{
"metadata": {},
- "source": [
- "image_bgr = cv2.imread(\"./chairs.jpeg\")\n",
- "\n",
- "for box in results[0].boxes.xyxy:\n",
- " cv2.rectangle(image_bgr, (int(box[0]), int(box[1])), (int(box[2]), int(box[3])), (0, 255, 0), 2)\n",
- "\n",
- "if IN_COLAB:\n",
- " cv2_imshow(image_bgr)\n",
- "else:\n",
- " cv2.imshow(\"demo\", image_bgr)\n",
- " cv2.waitKey()"
- ],
+ "source": "image_bgr = cv2.imread(\"./chairs.jpeg\")\n\nfor box in results[0].boxes.xyxy:\n cv2.rectangle(\n image_bgr,\n (int(box[0]), int(box[1])),\n (int(box[2]), int(box[3])),\n (0, 255, 0),\n 2,\n )\n\nif IN_COLAB:\n cv2_imshow(image_bgr)\nelse:\n cv2.imshow(\"demo\", image_bgr)\n cv2.waitKey()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -203,56 +135,28 @@
},
{
"metadata": {},
- "source": [
- "# Download SAM model weights\n",
- "\n",
- "CHECKPOINT_PATH = os.path.join(HOME, \"sam_vit_h_4b8939.pth\")\n",
- "\n",
- "if not os.path.isfile(CHECKPOINT_PATH):\n",
- " req = urllib.request.urlretrieve(\"https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth\", \"sam_vit_h_4b8939.pth\")\n"
- ],
+ "source": "# Download SAM model weights\n\nCHECKPOINT_PATH = os.path.join(HOME, \"sam_vit_h_4b8939.pth\")\n\nif not os.path.isfile(CHECKPOINT_PATH):\n req = urllib.request.urlretrieve(\n \"https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth\",\n \"sam_vit_h_4b8939.pth\",\n )",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "DEVICE = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')\n",
- "MODEL_TYPE = \"vit_h\""
- ],
+ "source": "DEVICE = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\nMODEL_TYPE = \"vit_h\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "sam = sam_model_registry[MODEL_TYPE](checkpoint=CHECKPOINT_PATH).to(device=DEVICE)\n",
- "mask_predictor = SamPredictor(sam)"
- ],
+ "source": "sam = sam_model_registry[MODEL_TYPE](checkpoint=CHECKPOINT_PATH).to(\n device=DEVICE)\nmask_predictor = SamPredictor(sam)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "transformed_boxes = mask_predictor.transform.apply_boxes_torch(results[0].boxes.xyxy, image_bgr.shape[:2])\n",
- "\n",
- "mask_predictor.set_image(image_bgr)\n",
- "\n",
- "masks, scores, logits = mask_predictor.predict_torch(\n",
- " boxes = transformed_boxes,\n",
- " multimask_output=False,\n",
- " point_coords=None,\n",
- " point_labels=None\n",
- ")\n",
- "masks = np.array(masks.cpu())\n",
- "\n",
- "# print(masks)\n",
- "# print(scores)"
- ],
+ "source": "transformed_boxes = mask_predictor.transform.apply_boxes_torch(\n results[0].boxes.xyxy, image_bgr.shape[:2])\n\nmask_predictor.set_image(image_bgr)\n\nmasks, scores, logits = mask_predictor.predict_torch(\n boxes=transformed_boxes,\n multimask_output=False,\n point_coords=None,\n point_labels=None,\n)\nmasks = np.array(masks.cpu())\n\n# print(masks)\n# print(scores)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -266,23 +170,7 @@
},
{
"metadata": {},
- "source": [
- "image_rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)\n",
- "\n",
- "final_mask = None\n",
- "for i in range(len(masks) - 1):\n",
- " if final_mask is None:\n",
- " final_mask = np.bitwise_or(masks[i][0], masks[i+1][0])\n",
- " else:\n",
- " final_mask = np.bitwise_or(final_mask, masks[i+1][0])\n",
- "\n",
- "plt.figure(figsize=(10, 10))\n",
- "plt.imshow(image_rgb)\n",
- "plt.axis('off')\n",
- "plt.imshow(final_mask, cmap='gray', alpha=0.7)\n",
- "\n",
- "plt.show()"
- ],
+ "source": "image_rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)\n\nfinal_mask = None\nfor i in range(len(masks) - 1):\n if final_mask is None:\n final_mask = np.bitwise_or(masks[i][0], masks[i + 1][0])\n else:\n final_mask = np.bitwise_or(final_mask, masks[i + 1][0])\n\nplt.figure(figsize=(10, 10))\nplt.imshow(image_rgb)\nplt.axis(\"off\")\nplt.imshow(final_mask, cmap=\"gray\", alpha=0.7)\n\nplt.show()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -296,156 +184,49 @@
},
{
"metadata": {},
- "source": [
- "# Create a Labelbox ObjectAnnotation of type mask for each predicted mask\n",
- "\n",
- "# Identifying what values in the numpy array correspond to the mask annotation\n",
- "color = (1, 1, 1)\n",
- "\n",
- "class_names = []\n",
- "for c in results[0].boxes.cls:\n",
- " class_names.append(model.names[int(c)])\n",
- "\n",
- "annotations = []\n",
- "for idx, mask in enumerate(masks):\n",
- " mask_data = lb_types.MaskData.from_2D_arr(np.asarray(mask[0], dtype=\"uint8\"))\n",
- " mask_annotation = lb_types.ObjectAnnotation(\n",
- " name = class_names[idx], # this is the class predicted in Step 1 (object detector)\n",
- " value=lb_types.Mask(mask=mask_data, color=color),\n",
- " )\n",
- " annotations.append(mask_annotation)"
- ],
+ "source": "# Create a Labelbox ObjectAnnotation of type mask for each predicted mask\n\n# Identifying what values in the numpy array correspond to the mask annotation\ncolor = (1, 1, 1)\n\nclass_names = []\nfor c in results[0].boxes.cls:\n class_names.append(model.names[int(c)])\n\nannotations = []\nfor idx, mask in enumerate(masks):\n mask_data = lb_types.MaskData.from_2D_arr(np.asarray(mask[0],\n dtype=\"uint8\"))\n mask_annotation = lb_types.ObjectAnnotation(\n name=class_names[\n idx], # this is the class predicted in Step 1 (object detector)\n value=lb_types.Mask(mask=mask_data, color=color),\n )\n annotations.append(mask_annotation)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Create a new dataset\n",
- "\n",
- "# read more here: https://docs.labelbox.com/reference/data-row-global-keys\n",
- "global_key = \"my_unique_global_key\"\n",
- "\n",
- "test_img_url = {\n",
- " \"row_data\": IMAGE_PATH,\n",
- " \"global_key\": global_key\n",
- "}\n",
- "\n",
- "dataset = client.create_dataset(name=\"auto-mask-classification-dataset\")\n",
- "task = dataset.create_data_rows([test_img_url])\n",
- "task.wait_till_done()\n",
- "\n",
- "print(f\"Errors: {task.errors}\")\n",
- "print(f\"Failed data rows: {task.failed_data_rows}\")"
- ],
+ "source": "# Create a new dataset\n\n# read more here: https://docs.labelbox.com/reference/data-row-global-keys\nglobal_key = \"my_unique_global_key\"\n\ntest_img_url = {\"row_data\": IMAGE_PATH, \"global_key\": global_key}\n\ndataset = client.create_dataset(name=\"auto-mask-classification-dataset\")\ntask = dataset.create_data_rows([test_img_url])\ntask.wait_till_done()\n\nprint(f\"Errors: {task.errors}\")\nprint(f\"Failed data rows: {task.failed_data_rows}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Create a new ontology if you don't have one\n",
- "\n",
- "# Add all unique classes detected in Step 1\n",
- "tools = []\n",
- "for name in set(class_names):\n",
- " tools.append(lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=name))\n",
- "\n",
- "ontology_builder = lb.OntologyBuilder(\n",
- " classifications=[],\n",
- " tools=tools\n",
- " )\n",
- "\n",
- "ontology = client.create_ontology(\"auto-mask-classification-ontology\",\n",
- " ontology_builder.asdict(),\n",
- " media_type=lb.MediaType.Image\n",
- " )\n",
- "\n",
- "# Or get an existing ontology by name or ID (uncomment one of the below)\n",
- "\n",
- "# ontology = client.get_ontologies(\"Demo Chair\").get_one()\n",
- "\n",
- "# ontology = client.get_ontology(\"clhee8kzt049v094h7stq7v25\")"
- ],
+ "source": "# Create a new ontology if you don't have one\n\n# Add all unique classes detected in Step 1\ntools = []\nfor name in set(class_names):\n tools.append(lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=name))\n\nontology_builder = lb.OntologyBuilder(classifications=[], tools=tools)\n\nontology = client.create_ontology(\n \"auto-mask-classification-ontology\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)\n\n# Or get an existing ontology by name or ID (uncomment one of the below)\n\n# ontology = client.get_ontologies(\"Demo Chair\").get_one()\n\n# ontology = client.get_ontology(\"clhee8kzt049v094h7stq7v25\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Create a new project if you don't have one\n",
- "\n",
- "# Project defaults to batch mode with benchmark quality settings if this argument is not provided\n",
- "# Queue mode will be deprecated once dataset mode is deprecated\n",
- "project = client.create_project(name=\"auto-mask-classification-project\",\n",
- " media_type=lb.MediaType.Image\n",
- " )\n",
- "\n",
- "# Or get an existing project by ID (uncomment the below)\n",
- "\n",
- "# project = get_project(\"fill_in_project_id\")\n",
- "\n",
- "# If the project already has an ontology set up, comment out this line\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "# Create a new project if you don't have one\n\n# Project defaults to batch mode with benchmark quality settings if this argument is not provided\n# Queue mode will be deprecated once dataset mode is deprecated\nproject = client.create_project(name=\"auto-mask-classification-project\",\n media_type=lb.MediaType.Image)\n\n# Or get an existing project by ID (uncomment the below)\n\n# project = get_project(\"fill_in_project_id\")\n\n# If the project already has an ontology set up, comment out this line\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Create a new batch of data for the project you specified above\n",
- "\n",
- "data_row_ids = client.get_data_row_ids_for_global_keys([global_key])['results']\n",
- "\n",
- "batch = project.create_batch(\n",
- " \"auto-mask-classification-batch\", # each batch in a project must have a unique name\n",
- " data_rows=data_row_ids,\n",
- "\n",
- " # you can also specify global_keys instead of data_rows\n",
- " #global_keys=[global_key], # paginated collection of data row objects, list of data row ids or global keys\n",
- "\n",
- " priority=1 # priority between 1(highest) - 5(lowest)\n",
- ")\n",
- "\n",
- "print(f\"Batch: {batch}\")"
- ],
+ "source": "# Create a new batch of data for the project you specified above\n\ndata_row_ids = client.get_data_row_ids_for_global_keys([global_key])[\"results\"]\n\nbatch = project.create_batch(\n \"auto-mask-classification-batch\", # each batch in a project must have a unique name\n data_rows=data_row_ids,\n # you can also specify global_keys instead of data_rows\n # global_keys=[global_key], # paginated collection of data row objects, list of data row ids or global keys\n priority=1, # priority between 1(highest) - 5(lowest)\n)\n\nprint(f\"Batch: {batch}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "labels = []\n",
- "labels.append(\n",
- " lb_types.Label(data=lb_types.ImageData(global_key=global_key),\n",
- " annotations=annotations))"
- ],
+ "source": "labels = []\nlabels.append(\n lb_types.Label(data=lb_types.ImageData(global_key=global_key),\n annotations=annotations))",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Upload the predictions to your specified project and data rows as pre-labels\n",
- "\n",
- "upload_job = lb.MALPredictionImport.create_from_objects(\n",
- " client=client,\n",
- " project_id=project.uid,\n",
- " name=\"mal_job\" + str(uuid.uuid4()),\n",
- " predictions=labels\n",
- ")\n",
- "upload_job.wait_until_done()\n",
- "\n",
- "print(f\"Errors: {upload_job.errors}\", )\n",
- "print(f\"Status of uploads: {upload_job.statuses}\")"
- ],
+ "source": "# Upload the predictions to your specified project and data rows as pre-labels\n\nupload_job = lb.MALPredictionImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"mal_job\" + str(uuid.uuid4()),\n predictions=labels,\n)\nupload_job.wait_until_done()\n\nprint(f\"Errors: {upload_job.errors}\",)\nprint(f\"Status of uploads: {upload_job.statuses}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -459,10 +240,7 @@
},
{
"metadata": {},
- "source": [
- "#dataset.delete()\n",
- "#project.delete()"
- ],
+ "source": "# dataset.delete()\n# project.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/integrations/sam/meta_sam_video.ipynb b/examples/integrations/sam/meta_sam_video.ipynb
index 1a3c1d7e0..76e64105e 100644
--- a/examples/integrations/sam/meta_sam_video.ipynb
+++ b/examples/integrations/sam/meta_sam_video.ipynb
@@ -6,8 +6,8 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
+ " | ",
+ " ",
" | \n"
],
"cell_type": "markdown"
@@ -16,12 +16,12 @@
"metadata": {},
"source": [
"\n",
- "![]() \n",
" | \n",
"\n",
"\n",
- "![]() \n",
" | "
],
@@ -45,85 +45,28 @@
},
{
"metadata": {},
- "source": [
- "%pip install -q \"labelbox[data]\"\n",
- "%pip install -q ultralytics==8.0.20\n",
- "%pip install -q \"git+https://github.com/facebookresearch/segment-anything.git\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"\n%pip install -q ultralytics==8.0.20\n%pip install -q \"git+https://github.com/facebookresearch/segment-anything.git\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Check if in google colab\n",
- "try:\n",
- " import google.colab\n",
- "\n",
- " IN_COLAB = True\n",
- "except:\n",
- " IN_COLAB = False"
- ],
+ "source": "# Check if in google colab\ntry:\n import google.colab\n\n IN_COLAB = True\nexcept:\n IN_COLAB = False",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import os\n",
- "import urllib\n",
- "import cv2\n",
- "import PIL\n",
- "from PIL import Image\n",
- "import numpy as np\n",
- "import uuid\n",
- "import tempfile\n",
- "\n",
- "if IN_COLAB:\n",
- " from google.colab.patches import cv2_imshow\n",
- "\n",
- "from IPython import display\n",
- "\n",
- "display.clear_output()\n",
- "from IPython.display import display, Image\n",
- "from io import BytesIO\n",
- "\n",
- "# YOLOv8 dependencies\n",
- "import ultralytics\n",
- "\n",
- "ultralytics.checks()\n",
- "from ultralytics import YOLO\n",
- "\n",
- "# SAM dependencies\n",
- "import torch\n",
- "import matplotlib.pyplot as plt\n",
- "from segment_anything import sam_model_registry, SamPredictor\n",
- "\n",
- "# Labelbox dependencies\n",
- "import labelbox as lb\n",
- "import labelbox.types as lb_types"
- ],
+ "source": "import os\nimport urllib\nimport cv2\nimport PIL\nfrom PIL import Image\nimport numpy as np\nimport uuid\nimport tempfile\n\nif IN_COLAB:\n from google.colab.patches import cv2_imshow\n\nfrom IPython import display\n\ndisplay.clear_output()\nfrom IPython.display import display, Image\nfrom io import BytesIO\n\n# YOLOv8 dependencies\nimport ultralytics\n\nultralytics.checks()\nfrom ultralytics import YOLO\n\n# SAM dependencies\nimport torch\nimport matplotlib.pyplot as plt\nfrom segment_anything import sam_model_registry, SamPredictor\n\n# Labelbox dependencies\nimport labelbox as lb\nimport labelbox.types as lb_types",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# You can also use the Labelbox Client API to get specific videos or an entire\n",
- "# dataset from your Catalog. Refer to these docs:\n",
- "# https://labelbox-python.readthedocs.io/en/latest/#labelbox.client.Client.get_data_row\n",
- "HOME = os.getcwd()\n",
- "VIDEO_PATH = os.path.join(HOME, \"skateboarding.mp4\")\n",
- "\n",
- "if not os.path.isfile(VIDEO_PATH):\n",
- " req = urllib.request.urlretrieve(\n",
- " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/skateboarding.mp4\",\n",
- " \"skateboarding.mp4\",\n",
- " )"
- ],
+ "source": "# You can also use the Labelbox Client API to get specific videos or an entire\n# dataset from your Catalog. Refer to these docs:\n# https://labelbox-python.readthedocs.io/en/latest/#labelbox.client.Client.get_data_row\nHOME = os.getcwd()\nVIDEO_PATH = os.path.join(HOME, \"skateboarding.mp4\")\n\nif not os.path.isfile(VIDEO_PATH):\n req = urllib.request.urlretrieve(\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/skateboarding.mp4\",\n \"skateboarding.mp4\",\n )",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -137,16 +80,7 @@
},
{
"metadata": {},
- "source": [
- "# Instantiate YOLOv8 model\n",
- "model = YOLO(f\"{HOME}/yolov8n.pt\")\n",
- "colors = np.random.randint(0, 256, size=(len(model.names), 3))\n",
- "\n",
- "print(model.names)\n",
- "\n",
- "# Specify which classes you care about. The rest of classes will be filtered out.\n",
- "chosen_class_ids = [0] # person"
- ],
+ "source": "# Instantiate YOLOv8 model\nmodel = YOLO(f\"{HOME}/yolov8n.pt\")\ncolors = np.random.randint(0, 256, size=(len(model.names), 3))\n\nprint(model.names)\n\n# Specify which classes you care about. The rest of classes will be filtered out.\nchosen_class_ids = [0] # person",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -160,29 +94,14 @@
},
{
"metadata": {},
- "source": [
- "# Download SAM model weights\n",
- "CHECKPOINT_PATH = os.path.join(HOME, \"sam_vit_h_4b8939.pth\")\n",
- "\n",
- "if not os.path.isfile(CHECKPOINT_PATH):\n",
- " req = urllib.request.urlretrieve(\n",
- " \"https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth\",\n",
- " \"sam_vit_h_4b8939.pth\",\n",
- " )"
- ],
+ "source": "# Download SAM model weights\nCHECKPOINT_PATH = os.path.join(HOME, \"sam_vit_h_4b8939.pth\")\n\nif not os.path.isfile(CHECKPOINT_PATH):\n req = urllib.request.urlretrieve(\n \"https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth\",\n \"sam_vit_h_4b8939.pth\",\n )",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Instantiate SAM model\n",
- "\n",
- "DEVICE = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\n",
- "sam = sam_model_registry[\"vit_h\"](checkpoint=CHECKPOINT_PATH).to(device=DEVICE)\n",
- "mask_predictor = SamPredictor(sam)"
- ],
+ "source": "# Instantiate SAM model\n\nDEVICE = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\nsam = sam_model_registry[\"vit_h\"](checkpoint=CHECKPOINT_PATH).to(device=DEVICE)\nmask_predictor = SamPredictor(sam)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -196,12 +115,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your API key\n",
- "API_KEY = None\n",
- "# To get your API key go to: Workspace settings -> API -> Create API Key\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your API key\nAPI_KEY = None\n# To get your API key go to: Workspace settings -> API -> Create API Key\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -215,150 +129,7 @@
},
{
"metadata": {},
- "source": [
- "# Cast color to ints\n",
- "def get_color(color):\n",
- " return (int(color[0]), int(color[1]), int(color[2]))\n",
- "\n",
- "\n",
- "# Get video dimensions\n",
- "def get_video_dimensions(input_cap):\n",
- " width = int(input_cap.get(cv2.CAP_PROP_FRAME_WIDTH))\n",
- " height = int(input_cap.get(cv2.CAP_PROP_FRAME_HEIGHT))\n",
- " return height, width\n",
- "\n",
- "\n",
- "# Get output video writer with same dimensions and fps as input video\n",
- "def get_output_video_writer(input_cap, output_path):\n",
- " # Get the video's properties (width, height, FPS)\n",
- " width = int(input_cap.get(cv2.CAP_PROP_FRAME_WIDTH))\n",
- " height = int(input_cap.get(cv2.CAP_PROP_FRAME_HEIGHT))\n",
- " fps = int(input_cap.get(cv2.CAP_PROP_FPS))\n",
- "\n",
- " # Define the output video file\n",
- " output_codec = cv2.VideoWriter_fourcc(*\"mp4v\") # MP4 codec\n",
- " output_video = cv2.VideoWriter(output_path, output_codec, fps,\n",
- " (width, height))\n",
- "\n",
- " return output_video\n",
- "\n",
- "\n",
- "# Visualize a video frame with bounding boxes, classes and confidence scores\n",
- "def visualize_detections(frame, boxes, conf_thresholds, class_ids):\n",
- " frame_copy = np.copy(frame)\n",
- " for idx in range(len(boxes)):\n",
- " class_id = int(class_ids[idx])\n",
- " conf = float(conf_thresholds[idx])\n",
- " x1, y1, x2, y2 = (\n",
- " int(boxes[idx][0]),\n",
- " int(boxes[idx][1]),\n",
- " int(boxes[idx][2]),\n",
- " int(boxes[idx][3]),\n",
- " )\n",
- " color = colors[class_id]\n",
- " label = f\"{model.names[class_id]}: {conf:.2f}\"\n",
- " cv2.rectangle(frame_copy, (x1, y1), (x2, y2), get_color(color), 2)\n",
- " cv2.putText(\n",
- " frame_copy,\n",
- " label,\n",
- " (x1, y1 - 10),\n",
- " cv2.FONT_HERSHEY_SIMPLEX,\n",
- " 0.9,\n",
- " get_color(color),\n",
- " 2,\n",
- " )\n",
- " return frame_copy\n",
- "\n",
- "\n",
- "def add_color_to_mask(mask, color):\n",
- " next_mask = mask.astype(np.uint8)\n",
- " next_mask = np.expand_dims(next_mask, 0).repeat(3, axis=0)\n",
- " next_mask = np.moveaxis(next_mask, 0, -1)\n",
- " return next_mask * color\n",
- "\n",
- "\n",
- "# Merge masks into a single, multi-colored mask\n",
- "def merge_masks_colored(masks, class_ids):\n",
- " filtered_class_ids = []\n",
- " filtered_masks = []\n",
- " for idx, cid in enumerate(class_ids):\n",
- " if int(cid) in chosen_class_ids:\n",
- " filtered_class_ids.append(cid)\n",
- " filtered_masks.append(masks[idx])\n",
- "\n",
- " merged_with_colors = add_color_to_mask(\n",
- " filtered_masks[0][0],\n",
- " get_color(colors[int(filtered_class_ids[0])])).astype(np.uint8)\n",
- "\n",
- " if len(filtered_masks) == 1:\n",
- " return merged_with_colors\n",
- "\n",
- " for i in range(1, len(filtered_masks)):\n",
- " curr_mask_with_colors = add_color_to_mask(\n",
- " filtered_masks[i][0], get_color(colors[int(filtered_class_ids[i])]))\n",
- " merged_with_colors = np.bitwise_or(merged_with_colors,\n",
- " curr_mask_with_colors)\n",
- "\n",
- " return merged_with_colors.astype(np.uint8)\n",
- "\n",
- "\n",
- "def get_instance_uri(client: lb.Client, global_key, array):\n",
- " \"\"\"Reads a numpy array into a temp Labelbox data row to-be-uploaded to Labelbox\n",
- " Args:\n",
- " client : Required (lb.Client) - Labelbox Client object\n",
- " global_key : Required (str) - Data row global key\n",
- " array : Required (np.ndarray) - NumPy ndarray representation of an image\n",
- " Returns:\n",
- " Temp Labelbox data row to-be-uploaded to Labelbox as row data\n",
- " \"\"\"\n",
- " # Convert array to PIL image\n",
- " image_as_pil = PIL.Image.fromarray(array)\n",
- " # Convert PIL image to PNG file bytes\n",
- " image_as_bytes = BytesIO()\n",
- " image_as_pil.save(image_as_bytes, format=\"PNG\")\n",
- " image_as_bytes = image_as_bytes.getvalue()\n",
- " # Convert PNG file bytes to a temporary Labelbox URL\n",
- " url = client.upload_data(\n",
- " content=image_as_bytes,\n",
- " filename=f\"{uuid.uuid4()}{global_key}\",\n",
- " content_type=\"image/jpeg\",\n",
- " sign=True,\n",
- " )\n",
- " # Return the URL\n",
- " return url\n",
- "\n",
- "\n",
- "def get_local_instance_uri(array):\n",
- " # Convert array to PIL image\n",
- " image_as_pil = PIL.Image.fromarray(array)\n",
- "\n",
- " with tempfile.NamedTemporaryFile(suffix=\".png\",\n",
- " dir=\"/content\",\n",
- " delete=False) as temp_file:\n",
- " image_as_pil.save(temp_file)\n",
- " file_name = temp_file.name\n",
- "\n",
- " # Return the URL\n",
- " return file_name\n",
- "\n",
- "\n",
- "def create_mask_frame(frame_num, instance_uri):\n",
- " return lb_types.MaskFrame(index=frame_num, instance_uri=instance_uri)\n",
- "\n",
- "\n",
- "def create_mask_instances(class_ids):\n",
- " instances = []\n",
- " for cid in list(set(class_ids)): # get unique class ids\n",
- " if int(cid) in chosen_class_ids:\n",
- " color = get_color(colors[int(cid)])\n",
- " name = model.names[int(cid)]\n",
- " instances.append(lb_types.MaskInstance(color_rgb=color, name=name))\n",
- " return instances\n",
- "\n",
- "\n",
- "def create_video_mask_annotation(frames, instance):\n",
- " return lb_types.VideoMaskAnnotation(frames=frames, instances=[instance])"
- ],
+ "source": "# Cast color to ints\ndef get_color(color):\n return (int(color[0]), int(color[1]), int(color[2]))\n\n\n# Get video dimensions\ndef get_video_dimensions(input_cap):\n width = int(input_cap.get(cv2.CAP_PROP_FRAME_WIDTH))\n height = int(input_cap.get(cv2.CAP_PROP_FRAME_HEIGHT))\n return height, width\n\n\n# Get output video writer with same dimensions and fps as input video\ndef get_output_video_writer(input_cap, output_path):\n # Get the video's properties (width, height, FPS)\n width = int(input_cap.get(cv2.CAP_PROP_FRAME_WIDTH))\n height = int(input_cap.get(cv2.CAP_PROP_FRAME_HEIGHT))\n fps = int(input_cap.get(cv2.CAP_PROP_FPS))\n\n # Define the output video file\n output_codec = cv2.VideoWriter_fourcc(*\"mp4v\") # MP4 codec\n output_video = cv2.VideoWriter(output_path, output_codec, fps,\n (width, height))\n\n return output_video\n\n\n# Visualize a video frame with bounding boxes, classes and confidence scores\ndef visualize_detections(frame, boxes, conf_thresholds, class_ids):\n frame_copy = np.copy(frame)\n for idx in range(len(boxes)):\n class_id = int(class_ids[idx])\n conf = float(conf_thresholds[idx])\n x1, y1, x2, y2 = (\n int(boxes[idx][0]),\n int(boxes[idx][1]),\n int(boxes[idx][2]),\n int(boxes[idx][3]),\n )\n color = colors[class_id]\n label = f\"{model.names[class_id]}: {conf:.2f}\"\n cv2.rectangle(frame_copy, (x1, y1), (x2, y2), get_color(color), 2)\n cv2.putText(\n frame_copy,\n label,\n (x1, y1 - 10),\n cv2.FONT_HERSHEY_SIMPLEX,\n 0.9,\n get_color(color),\n 2,\n )\n return frame_copy\n\n\ndef add_color_to_mask(mask, color):\n next_mask = mask.astype(np.uint8)\n next_mask = np.expand_dims(next_mask, 0).repeat(3, axis=0)\n next_mask = np.moveaxis(next_mask, 0, -1)\n return next_mask * color\n\n\n# Merge masks into a single, multi-colored mask\ndef merge_masks_colored(masks, class_ids):\n filtered_class_ids = []\n filtered_masks = []\n for idx, cid in enumerate(class_ids):\n if int(cid) in chosen_class_ids:\n filtered_class_ids.append(cid)\n filtered_masks.append(masks[idx])\n\n merged_with_colors = add_color_to_mask(\n filtered_masks[0][0],\n get_color(colors[int(filtered_class_ids[0])])).astype(np.uint8)\n\n if len(filtered_masks) == 1:\n return merged_with_colors\n\n for i in range(1, len(filtered_masks)):\n curr_mask_with_colors = add_color_to_mask(\n filtered_masks[i][0], get_color(colors[int(filtered_class_ids[i])]))\n merged_with_colors = np.bitwise_or(merged_with_colors,\n curr_mask_with_colors)\n\n return merged_with_colors.astype(np.uint8)\n\n\ndef get_instance_uri(client: lb.Client, global_key, array):\n \"\"\"Reads a numpy array into a temp Labelbox data row to-be-uploaded to Labelbox\n Args:\n client : Required (lb.Client) - Labelbox Client object\n global_key : Required (str) - Data row global key\n array : Required (np.ndarray) - NumPy ndarray representation of an image\n Returns:\n Temp Labelbox data row to-be-uploaded to Labelbox as row data\n \"\"\"\n # Convert array to PIL image\n image_as_pil = PIL.Image.fromarray(array)\n # Convert PIL image to PNG file bytes\n image_as_bytes = BytesIO()\n image_as_pil.save(image_as_bytes, format=\"PNG\")\n image_as_bytes = image_as_bytes.getvalue()\n # Convert PNG file bytes to a temporary Labelbox URL\n url = client.upload_data(\n content=image_as_bytes,\n filename=f\"{uuid.uuid4()}{global_key}\",\n content_type=\"image/jpeg\",\n sign=True,\n )\n # Return the URL\n return url\n\n\ndef get_local_instance_uri(array):\n # Convert array to PIL image\n image_as_pil = PIL.Image.fromarray(array)\n\n with tempfile.NamedTemporaryFile(suffix=\".png\",\n dir=\"/content\",\n delete=False) as temp_file:\n image_as_pil.save(temp_file)\n file_name = temp_file.name\n\n # Return the URL\n return file_name\n\n\ndef create_mask_frame(frame_num, instance_uri):\n return lb_types.MaskFrame(index=frame_num, instance_uri=instance_uri)\n\n\ndef create_mask_instances(class_ids):\n instances = []\n for cid in list(set(class_ids)): # get unique class ids\n if int(cid) in chosen_class_ids:\n color = get_color(colors[int(cid)])\n name = model.names[int(cid)]\n instances.append(lb_types.MaskInstance(color_rgb=color, name=name))\n return instances\n\n\ndef create_video_mask_annotation(frames, instance):\n return lb_types.VideoMaskAnnotation(frames=frames, instances=[instance])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -372,151 +143,49 @@
},
{
"metadata": {},
- "source": [
- "# Create a new dataset\n",
- "# read more here: https://docs.labelbox.com/reference/data-row-global-keys\n",
- "global_key = os.path.basename(VIDEO_PATH)\n",
- "\n",
- "asset = {\n",
- " \"row_data\": VIDEO_PATH,\n",
- " \"global_key\": global_key,\n",
- " \"media_type\": \"VIDEO\"\n",
- "}\n",
- "\n",
- "dataset = client.create_dataset(name=\"yolo-sam-video-masks-dataset\")\n",
- "task = dataset.create_data_rows([asset])\n",
- "task.wait_till_done()\n",
- "\n",
- "print(f\"Errors: {task.errors}\")\n",
- "print(f\"Failed data rows: {task.failed_data_rows}\")"
- ],
+ "source": "# Create a new dataset\n# read more here: https://docs.labelbox.com/reference/data-row-global-keys\nglobal_key = os.path.basename(VIDEO_PATH)\n\nasset = {\n \"row_data\": VIDEO_PATH,\n \"global_key\": global_key,\n \"media_type\": \"VIDEO\",\n}\n\ndataset = client.create_dataset(name=\"yolo-sam-video-masks-dataset\")\ntask = dataset.create_data_rows([asset])\ntask.wait_till_done()\n\nprint(f\"Errors: {task.errors}\")\nprint(f\"Failed data rows: {task.failed_data_rows}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Run through YOLOv8 on the video once quickly to get unique class ids present\n",
- "# This will inform which classes we add to the ontology\n",
- "\n",
- "cap = cv2.VideoCapture(VIDEO_PATH)\n",
- "\n",
- "unique_class_ids = set()\n",
- "\n",
- "# Loop through the frames of the video\n",
- "frame_num = 1\n",
- "while cap.isOpened():\n",
- " if frame_num % 30 == 0 or frame_num == 1:\n",
- " print(\"Processing frame number\", frame_num)\n",
- " ret, frame = cap.read()\n",
- " if not ret:\n",
- " break\n",
- "\n",
- " # Run frame through YOLOv8 and get class ids predicted\n",
- " detections = model.predict(frame, conf=0.7) # frame is a numpy array\n",
- " for cid in detections[0].boxes.cls:\n",
- " unique_class_ids.add(int(cid))\n",
- " frame_num += 1\n",
- "\n",
- "cap.release()"
- ],
+ "source": "# Run through YOLOv8 on the video once quickly to get unique class ids present\n# This will inform which classes we add to the ontology\n\ncap = cv2.VideoCapture(VIDEO_PATH)\n\nunique_class_ids = set()\n\n# Loop through the frames of the video\nframe_num = 1\nwhile cap.isOpened():\n if frame_num % 30 == 0 or frame_num == 1:\n print(\"Processing frame number\", frame_num)\n ret, frame = cap.read()\n if not ret:\n break\n\n # Run frame through YOLOv8 and get class ids predicted\n detections = model.predict(frame, conf=0.7) # frame is a numpy array\n for cid in detections[0].boxes.cls:\n unique_class_ids.add(int(cid))\n frame_num += 1\n\ncap.release()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "unique_class_ids"
- ],
+ "source": "unique_class_ids",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Create a new ontology if you don't have one\n",
- "\n",
- "# Add all chosen classes into the ontology\n",
- "tools = []\n",
- "for cls in chosen_class_ids:\n",
- " tools.append(\n",
- " lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=model.names[cls]))\n",
- "\n",
- "ontology_builder = lb.OntologyBuilder(classifications=[], tools=tools)\n",
- "\n",
- "ontology = client.create_ontology(\n",
- " \"yolo-sam-video-masks-ontology\",\n",
- " ontology_builder.asdict(),\n",
- ")\n",
- "\n",
- "# Or get an existing ontology by name or ID (uncomment one of the below)\n",
- "\n",
- "# ontology = client.get_ontologies(\"yolo-sam-video-masks-ontology\").get_one()\n",
- "\n",
- "# ontology = client.get_ontology(\"\")"
- ],
+ "source": "# Create a new ontology if you don't have one\n\n# Add all chosen classes into the ontology\ntools = []\nfor cls in chosen_class_ids:\n tools.append(\n lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=model.names[cls]))\n\nontology_builder = lb.OntologyBuilder(classifications=[], tools=tools)\n\nontology = client.create_ontology(\n \"yolo-sam-video-masks-ontology\",\n ontology_builder.asdict(),\n)\n\n# Or get an existing ontology by name or ID (uncomment one of the below)\n\n# ontology = client.get_ontologies(\"yolo-sam-video-masks-ontology\").get_one()\n\n# ontology = client.get_ontology(\"\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Create a new project if you don't have one\n",
- "\n",
- "# Project defaults to batch mode with benchmark quality settings if this argument is not provided\n",
- "# Queue mode will be deprecated once dataset mode is deprecated\n",
- "project = client.create_project(name=\"yolo-sam-video-masks-project\",\n",
- " media_type=lb.MediaType.Video)\n",
- "\n",
- "# Or get an existing project by ID (uncomment the below)\n",
- "\n",
- "# project = get_project(\"fill_in_project_id\")\n",
- "\n",
- "# If the project already has an ontology set up, comment out this line\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "# Create a new project if you don't have one\n\n# Project defaults to batch mode with benchmark quality settings if this argument is not provided\n# Queue mode will be deprecated once dataset mode is deprecated\nproject = client.create_project(name=\"yolo-sam-video-masks-project\",\n media_type=lb.MediaType.Video)\n\n# Or get an existing project by ID (uncomment the below)\n\n# project = get_project(\"fill_in_project_id\")\n\n# If the project already has an ontology set up, comment out this line\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Create a new batch of data for the project you specified above\n",
- "\n",
- "# Uncomment if you are using `data_rows` parameter below\n",
- "# data_row_ids = client.get_data_row_ids_for_global_keys([global_key])['results']\n",
- "\n",
- "batch = project.create_batch(\n",
- " \"yolo-sam-video-masks-project\", # each batch in a project must have a unique name\n",
- " # you can also specify global_keys instead of data_rows\n",
- " global_keys=[global_key],\n",
- " # you can also specify data_rows instead of global_keys\n",
- " # data_rows=data_row_ids,\n",
- " priority=1, # priority between 1(highest) - 5(lowest)\n",
- ")\n",
- "\n",
- "print(f\"Batch: {batch}\")"
- ],
+ "source": "# Create a new batch of data for the project you specified above\n\n# Uncomment if you are using `data_rows` parameter below\n# data_row_ids = client.get_data_row_ids_for_global_keys([global_key])['results']\n\nbatch = project.create_batch(\n \"yolo-sam-video-masks-project\", # each batch in a project must have a unique name\n # you can also specify global_keys instead of data_rows\n global_keys=[global_key],\n # you can also specify data_rows instead of global_keys\n # data_rows=data_row_ids,\n priority=1, # priority between 1(highest) - 5(lowest)\n)\n\nprint(f\"Batch: {batch}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "tools = ontology.tools()\n",
- "\n",
- "feature_schema_ids = dict()\n",
- "for tool in tools:\n",
- " feature_schema_ids[tool.name] = tool.feature_schema_id\n",
- "\n",
- "print(feature_schema_ids)"
- ],
+ "source": "tools = ontology.tools()\n\nfeature_schema_ids = dict()\nfor tool in tools:\n feature_schema_ids[tool.name] = tool.feature_schema_id\n\nprint(feature_schema_ids)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -532,96 +201,14 @@
},
{
"metadata": {},
- "source": [
- "cap = cv2.VideoCapture(VIDEO_PATH)\n",
- "\n",
- "output_video_boxes = get_output_video_writer(\n",
- " cap, \"/content/skateboarding_boxes.mp4\")\n",
- "output_video_masks = get_output_video_writer(\n",
- " cap, \"/content/skateboarding_masks.mp4\")\n",
- "mask_frames = []\n",
- "\n",
- "# Loop through the frames of the video\n",
- "frame_num = 1\n",
- "while cap.isOpened():\n",
- " if frame_num % 30 == 0 or frame_num == 1:\n",
- " print(\"Processing frames\", frame_num, \"-\", frame_num + 29)\n",
- " ret, frame = cap.read()\n",
- " if not ret:\n",
- " break\n",
- "\n",
- " # Run frame through YOLOv8 to get detections\n",
- " detections = model.predict(frame, conf=0.7) # frame is a numpy array\n",
- "\n",
- " # Write detections to output video\n",
- " frame_with_detections = visualize_detections(\n",
- " frame,\n",
- " detections[0].boxes.cpu().xyxy,\n",
- " detections[0].boxes.cpu().conf,\n",
- " detections[0].boxes.cpu().cls,\n",
- " )\n",
- " output_video_boxes.write(frame_with_detections)\n",
- "\n",
- " # Run frame and detections through SAM to get masks\n",
- " transformed_boxes = mask_predictor.transform.apply_boxes_torch(\n",
- " detections[0].boxes.xyxy, list(get_video_dimensions(cap)))\n",
- " if len(transformed_boxes) == 0:\n",
- " print(\"No boxes found on frame\", frame_num)\n",
- " output_video_masks.write(frame)\n",
- " frame_num += 1\n",
- " continue\n",
- " mask_predictor.set_image(frame)\n",
- " masks, scores, logits = mask_predictor.predict_torch(\n",
- " boxes=transformed_boxes,\n",
- " multimask_output=False,\n",
- " point_coords=None,\n",
- " point_labels=None,\n",
- " )\n",
- " masks = np.array(masks.cpu())\n",
- " if masks is None or len(masks) == 0:\n",
- " print(\"No masks found on frame\", frame_num)\n",
- " output_video_masks.write(frame)\n",
- " frame_num += 1\n",
- " continue\n",
- " merged_colored_mask = merge_masks_colored(masks, detections[0].boxes.cls)\n",
- "\n",
- " # Write masks to output video\n",
- " image_combined = cv2.addWeighted(frame, 0.7, merged_colored_mask, 0.7, 0)\n",
- " output_video_masks.write(image_combined)\n",
- "\n",
- " # Create video mask annotation for upload to Labelbox\n",
- " instance_uri = get_instance_uri(client, global_key, merged_colored_mask)\n",
- " mask_frame = create_mask_frame(frame_num, instance_uri)\n",
- " mask_frames.append(mask_frame)\n",
- " print(\"Boxes found on frame\", frame_num)\n",
- " frame_num += 1\n",
- "\n",
- " # For the purposes of this demo, only look at the first 80 frames\n",
- " if frame_num > 80:\n",
- " break\n",
- "\n",
- "cap.release()\n",
- "output_video_boxes.release()\n",
- "output_video_masks.release()\n",
- "cv2.destroyAllWindows()"
- ],
+ "source": "cap = cv2.VideoCapture(VIDEO_PATH)\n\noutput_video_boxes = get_output_video_writer(\n cap, \"/content/skateboarding_boxes.mp4\")\noutput_video_masks = get_output_video_writer(\n cap, \"/content/skateboarding_masks.mp4\")\nmask_frames = []\n\n# Loop through the frames of the video\nframe_num = 1\nwhile cap.isOpened():\n if frame_num % 30 == 0 or frame_num == 1:\n print(\"Processing frames\", frame_num, \"-\", frame_num + 29)\n ret, frame = cap.read()\n if not ret:\n break\n\n # Run frame through YOLOv8 to get detections\n detections = model.predict(frame, conf=0.7) # frame is a numpy array\n\n # Write detections to output video\n frame_with_detections = visualize_detections(\n frame,\n detections[0].boxes.cpu().xyxy,\n detections[0].boxes.cpu().conf,\n detections[0].boxes.cpu().cls,\n )\n output_video_boxes.write(frame_with_detections)\n\n # Run frame and detections through SAM to get masks\n transformed_boxes = mask_predictor.transform.apply_boxes_torch(\n detections[0].boxes.xyxy, list(get_video_dimensions(cap)))\n if len(transformed_boxes) == 0:\n print(\"No boxes found on frame\", frame_num)\n output_video_masks.write(frame)\n frame_num += 1\n continue\n mask_predictor.set_image(frame)\n masks, scores, logits = mask_predictor.predict_torch(\n boxes=transformed_boxes,\n multimask_output=False,\n point_coords=None,\n point_labels=None,\n )\n masks = np.array(masks.cpu())\n if masks is None or len(masks) == 0:\n print(\"No masks found on frame\", frame_num)\n output_video_masks.write(frame)\n frame_num += 1\n continue\n merged_colored_mask = merge_masks_colored(masks, detections[0].boxes.cls)\n\n # Write masks to output video\n image_combined = cv2.addWeighted(frame, 0.7, merged_colored_mask, 0.7, 0)\n output_video_masks.write(image_combined)\n\n # Create video mask annotation for upload to Labelbox\n instance_uri = get_instance_uri(client, global_key, merged_colored_mask)\n mask_frame = create_mask_frame(frame_num, instance_uri)\n mask_frames.append(mask_frame)\n print(\"Boxes found on frame\", frame_num)\n frame_num += 1\n\n # For the purposes of this demo, only look at the first 80 frames\n if frame_num > 80:\n break\n\ncap.release()\noutput_video_boxes.release()\noutput_video_masks.release()\ncv2.destroyAllWindows()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Create annotations for LB upload\n",
- "mask_instances = create_mask_instances(unique_class_ids)\n",
- "annotations = []\n",
- "for instance in mask_instances:\n",
- " annotations.append(create_video_mask_annotation(mask_frames, instance))\n",
- "\n",
- "labels = []\n",
- "labels.append(\n",
- " lb_types.Label(data={\"global_key\": global_key}, annotations=annotations))"
- ],
+ "source": "# Create annotations for LB upload\nmask_instances = create_mask_instances(unique_class_ids)\nannotations = []\nfor instance in mask_instances:\n annotations.append(create_video_mask_annotation(mask_frames, instance))\n\nlabels = []\nlabels.append(\n lb_types.Label(data={\"global_key\": global_key}, annotations=annotations))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -637,17 +224,7 @@
},
{
"metadata": {},
- "source": [
- "upload_job = lb.MALPredictionImport.create_from_objects(\n",
- " client=client,\n",
- " project_id=project.uid,\n",
- " name=\"mal_import_job\" + str(uuid.uuid4()),\n",
- " predictions=labels,\n",
- ")\n",
- "upload_job.wait_until_done()\n",
- "print(f\"Errors: {upload_job.errors}\",)\n",
- "print(f\"Status of uploads: {upload_job.statuses}\")"
- ],
+ "source": "upload_job = lb.MALPredictionImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"mal_import_job\" + str(uuid.uuid4()),\n predictions=labels,\n)\nupload_job.wait_until_done()\nprint(f\"Errors: {upload_job.errors}\",)\nprint(f\"Status of uploads: {upload_job.statuses}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/model_experiments/custom_metrics_basics.ipynb b/examples/model_experiments/custom_metrics_basics.ipynb
index 546296f46..0face2b24 100644
--- a/examples/model_experiments/custom_metrics_basics.ipynb
+++ b/examples/model_experiments/custom_metrics_basics.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -16,12 +16,12 @@
"metadata": {},
"source": [
"\n",
- "![]() \n",
" | \n",
"\n",
"\n",
- "![]() \n",
" | "
],
@@ -57,9 +57,7 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -73,12 +71,7 @@
},
{
"metadata": {},
- "source": [
- "import labelbox.types as lb_types\n",
- "import labelbox as lb\n",
- "import uuid\n",
- "import json"
- ],
+ "source": "import labelbox.types as lb_types\nimport labelbox as lb\nimport uuid\nimport json",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -111,27 +104,14 @@
},
{
"metadata": {},
- "source": [
- "from labelbox.data.annotation_types import (ScalarMetric,\n",
- " ScalarMetricAggregation,\n",
- " ConfusionMatrixMetric)"
- ],
+ "source": "from labelbox.data.annotation_types import (\n ScalarMetric,\n ScalarMetricAggregation,\n ConfusionMatrixMetric,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "data_row_metric = ScalarMetric(metric_name=\"iou_custom\", value=0.5)\n",
- "\n",
- "feature_metric = ScalarMetric(metric_name=\"iou_custom\", feature_name=\"cat\", value=0.5)\n",
- "\n",
- "subclass_metric = ScalarMetric(metric_name=\"iou_custom\",\n",
- " feature_name=\"cat\",\n",
- " subclass_name=\"organge\",\n",
- " value=0.5)"
- ],
+ "source": "data_row_metric = ScalarMetric(metric_name=\"iou_custom\", value=0.5)\n\nfeature_metric = ScalarMetric(metric_name=\"iou_custom\",\n feature_name=\"cat\",\n value=0.5)\n\nsubclass_metric = ScalarMetric(\n metric_name=\"iou_custom\",\n feature_name=\"cat\",\n subclass_name=\"organge\",\n value=0.5,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -148,22 +128,7 @@
},
{
"metadata": {},
- "source": [
- "data_row_metric = ConfusionMatrixMetric(metric_name=\"50pct_iou\",\n",
- " feature_name=\"cat\",\n",
- " subclass_name=\"organge\",\n",
- " value=[1, 0, 1, 0])\n",
- "\n",
- "feature_metric = ConfusionMatrixMetric(metric_name=\"50pct_iou\",\n",
- " feature_name=\"cat\",\n",
- " subclass_name=\"organge\",\n",
- " value=[1, 0, 1, 0])\n",
- "\n",
- "subclass_metric = ConfusionMatrixMetric(metric_name=\"50pct_iou\",\n",
- " feature_name=\"cat\",\n",
- " subclass_name=\"organge\",\n",
- " value=[1, 0, 1, 0])"
- ],
+ "source": "data_row_metric = ConfusionMatrixMetric(\n metric_name=\"50pct_iou\",\n feature_name=\"cat\",\n subclass_name=\"organge\",\n value=[1, 0, 1, 0],\n)\n\nfeature_metric = ConfusionMatrixMetric(\n metric_name=\"50pct_iou\",\n feature_name=\"cat\",\n subclass_name=\"organge\",\n value=[1, 0, 1, 0],\n)\n\nsubclass_metric = ConfusionMatrixMetric(\n metric_name=\"50pct_iou\",\n feature_name=\"cat\",\n subclass_name=\"organge\",\n value=[1, 0, 1, 0],\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -181,28 +146,7 @@
},
{
"metadata": {},
- "source": [
- "confusion_matrix_metric_with_confidence = ConfusionMatrixMetric(\n",
- " metric_name=\"confusion_matrix_50pct_iou\",\n",
- " feature_name=\"cat\",\n",
- " subclass_name=\"organge\",\n",
- " value={\n",
- " 0.1: [1, 0, 1, 0],\n",
- " 0.3: [1, 0, 1, 0],\n",
- " 0.5: [1, 0, 1, 0],\n",
- " 0.7: [1, 0, 1, 0],\n",
- " 0.9: [1, 0, 1, 0]\n",
- " })\n",
- "\n",
- "scalar_metric_with_confidence = ScalarMetric(metric_name=\"iou_custom\",\n",
- " value={\n",
- " 0.1: 0.2,\n",
- " 0.3: 0.25,\n",
- " 0.5: 0.3,\n",
- " 0.7: 0.4,\n",
- " 0.9: 0.3\n",
- " })"
- ],
+ "source": "confusion_matrix_metric_with_confidence = ConfusionMatrixMetric(\n metric_name=\"confusion_matrix_50pct_iou\",\n feature_name=\"cat\",\n subclass_name=\"organge\",\n value={\n 0.1: [1, 0, 1, 0],\n 0.3: [1, 0, 1, 0],\n 0.5: [1, 0, 1, 0],\n 0.7: [1, 0, 1, 0],\n 0.9: [1, 0, 1, 0],\n },\n)\n\nscalar_metric_with_confidence = ScalarMetric(\n metric_name=\"iou_custom\",\n value={\n 0.1: 0.2,\n 0.3: 0.25,\n 0.5: 0.3,\n 0.7: 0.4,\n 0.9: 0.3\n },\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -222,25 +166,7 @@
},
{
"metadata": {},
- "source": [
- "\"\"\"\n",
- "If the following metrics are uploaded then\n",
- "in the web app, users will see:\n",
- "true positives dog = 4\n",
- "true positives cat = 3\n",
- "true positives = 7\n",
- "\"\"\"\n",
- "\n",
- "feature_metric = ScalarMetric(metric_name=\"true_positives\",\n",
- " feature_name=\"cat\",\n",
- " value=3,\n",
- " aggregation=ScalarMetricAggregation.SUM)\n",
- "\n",
- "feature_metric = ScalarMetric(metric_name=\"true_positives\",\n",
- " feature_name=\"dog\",\n",
- " value=4,\n",
- " aggregation=ScalarMetricAggregation.SUM)"
- ],
+ "source": "\"\"\"\nIf the following metrics are uploaded then\nin the web app, users will see:\ntrue positives dog = 4\ntrue positives cat = 3\ntrue positives = 7\n\"\"\"\n\nfeature_metric = ScalarMetric(\n metric_name=\"true_positives\",\n feature_name=\"cat\",\n value=3,\n aggregation=ScalarMetricAggregation.SUM,\n)\n\nfeature_metric = ScalarMetric(\n metric_name=\"true_positives\",\n feature_name=\"dog\",\n value=4,\n aggregation=ScalarMetricAggregation.SUM,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -265,99 +191,42 @@
},
{
"metadata": {},
- "source": [
- "from labelbox.data.metrics import (feature_miou_metric, miou_metric,\n",
- " confusion_matrix_metric,\n",
- " feature_confusion_matrix_metric)"
- ],
+ "source": "from labelbox.data.metrics import (\n feature_miou_metric,\n miou_metric,\n confusion_matrix_metric,\n feature_confusion_matrix_metric,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "predictions = [\n",
- " lb_types.ObjectAnnotation(name=\"cat\",\n",
- " value=lb_types.Rectangle(start=lb_types.Point(x=0, y=0),\n",
- " end=lb_types.Point(x=10, y=10)))\n",
- "]\n",
- "\n",
- "ground_truths = [\n",
- " lb_types.ObjectAnnotation(name=\"cat\",\n",
- " value=lb_types.Rectangle(start=lb_types.Point(x=0, y=0), end=lb_types.Point(x=8,\n",
- " y=8)))\n",
- "]"
- ],
+ "source": "predictions = [\n lb_types.ObjectAnnotation(\n name=\"cat\",\n value=lb_types.Rectangle(start=lb_types.Point(x=0, y=0),\n end=lb_types.Point(x=10, y=10)),\n )\n]\n\nground_truths = [\n lb_types.ObjectAnnotation(\n name=\"cat\",\n value=lb_types.Rectangle(start=lb_types.Point(x=0, y=0),\n end=lb_types.Point(x=8, y=8)),\n )\n]",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "print(feature_miou_metric(ground_truths, predictions))\n",
- "print(miou_metric(ground_truths, predictions))\n",
- "print(confusion_matrix_metric(ground_truths, predictions))\n",
- "print(feature_confusion_matrix_metric(ground_truths, predictions))"
- ],
+ "source": "print(feature_miou_metric(ground_truths, predictions))\nprint(miou_metric(ground_truths, predictions))\nprint(confusion_matrix_metric(ground_truths, predictions))\nprint(feature_confusion_matrix_metric(ground_truths, predictions))",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Adjust iou for iou calcuations.\n",
- "# Set it higher than 0.64 and we get a false postive and a false negative for the other ground truth object.\n",
- "print(feature_confusion_matrix_metric(ground_truths, predictions, iou=0.9))"
- ],
+ "source": "# Adjust iou for iou calcuations.\n# Set it higher than 0.64 and we get a false postive and a false negative for the other ground truth object.\nprint(feature_confusion_matrix_metric(ground_truths, predictions, iou=0.9))",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "\n",
- "# subclasses are included by default\n",
- "predictions = [\n",
- " lb_types.ObjectAnnotation(\n",
- " name=\"cat\",\n",
- " value=lb_types.Rectangle(start=lb_types.Point(x=0, y=0), end=lb_types.Point(x=10, y=10)),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"height\",\n",
- " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(name=\"tall\")))\n",
- " ])\n",
- "]\n",
- "\n",
- "ground_truths = [\n",
- " lb_types.ObjectAnnotation(\n",
- " name=\"cat\",\n",
- " value=lb_types.Rectangle(start=lb_types.Point(x=0, y=0), end=lb_types.Point(x=10, y=10)),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"height\",\n",
- " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(name=\"short\")))\n",
- " ])\n",
- "]\n",
- "conf_matrix_metrics = feature_confusion_matrix_metric(ground_truths,\n",
- " predictions)\n",
- "iou_metrics = feature_confusion_matrix_metric(ground_truths,\n",
- " predictions,\n",
- " include_subclasses=False)"
- ],
+ "source": "# subclasses are included by default\npredictions = [\n lb_types.ObjectAnnotation(\n name=\"cat\",\n value=lb_types.Rectangle(start=lb_types.Point(x=0, y=0),\n end=lb_types.Point(x=10, y=10)),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"height\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"tall\")),\n )\n ],\n )\n]\n\nground_truths = [\n lb_types.ObjectAnnotation(\n name=\"cat\",\n value=lb_types.Rectangle(start=lb_types.Point(x=0, y=0),\n end=lb_types.Point(x=10, y=10)),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"height\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"short\")),\n )\n ],\n )\n]\nconf_matrix_metrics = feature_confusion_matrix_metric(ground_truths,\n predictions)\niou_metrics = feature_confusion_matrix_metric(ground_truths,\n predictions,\n include_subclasses=False)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "print(\"Subclasses:\", conf_matrix_metrics[0].value)\n",
- "print(\"Excluding Subclasses:\", iou_metrics[0].value)"
- ],
+ "source": "print(\"Subclasses:\", conf_matrix_metrics[0].value)\nprint(\"Excluding Subclasses:\", iou_metrics[0].value)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -377,16 +246,7 @@
},
{
"metadata": {},
- "source": [
- "# Continuing with the last example:\n",
- "global_key = \"\"\n",
- "metrics = [*conf_matrix_metrics, *iou_metrics]\n",
- "labels = [\n",
- " lb_types.Label(data=lb_types.ImageData(global_key=global_key), annotations=metrics)\n",
- "]\n",
- "# We can upload these metric with other annotations\n",
- "#model_run.add_predictions(f'diagnostics-import-{uuid.uuid4()}', labels)"
- ],
+ "source": "# Continuing with the last example:\nglobal_key = \"\"\nmetrics = [*conf_matrix_metrics, *iou_metrics]\nlabels = [\n lb_types.Label(data=lb_types.ImageData(global_key=global_key),\n annotations=metrics)\n]\n# We can upload these metric with other annotations\n# model_run.add_predictions(f'diagnostics-import-{uuid.uuid4()}', labels)",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/model_experiments/custom_metrics_demo.ipynb b/examples/model_experiments/custom_metrics_demo.ipynb
index 318b382c6..8e0412f40 100644
--- a/examples/model_experiments/custom_metrics_demo.ipynb
+++ b/examples/model_experiments/custom_metrics_demo.ipynb
@@ -6,23 +6,22 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
{
"metadata": {},
"source": [
- "\n",
"\n",
" \n",
" | \n",
"\n",
"\n",
- "![]() \n",
" | "
],
@@ -51,21 +50,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q 'labelbox[data]'"
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import uuid\n",
- "import requests\n",
- "import labelbox as lb\n",
- "import labelbox.types as lb_types"
- ],
+ "source": "import uuid\nimport requests\nimport labelbox as lb\nimport labelbox.types as lb_types",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -80,10 +72,7 @@
},
{
"metadata": {},
- "source": [
- "API_KEY = \"\"\n",
- "client = lb.Client(API_KEY)"
- ],
+ "source": "API_KEY = \"\"\nclient = lb.Client(API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -104,37 +93,7 @@
},
{
"metadata": {},
- "source": [
- "radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer = lb_types.ClassificationAnswer(\n",
- " name = \"second_radio_answer\", confidence=0.5,\n",
- " custom_metrics=[{ 'name': 'iou', 'value': 0.1 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }],\n",
- " )\n",
- " )\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "radio_prediction_ndjson = {\n",
- " \"name\": \"radio_question\",\n",
- " \"answer\": {'name': 'first_radio_answer', 'confidence': 0.5,\n",
- " 'customMetrics': [\n",
- " { 'name': 'iou', 'value': 0.1 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ]\n",
- " }\n",
- "}"
- ],
+ "source": "radio_prediction = lb_types.ClassificationAnnotation(\n name=\"radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"second_radio_answer\",\n confidence=0.5,\n custom_metrics=[\n {\n \"name\": \"iou\",\n \"value\": 0.1\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n )),\n)\n\n# NDJSON\nradio_prediction_ndjson = {\n \"name\": \"radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"confidence\":\n 0.5,\n \"customMetrics\": [\n {\n \"name\": \"iou\",\n \"value\": 0.1\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -148,62 +107,7 @@
},
{
"metadata": {},
- "source": [
- "checklist_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\",\n",
- " confidence=0.5,\n",
- " custom_metrics=[\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ]\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\",\n",
- " confidence=0.5,\n",
- " custom_metrics= [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ]\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- "checklist_prediction_ndjson = {\n",
- " 'name': 'checklist_question',\n",
- " 'answer': [\n",
- " {'name': 'first_checklist_answer' , 'confidence': 0.5,\n",
- " 'customMetrics': [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ]},\n",
- " {'name': 'second_checklist_answer', 'confidence': 0.5,\n",
- " 'customMetrics': [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ]}\n",
- " ]\n",
- "}"
- ],
+ "source": "checklist_prediction = lb_types.ClassificationAnnotation(\n name=\"checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n confidence=0.5,\n custom_metrics=[\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n ),\n lb_types.ClassificationAnswer(\n name=\"second_checklist_answer\",\n confidence=0.5,\n custom_metrics=[\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n ),\n ]),\n)\nchecklist_prediction_ndjson = {\n \"name\":\n \"checklist_question\",\n \"answer\": [\n {\n \"name\":\n \"first_checklist_answer\",\n \"confidence\":\n 0.5,\n \"customMetrics\": [\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n },\n {\n \"name\":\n \"second_checklist_answer\",\n \"confidence\":\n 0.5,\n \"customMetrics\": [\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -217,141 +121,7 @@
},
{
"metadata": {},
- "source": [
- "nested_radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " confidence=0.5,\n",
- " custom_metrics=[\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ],\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\",\n",
- " confidence=0.5,\n",
- " custom_metrics=[\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ]\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "\n",
- "nested_radio_prediction_ndjson = {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"confidence\": 0.5 ,\n",
- " \"answer\": { \"name\": \"first_radio_answer\", \"confidence\": 0.5,\n",
- " 'customMetrics': [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ]\n",
- " },\n",
- " \"classifications\" : [\n",
- " {\n",
- " \"name\": \"sub_radio_question\",\n",
- " \"answer\": { \"name\": \"first_sub_radio_answer\", \"confidence\": 0.5,\n",
- " 'customMetrics': [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ]\n",
- " }\n",
- " }\n",
- " ]\n",
- "}\n",
- "\n",
- "nested_checklist_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " confidence=0.5,\n",
- " custom_metrics = [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ],\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\",\n",
- " confidence=0.5,\n",
- " custom_metrics= [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ]\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "\n",
- "nested_checklist_prediction_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"confidence\": 0.5 ,\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"confidence\": 0.5,\n",
- " 'customMetrics': [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ],\n",
- " \"classifications\" : [{\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_sub_checklist_answer\", \"confidence\": 0.5,\n",
- " 'customMetrics': [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ]}\n",
- " }\n",
- " ]\n",
- " }]\n",
- "}"
- ],
+ "source": "nested_radio_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n confidence=0.5,\n custom_metrics=[\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\",\n confidence=0.5,\n custom_metrics=[\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332,\n },\n ],\n )),\n )\n ],\n )),\n)\n\nnested_radio_prediction_ndjson = {\n \"name\":\n \"nested_radio_question\",\n \"confidence\":\n 0.5,\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"confidence\":\n 0.5,\n \"customMetrics\": [\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n },\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\":\n \"first_sub_radio_answer\",\n \"confidence\":\n 0.5,\n \"customMetrics\": [\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n },\n }],\n}\n\nnested_checklist_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n confidence=0.5,\n custom_metrics=[\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\",\n confidence=0.5,\n custom_metrics=[\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332,\n },\n ],\n )\n ]),\n )\n ],\n )\n ]),\n)\n\nnested_checklist_prediction_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"confidence\":\n 0.5,\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"confidence\":\n 0.5,\n \"customMetrics\": [\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\":\n \"first_sub_checklist_answer\",\n \"confidence\":\n 0.5,\n \"customMetrics\": [\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332,\n },\n ],\n },\n }],\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -365,44 +135,7 @@
},
{
"metadata": {},
- "source": [
- "bbox_prediction = lb_types.ObjectAnnotation(\n",
- " name = \"bounding_box\",\n",
- " confidence=0.5,\n",
- " custom_metrics= [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ],\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=1690, y=977), # x = left, y = top\n",
- " end=lb_types.Point(x=1915, y=1307), # x= left + width , y = top + height\n",
- " )\n",
- ")\n",
- "\n",
- "\n",
- "bbox_prediction_ndjson = {\n",
- " \"name\": \"bounding_box\",\n",
- " \"confidence\": 0.5,\n",
- " 'customMetrics': [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ],\n",
- " \"bbox\": {\n",
- " \"top\": 977,\n",
- " \"left\": 1690,\n",
- " \"height\": 330,\n",
- " \"width\": 225\n",
- " }\n",
- "}\n"
- ],
+ "source": "bbox_prediction = lb_types.ObjectAnnotation(\n name=\"bounding_box\",\n confidence=0.5,\n custom_metrics=[\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n value=lb_types.Rectangle(\n start=lb_types.Point(x=1690, y=977), # x = left, y = top\n end=lb_types.Point(x=1915,\n y=1307), # x= left + width , y = top + height\n ),\n)\n\nbbox_prediction_ndjson = {\n \"name\": \"bounding_box\",\n \"confidence\": 0.5,\n \"customMetrics\": [\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n \"bbox\": {\n \"top\": 977,\n \"left\": 1690,\n \"height\": 330,\n \"width\": 225\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -416,76 +149,7 @@
},
{
"metadata": {},
- "source": [
- "bbox_with_radio_subclass_prediction = lb_types.ObjectAnnotation(\n",
- " name=\"bbox_with_radio_subclass\",\n",
- " confidence=0.5,\n",
- " custom_metrics = [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.2 },\n",
- " { 'name': 'precision', 'value': 0.1 },\n",
- " { 'name': 'recall', 'value': 0.3 },\n",
- " { 'name': 'tagsCount', 'value': 23 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ],\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=541, y=933), # x = left, y = top\n",
- " end=lb_types.Point(x=871, y=1124), # x= left + width , y = top + height\n",
- " ),\n",
- " classifications=[\n",
- " \tlb_types.ClassificationAnnotation(\n",
- " \tname=\"sub_radio_question\",\n",
- " \t\tvalue=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\",\n",
- " confidence=0.5,\n",
- " custom_metrics =[\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.2 },\n",
- " { 'name': 'precision', 'value': 0.1 },\n",
- " { 'name': 'recall', 'value': 0.3 },\n",
- " { 'name': 'tagsCount', 'value': 23 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ]\n",
- " ))\n",
- " )\n",
- " ]\n",
- ")\n",
- "## NDJSON\n",
- "bbox_with_radio_subclass_prediction_ndjson = {\n",
- " \"name\": \"bbox_with_radio_subclass\",\n",
- " \"confidence\": 0.5,\n",
- " 'customMetrics': [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.2 },\n",
- " { 'name': 'precision', 'value': 0.1 },\n",
- " { 'name': 'recall', 'value': 0.3 },\n",
- " { 'name': 'tagsCount', 'value': 23 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ],\n",
- " \"classifications\": [{\n",
- " \"name\": \"sub_radio_question\",\n",
- " \"answer\":\n",
- " { \"name\":\"first_sub_radio_answer\",\n",
- " \"confidence\": 0.5,\n",
- " 'customMetrics': [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.2 },\n",
- " { 'name': 'precision', 'value': 0.1 },\n",
- " { 'name': 'recall', 'value': 0.3 },\n",
- " { 'name': 'tagsCount', 'value': 23 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ]}\n",
- "\n",
- " }],\n",
- " \"bbox\": {\n",
- " \"top\": 933,\n",
- " \"left\": 541,\n",
- " \"height\": 191,\n",
- " \"width\": 330\n",
- " }\n",
- "}"
- ],
+ "source": "bbox_with_radio_subclass_prediction = lb_types.ObjectAnnotation(\n name=\"bbox_with_radio_subclass\",\n confidence=0.5,\n custom_metrics=[\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.2\n },\n {\n \"name\": \"precision\",\n \"value\": 0.1\n },\n {\n \"name\": \"recall\",\n \"value\": 0.3\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 23\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n value=lb_types.Rectangle(\n start=lb_types.Point(x=541, y=933), # x = left, y = top\n end=lb_types.Point(x=871, y=1124), # x= left + width , y = top + height\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\",\n confidence=0.5,\n custom_metrics=[\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.2\n },\n {\n \"name\": \"precision\",\n \"value\": 0.1\n },\n {\n \"name\": \"recall\",\n \"value\": 0.3\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 23\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332,\n },\n ],\n )),\n )\n ],\n)\n## NDJSON\nbbox_with_radio_subclass_prediction_ndjson = {\n \"name\": \"bbox_with_radio_subclass\",\n \"confidence\": 0.5,\n \"customMetrics\": [\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.2\n },\n {\n \"name\": \"precision\",\n \"value\": 0.1\n },\n {\n \"name\": \"recall\",\n \"value\": 0.3\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 23\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\":\n \"first_sub_radio_answer\",\n \"confidence\":\n 0.5,\n \"customMetrics\": [\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.2\n },\n {\n \"name\": \"precision\",\n \"value\": 0.1\n },\n {\n \"name\": \"recall\",\n \"value\": 0.3\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 23\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n },\n }],\n \"bbox\": {\n \"top\": 933,\n \"left\": 541,\n \"height\": 191,\n \"width\": 330\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -499,58 +163,7 @@
},
{
"metadata": {},
- "source": [
- "# Python Anotation\n",
- "polygon_prediction = lb_types.ObjectAnnotation(\n",
- " name = \"polygon\",\n",
- " confidence = 0.5,\n",
- " custom_metrics = [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ],\n",
- " value=lb_types.Polygon(\n",
- " points=[lb_types.Point(x=1489.581,y=183.934), lb_types.Point(x=2278.306,y=256.885), lb_types.Point(x=2428.197,y=200.437), lb_types.Point(x=2560.0,y=335.419),\n",
- " lb_types.Point(x=2557.386,y=503.165), lb_types.Point(x=2320.596,y=503.103), lb_types.Point(x=2156.083, y=628.943), lb_types.Point(x=2161.111,y=785.519),\n",
- " lb_types.Point(x=2002.115, y=894.647), lb_types.Point(x=1838.456,y=877.874), lb_types.Point(x=1436.53,y=874.636), lb_types.Point(x=1411.403,y=758.579),\n",
- " lb_types.Point(x=1353.853,y=751.74), lb_types.Point(x=1345.264, y=453.461), lb_types.Point(x=1426.011,y=421.129)]\n",
- " ),\n",
- ")\n",
- "\n",
- "polygon_prediction_ndjson = {\n",
- " \"name\": \"polygon\",\n",
- " \"confidence\": 0.5,\n",
- " 'customMetrics': [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ],\n",
- " \"polygon\": [\n",
- " {\"x\": 1489.581, \"y\": 183.934},\n",
- " {\"x\": 2278.306, \"y\": 256.885},\n",
- " {\"x\": 2428.197, \"y\": 200.437},\n",
- " {\"x\": 2560.0, \"y\": 335.419},\n",
- " {\"x\": 2557.386, \"y\": 503.165},\n",
- " {\"x\": 2320.596, \"y\": 503.103},\n",
- " {\"x\": 2156.083, \"y\": 628.943},\n",
- " {\"x\": 2161.111, \"y\": 785.519},\n",
- " {\"x\": 2002.115, \"y\": 894.647},\n",
- " {\"x\": 1838.456, \"y\": 877.874},\n",
- " {\"x\": 1436.53, \"y\": 874.636},\n",
- " {\"x\": 1411.403, \"y\": 758.579},\n",
- " {\"x\": 1353.853, \"y\": 751.74},\n",
- " {\"x\": 1345.264, \"y\": 453.461},\n",
- " {\"x\": 1426.011, \"y\": 421.129},\n",
- " {\"x\": 1489.581, \"y\": 183.934}\n",
- " ]\n",
- "}"
- ],
+ "source": "# Python Anotation\npolygon_prediction = lb_types.ObjectAnnotation(\n name=\"polygon\",\n confidence=0.5,\n custom_metrics=[\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n value=lb_types.Polygon(points=[\n lb_types.Point(x=1489.581, y=183.934),\n lb_types.Point(x=2278.306, y=256.885),\n lb_types.Point(x=2428.197, y=200.437),\n lb_types.Point(x=2560.0, y=335.419),\n lb_types.Point(x=2557.386, y=503.165),\n lb_types.Point(x=2320.596, y=503.103),\n lb_types.Point(x=2156.083, y=628.943),\n lb_types.Point(x=2161.111, y=785.519),\n lb_types.Point(x=2002.115, y=894.647),\n lb_types.Point(x=1838.456, y=877.874),\n lb_types.Point(x=1436.53, y=874.636),\n lb_types.Point(x=1411.403, y=758.579),\n lb_types.Point(x=1353.853, y=751.74),\n lb_types.Point(x=1345.264, y=453.461),\n lb_types.Point(x=1426.011, y=421.129),\n ]),\n)\n\npolygon_prediction_ndjson = {\n \"name\":\n \"polygon\",\n \"confidence\":\n 0.5,\n \"customMetrics\": [\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n \"polygon\": [\n {\n \"x\": 1489.581,\n \"y\": 183.934\n },\n {\n \"x\": 2278.306,\n \"y\": 256.885\n },\n {\n \"x\": 2428.197,\n \"y\": 200.437\n },\n {\n \"x\": 2560.0,\n \"y\": 335.419\n },\n {\n \"x\": 2557.386,\n \"y\": 503.165\n },\n {\n \"x\": 2320.596,\n \"y\": 503.103\n },\n {\n \"x\": 2156.083,\n \"y\": 628.943\n },\n {\n \"x\": 2161.111,\n \"y\": 785.519\n },\n {\n \"x\": 2002.115,\n \"y\": 894.647\n },\n {\n \"x\": 1838.456,\n \"y\": 877.874\n },\n {\n \"x\": 1436.53,\n \"y\": 874.636\n },\n {\n \"x\": 1411.403,\n \"y\": 758.579\n },\n {\n \"x\": 1353.853,\n \"y\": 751.74\n },\n {\n \"x\": 1345.264,\n \"y\": 453.461\n },\n {\n \"x\": 1426.011,\n \"y\": 421.129\n },\n {\n \"x\": 1489.581,\n \"y\": 183.934\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -564,39 +177,7 @@
},
{
"metadata": {},
- "source": [
- "# Python annotation\n",
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"free_text\",\n",
- " value=lb_types.Text(\n",
- " answer=\"sample text\",\n",
- " confidence=0.5,\n",
- " custom_metrics = [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ]\n",
- " )\n",
- ")\n",
- "\n",
- "\n",
- "text_annotation_ndjson = {\n",
- " \"name\": \"free_text\",\n",
- " \"answer\": \"sample text\",\n",
- " 'customMetrics': [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ],\n",
- " \"confidence\": 0.5\n",
- "}"
- ],
+ "source": "# Python annotation\ntext_annotation = lb_types.ClassificationAnnotation(\n name=\"free_text\",\n value=lb_types.Text(\n answer=\"sample text\",\n confidence=0.5,\n custom_metrics=[\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n ),\n)\n\ntext_annotation_ndjson = {\n \"name\": \"free_text\",\n \"answer\": \"sample text\",\n \"customMetrics\": [\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n \"confidence\": 0.5,\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -610,37 +191,7 @@
},
{
"metadata": {},
- "source": [
- "# Python Annotation\n",
- "point_prediction = lb_types.ObjectAnnotation(\n",
- " name = \"point\",\n",
- " confidence=0.5,\n",
- " custom_metrics= [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ],\n",
- " value = lb_types.Point(x=1166.606, y=1441.768),\n",
- ")\n",
- "\n",
- "point_prediction_ndjson = {\n",
- " \"name\": \"point\",\n",
- " \"confidence\": 0.5,\n",
- " 'customMetrics': [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ],\n",
- " \"classifications\": [],\n",
- " \"point\": {\"x\": 1166.606, \"y\": 1441.768}\n",
- "}"
- ],
+ "source": "# Python Annotation\npoint_prediction = lb_types.ObjectAnnotation(\n name=\"point\",\n confidence=0.5,\n custom_metrics=[\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n value=lb_types.Point(x=1166.606, y=1441.768),\n)\n\npoint_prediction_ndjson = {\n \"name\": \"point\",\n \"confidence\": 0.5,\n \"customMetrics\": [\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n \"classifications\": [],\n \"point\": {\n \"x\": 1166.606,\n \"y\": 1441.768\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -654,65 +205,7 @@
},
{
"metadata": {},
- "source": [
- "polyline_prediction = lb_types.ObjectAnnotation(\n",
- " name = \"polyline\",\n",
- " confidence=0.5,\n",
- " custom_metrics=[\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ],\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=2534.353, y=249.471), lb_types.Point(x=2429.492, y=182.092), lb_types.Point(x=2294.322, y=221.962), lb_types.Point(x=2224.491, y=180.463), lb_types.Point(x=2136.123, y=204.716),\n",
- " lb_types.Point(x=1712.247, y=173.949), lb_types.Point(x=1703.838, y=84.438), lb_types.Point(x=1579.772, y=82.61), lb_types.Point(x=1583.442, y=167.552),\n",
- " lb_types.Point(x=1478.869, y=164.903), lb_types.Point(x=1418.941, y=318.149), lb_types.Point(x=1243.128, y=400.815), lb_types.Point(x=1022.067, y=319.007),\n",
- " lb_types.Point(x=892.367, y=379.216), lb_types.Point(x=670.273, y=364.408), lb_types.Point(x=613.114, y=288.16), lb_types.Point(x=377.559, y=238.251),\n",
- " lb_types.Point(x=368.087, y=185.064), lb_types.Point(x=246.557, y=167.286), lb_types.Point(x=236.648, y=285.61), lb_types.Point(x=90.929, y=326.412)]\n",
- " ),\n",
- ")\n",
- "\n",
- "\n",
- "polyline_prediction_ndjson = {\n",
- " \"name\": \"polyline\",\n",
- " \"confidence\":0.5,\n",
- " 'customMetrics': [\n",
- " { 'name': 'iou', 'value': 0.5 },\n",
- " { 'name': 'f1', 'value': 0.33 },\n",
- " { 'name': 'precision', 'value': 0.55 },\n",
- " { 'name': 'recall', 'value': 0.33 },\n",
- " { 'name': 'tagsCount', 'value': 43 },\n",
- " { 'name': 'metric_with_a_very_long_name', 'value': 0.334332 }\n",
- " ],\n",
- " \"classifications\": [],\n",
- " \"line\": [\n",
- " {\"x\": 2534.353, \"y\": 249.471},\n",
- " {\"x\": 2429.492, \"y\": 182.092},\n",
- " {\"x\": 2294.322, \"y\": 221.962},\n",
- " {\"x\": 2224.491, \"y\": 180.463},\n",
- " {\"x\": 2136.123, \"y\": 204.716},\n",
- " {\"x\": 1712.247, \"y\": 173.949},\n",
- " {\"x\": 1703.838, \"y\": 84.438},\n",
- " {\"x\": 1579.772, \"y\": 82.61},\n",
- " {\"x\": 1583.442, \"y\": 167.552},\n",
- " {\"x\": 1478.869, \"y\": 164.903},\n",
- " {\"x\": 1418.941, \"y\": 318.149},\n",
- " {\"x\": 1243.128, \"y\": 400.815},\n",
- " {\"x\": 1022.067, \"y\": 319.007},\n",
- " {\"x\": 892.367, \"y\": 379.216},\n",
- " {\"x\": 670.273, \"y\": 364.408},\n",
- " {\"x\": 613.114, \"y\": 288.16},\n",
- " {\"x\": 377.559, \"y\": 238.251},\n",
- " {\"x\": 368.087, \"y\": 185.064},\n",
- " {\"x\": 246.557, \"y\": 167.286},\n",
- " {\"x\": 236.648, \"y\": 285.61},\n",
- " {\"x\": 90.929, \"y\": 326.412}\n",
- " ]\n",
- "}\n"
- ],
+ "source": "polyline_prediction = lb_types.ObjectAnnotation(\n name=\"polyline\",\n confidence=0.5,\n custom_metrics=[\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n value=lb_types.Line(points=[\n lb_types.Point(x=2534.353, y=249.471),\n lb_types.Point(x=2429.492, y=182.092),\n lb_types.Point(x=2294.322, y=221.962),\n lb_types.Point(x=2224.491, y=180.463),\n lb_types.Point(x=2136.123, y=204.716),\n lb_types.Point(x=1712.247, y=173.949),\n lb_types.Point(x=1703.838, y=84.438),\n lb_types.Point(x=1579.772, y=82.61),\n lb_types.Point(x=1583.442, y=167.552),\n lb_types.Point(x=1478.869, y=164.903),\n lb_types.Point(x=1418.941, y=318.149),\n lb_types.Point(x=1243.128, y=400.815),\n lb_types.Point(x=1022.067, y=319.007),\n lb_types.Point(x=892.367, y=379.216),\n lb_types.Point(x=670.273, y=364.408),\n lb_types.Point(x=613.114, y=288.16),\n lb_types.Point(x=377.559, y=238.251),\n lb_types.Point(x=368.087, y=185.064),\n lb_types.Point(x=246.557, y=167.286),\n lb_types.Point(x=236.648, y=285.61),\n lb_types.Point(x=90.929, y=326.412),\n ]),\n)\n\npolyline_prediction_ndjson = {\n \"name\":\n \"polyline\",\n \"confidence\":\n 0.5,\n \"customMetrics\": [\n {\n \"name\": \"iou\",\n \"value\": 0.5\n },\n {\n \"name\": \"f1\",\n \"value\": 0.33\n },\n {\n \"name\": \"precision\",\n \"value\": 0.55\n },\n {\n \"name\": \"recall\",\n \"value\": 0.33\n },\n {\n \"name\": \"tagsCount\",\n \"value\": 43\n },\n {\n \"name\": \"metric_with_a_very_long_name\",\n \"value\": 0.334332\n },\n ],\n \"classifications\": [],\n \"line\": [\n {\n \"x\": 2534.353,\n \"y\": 249.471\n },\n {\n \"x\": 2429.492,\n \"y\": 182.092\n },\n {\n \"x\": 2294.322,\n \"y\": 221.962\n },\n {\n \"x\": 2224.491,\n \"y\": 180.463\n },\n {\n \"x\": 2136.123,\n \"y\": 204.716\n },\n {\n \"x\": 1712.247,\n \"y\": 173.949\n },\n {\n \"x\": 1703.838,\n \"y\": 84.438\n },\n {\n \"x\": 1579.772,\n \"y\": 82.61\n },\n {\n \"x\": 1583.442,\n \"y\": 167.552\n },\n {\n \"x\": 1478.869,\n \"y\": 164.903\n },\n {\n \"x\": 1418.941,\n \"y\": 318.149\n },\n {\n \"x\": 1243.128,\n \"y\": 400.815\n },\n {\n \"x\": 1022.067,\n \"y\": 319.007\n },\n {\n \"x\": 892.367,\n \"y\": 379.216\n },\n {\n \"x\": 670.273,\n \"y\": 364.408\n },\n {\n \"x\": 613.114,\n \"y\": 288.16\n },\n {\n \"x\": 377.559,\n \"y\": 238.251\n },\n {\n \"x\": 368.087,\n \"y\": 185.064\n },\n {\n \"x\": 246.557,\n \"y\": 167.286\n },\n {\n \"x\": 236.648,\n \"y\": 285.61\n },\n {\n \"x\": 90.929,\n \"y\": 326.412\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -726,27 +219,7 @@
},
{
"metadata": {},
- "source": [
- "# send a sample image as batch to the project\n",
- "global_key = \"2560px-Kitano_Street_Kobe01s5s4110.jpeg\"\n",
- "test_img_urls = {\n",
- " \"row_data\": \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n",
- " \"global_key\": global_key\n",
- "}\n",
- "\n",
- "dataset = client.create_dataset(name=\"Custom metrics demo\", iam_integration=None)\n",
- "task = dataset.create_data_rows([test_img_urls])\n",
- "\n",
- "print(f\"Failed data rows: {task.failed_data_rows}\")\n",
- "print(f\"Errors: {task.errors}\")\n",
- "\n",
- "if task.errors:\n",
- " for error in task.errors:\n",
- " if 'Duplicate global key' in error['message'] and dataset.row_count == 0:\n",
- " # If the global key already exists in the workspace the dataset will be created empty, so we can delete it.\n",
- " print(f\"Deleting empty dataset: {dataset}\")\n",
- " dataset.delete()"
- ],
+ "source": "# send a sample image as batch to the project\nglobal_key = \"2560px-Kitano_Street_Kobe01s5s4110.jpeg\"\ntest_img_urls = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n}\n\ndataset = client.create_dataset(name=\"Custom metrics demo\",\n iam_integration=None)\ntask = dataset.create_data_rows([test_img_urls])\n\nprint(f\"Failed data rows: {task.failed_data_rows}\")\nprint(f\"Errors: {task.errors}\")\n\nif task.errors:\n for error in task.errors:\n if (\"Duplicate global key\" in error[\"message\"] and\n dataset.row_count == 0):\n # If the global key already exists in the workspace the dataset will be created empty, so we can delete it.\n print(f\"Deleting empty dataset: {dataset}\")\n dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -761,93 +234,7 @@
},
{
"metadata": {},
- "source": [
- "ontology_builder = lb.OntologyBuilder(\n",
- " classifications=[ # List of Classification objects\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\"),\n",
- " lb.Option(value=\"second_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"free_text\"\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " options=[\n",
- " lb.Option(\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[lb.Option(\"first_sub_radio_answer\")]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- " ),\n",
- " ],\n",
- " tools=[ # List of tools\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.BBOX,\n",
- " name=\"bounding_box\"),\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.BBOX,\n",
- " name=\"bbox_with_radio_subclass\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_sub_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " ]\n",
- " ),\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.POLYGON,\n",
- " name=\"polygon\"),\n",
- " \t lb.Tool(\n",
- " tool=lb.Tool.Type.POINT,\n",
- " name=\"point\"),\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.LINE,\n",
- " name=\"polyline\")]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Image Prediction Import Demo\",\n",
- " ontology_builder.asdict(),\n",
- " media_type=lb.MediaType.Image\n",
- " )"
- ],
+ "source": "ontology_builder = lb.OntologyBuilder(\n classifications=[ # List of Classification objects\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_question\",\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_question\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n ),\n lb.Classification(class_type=lb.Classification.Type.TEXT,\n name=\"free_text\"),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n options=[\n lb.Option(\n \"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(\"first_sub_radio_answer\")],\n )\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n ],\n tools=[ # List of tools\n lb.Tool(tool=lb.Tool.Type.BBOX, name=\"bounding_box\"),\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"bbox_with_radio_subclass\",\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(value=\"first_sub_radio_answer\")],\n ),\n ],\n ),\n lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"polygon\"),\n lb.Tool(tool=lb.Tool.Type.POINT, name=\"point\"),\n lb.Tool(tool=lb.Tool.Type.LINE, name=\"polyline\"),\n ],\n)\n\nontology = client.create_ontology(\n \"Image Prediction Import Demo\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -861,13 +248,7 @@
},
{
"metadata": {},
- "source": [
- "# create Model\n",
- "model = client.create_model(name=\"model_with_aggregated_custom_metrics\" + str(uuid.uuid4()),\n",
- " ontology_id=ontology.uid)\n",
- "# create Model Run\n",
- "model_run = model.create_model_run(\"iteration 1\")"
- ],
+ "source": "# create Model\nmodel = client.create_model(\n name=\"model_with_aggregated_custom_metrics\" + str(uuid.uuid4()),\n ontology_id=ontology.uid,\n)\n# create Model Run\nmodel_run = model.create_model_run(\"iteration 1\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -881,9 +262,7 @@
},
{
"metadata": {},
- "source": [
- "model_run.upsert_data_rows(global_keys=[global_key])"
- ],
+ "source": "model_run.upsert_data_rows(global_keys=[global_key])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -901,27 +280,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Label for predictions\n",
- "label_prediction = []\n",
- "label_prediction.append(lb_types.Label(\n",
- " data=lb_types.ImageData(global_key=global_key),\n",
- " annotations = [\n",
- " radio_prediction,\n",
- " nested_radio_prediction,\n",
- " checklist_prediction,\n",
- " nested_checklist_prediction,\n",
- " bbox_prediction,\n",
- " bbox_with_radio_subclass_prediction,\n",
- " polyline_prediction,\n",
- " polygon_prediction,\n",
- " point_prediction,\n",
- " text_annotation\n",
- "\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "# Create a Label for predictions\nlabel_prediction = []\nlabel_prediction.append(\n lb_types.Label(\n data=lb_types.ImageData(global_key=global_key),\n annotations=[\n radio_prediction,\n nested_radio_prediction,\n checklist_prediction,\n nested_checklist_prediction,\n bbox_prediction,\n bbox_with_radio_subclass_prediction,\n polyline_prediction,\n polygon_prediction,\n point_prediction,\n text_annotation,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -935,26 +294,7 @@
},
{
"metadata": {},
- "source": [
- "label_prediction_ndjson = []\n",
- "\n",
- "for annot in [\n",
- " radio_prediction_ndjson,\n",
- " checklist_prediction_ndjson,\n",
- " bbox_prediction_ndjson,\n",
- " bbox_with_radio_subclass_prediction_ndjson,\n",
- " polygon_prediction_ndjson,\n",
- " point_prediction_ndjson,\n",
- " polyline_prediction_ndjson,\n",
- " text_annotation_ndjson,\n",
- " nested_radio_prediction_ndjson,\n",
- " nested_checklist_prediction_ndjson\n",
- "]:\n",
- " annot.update({\n",
- " \"dataRow\": {\"globalKey\": global_key}\n",
- " })\n",
- " label_prediction_ndjson.append(annot)"
- ],
+ "source": "label_prediction_ndjson = []\n\nfor annot in [\n radio_prediction_ndjson,\n checklist_prediction_ndjson,\n bbox_prediction_ndjson,\n bbox_with_radio_subclass_prediction_ndjson,\n polygon_prediction_ndjson,\n point_prediction_ndjson,\n polyline_prediction_ndjson,\n text_annotation_ndjson,\n nested_radio_prediction_ndjson,\n nested_checklist_prediction_ndjson,\n]:\n annot.update({\"dataRow\": {\"globalKey\": global_key}})\n label_prediction_ndjson.append(annot)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -968,15 +308,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload the prediction label to the Model Run\n",
- "upload_job_prediction = model_run.add_predictions(\n",
- " name=\"prediction_upload_job\"+str(uuid.uuid4()),\n",
- " predictions=label_prediction)\n",
- "\n",
- "# Errors will appear for prediction uploads that failed.\n",
- "print(\"Errors:\", upload_job_prediction.errors)"
- ],
+ "source": "# Upload the prediction label to the Model Run\nupload_job_prediction = model_run.add_predictions(\n name=\"prediction_upload_job\" + str(uuid.uuid4()),\n predictions=label_prediction,\n)\n\n# Errors will appear for prediction uploads that failed.\nprint(\"Errors:\", upload_job_prediction.errors)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -999,12 +331,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Labelbox project\n",
- "project = client.create_project(name=\"image_prediction_many_kinds\",\n",
- " media_type=lb.MediaType.Image)\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "# Create a Labelbox project\nproject = client.create_project(name=\"image_prediction_many_kinds\",\n media_type=lb.MediaType.Image)\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1018,13 +345,7 @@
},
{
"metadata": {},
- "source": [
- "project.create_batch(\n",
- " \"batch_predictions_demo\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")"
- ],
+ "source": "project.create_batch(\n \"batch_predictions_demo\", # Each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # Paginated collection of data row objects, list of data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1038,112 +359,7 @@
},
{
"metadata": {},
- "source": [
- "########### Annotations ###########\n",
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question\",\n",
- " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n",
- " name=\"second_radio_answer\"))\n",
- ")\n",
- "\n",
- "nested_radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "\n",
- "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\"\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "\n",
- "checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question\",\n",
- " value=lb_types.Checklist(answer=[\n",
- " lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n",
- " lb_types.ClassificationAnswer(name=\"second_checklist_answer\")\n",
- " ])\n",
- ")\n",
- "\n",
- "bbox_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"bounding_box\",\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=1690, y=977), # x = left, y = top\n",
- " end=lb_types.Point(x=1915, y=1307), # x= left + width , y = top + height\n",
- " )\n",
- ")\n",
- "\n",
- "bbox_with_radio_subclass_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"bbox_with_radio_subclass\",\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=541, y=933), # x = left, y = top\n",
- " end=lb_types.Point(x=871, y=1124), # x= left + width , y = top + height\n",
- " ),\n",
- " classifications=[\n",
- " \tlb_types.ClassificationAnnotation(\n",
- " \tname=\"sub_radio_question\",\n",
- " \t\tvalue=lb_types.Radio(answer=lb_types.ClassificationAnswer(name=\"first_sub_radio_answer\", confidence=0.5))\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "polygon_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"polygon\",\n",
- " value=lb_types.Polygon(\n",
- " points=[lb_types.Point(x=1489.581,y=183.934), lb_types.Point(x=2278.306,y=256.885), lb_types.Point(x=2428.197,y=200.437), lb_types.Point(x=2560.0,y=335.419),\n",
- " lb_types.Point(x=2557.386,y=503.165), lb_types.Point(x=2320.596,y=503.103), lb_types.Point(x=2156.083, y=628.943), lb_types.Point(x=2161.111,y=785.519),\n",
- " lb_types.Point(x=2002.115, y=894.647), lb_types.Point(x=1838.456,y=877.874), lb_types.Point(x=1436.53,y=874.636), lb_types.Point(x=1411.403,y=758.579),\n",
- " lb_types.Point(x=1353.853,y=751.74), lb_types.Point(x=1345.264, y=453.461), lb_types.Point(x=1426.011,y=421.129)]\n",
- " ),\n",
- ")\n",
- "\n",
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"free_text\",\n",
- " value=lb_types.Text(answer=\"sample text\")\n",
- ")\n",
- "\n",
- "point_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"point\",\n",
- " value = lb_types.Point(x=1166.606, y=1441.768),\n",
- ")\n",
- "\n",
- "polyline_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"polyline\",\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=2534.353, y=249.471), lb_types.Point(x=2429.492, y=182.092), lb_types.Point(x=2294.322, y=221.962), lb_types.Point(x=2224.491, y=180.463), lb_types.Point(x=2136.123, y=204.716),\n",
- " lb_types.Point(x=1712.247, y=173.949), lb_types.Point(x=1703.838, y=84.438), lb_types.Point(x=1579.772, y=82.61), lb_types.Point(x=1583.442, y=167.552),\n",
- " lb_types.Point(x=1478.869, y=164.903), lb_types.Point(x=1418.941, y=318.149), lb_types.Point(x=1243.128, y=400.815), lb_types.Point(x=1022.067, y=319.007),\n",
- " lb_types.Point(x=892.367, y=379.216), lb_types.Point(x=670.273, y=364.408), lb_types.Point(x=613.114, y=288.16), lb_types.Point(x=377.559, y=238.251),\n",
- " lb_types.Point(x=368.087, y=185.064), lb_types.Point(x=246.557, y=167.286), lb_types.Point(x=236.648, y=285.61), lb_types.Point(x=90.929, y=326.412)]\n",
- " )\n",
- ")"
- ],
+ "source": "########### Annotations ###########\nradio_annotation = lb_types.ClassificationAnnotation(\n name=\"radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"second_radio_answer\")),\n)\n\nnested_radio_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n)\n\nnested_checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n )\n ]),\n)\n\nchecklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n ]),\n)\n\nbbox_annotation = lb_types.ObjectAnnotation(\n name=\"bounding_box\",\n value=lb_types.Rectangle(\n start=lb_types.Point(x=1690, y=977), # x = left, y = top\n end=lb_types.Point(x=1915,\n y=1307), # x= left + width , y = top + height\n ),\n)\n\nbbox_with_radio_subclass_annotation = lb_types.ObjectAnnotation(\n name=\"bbox_with_radio_subclass\",\n value=lb_types.Rectangle(\n start=lb_types.Point(x=541, y=933), # x = left, y = top\n end=lb_types.Point(x=871, y=1124), # x= left + width , y = top + height\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\", confidence=0.5)),\n )\n ],\n)\n\npolygon_annotation = lb_types.ObjectAnnotation(\n name=\"polygon\",\n value=lb_types.Polygon(points=[\n lb_types.Point(x=1489.581, y=183.934),\n lb_types.Point(x=2278.306, y=256.885),\n lb_types.Point(x=2428.197, y=200.437),\n lb_types.Point(x=2560.0, y=335.419),\n lb_types.Point(x=2557.386, y=503.165),\n lb_types.Point(x=2320.596, y=503.103),\n lb_types.Point(x=2156.083, y=628.943),\n lb_types.Point(x=2161.111, y=785.519),\n lb_types.Point(x=2002.115, y=894.647),\n lb_types.Point(x=1838.456, y=877.874),\n lb_types.Point(x=1436.53, y=874.636),\n lb_types.Point(x=1411.403, y=758.579),\n lb_types.Point(x=1353.853, y=751.74),\n lb_types.Point(x=1345.264, y=453.461),\n lb_types.Point(x=1426.011, y=421.129),\n ]),\n)\n\ntext_annotation = lb_types.ClassificationAnnotation(\n name=\"free_text\", value=lb_types.Text(answer=\"sample text\"))\n\npoint_annotation = lb_types.ObjectAnnotation(\n name=\"point\",\n value=lb_types.Point(x=1166.606, y=1441.768),\n)\n\npolyline_annotation = lb_types.ObjectAnnotation(\n name=\"polyline\",\n value=lb_types.Line(points=[\n lb_types.Point(x=2534.353, y=249.471),\n lb_types.Point(x=2429.492, y=182.092),\n lb_types.Point(x=2294.322, y=221.962),\n lb_types.Point(x=2224.491, y=180.463),\n lb_types.Point(x=2136.123, y=204.716),\n lb_types.Point(x=1712.247, y=173.949),\n lb_types.Point(x=1703.838, y=84.438),\n lb_types.Point(x=1579.772, y=82.61),\n lb_types.Point(x=1583.442, y=167.552),\n lb_types.Point(x=1478.869, y=164.903),\n lb_types.Point(x=1418.941, y=318.149),\n lb_types.Point(x=1243.128, y=400.815),\n lb_types.Point(x=1022.067, y=319.007),\n lb_types.Point(x=892.367, y=379.216),\n lb_types.Point(x=670.273, y=364.408),\n lb_types.Point(x=613.114, y=288.16),\n lb_types.Point(x=377.559, y=238.251),\n lb_types.Point(x=368.087, y=185.064),\n lb_types.Point(x=246.557, y=167.286),\n lb_types.Point(x=236.648, y=285.61),\n lb_types.Point(x=90.929, y=326.412),\n ]),\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1157,26 +373,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Label object by identifying the applicable data row in Labelbox and providing a list of annotations\n",
- "label = []\n",
- "annotations = [\n",
- " radio_annotation,\n",
- " nested_radio_annotation,\n",
- " checklist_annotation,\n",
- " nested_checklist_annotation,\n",
- " text_annotation,\n",
- " bbox_annotation,\n",
- " bbox_with_radio_subclass_annotation,\n",
- " polygon_annotation,\n",
- " point_annotation,\n",
- " polyline_annotation\n",
- "]\n",
- "label.append(\n",
- " lb_types.Label(\n",
- " data=lb_types.ImageData(global_key=global_key),\n",
- " annotations=annotations))"
- ],
+ "source": "# Create a Label object by identifying the applicable data row in Labelbox and providing a list of annotations\nlabel = []\nannotations = [\n radio_annotation,\n nested_radio_annotation,\n checklist_annotation,\n nested_checklist_annotation,\n text_annotation,\n bbox_annotation,\n bbox_with_radio_subclass_annotation,\n polygon_annotation,\n point_annotation,\n polyline_annotation,\n]\nlabel.append(\n lb_types.Label(data=lb_types.ImageData(global_key=global_key),\n annotations=annotations))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1190,18 +387,7 @@
},
{
"metadata": {},
- "source": [
- "upload_job_annotation = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"annotation_import_\" + str(uuid.uuid4()),\n",
- " labels=label)\n",
- "\n",
- "upload_job_annotation.wait_until_done()\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_annotation.errors)\n",
- "print(\"Status of uploads: \", upload_job_annotation.statuses)"
- ],
+ "source": "upload_job_annotation = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"annotation_import_\" + str(uuid.uuid4()),\n labels=label,\n)\n\nupload_job_annotation.wait_until_done()\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_annotation.errors)\nprint(\"Status of uploads: \", upload_job_annotation.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1215,9 +401,7 @@
},
{
"metadata": {},
- "source": [
- "model_run.upsert_labels(project_id=project.uid)"
- ],
+ "source": "model_run.upsert_labels(project_id=project.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1231,10 +415,7 @@
},
{
"metadata": {},
- "source": [
- "# project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/model_experiments/model_predictions_to_project.ipynb b/examples/model_experiments/model_predictions_to_project.ipynb
index ed7ebc3d4..a1560feec 100644
--- a/examples/model_experiments/model_predictions_to_project.ipynb
+++ b/examples/model_experiments/model_predictions_to_project.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -37,21 +37,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import labelbox.types as lb_types\n",
- "from labelbox.schema.conflict_resolution_strategy import ConflictResolutionStrategy\n",
- "import uuid"
- ],
+ "source": "import labelbox as lb\nimport labelbox.types as lb_types\nfrom labelbox.schema.conflict_resolution_strategy import (\n ConflictResolutionStrategy,)\nimport uuid",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -66,12 +59,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your API key\n",
- "API_KEY = \"\"\n",
- "# To get your API key go to: Workspace settings -> API -> Create API Key\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your API key\nAPI_KEY = \"\"\n# To get your API key go to: Workspace settings -> API -> Create API Key\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -103,29 +91,7 @@
},
{
"metadata": {},
- "source": [
- "classification_features = [\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"Demo Feature\",\n",
- " options=[\n",
- " lb.Option(value=\"option 1\"),\n",
- " lb.Option(value=\"option 2\")\n",
- " ]\n",
- " )\n",
- "]\n",
- "\n",
- "ontology_builder = lb.OntologyBuilder(\n",
- " tools=[],\n",
- " classifications=classification_features\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\n",
- " \"Demo Ontology\",\n",
- " ontology_builder.asdict(),\n",
- " media_type=lb.MediaType.Image\n",
- ")"
- ],
+ "source": "classification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Demo Feature\",\n options=[lb.Option(value=\"option 1\"),\n lb.Option(value=\"option 2\")],\n )\n]\n\nontology_builder = lb.OntologyBuilder(tools=[],\n classifications=classification_features)\n\nontology = client.create_ontology(\"Demo Ontology\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -139,12 +105,7 @@
},
{
"metadata": {},
- "source": [
- "model = client.create_model(\n",
- " name = f\"Model Experiment Demo {str(uuid.uuid4())}\",\n",
- " ontology_id=ontology.uid\n",
- ")"
- ],
+ "source": "model = client.create_model(name=f\"Model Experiment Demo {str(uuid.uuid4())}\",\n ontology_id=ontology.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -167,31 +128,7 @@
},
{
"metadata": {},
- "source": [
- "# send a sample image as data row for a dataset\n",
- "global_key = \"2560px-Kitano_Street_Kobe01s5s4110\"\n",
- "\n",
- "test_img_url = {\n",
- " \"row_data\":\n",
- " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n",
- " \"global_key\":\n",
- " global_key\n",
- "}\n",
- "\n",
- "dataset = client.create_dataset(name=\"foundry-demo-dataset\")\n",
- "task = dataset.create_data_rows([test_img_url])\n",
- "task.wait_till_done()\n",
- "\n",
- "print(f\"Errors: {task.errors}\")\n",
- "print(f\"Failed data rows: {task.failed_data_rows}\")\n",
- "\n",
- "if task.errors:\n",
- " for error in task.errors:\n",
- " if 'Duplicate global key' in error['message'] and dataset.row_count == 0:\n",
- " # If the global key already exists in the workspace the dataset will be created empty, so we can delete it.\n",
- " print(f\"Deleting empty dataset: {dataset}\")\n",
- " dataset.delete()"
- ],
+ "source": "# send a sample image as data row for a dataset\nglobal_key = \"2560px-Kitano_Street_Kobe01s5s4110\"\n\ntest_img_url = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n}\n\ndataset = client.create_dataset(name=\"foundry-demo-dataset\")\ntask = dataset.create_data_rows([test_img_url])\ntask.wait_till_done()\n\nprint(f\"Errors: {task.errors}\")\nprint(f\"Failed data rows: {task.failed_data_rows}\")\n\nif task.errors:\n for error in task.errors:\n if (\"Duplicate global key\" in error[\"message\"] and\n dataset.row_count == 0):\n # If the global key already exists in the workspace the dataset will be created empty, so we can delete it.\n print(f\"Deleting empty dataset: {dataset}\")\n dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -205,20 +142,14 @@
},
{
"metadata": {},
- "source": [
- "model_run_name = f\"Model Run Demo {str(uuid.uuid4())}\"\n",
- "\n",
- "model_run = model.create_model_run(name=model_run_name)"
- ],
+ "source": "model_run_name = f\"Model Run Demo {str(uuid.uuid4())}\"\n\nmodel_run = model.create_model_run(name=model_run_name)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "model_run.upsert_data_rows(global_keys=[global_key])"
- ],
+ "source": "model_run.upsert_data_rows(global_keys=[global_key])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -233,29 +164,7 @@
},
{
"metadata": {},
- "source": [
- "checklist_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"Demo Feature\",\n",
- " value=lb_types.Checklist(answer = [lb_types.ClassificationAnswer(name = \"option 1\", confidence=0.5)])\n",
- ")\n",
- "\n",
- "# Create prediction label\n",
- "label_prediction = [\n",
- " lb_types.Label(\n",
- " data = lb_types.ImageData(global_key=global_key),\n",
- " annotations = [checklist_prediction]\n",
- " )\n",
- "]\n",
- "\n",
- "# Upload the prediction label to the Model Run\n",
- "upload_job_prediction = model_run.add_predictions(\n",
- " name=\"prediction_upload_job\"+str(uuid.uuid4()),\n",
- " predictions=label_prediction)\n",
- "\n",
- "# Errors will appear for prediction uploads that failed.\n",
- "print(\"Errors:\", upload_job_prediction.errors)\n",
- "print(\"Status of uploads: \", upload_job_prediction.statuses)"
- ],
+ "source": "checklist_prediction = lb_types.ClassificationAnnotation(\n name=\"Demo Feature\",\n value=lb_types.Checklist(\n answer=[lb_types.ClassificationAnswer(name=\"option 1\", confidence=0.5)\n ]),\n)\n\n# Create prediction label\nlabel_prediction = [\n lb_types.Label(\n data=lb_types.ImageData(global_key=global_key),\n annotations=[checklist_prediction],\n )\n]\n\n# Upload the prediction label to the Model Run\nupload_job_prediction = model_run.add_predictions(\n name=\"prediction_upload_job\" + str(uuid.uuid4()),\n predictions=label_prediction,\n)\n\n# Errors will appear for prediction uploads that failed.\nprint(\"Errors:\", upload_job_prediction.errors)\nprint(\"Status of uploads: \", upload_job_prediction.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -277,23 +186,14 @@
},
{
"metadata": {},
- "source": [
- "# Create a new project\n",
- "project = client.create_project(\n",
- " name=\"Model Run Import Demo Project\",\n",
- " media_type=lb.MediaType.Image\n",
- ")"
- ],
+ "source": "# Create a new project\nproject = client.create_project(name=\"Model Run Import Demo Project\",\n media_type=lb.MediaType.Image)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Setup Ontology\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "# Setup Ontology\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -308,16 +208,7 @@
},
{
"metadata": {},
- "source": [
- "# Get ontology dictionary to obtain featureSchemaIds\n",
- "ontology_normalized = ontology.normalized\n",
- "\n",
- "PREDICTIONS_ONTOLOGY_MAPPING = {\n",
- " ontology_normalized[\"classifications\"][0][\"featureSchemaId\"]:ontology_normalized[\"classifications\"][0][\"featureSchemaId\"], # Classification featureSchemaID\n",
- " ontology_normalized[\"classifications\"][0][\"options\"][0][\"featureSchemaId\"]:ontology_normalized[\"classifications\"][0][\"options\"][0][\"featureSchemaId\"], # Different Classification Answer featureSchemaIDs\n",
- " ontology_normalized[\"classifications\"][0][\"options\"][1][\"featureSchemaId\"]:ontology_normalized[\"classifications\"][0][\"options\"][1][\"featureSchemaId\"]\n",
- "}"
- ],
+ "source": "# Get ontology dictionary to obtain featureSchemaIds\nontology_normalized = ontology.normalized\n\nPREDICTIONS_ONTOLOGY_MAPPING = {\n ontology_normalized[\"classifications\"][0][\"featureSchemaId\"]:\n ontology_normalized[\"classifications\"][0]\n [\"featureSchemaId\"], # Classification featureSchemaID\n ontology_normalized[\"classifications\"][0][\"options\"][0][\"featureSchemaId\"]:\n ontology_normalized[\"classifications\"][0][\"options\"][0]\n [\"featureSchemaId\"], # Different Classification Answer featureSchemaIDs\n ontology_normalized[\"classifications\"][0][\"options\"][1][\"featureSchemaId\"]:\n ontology_normalized[\"classifications\"][0][\"options\"][1]\n [\"featureSchemaId\"],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -356,31 +247,7 @@
},
{
"metadata": {},
- "source": [
- "send_to_annotations_params = {\n",
- " \"predictions_ontology_mapping\": PREDICTIONS_ONTOLOGY_MAPPING,\n",
- " \"exclude_data_rows_in_project\": False,\n",
- " \"override_existing_annotations_rule\": ConflictResolutionStrategy.OverrideWithPredictions,\n",
- " \"batch_priority\": 5,\n",
- "}\n",
- "\n",
- "# Send the predictions as pre-labels\n",
- "queue_id = [queue.uid for queue in project.task_queues() if queue.queue_type == \"INITIAL_LABELING_QUEUE\" ][0]\n",
- "\n",
- "task = model_run.send_to_annotate_from_model(\n",
- " destination_project_id=project.uid,\n",
- " task_queue_id=queue_id, # ID of workflow task, set ID to None if you want to convert pre-labels to ground truths .\n",
- " batch_name=\"Prediction Import Demo Batch\",\n",
- " data_rows=lb.GlobalKeys(\n",
- " [global_key] # Provide a list of global keys from foundry app task\n",
- " ),\n",
- " params=send_to_annotations_params\n",
- " )\n",
- "\n",
- "task.wait_till_done()\n",
- "\n",
- "print(f\"Errors: {task.errors}\")"
- ],
+ "source": "send_to_annotations_params = {\n \"predictions_ontology_mapping\":\n PREDICTIONS_ONTOLOGY_MAPPING,\n \"exclude_data_rows_in_project\":\n False,\n \"override_existing_annotations_rule\":\n ConflictResolutionStrategy.OverrideWithPredictions,\n \"batch_priority\":\n 5,\n}\n\n# Send the predictions as pre-labels\nqueue_id = [\n queue.uid\n for queue in project.task_queues()\n if queue.queue_type == \"INITIAL_LABELING_QUEUE\"\n][0]\n\ntask = model_run.send_to_annotate_from_model(\n destination_project_id=project.uid,\n task_queue_id=\n queue_id, # ID of workflow task, set ID to None if you want to convert pre-labels to ground truths .\n batch_name=\"Prediction Import Demo Batch\",\n data_rows=lb.GlobalKeys(\n [global_key] # Provide a list of global keys from foundry app task\n ),\n params=send_to_annotations_params,\n)\n\ntask.wait_till_done()\n\nprint(f\"Errors: {task.errors}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -394,11 +261,7 @@
},
{
"metadata": {},
- "source": [
- "#project.delete()\n",
- "#dataset.delete()\n",
- "#model_run.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()\n# model_run.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/model_experiments/model_slices.ipynb b/examples/model_experiments/model_slices.ipynb
index 3fdd61110..a91709fa0 100644
--- a/examples/model_experiments/model_slices.ipynb
+++ b/examples/model_experiments/model_slices.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -42,19 +42,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install labelbox"
- ],
+ "source": "%pip install labelbox",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import uuid"
- ],
+ "source": "import labelbox as lb\nimport uuid",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -69,12 +64,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your API key\n",
- "API_KEY = \"\"\n",
- "# To get your API key go to: Workspace settings -> API -> Create API Key\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your API key\nAPI_KEY = \"\"\n# To get your API key go to: Workspace settings -> API -> Create API Key\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -106,30 +96,7 @@
},
{
"metadata": {},
- "source": [
- "classification_features = [\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"Quality Issues\",\n",
- " options=[\n",
- " lb.Option(value=\"blurry\", label=\"Blurry\"),\n",
- " lb.Option(value=\"distorted\", label=\"Distorted\")\n",
- " ]\n",
- " )\n",
- "\n",
- "]\n",
- "\n",
- "ontology_builder = lb.OntologyBuilder(\n",
- " tools=[],\n",
- " classifications=classification_features\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\n",
- " \"Ontology from new features\",\n",
- " ontology_builder.asdict(),\n",
- " media_type=lb.MediaType.Image\n",
- ")"
- ],
+ "source": "classification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\nontology_builder = lb.OntologyBuilder(tools=[],\n classifications=classification_features)\n\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -143,12 +110,7 @@
},
{
"metadata": {},
- "source": [
- "model = client.create_model(\n",
- " name=\"Model Slice Demo\",\n",
- " ontology_id=ontology.uid\n",
- ")"
- ],
+ "source": "model = client.create_model(name=\"Model Slice Demo\", ontology_id=ontology.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -171,24 +133,7 @@
},
{
"metadata": {},
- "source": [
- "# send a sample image as data row for a dataset\n",
- "global_key = str(uuid.uuid4())\n",
- "\n",
- "test_img_url = {\n",
- " \"row_data\":\n",
- " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n",
- " \"global_key\":\n",
- " global_key\n",
- "}\n",
- "\n",
- "dataset = client.create_dataset(name=\"foundry-demo-dataset\")\n",
- "task = dataset.create_data_rows([test_img_url])\n",
- "task.wait_till_done()\n",
- "\n",
- "print(f\"Errors: {task.errors}\")\n",
- "print(f\"Failed data rows: {task.failed_data_rows}\")"
- ],
+ "source": "# send a sample image as data row for a dataset\nglobal_key = str(uuid.uuid4())\n\ntest_img_url = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n}\n\ndataset = client.create_dataset(name=\"foundry-demo-dataset\")\ntask = dataset.create_data_rows([test_img_url])\ntask.wait_till_done()\n\nprint(f\"Errors: {task.errors}\")\nprint(f\"Failed data rows: {task.failed_data_rows}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -202,23 +147,14 @@
},
{
"metadata": {},
- "source": [
- "model_run_name = \"Model Slice Demo\"\n",
- "example_config = {\n",
- " \"learning_rate\": 0.001,\n",
- " \"batch_size\": 32,\n",
- "}\n",
- "model_run = model.create_model_run(name=model_run_name, config=example_config)"
- ],
+ "source": "model_run_name = \"Model Slice Demo\"\nexample_config = {\n \"learning_rate\": 0.001,\n \"batch_size\": 32,\n}\nmodel_run = model.create_model_run(name=model_run_name, config=example_config)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "model_run.upsert_data_rows(global_keys=[global_key])"
- ],
+ "source": "model_run.upsert_data_rows(global_keys=[global_key])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -244,9 +180,7 @@
},
{
"metadata": {},
- "source": [
- "SLICE_ID = \"\""
- ],
+ "source": "SLICE_ID = \"\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -260,9 +194,7 @@
},
{
"metadata": {},
- "source": [
- "model_slice = client.get_model_slice(SLICE_ID)"
- ],
+ "source": "model_slice = client.get_model_slice(SLICE_ID)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -276,12 +208,7 @@
},
{
"metadata": {},
- "source": [
- "data_row_ids = model_slice.get_data_row_ids(model_run.uid)\n",
- "\n",
- "for data_row_id in data_row_ids:\n",
- " print(data_row_id)"
- ],
+ "source": "data_row_ids = model_slice.get_data_row_ids(model_run.uid)\n\nfor data_row_id in data_row_ids:\n print(data_row_id)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -295,12 +222,7 @@
},
{
"metadata": {},
- "source": [
- "data_rows = model_slice.get_data_row_identifiers(model_run.uid)\n",
- "\n",
- "for data_row in data_rows:\n",
- " print(data_row)"
- ],
+ "source": "data_rows = model_slice.get_data_row_identifiers(model_run.uid)\n\nfor data_row in data_rows:\n print(data_row)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -314,22 +236,7 @@
},
{
"metadata": {},
- "source": [
- "# name (str)\n",
- "model_slice.name\n",
- "\n",
- "# description (str)\n",
- "model_slice.description\n",
- "\n",
- "# updated at (datetime)\n",
- "model_slice.updated_at\n",
- "\n",
- "# created at (datetime)\n",
- "model_slice.created_at\n",
- "\n",
- "# filter (list[dict])\n",
- "model_slice.filter"
- ],
+ "source": "# name (str)\nmodel_slice.name\n\n# description (str)\nmodel_slice.description\n\n# updated at (datetime)\nmodel_slice.updated_at\n\n# created at (datetime)\nmodel_slice.created_at\n\n# filter (list[dict])\nmodel_slice.filter",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/prediction_upload/conversational_LLM_predictions.ipynb b/examples/prediction_upload/conversational_LLM_predictions.ipynb
index fdeed6417..be9878401 100644
--- a/examples/prediction_upload/conversational_LLM_predictions.ipynb
+++ b/examples/prediction_upload/conversational_LLM_predictions.ipynb
@@ -6,10 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | \n",
- "\n"
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -21,9 +20,7 @@
"src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\">\n",
"\n",
"\n",
- "\n",
"\n",
- "\n",
" \n",
" | "
@@ -41,9 +38,7 @@
},
{
"metadata": {},
- "source": [
- "!pip install \"labelbox[data]\" -q"
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -57,11 +52,7 @@
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import labelbox.types as lb_types\n",
- "import uuid"
- ],
+ "source": "import labelbox as lb\nimport labelbox.types as lb_types\nimport uuid",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -75,10 +66,7 @@
},
{
"metadata": {},
- "source": [
- "API_KEY = \"\"\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "API_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -99,27 +87,7 @@
},
{
"metadata": {},
- "source": [
- "ner_prediction = lb_types.ObjectAnnotation(\n",
- " name=\"ner\",\n",
- " confidence=0.5,\n",
- " value=lb_types.ConversationEntity(\n",
- " start=0,\n",
- " end=8,\n",
- " message_id=\"message-1\"\n",
- " )\n",
- ")\n",
- "\n",
- "ner_prediction_ndjson = {\n",
- " \"name\": \"ner\",\n",
- " \"confidence\": 0.5,\n",
- " \"location\": {\n",
- " \"start\": 0,\n",
- " \"end\": 8\n",
- " },\n",
- " \"messageId\": \"message-1\"\n",
- " }"
- ],
+ "source": "ner_prediction = lb_types.ObjectAnnotation(\n name=\"ner\",\n confidence=0.5,\n value=lb_types.ConversationEntity(start=0, end=8, message_id=\"message-1\"),\n)\n\nner_prediction_ndjson = {\n \"name\": \"ner\",\n \"confidence\": 0.5,\n \"location\": {\n \"start\": 0,\n \"end\": 8\n },\n \"messageId\": \"message-1\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -133,22 +101,7 @@
},
{
"metadata": {},
- "source": [
- "radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"Choose the best response\",\n",
- " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n",
- " name=\"Response B\", confidence=0.5)))\n",
- "\n",
- "\n",
- "\n",
- "radio_prediction_ndjson = {\n",
- " \"name\": \"Choose the best response\",\n",
- " \"answer\": {\n",
- " \"name\": \"Response B\",\n",
- " \"confidence\": 0.5\n",
- " }\n",
- "}\n"
- ],
+ "source": "radio_prediction = lb_types.ClassificationAnnotation(\n name=\"Choose the best response\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(name=\"Response B\",\n confidence=0.5)),\n)\n\nradio_prediction_ndjson = {\n \"name\": \"Choose the best response\",\n \"answer\": {\n \"name\": \"Response B\",\n \"confidence\": 0.5\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -162,20 +115,7 @@
},
{
"metadata": {},
- "source": [
- "text_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"Provide a reason for your choice\",\n",
- " value=lb_types.Text(answer=\"the answer to the text questions right here\", confidence=0.5)\n",
- ")\n",
- "\n",
- "\n",
- "text_prediction_ndjson = {\n",
- " \"name\": \"Provide a reason for your choice\",\n",
- " \"answer\": \"This is the more concise answer\",\n",
- " \"confidence\": 0.5\n",
- "\n",
- "}"
- ],
+ "source": "text_prediction = lb_types.ClassificationAnnotation(\n name=\"Provide a reason for your choice\",\n value=lb_types.Text(answer=\"the answer to the text questions right here\",\n confidence=0.5),\n)\n\ntext_prediction_ndjson = {\n \"name\": \"Provide a reason for your choice\",\n \"answer\": \"This is the more concise answer\",\n \"confidence\": 0.5,\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -189,34 +129,7 @@
},
{
"metadata": {},
- "source": [
- "checklist_prediction= lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_convo\", # must match your ontology feature\"s name\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\",\n",
- " confidence=0.5\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\",\n",
- " confidence=0.5\n",
- " )\n",
- " ]\n",
- " ),\n",
- " message_id=\"message-1\" # Message specific annotation\n",
- " )\n",
- "\n",
- "\n",
- "checklist_prediction_ndjson = {\n",
- " \"name\": \"checklist_convo\",\n",
- " \"answers\": [\n",
- " {\"name\": \"first_checklist_answer\",\"confidence\":0.5},\n",
- " {\"name\": \"second_checklist_answer\",\"confidence\":0.5}\n",
- " ],\n",
- " \"messageId\": \"message-1\"\n",
- "}"
- ],
+ "source": "checklist_prediction = lb_types.ClassificationAnnotation(\n name=\"checklist_convo\", # must match your ontology feature\"s name\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\",\n confidence=0.5),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\",\n confidence=0.5),\n ]),\n message_id=\"message-1\", # Message specific annotation\n)\n\nchecklist_prediction_ndjson = {\n \"name\": \"checklist_convo\",\n \"answers\": [\n {\n \"name\": \"first_checklist_answer\",\n \"confidence\": 0.5\n },\n {\n \"name\": \"second_checklist_answer\",\n \"confidence\": 0.5\n },\n ],\n \"messageId\": \"message-1\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -230,83 +143,7 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "# Message based\n",
- "nested_checklist_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " message_id=\"message-1\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " confidence=0.5, # Confidence scores should be added to the answer\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\",\n",
- " confidence=0.5 # Confidence scores should be added to the answer\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "# Message based\n",
- "nested_checklist_prediction_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"messageId\": \"message-1\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"confidence\": 0.5, # Confidence scores should be added to the answer\n",
- " \"classifications\" : [\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_sub_checklist_answer\",\n",
- " \"confidence\": 0.5, # Confidence scores should be added to the answer\n",
- " }\n",
- " }\n",
- " ]\n",
- " }]\n",
- "}\n",
- "# Global\n",
- "nested_radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " confidence=0.5, # Confidence scores should be added to the answer\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\",\n",
- " confidence=0.5 # Confidence scores should be added to the answer\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "#Global\n",
- "nested_radio_prediction_ndjson = {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\",\n",
- " \"confidence\": 0.5,\n",
- " \"classifications\": [{\n",
- " \"name\":\"sub_radio_question\",\n",
- " \"answer\": { \"name\" : \"first_sub_radio_answer\",\n",
- " \"confidence\": 0.5}\n",
- " }]\n",
- " }\n",
- "}\n",
- "\n"
- ],
+ "source": "# Message based\nnested_checklist_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n message_id=\"message-1\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n confidence=0.5, # Confidence scores should be added to the answer\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\",\n confidence=\n 0.5, # Confidence scores should be added to the answer\n )\n ]),\n )\n ],\n )\n ]),\n)\n# Message based\nnested_checklist_prediction_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"messageId\":\n \"message-1\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"confidence\":\n 0.5, # Confidence scores should be added to the answer\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\",\n \"confidence\":\n 0.5, # Confidence scores should be added to the answer\n },\n }],\n }],\n}\n# Global\nnested_radio_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n confidence=0.5, # Confidence scores should be added to the answer\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\",\n confidence=\n 0.5, # Confidence scores should be added to the answer\n )),\n )\n ],\n )),\n)\n# Global\nnested_radio_prediction_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"confidence\":\n 0.5,\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\",\n \"confidence\": 0.5\n },\n }],\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -344,70 +181,14 @@
},
{
"metadata": {},
- "source": [
- "pairwise_shopping_2 = \"\"\"\n",
- " {\n",
- " \"type\": \"application/vnd.labelbox.conversational\",\n",
- " \"version\": 1,\n",
- " \"messages\": [\n",
- " {\n",
- " \"messageId\": \"message-0\",\n",
- " \"timestampUsec\": 1530718491,\n",
- " \"content\": \"Hi! How can I help?\",\n",
- " \"user\": {\n",
- " \"userId\": \"Bot 002\",\n",
- " \"name\": \"Bot\"\n",
- " },\n",
- " \"align\": \"left\",\n",
- " \"canLabel\": false\n",
- " },\n",
- " {\n",
- " \"messageId\": \"message-1\",\n",
- " \"timestampUsec\": 1530718503,\n",
- " \"content\": \"I just bought a vacuum cleaner from you guys like a week ago and it's already broken!!\",\n",
- " \"user\": {\n",
- " \"userId\": \"User 00686\",\n",
- " \"name\": \"User\"\n",
- " },\n",
- " \"align\": \"right\",\n",
- " \"canLabel\": true\n",
- " }\n",
- "\n",
- " ],\n",
- " \"modelOutputs\": [\n",
- " {\n",
- " \"title\": \"Response A\",\n",
- " \"content\": \"I'm really sorry to hear that your vacuum cleaner is not working as expected. We certainly understand how frustrating this can be, especially with a recent purchase. I assure you, we're here to help!\\n\\n To proceed with resolving this issue, could you please provide some details about the problem you're experiencing with the vacuum cleaner? Additionally, if you could share your order number or receipt details, that would be very helpful. We will definitely look into the available options for you, which may include a replacement or a refund, depending on the specific circumstances and our return policy.\\n\\n Your satisfaction is our priority, and we'll do our best to resolve this matter promptly and to your satisfaction.\",\n",
- " \"modelConfigName\": \"GPT-3.5 with temperature 0\"\n",
- " },\n",
- " {\n",
- " \"title\": \"Response B\",\n",
- " \"content\": \"I'm sorry about the issue with your vacuum cleaner. Please send us the order number or receipt details so we can quickly assist you with a replacement. Your satisfaction is important to us!\",\n",
- " \"modelConfigName\": \"Fine Tuned GPT-3.5 with demo data\"\n",
- " }\n",
- " ]\n",
- "}\n",
- "\"\"\""
- ],
+ "source": "pairwise_shopping_2 = \"\"\"\n {\n \"type\": \"application/vnd.labelbox.conversational\",\n \"version\": 1,\n \"messages\": [\n {\n \"messageId\": \"message-0\",\n \"timestampUsec\": 1530718491,\n \"content\": \"Hi! How can I help?\",\n \"user\": {\n \"userId\": \"Bot 002\",\n \"name\": \"Bot\"\n },\n \"align\": \"left\",\n \"canLabel\": false\n },\n {\n \"messageId\": \"message-1\",\n \"timestampUsec\": 1530718503,\n \"content\": \"I just bought a vacuum cleaner from you guys like a week ago and it's already broken!!\",\n \"user\": {\n \"userId\": \"User 00686\",\n \"name\": \"User\"\n },\n \"align\": \"right\",\n \"canLabel\": true\n }\n\n ],\n \"modelOutputs\": [\n {\n \"title\": \"Response A\",\n \"content\": \"I'm really sorry to hear that your vacuum cleaner is not working as expected. We certainly understand how frustrating this can be, especially with a recent purchase. I assure you, we're here to help!\\n\\n To proceed with resolving this issue, could you please provide some details about the problem you're experiencing with the vacuum cleaner? Additionally, if you could share your order number or receipt details, that would be very helpful. We will definitely look into the available options for you, which may include a replacement or a refund, depending on the specific circumstances and our return policy.\\n\\n Your satisfaction is our priority, and we'll do our best to resolve this matter promptly and to your satisfaction.\",\n \"modelConfigName\": \"GPT-3.5 with temperature 0\"\n },\n {\n \"title\": \"Response B\",\n \"content\": \"I'm sorry about the issue with your vacuum cleaner. Please send us the order number or receipt details so we can quickly assist you with a replacement. Your satisfaction is important to us!\",\n \"modelConfigName\": \"Fine Tuned GPT-3.5 with demo data\"\n }\n ]\n}\n\"\"\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "global_key = \"pairwise_shooping_asset\"\n",
- "convo_data = {\n",
- " \"row_data\": \"https://storage.googleapis.com/labelbox-datasets/conversational-sample-data/pairwise_shopping_2.json\",\n",
- " \"global_key\": global_key\n",
- "}\n",
- "# Create a dataset\n",
- "dataset = client.create_dataset(name=\"pairwise_prediction_demo\")\n",
- "# Create a datarows\n",
- "task = dataset.create_data_rows([convo_data])\n",
- "print(\"Errors:\",task.errors)\n",
- "print(\"Failed data rows:\", task.failed_data_rows)"
- ],
+ "source": "global_key = \"pairwise_shooping_asset\"\nconvo_data = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/conversational-sample-data/pairwise_shopping_2.json\",\n \"global_key\":\n global_key,\n}\n# Create a dataset\ndataset = client.create_dataset(name=\"pairwise_prediction_demo\")\n# Create a datarows\ntask = dataset.create_data_rows([convo_data])\nprint(\"Errors:\", task.errors)\nprint(\"Failed data rows:\", task.failed_data_rows)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -421,69 +202,7 @@
},
{
"metadata": {},
- "source": [
- "# Create an ontology with relevant classifications\n",
- "\n",
- "ontology_builder = lb.OntologyBuilder(\n",
- " tools=[\n",
- " lb.Tool(tool=lb.Tool.Type.NER,name=\"ner\"),\n",
- " ],\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " scope=lb.Classification.Scope.GLOBAL,\n",
- " name=\"Choose the best response\",\n",
- " options=[lb.Option(value=\"Response A\"), lb.Option(value=\"Response B\"), lb.Option(value=\"Tie\")]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"Provide a reason for your choice\"\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " scope=lb.Classification.Scope.INDEX,\n",
- " name=\"checklist_convo\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " scope = lb.Classification.Scope.INDEX,\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ])\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " scope = lb.Classification.Scope.GLOBAL,\n",
- " options=[\n",
- " lb.Option(\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[lb.Option(\"first_sub_radio_answer\")]\n",
- " )\n",
- " ])\n",
- " ]\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Pairwise comparison ontology\", ontology_builder.asdict(), media_type=lb.MediaType.Conversational)\n",
- "\n"
- ],
+ "source": "# Create an ontology with relevant classifications\n\nontology_builder = lb.OntologyBuilder(\n tools=[\n lb.Tool(tool=lb.Tool.Type.NER, name=\"ner\"),\n ],\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n scope=lb.Classification.Scope.GLOBAL,\n name=\"Choose the best response\",\n options=[\n lb.Option(value=\"Response A\"),\n lb.Option(value=\"Response B\"),\n lb.Option(value=\"Tie\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.TEXT,\n name=\"Provide a reason for your choice\",\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n scope=lb.Classification.Scope.INDEX,\n name=\"checklist_convo\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n scope=lb.Classification.Scope.INDEX,\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n scope=lb.Classification.Scope.GLOBAL,\n options=[\n lb.Option(\n \"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(\"first_sub_radio_answer\")],\n )\n ],\n )\n ],\n ),\n ],\n)\n\nontology = client.create_ontology(\n \"Pairwise comparison ontology\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Conversational,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -497,13 +216,7 @@
},
{
"metadata": {},
- "source": [
- "# create model\n",
- "model = client.create_model(name=\"Comparison_model_run_\"+ str(uuid.uuid4()),\n",
- " ontology_id=ontology.uid)\n",
- "# create model run\n",
- "model_run = model.create_model_run(\"iteration 1\")"
- ],
+ "source": "# create model\nmodel = client.create_model(name=\"Comparison_model_run_\" + str(uuid.uuid4()),\n ontology_id=ontology.uid)\n# create model run\nmodel_run = model.create_model_run(\"iteration 1\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -517,9 +230,7 @@
},
{
"metadata": {},
- "source": [
- "model_run.upsert_data_rows(global_keys=[global_key])"
- ],
+ "source": "model_run.upsert_data_rows(global_keys=[global_key])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -533,20 +244,7 @@
},
{
"metadata": {},
- "source": [
- "label_prediction = []\n",
- "label_prediction.append(lb_types.Label(\n",
- " data= {\"global_key\": global_key},\n",
- " annotations= [\n",
- " ner_prediction,\n",
- " text_prediction,\n",
- " checklist_prediction,\n",
- " radio_prediction,\n",
- " nested_radio_prediction,\n",
- " nested_checklist_prediction\n",
- " ]\n",
- "))"
- ],
+ "source": "label_prediction = []\nlabel_prediction.append(\n lb_types.Label(\n data={\"global_key\": global_key},\n annotations=[\n ner_prediction,\n text_prediction,\n checklist_prediction,\n radio_prediction,\n nested_radio_prediction,\n nested_checklist_prediction,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -560,23 +258,7 @@
},
{
"metadata": {},
- "source": [
- "label_ndjson = []\n",
- "for annotations in [\n",
- " ner_prediction_ndjson,\n",
- " text_prediction_ndjson,\n",
- " checklist_prediction_ndjson,\n",
- " radio_prediction_ndjson,\n",
- " nested_checklist_prediction_ndjson,\n",
- " nested_radio_prediction_ndjson\n",
- " ]:\n",
- " annotations.update({\n",
- " \"dataRow\": {\n",
- " \"globalKey\": global_key\n",
- " }\n",
- " })\n",
- " label_ndjson.append(annotations)"
- ],
+ "source": "label_ndjson = []\nfor annotations in [\n ner_prediction_ndjson,\n text_prediction_ndjson,\n checklist_prediction_ndjson,\n radio_prediction_ndjson,\n nested_checklist_prediction_ndjson,\n nested_radio_prediction_ndjson,\n]:\n annotations.update({\"dataRow\": {\"globalKey\": global_key}})\n label_ndjson.append(annotations)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -590,16 +272,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload the prediction label to the Model Run\n",
- "upload_job_prediction = model_run.add_predictions(\n",
- " name=\"prediction_upload_job\"+str(uuid.uuid4()),\n",
- " predictions=label_prediction)\n",
- "\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_prediction.errors)\n",
- "print(\"Status of uploads: \", upload_job_prediction.statuses)"
- ],
+ "source": "# Upload the prediction label to the Model Run\nupload_job_prediction = model_run.add_predictions(\n name=\"prediction_upload_job\" + str(uuid.uuid4()),\n predictions=label_prediction,\n)\n\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_prediction.errors)\nprint(\"Status of uploads: \", upload_job_prediction.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -620,11 +293,7 @@
},
{
"metadata": {},
- "source": [
- "project = client.create_project(name=\"Conversational Human Evaluation Demo\",\n",
- " media_type=lb.MediaType.Conversational)\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "project = client.create_project(\n name=\"Conversational Human Evaluation Demo\",\n media_type=lb.MediaType.Conversational,\n)\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -638,13 +307,7 @@
},
{
"metadata": {},
- "source": [
- "project.create_batch(\n",
- " \"batch_convo_prediction_demo\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")"
- ],
+ "source": "project.create_batch(\n \"batch_convo_prediction_demo\", # Each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # Paginated collection of data row objects, list of data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -658,80 +321,7 @@
},
{
"metadata": {},
- "source": [
- "ner_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"ner\",\n",
- " value=lb_types.ConversationEntity(\n",
- " start=0,\n",
- " end=8,\n",
- " message_id=\"message-1\"\n",
- " )\n",
- ")\n",
- "\n",
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"Choose the best response\",\n",
- " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n",
- " name=\"Response B\"))\n",
- ")\n",
- "\n",
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"Provide a reason for your choice\",\n",
- " value=lb_types.Text(answer=\"the answer to the text questions right here\")\n",
- ")\n",
- "\n",
- "checklist_annotation= lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_convo\", # must match your ontology feature\"s name\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\"\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\"\n",
- " )\n",
- " ]\n",
- " ),\n",
- " message_id=\"message-1\" # Message specific annotation\n",
- " )\n",
- "\n",
- "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " message_id=\"message-1\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\"\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "\n",
- "nested_radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")"
- ],
+ "source": "ner_annotation = lb_types.ObjectAnnotation(\n name=\"ner\",\n value=lb_types.ConversationEntity(start=0, end=8, message_id=\"message-1\"),\n)\n\nradio_annotation = lb_types.ClassificationAnnotation(\n name=\"Choose the best response\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"Response B\")),\n)\n\ntext_annotation = lb_types.ClassificationAnnotation(\n name=\"Provide a reason for your choice\",\n value=lb_types.Text(answer=\"the answer to the text questions right here\"),\n)\n\nchecklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_convo\", # must match your ontology feature\"s name\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n ]),\n message_id=\"message-1\", # Message specific annotation\n)\n\nnested_checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n message_id=\"message-1\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n )\n ]),\n)\n\nnested_radio_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -745,22 +335,7 @@
},
{
"metadata": {},
- "source": [
- "label_annotation = []\n",
- "label_annotation.append(lb_types.Label(\n",
- " data=lb_types.ConversationData(\n",
- " global_key=global_key\n",
- " ),\n",
- " annotations= [\n",
- " ner_annotation,\n",
- " text_annotation,\n",
- " checklist_annotation,\n",
- " radio_annotation,\n",
- " nested_radio_annotation,\n",
- " nested_checklist_annotation\n",
- " ]\n",
- "))"
- ],
+ "source": "label_annotation = []\nlabel_annotation.append(\n lb_types.Label(\n data=lb_types.ConversationData(global_key=global_key),\n annotations=[\n ner_annotation,\n text_annotation,\n checklist_annotation,\n radio_annotation,\n nested_radio_annotation,\n nested_checklist_annotation,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -774,18 +349,7 @@
},
{
"metadata": {},
- "source": [
- "upload_job_annotation = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"label_import_job\"+ str(uuid.uuid4()),\n",
- " labels=label_annotation)\n",
- "\n",
- "upload_job_annotation.wait_until_done()\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_annotation.errors)\n",
- "print(\"Status of uploads: \", upload_job_annotation.statuses)"
- ],
+ "source": "upload_job_annotation = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"label_import_job\" + str(uuid.uuid4()),\n labels=label_annotation,\n)\n\nupload_job_annotation.wait_until_done()\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_annotation.errors)\nprint(\"Status of uploads: \", upload_job_annotation.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -799,10 +363,7 @@
},
{
"metadata": {},
- "source": [
- "# get the labels id from the project\n",
- "model_run.upsert_labels(project_id=project.uid)"
- ],
+ "source": "# get the labels id from the project\nmodel_run.upsert_labels(project_id=project.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -816,10 +377,7 @@
},
{
"metadata": {},
- "source": [
- "# project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/prediction_upload/conversational_predictions.ipynb b/examples/prediction_upload/conversational_predictions.ipynb
index 1d265e780..b6a649d56 100644
--- a/examples/prediction_upload/conversational_predictions.ipynb
+++ b/examples/prediction_upload/conversational_predictions.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -62,20 +62,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import uuid\n",
- "import labelbox.types as lb_types"
- ],
+ "source": "import labelbox as lb\nimport uuid\nimport labelbox.types as lb_types",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -89,11 +83,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your api key\n",
- "API_KEY = \"\"\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your api key\nAPI_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -107,215 +97,42 @@
},
{
"metadata": {},
- "source": [
- "########### Radio Classification ###########\n",
- "\n",
- "# Python annotation\n",
- "radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question\",\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(name = \"second_radio_answer\", confidence=0.5))\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "radio_prediction_ndjson = {\n",
- " \"name\": \"radio_question\",\n",
- " \"answer\": {\"name\": \"second_radio_answer\", \"confidence\": 0.5}\n",
- "}"
- ],
+ "source": "########### Radio Classification ###########\n\n# Python annotation\nradio_prediction = lb_types.ClassificationAnnotation(\n name=\"radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"second_radio_answer\", confidence=0.5)),\n)\n\n# NDJSON\nradio_prediction_ndjson = {\n \"name\": \"radio_question\",\n \"answer\": {\n \"name\": \"second_radio_answer\",\n \"confidence\": 0.5\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "\n",
- "# message based classifications\n",
- "ner_prediction = lb_types.ObjectAnnotation(\n",
- " name=\"ner\",\n",
- " confidence=0.5,\n",
- " value=lb_types.ConversationEntity(\n",
- " start=0,\n",
- " end=8,\n",
- " message_id=\"4\"\n",
- " )\n",
- ")\n",
- "\n",
- "ner_prediction_ndjson = {\n",
- " \"name\": \"ner\",\n",
- " \"confidence\":0.5,\n",
- " \"location\": {\n",
- " \"start\": 0,\n",
- " \"end\": 8\n",
- " },\n",
- " \"messageId\": \"4\"\n",
- " }"
- ],
+ "source": "# message based classifications\nner_prediction = lb_types.ObjectAnnotation(\n name=\"ner\",\n confidence=0.5,\n value=lb_types.ConversationEntity(start=0, end=8, message_id=\"4\"),\n)\n\nner_prediction_ndjson = {\n \"name\": \"ner\",\n \"confidence\": 0.5,\n \"location\": {\n \"start\": 0,\n \"end\": 8\n },\n \"messageId\": \"4\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "##### Classification free text #####\n",
- "# Confidence scores are not supported for text predictions\n",
- "\n",
- "text_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"text_convo\",\n",
- " value=lb_types.Text(answer=\"the answer to the text questions are right here\"),\n",
- " message_id=\"0\"\n",
- ")\n",
- "\n",
- "\n",
- "text_prediction_ndjson = {\n",
- " \"name\": \"text_convo\",\n",
- " \"answer\": \"the answer to the text questions are right here\",\n",
- " \"messageId\": \"0\"\n",
- "}"
- ],
+ "source": "##### Classification free text #####\n# Confidence scores are not supported for text predictions\n\ntext_prediction = lb_types.ClassificationAnnotation(\n name=\"text_convo\",\n value=lb_types.Text(\n answer=\"the answer to the text questions are right here\"),\n message_id=\"0\",\n)\n\ntext_prediction_ndjson = {\n \"name\": \"text_convo\",\n \"answer\": \"the answer to the text questions are right here\",\n \"messageId\": \"0\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "\n",
- "##### Checklist Classification #######\n",
- "\n",
- "checklist_prediction= lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_convo\", # must match your ontology feature\"s name\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\", confidence=0.5\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\", confidence=0.5\n",
- " )\n",
- " ]\n",
- " ),\n",
- " message_id=\"2\"\n",
- " )\n",
- "\n",
- "\n",
- "checklist_prediction_ndjson = {\n",
- " \"name\": \"checklist_convo\",\n",
- " \"answers\": [\n",
- " {\"name\": \"first_checklist_answer\", \"confidence\":0.5},\n",
- " {\"name\": \"second_checklist_answer\", \"confidence\":0.5}\n",
- " ],\n",
- " \"messageId\": \"2\"\n",
- "}"
- ],
+ "source": "##### Checklist Classification #######\n\nchecklist_prediction = lb_types.ClassificationAnnotation(\n name=\"checklist_convo\", # must match your ontology feature\"s name\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\",\n confidence=0.5),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\",\n confidence=0.5),\n ]),\n message_id=\"2\",\n)\n\nchecklist_prediction_ndjson = {\n \"name\": \"checklist_convo\",\n \"answers\": [\n {\n \"name\": \"first_checklist_answer\",\n \"confidence\": 0.5\n },\n {\n \"name\": \"second_checklist_answer\",\n \"confidence\": 0.5\n },\n ],\n \"messageId\": \"2\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "######## Radio Classification ######\n",
- "\n",
- "radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_convo\",\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(name = \"first_radio_answer\", confidence=0.5)),\n",
- " message_id=\"0\"\n",
- ")\n",
- "\n",
- "radio_prediction_ndjson = {\n",
- " \"name\": \"radio_convo\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\", \"confidence\":0.5\n",
- " },\n",
- " \"messageId\": \"0\",\n",
- "}"
- ],
+ "source": "######## Radio Classification ######\n\nradio_prediction = lb_types.ClassificationAnnotation(\n name=\"radio_convo\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\", confidence=0.5)),\n message_id=\"0\",\n)\n\nradio_prediction_ndjson = {\n \"name\": \"radio_convo\",\n \"answer\": {\n \"name\": \"first_radio_answer\",\n \"confidence\": 0.5\n },\n \"messageId\": \"0\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# ############ global nested classifications ###########\n",
- "\n",
- "# Message based\n",
- "nested_checklist_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " message_id=\"10\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " confidence=0.5, # Confidence scores should be added to the answer\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\",\n",
- " confidence=0.5 # Confidence scores should be added to the answer\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "# Message based\n",
- "nested_checklist_prediction_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"messageId\": \"10\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"confidence\": 0.5, # Confidence scores should be added to the answer\n",
- " \"classifications\" : [\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_sub_checklist_answer\",\n",
- " \"confidence\": 0.5, # Confidence scores should be added to the answer\n",
- " }\n",
- " }\n",
- " ]\n",
- " }]\n",
- "}\n",
- "# Global\n",
- "nested_radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " confidence=0.5, # Confidence scores should be added to the answer\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\",\n",
- " confidence=0.5 # Confidence scores should be added to the answer\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "#Global\n",
- "nested_radio_prediction_ndjson = {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\",\n",
- " \"confidence\": 0.5,\n",
- " \"classifications\": [{\n",
- " \"name\":\"sub_radio_question\",\n",
- " \"answer\": { \"name\" : \"first_sub_radio_answer\",\n",
- " \"confidence\": 0.5}\n",
- " }]\n",
- " }\n",
- "}\n",
- "\n"
- ],
+ "source": "# ############ global nested classifications ###########\n\n# Message based\nnested_checklist_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n message_id=\"10\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n confidence=0.5, # Confidence scores should be added to the answer\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\",\n confidence=\n 0.5, # Confidence scores should be added to the answer\n )\n ]),\n )\n ],\n )\n ]),\n)\n# Message based\nnested_checklist_prediction_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"messageId\":\n \"10\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"confidence\":\n 0.5, # Confidence scores should be added to the answer\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\",\n \"confidence\":\n 0.5, # Confidence scores should be added to the answer\n },\n }],\n }],\n}\n# Global\nnested_radio_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n confidence=0.5, # Confidence scores should be added to the answer\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\",\n confidence=\n 0.5, # Confidence scores should be added to the answer\n )),\n )\n ],\n )),\n)\n# Global\nnested_radio_prediction_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"confidence\":\n 0.5,\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\",\n \"confidence\": 0.5\n },\n }],\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -329,22 +146,7 @@
},
{
"metadata": {},
- "source": [
- "# Create one Labelbox dataset\n",
- "\n",
- "global_key = \"conversation-1.json\"\n",
- "\n",
- "asset = {\n",
- " \"row_data\": \"https://storage.googleapis.com/labelbox-developer-testing-assets/conversational_text/1000-conversations/conversation-1.json\",\n",
- " \"global_key\": global_key\n",
- "}\n",
- "\n",
- "dataset = client.create_dataset(name=\"conversational_annotation_import_demo_dataset\")\n",
- "task = dataset.create_data_rows([asset])\n",
- "task.wait_till_done()\n",
- "print(\"Errors:\", task.errors)\n",
- "print(\"Failed data rows: \", task.failed_data_rows)"
- ],
+ "source": "# Create one Labelbox dataset\n\nglobal_key = \"conversation-1.json\"\n\nasset = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-developer-testing-assets/conversational_text/1000-conversations/conversation-1.json\",\n \"global_key\":\n global_key,\n}\n\ndataset = client.create_dataset(\n name=\"conversational_annotation_import_demo_dataset\")\ntask = dataset.create_data_rows([asset])\ntask.wait_till_done()\nprint(\"Errors:\", task.errors)\nprint(\"Failed data rows: \", task.failed_data_rows)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -359,69 +161,7 @@
},
{
"metadata": {},
- "source": [
- "ontology_builder = lb.OntologyBuilder(\n",
- " tools=[\n",
- " lb.Tool(tool=lb.Tool.Type.NER,name=\"ner\")\n",
- " ],\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " scope=lb.Classification.Scope.INDEX,\n",
- " name=\"text_convo\"),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " scope=lb.Classification.Scope.INDEX,\n",
- " name=\"checklist_convo\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_convo\",\n",
- " scope=lb.Classification.Scope.INDEX,\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\"),\n",
- " lb.Option(value=\"second_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " scope = lb.Classification.Scope.INDEX,\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ])\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " scope = lb.Classification.Scope.GLOBAL,\n",
- " options=[\n",
- " lb.Option(\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[lb.Option(\"first_sub_radio_answer\")]\n",
- " )\n",
- " ])\n",
- " ]\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Ontology Conversation Annotations\", ontology_builder.asdict())"
- ],
+ "source": "ontology_builder = lb.OntologyBuilder(\n tools=[lb.Tool(tool=lb.Tool.Type.NER, name=\"ner\")],\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.TEXT,\n scope=lb.Classification.Scope.INDEX,\n name=\"text_convo\",\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n scope=lb.Classification.Scope.INDEX,\n name=\"checklist_convo\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_convo\",\n scope=lb.Classification.Scope.INDEX,\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n scope=lb.Classification.Scope.INDEX,\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n scope=lb.Classification.Scope.GLOBAL,\n options=[\n lb.Option(\n \"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(\"first_sub_radio_answer\")],\n )\n ],\n )\n ],\n ),\n ],\n)\n\nontology = client.create_ontology(\"Ontology Conversation Annotations\",\n ontology_builder.asdict())",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -435,13 +175,7 @@
},
{
"metadata": {},
- "source": [
- "# create Model\n",
- "model = client.create_model(name=\"Conversational_model_run_\"+ str(uuid.uuid4()),\n",
- " ontology_id=ontology.uid)\n",
- "# create Model Run\n",
- "model_run = model.create_model_run(\"iteration 1\")"
- ],
+ "source": "# create Model\nmodel = client.create_model(\n name=\"Conversational_model_run_\" + str(uuid.uuid4()),\n ontology_id=ontology.uid,\n)\n# create Model Run\nmodel_run = model.create_model_run(\"iteration 1\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -455,9 +189,7 @@
},
{
"metadata": {},
- "source": [
- "model_run.upsert_data_rows(global_keys=[global_key])"
- ],
+ "source": "model_run.upsert_data_rows(global_keys=[global_key])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -483,22 +215,7 @@
},
{
"metadata": {},
- "source": [
- "label_prediction = []\n",
- "label_prediction.append(\n",
- " lb_types.Label(\n",
- " data= {\"global_key\": global_key},\n",
- " annotations=[\n",
- " ner_prediction,\n",
- " checklist_prediction,\n",
- " text_prediction,\n",
- " radio_prediction,\n",
- " nested_checklist_prediction,\n",
- " nested_radio_prediction\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "label_prediction = []\nlabel_prediction.append(\n lb_types.Label(\n data={\"global_key\": global_key},\n annotations=[\n ner_prediction,\n checklist_prediction,\n text_prediction,\n radio_prediction,\n nested_checklist_prediction,\n nested_radio_prediction,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -512,23 +229,7 @@
},
{
"metadata": {},
- "source": [
- "label_prediction_ndjson = []\n",
- "for annotations in [\n",
- " ner_prediction_ndjson,\n",
- " text_prediction_ndjson,\n",
- " checklist_prediction_ndjson,\n",
- " radio_prediction_ndjson,\n",
- " nested_checklist_prediction_ndjson,\n",
- " nested_radio_prediction_ndjson\n",
- " ]:\n",
- " annotations.update({\n",
- " \"dataRow\": {\n",
- " \"globalKey\": global_key\n",
- " }\n",
- " })\n",
- " label_prediction_ndjson.append(annotations)"
- ],
+ "source": "label_prediction_ndjson = []\nfor annotations in [\n ner_prediction_ndjson,\n text_prediction_ndjson,\n checklist_prediction_ndjson,\n radio_prediction_ndjson,\n nested_checklist_prediction_ndjson,\n nested_radio_prediction_ndjson,\n]:\n annotations.update({\"dataRow\": {\"globalKey\": global_key}})\n label_prediction_ndjson.append(annotations)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -542,16 +243,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload the prediction label to the Model Run\n",
- "upload_job_prediction = model_run.add_predictions(\n",
- " name=\"prediction_upload_job\"+str(uuid.uuid4()),\n",
- " predictions=label_prediction)\n",
- "\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_prediction.errors)\n",
- "print(\"Status of uploads: \", upload_job_prediction.statuses)"
- ],
+ "source": "# Upload the prediction label to the Model Run\nupload_job_prediction = model_run.add_predictions(\n name=\"prediction_upload_job\" + str(uuid.uuid4()),\n predictions=label_prediction,\n)\n\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_prediction.errors)\nprint(\"Status of uploads: \", upload_job_prediction.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -572,11 +264,7 @@
},
{
"metadata": {},
- "source": [
- "project = client.create_project(name=\"Conversational Text Prediction Import Demo\",\n",
- " media_type=lb.MediaType.Conversational)\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "project = client.create_project(\n name=\"Conversational Text Prediction Import Demo\",\n media_type=lb.MediaType.Conversational,\n)\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -590,13 +278,7 @@
},
{
"metadata": {},
- "source": [
- "project.create_batch(\n",
- " \"batch_convo_prediction_demo\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")"
- ],
+ "source": "project.create_batch(\n \"batch_convo_prediction_demo\", # Each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # Paginated collection of data row objects, list of data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -610,82 +292,7 @@
},
{
"metadata": {},
- "source": [
- "ner_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"ner\",\n",
- " value=lb_types.ConversationEntity(\n",
- " start=0,\n",
- " end=8,\n",
- " message_id=\"4\"\n",
- " )\n",
- ")\n",
- "\n",
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"text_convo\",\n",
- " value=lb_types.Text(answer=\"the answer to the text questions are right here\"),\n",
- " message_id=\"0\"\n",
- ")\n",
- "\n",
- "checklist_annotation= lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_convo\", # must match your ontology feature\"s name\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\"\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\"\n",
- " )\n",
- " ]\n",
- " ),\n",
- " message_id=\"2\"\n",
- " )\n",
- "\n",
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_convo\",\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(name = \"first_radio_answer\")),\n",
- " message_id=\"0\"\n",
- ")\n",
- "\n",
- "\n",
- "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " message_id=\"10\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\"\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "\n",
- "nested_radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")"
- ],
+ "source": "ner_annotation = lb_types.ObjectAnnotation(\n name=\"ner\",\n value=lb_types.ConversationEntity(start=0, end=8, message_id=\"4\"),\n)\n\ntext_annotation = lb_types.ClassificationAnnotation(\n name=\"text_convo\",\n value=lb_types.Text(\n answer=\"the answer to the text questions are right here\"),\n message_id=\"0\",\n)\n\nchecklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_convo\", # must match your ontology feature\"s name\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n ]),\n message_id=\"2\",\n)\n\nradio_annotation = lb_types.ClassificationAnnotation(\n name=\"radio_convo\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\")),\n message_id=\"0\",\n)\n\nnested_checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n message_id=\"10\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n )\n ]),\n)\n\nnested_radio_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -699,24 +306,7 @@
},
{
"metadata": {},
- "source": [
- "label = []\n",
- "label.append(\n",
- " lb_types.Label(\n",
- " data=lb_types.ConversationData(\n",
- " global_key=global_key\n",
- " ),\n",
- " annotations=[\n",
- " ner_annotation,\n",
- " text_annotation,\n",
- " checklist_annotation,\n",
- " radio_annotation,\n",
- " nested_radio_annotation,\n",
- " nested_checklist_annotation\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "label = []\nlabel.append(\n lb_types.Label(\n data=lb_types.ConversationData(global_key=global_key),\n annotations=[\n ner_annotation,\n text_annotation,\n checklist_annotation,\n radio_annotation,\n nested_radio_annotation,\n nested_checklist_annotation,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -730,18 +320,7 @@
},
{
"metadata": {},
- "source": [
- "upload_job_annotation = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"text_label_import_job\"+ str(uuid.uuid4()),\n",
- " labels=label)\n",
- "\n",
- "upload_job_annotation.wait_until_done()\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_annotation.errors)\n",
- "print(\"Status of uploads: \", upload_job_annotation.statuses)"
- ],
+ "source": "upload_job_annotation = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"text_label_import_job\" + str(uuid.uuid4()),\n labels=label,\n)\n\nupload_job_annotation.wait_until_done()\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_annotation.errors)\nprint(\"Status of uploads: \", upload_job_annotation.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -755,10 +334,7 @@
},
{
"metadata": {},
- "source": [
- "# get the labels id from the project\n",
- "model_run.upsert_labels(project_id=project.uid)"
- ],
+ "source": "# get the labels id from the project\nmodel_run.upsert_labels(project_id=project.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -772,10 +348,7 @@
},
{
"metadata": {},
- "source": [
- "# project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/prediction_upload/geospatial_predictions.ipynb b/examples/prediction_upload/geospatial_predictions.ipynb
index 636a7a43b..e3c1212f3 100644
--- a/examples/prediction_upload/geospatial_predictions.ipynb
+++ b/examples/prediction_upload/geospatial_predictions.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -21,7 +21,7 @@
"\n",
"\n",
"\n",
- "![]() \n",
" | "
],
@@ -61,26 +61,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q 'labelbox[data]'"
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import os\n",
- "\n",
- "import uuid\n",
- "import numpy as np\n",
- "from PIL import Image\n",
- "import cv2\n",
- "\n",
- "import labelbox as lb\n",
- "import labelbox.types as lb_types"
- ],
+ "source": "import os\n\nimport uuid\nimport numpy as np\nfrom PIL import Image\nimport cv2\n\nimport labelbox as lb\nimport labelbox.types as lb_types",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -95,10 +83,7 @@
},
{
"metadata": {},
- "source": [
- "API_KEY = \"\"\n",
- "client = lb.Client(API_KEY)"
- ],
+ "source": "API_KEY = \"\"\nclient = lb.Client(API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -113,605 +98,63 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "####### Point #######\n",
- "\n",
- "# Python Annotation\n",
- "point_prediction = lb_types.ObjectAnnotation(\n",
- " name = \"point_geo\",\n",
- " confidence=0.4,\n",
- " value = lb_types.Point(x=-99.20647859573366, y=19.40018029091072),\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "point_prediction_ndjson = {\n",
- " \"name\": \"point_geo\",\n",
- " \"confidence\": 0.4,\n",
- " \"point\": {\n",
- " \"x\": -99.20647859573366,\n",
- " \"y\": 19.40018029091072\n",
- " }\n",
- "}"
- ],
+ "source": "####### Point #######\n\n# Python Annotation\npoint_prediction = lb_types.ObjectAnnotation(\n name=\"point_geo\",\n confidence=0.4,\n value=lb_types.Point(x=-99.20647859573366, y=19.40018029091072),\n)\n\n# NDJSON\npoint_prediction_ndjson = {\n \"name\": \"point_geo\",\n \"confidence\": 0.4,\n \"point\": {\n \"x\": -99.20647859573366,\n \"y\": 19.40018029091072\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "\n",
- "####### Polyline #######\n",
- "# Coordinates\n",
- "coords = [\n",
- " [\n",
- " -99.20842051506044,\n",
- " 19.40032196622975\n",
- " ],\n",
- " [\n",
- " -99.20809864997865,\n",
- " 19.39758963475322\n",
- " ],\n",
- " [\n",
- " -99.20758366584778,\n",
- " 19.39776167179227\n",
- " ],\n",
- " [\n",
- " -99.20728325843811,\n",
- " 19.3973265189299\n",
- " ]\n",
- " ]\n",
- "\n",
- "line_points = []\n",
- "line_points_ndjson = []\n",
- "\n",
- "for sub in coords:\n",
- " line_points.append(lb_types.Point(x=sub[0], y=sub[1]))\n",
- " line_points_ndjson.append({\"x\":sub[0], \"y\":sub[1]})\n",
- "\n",
- "# Python Annotation\n",
- "polyline_prediction = lb_types.ObjectAnnotation(\n",
- " name = \"polyline_geo\",\n",
- " confidence=0.5,\n",
- " value = lb_types.Line(points=line_points),\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "polyline_prediction_ndjson = {\n",
- " \"name\": \"polyline_geo\",\n",
- " \"confidence\": 0.5,\n",
- " \"line\": line_points_ndjson\n",
- "}"
- ],
+ "source": "####### Polyline #######\n# Coordinates\ncoords = [\n [-99.20842051506044, 19.40032196622975],\n [-99.20809864997865, 19.39758963475322],\n [-99.20758366584778, 19.39776167179227],\n [-99.20728325843811, 19.3973265189299],\n]\n\nline_points = []\nline_points_ndjson = []\n\nfor sub in coords:\n line_points.append(lb_types.Point(x=sub[0], y=sub[1]))\n line_points_ndjson.append({\"x\": sub[0], \"y\": sub[1]})\n\n# Python Annotation\npolyline_prediction = lb_types.ObjectAnnotation(\n name=\"polyline_geo\",\n confidence=0.5,\n value=lb_types.Line(points=line_points),\n)\n\n# NDJSON\npolyline_prediction_ndjson = {\n \"name\": \"polyline_geo\",\n \"confidence\": 0.5,\n \"line\": line_points_ndjson,\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "\n",
- "####### Polygon #######\n",
- "# Coordinates in the desired EPSG coordinate system\n",
- "coords_polygon = [\n",
- " [\n",
- " -99.21042680740356,\n",
- " 19.40036244486966\n",
- " ],\n",
- " [\n",
- " -99.2104160785675,\n",
- " 19.40017017124035\n",
- " ],\n",
- " [\n",
- " -99.2103409767151,\n",
- " 19.400008256428897\n",
- " ],\n",
- " [\n",
- " -99.21014785766603,\n",
- " 19.400008256428897\n",
- " ],\n",
- " [\n",
- " -99.21019077301027,\n",
- " 19.39983622176518\n",
- " ],\n",
- " [\n",
- " -99.21022295951845,\n",
- " 19.399674306621385\n",
- " ],\n",
- " [\n",
- " -99.21029806137086,\n",
- " 19.39951239131646\n",
- " ],\n",
- " [\n",
- " -99.2102873325348,\n",
- " 19.399340356128437\n",
- " ],\n",
- " [\n",
- " -99.21025514602663,\n",
- " 19.399117722085677\n",
- " ],\n",
- " [\n",
- " -99.21024441719057,\n",
- " 19.39892544698541\n",
- " ],\n",
- " [\n",
- " -99.2102336883545,\n",
- " 19.39874329141769\n",
- " ],\n",
- " [\n",
- " -99.21021223068239,\n",
- " 19.398561135646027\n",
- " ],\n",
- " [\n",
- " -99.21018004417421,\n",
- " 19.398399219233365\n",
- " ],\n",
- " [\n",
- " -99.21011567115785,\n",
- " 19.39822718286836\n",
- " ],\n",
- " [\n",
- " -99.20992255210878,\n",
- " 19.398136104719125\n",
- " ],\n",
- " [\n",
- " -99.20974016189577,\n",
- " 19.398085505725305\n",
- " ],\n",
- " [\n",
- " -99.20957922935487,\n",
- " 19.398004547302467\n",
- " ],\n",
- " [\n",
- " -99.20939683914186,\n",
- " 19.39792358883935\n",
- " ],\n",
- " [\n",
- " -99.20918226242067,\n",
- " 19.39786286996558\n",
- " ],\n",
- " [\n",
- " -99.20899987220764,\n",
- " 19.397822390703805\n",
- " ],\n",
- " [\n",
- " -99.20891404151918,\n",
- " 19.397994427496787\n",
- " ],\n",
- " [\n",
- " -99.20890331268312,\n",
- " 19.398176583902874\n",
- " ],\n",
- " [\n",
- " -99.20889258384706,\n",
- " 19.398368859888045\n",
- " ],\n",
- " [\n",
- " -99.20889258384706,\n",
- " 19.398540896103246\n",
- " ],\n",
- " [\n",
- " -99.20890331268312,\n",
- " 19.39872305189756\n",
- " ],\n",
- " [\n",
- " -99.20889258384706,\n",
- " 19.39890520748796\n",
- " ],\n",
- " [\n",
- " -99.20889258384706,\n",
- " 19.39907724313608\n",
- " ],\n",
- " [\n",
- " -99.20889258384706,\n",
- " 19.399259398329956\n",
- " ],\n",
- " [\n",
- " -99.20890331268312,\n",
- " 19.399431433603585\n",
- " ],\n",
- " [\n",
- " -99.20890331268312,\n",
- " 19.39961358840092\n",
- " ],\n",
- " [\n",
- " -99.20890331268312,\n",
- " 19.399785623300048\n",
- " ],\n",
- " [\n",
- " -99.20897841453552,\n",
- " 19.399937418648214\n",
- " ],\n",
- " [\n",
- " -99.20919299125673,\n",
- " 19.399937418648214\n",
- " ],\n",
- " [\n",
- " -99.2093861103058,\n",
- " 19.39991717927664\n",
- " ],\n",
- " [\n",
- " -99.20956850051881,\n",
- " 19.39996777770086\n",
- " ],\n",
- " [\n",
- " -99.20961141586305,\n",
- " 19.40013981222548\n",
- " ],\n",
- " [\n",
- " -99.20963287353517,\n",
- " 19.40032196622975\n",
- " ],\n",
- " [\n",
- " -99.20978307724,\n",
- " 19.4004130431554\n",
- " ],\n",
- " [\n",
- " -99.20996546745302,\n",
- " 19.40039280384301\n",
- " ],\n",
- " [\n",
- " -99.21019077301027,\n",
- " 19.400372564528084\n",
- " ],\n",
- " [\n",
- " -99.21042680740356,\n",
- " 19.40036244486966\n",
- " ]\n",
- "\n",
- "]\n",
- "\n",
- "polygon_points = []\n",
- "polygon_points_ndjson = []\n",
- "\n",
- "for sub in coords_polygon:\n",
- " polygon_points.append(lb_types.Point(x=sub[0], y=sub[1]))\n",
- " polygon_points_ndjson.append({\"x\":sub[0], \"y\":sub[1]})\n",
- "\n",
- "# Python Annotation\n",
- "polygon_prediction = lb_types.ObjectAnnotation(\n",
- " name = \"polygon_geo\",\n",
- " confidence=0.5,\n",
- " value = lb_types.Polygon(points=polygon_points),\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "polygon_prediction_ndjson = {\n",
- " \"name\": \"polygon_geo\",\n",
- " \"confidence\": 0.5,\n",
- " \"polygon\": polygon_points_ndjson\n",
- "}"
- ],
+ "source": "####### Polygon #######\n# Coordinates in the desired EPSG coordinate system\ncoords_polygon = [\n [-99.21042680740356, 19.40036244486966],\n [-99.2104160785675, 19.40017017124035],\n [-99.2103409767151, 19.400008256428897],\n [-99.21014785766603, 19.400008256428897],\n [-99.21019077301027, 19.39983622176518],\n [-99.21022295951845, 19.399674306621385],\n [-99.21029806137086, 19.39951239131646],\n [-99.2102873325348, 19.399340356128437],\n [-99.21025514602663, 19.399117722085677],\n [-99.21024441719057, 19.39892544698541],\n [-99.2102336883545, 19.39874329141769],\n [-99.21021223068239, 19.398561135646027],\n [-99.21018004417421, 19.398399219233365],\n [-99.21011567115785, 19.39822718286836],\n [-99.20992255210878, 19.398136104719125],\n [-99.20974016189577, 19.398085505725305],\n [-99.20957922935487, 19.398004547302467],\n [-99.20939683914186, 19.39792358883935],\n [-99.20918226242067, 19.39786286996558],\n [-99.20899987220764, 19.397822390703805],\n [-99.20891404151918, 19.397994427496787],\n [-99.20890331268312, 19.398176583902874],\n [-99.20889258384706, 19.398368859888045],\n [-99.20889258384706, 19.398540896103246],\n [-99.20890331268312, 19.39872305189756],\n [-99.20889258384706, 19.39890520748796],\n [-99.20889258384706, 19.39907724313608],\n [-99.20889258384706, 19.399259398329956],\n [-99.20890331268312, 19.399431433603585],\n [-99.20890331268312, 19.39961358840092],\n [-99.20890331268312, 19.399785623300048],\n [-99.20897841453552, 19.399937418648214],\n [-99.20919299125673, 19.399937418648214],\n [-99.2093861103058, 19.39991717927664],\n [-99.20956850051881, 19.39996777770086],\n [-99.20961141586305, 19.40013981222548],\n [-99.20963287353517, 19.40032196622975],\n [-99.20978307724, 19.4004130431554],\n [-99.20996546745302, 19.40039280384301],\n [-99.21019077301027, 19.400372564528084],\n [-99.21042680740356, 19.40036244486966],\n]\n\npolygon_points = []\npolygon_points_ndjson = []\n\nfor sub in coords_polygon:\n polygon_points.append(lb_types.Point(x=sub[0], y=sub[1]))\n polygon_points_ndjson.append({\"x\": sub[0], \"y\": sub[1]})\n\n# Python Annotation\npolygon_prediction = lb_types.ObjectAnnotation(\n name=\"polygon_geo\",\n confidence=0.5,\n value=lb_types.Polygon(points=polygon_points),\n)\n\n# NDJSON\npolygon_prediction_ndjson = {\n \"name\": \"polygon_geo\",\n \"confidence\": 0.5,\n \"polygon\": polygon_points_ndjson,\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "\n",
- "####### Bounding Box #######\n",
- "coord_object = {\n",
- " \"coordinates\" : [[\n",
- " [\n",
- " -99.20746564865112,\n",
- " 19.39799442829336\n",
- " ],\n",
- " [\n",
- " -99.20746564865112,\n",
- " 19.39925939999194\n",
- " ],\n",
- " [\n",
- " -99.20568466186523,\n",
- " 19.39925939999194\n",
- " ],\n",
- " [\n",
- " -99.20568466186523,\n",
- " 19.39799442829336\n",
- " ],\n",
- " [\n",
- " -99.20746564865112,\n",
- " 19.39799442829336\n",
- " ]\n",
- " ]]\n",
- "}\n",
- "\n",
- "\n",
- "\n",
- "\n",
- "bbox_top_left = lb_types.Point(x= -99.20746564865112, y=19.39799442829336)\n",
- "bbox_bottom_right = lb_types.Point(x=-99.20568466186523, y=19.39925939999194)\n",
- "\n",
- "# Python Annotation\n",
- "bbox_prediction = lb_types.ObjectAnnotation(\n",
- " name = \"bbox_geo\",\n",
- " confidence=0.5,\n",
- " value = lb_types.Rectangle(start=bbox_top_left, end=bbox_bottom_right)\n",
- ")\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "bbox_prediction_ndjson = {\n",
- " \"name\" : \"bbox_geo\",\n",
- " \"confidence\": 0.5,\n",
- " \"bbox\" : {\n",
- " 'top': coord_object[\"coordinates\"][0][1][1],\n",
- " 'left': coord_object[\"coordinates\"][0][1][0],\n",
- " 'height': coord_object[\"coordinates\"][0][3][1] - coord_object[\"coordinates\"][0][1][1],\n",
- " 'width': coord_object[\"coordinates\"][0][3][0] - coord_object[\"coordinates\"][0][1][0]\n",
- " }\n",
- "}\n"
- ],
+ "source": "####### Bounding Box #######\ncoord_object = {\n \"coordinates\": [[\n [-99.20746564865112, 19.39799442829336],\n [-99.20746564865112, 19.39925939999194],\n [-99.20568466186523, 19.39925939999194],\n [-99.20568466186523, 19.39799442829336],\n [-99.20746564865112, 19.39799442829336],\n ]]\n}\n\nbbox_top_left = lb_types.Point(x=-99.20746564865112, y=19.39799442829336)\nbbox_bottom_right = lb_types.Point(x=-99.20568466186523, y=19.39925939999194)\n\n# Python Annotation\nbbox_prediction = lb_types.ObjectAnnotation(\n name=\"bbox_geo\",\n confidence=0.5,\n value=lb_types.Rectangle(start=bbox_top_left, end=bbox_bottom_right),\n)\n\n# NDJSON\nbbox_prediction_ndjson = {\n \"name\": \"bbox_geo\",\n \"confidence\": 0.5,\n \"bbox\": {\n \"top\":\n coord_object[\"coordinates\"][0][1][1],\n \"left\":\n coord_object[\"coordinates\"][0][1][0],\n \"height\":\n coord_object[\"coordinates\"][0][3][1] -\n coord_object[\"coordinates\"][0][1][1],\n \"width\":\n coord_object[\"coordinates\"][0][3][0] -\n coord_object[\"coordinates\"][0][1][0],\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "\n",
- "####### Classification - radio (single choice) #######\n",
- "\n",
- "# Python Annotation\n",
- "radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question_geo\",\n",
- " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(name=\"first_radio_answer\", confidence=0.5))\n",
- ")\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "radio_prediction_ndjson = {\n",
- " \"name\": \"radio_question_geo\",\n",
- " \"answer\": { \"name\": \"first_radio_answer\", \"confidence\": 0.5}\n",
- "}"
- ],
+ "source": "####### Classification - radio (single choice) #######\n\n# Python Annotation\nradio_prediction = lb_types.ClassificationAnnotation(\n name=\"radio_question_geo\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\", confidence=0.5)),\n)\n\n# NDJSON\nradio_prediction_ndjson = {\n \"name\": \"radio_question_geo\",\n \"answer\": {\n \"name\": \"first_radio_answer\",\n \"confidence\": 0.5\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "####### Classification - Checklist (multi-choice) #######\n",
- "\n",
- "coord_object_checklist = {\n",
- " \"coordinates\": [\n",
- " [\n",
- " [\n",
- " -99.210266,\n",
- " 19.39540372195134\n",
- " ],\n",
- " [\n",
- " -99.210266,\n",
- " 19.396901\n",
- " ],\n",
- " [\n",
- " -99.20621067903966,\n",
- " 19.396901\n",
- " ],\n",
- " [\n",
- " -99.20621067903966,\n",
- " 19.39540372195134\n",
- " ],\n",
- " [\n",
- " -99.210266,\n",
- " 19.39540372195134\n",
- " ]\n",
- " ]\n",
- " ]\n",
- "}\n",
- "\n",
- "# Python Annotation\n",
- "bbox_with_checklist_subclass = lb_types.ObjectAnnotation(\n",
- " name=\"bbox_checklist_geo\",\n",
- " confidence=0.5,\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=-99.210266, y=19.39540372195134), # Top left\n",
- " end=lb_types.Point(x=-99.20621067903966, y=19.396901), # Bottom right\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_class_name\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(name=\"first_checklist_answer\", confidence=0.5)]\n",
- " )\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "bbox_with_checklist_subclass_ndjson = {\n",
- " \"name\": \"bbox_checklist_geo\",\n",
- " \"confidence\": 0.5,\n",
- " \"classifications\": [{\n",
- " \"name\": \"checklist_class_name\",\n",
- " \"answer\": [\n",
- " { \"name\":\"first_checklist_answer\", \"confidence\": 0.5}\n",
- " ]\n",
- " }],\n",
- " \"bbox\": {\n",
- " 'top': coord_object_checklist[\"coordinates\"][0][1][1],\n",
- " 'left': coord_object_checklist[\"coordinates\"][0][1][0],\n",
- " 'height': coord_object_checklist[\"coordinates\"][0][3][1] - coord_object_checklist[\"coordinates\"][0][1][1],\n",
- " 'width': coord_object_checklist[\"coordinates\"][0][3][0] - coord_object_checklist[\"coordinates\"][0][1][0]\n",
- " }\n",
- "}"
- ],
+ "source": "####### Classification - Checklist (multi-choice) #######\n\ncoord_object_checklist = {\n \"coordinates\": [[\n [-99.210266, 19.39540372195134],\n [-99.210266, 19.396901],\n [-99.20621067903966, 19.396901],\n [-99.20621067903966, 19.39540372195134],\n [-99.210266, 19.39540372195134],\n ]]\n}\n\n# Python Annotation\nbbox_with_checklist_subclass = lb_types.ObjectAnnotation(\n name=\"bbox_checklist_geo\",\n confidence=0.5,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=-99.210266, y=19.39540372195134), # Top left\n end=lb_types.Point(x=-99.20621067903966, y=19.396901), # Bottom right\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"checklist_class_name\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\",\n confidence=0.5)\n ]),\n )\n ],\n)\n\n# NDJSON\nbbox_with_checklist_subclass_ndjson = {\n \"name\": \"bbox_checklist_geo\",\n \"confidence\": 0.5,\n \"classifications\": [{\n \"name\": \"checklist_class_name\",\n \"answer\": [{\n \"name\": \"first_checklist_answer\",\n \"confidence\": 0.5\n }],\n }],\n \"bbox\": {\n \"top\":\n coord_object_checklist[\"coordinates\"][0][1][1],\n \"left\":\n coord_object_checklist[\"coordinates\"][0][1][0],\n \"height\":\n coord_object_checklist[\"coordinates\"][0][3][1] -\n coord_object_checklist[\"coordinates\"][0][1][1],\n \"width\":\n coord_object_checklist[\"coordinates\"][0][3][0] -\n coord_object_checklist[\"coordinates\"][0][1][0],\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "####### Classification free form text with bbox #######\n",
- "\n",
- "coord_object_text ={\n",
- " \"coordinates\": [\n",
- " [\n",
- " [\n",
- " -99.21019613742828,\n",
- " 19.397447957052933\n",
- " ],\n",
- " [\n",
- " -99.21019613742828,\n",
- " 19.39772119262215\n",
- " ],\n",
- " [\n",
- " -99.20986354351044,\n",
- " 19.39772119262215\n",
- " ],\n",
- " [\n",
- " -99.20986354351044,\n",
- " 19.397447957052933\n",
- " ],\n",
- " [\n",
- " -99.21019613742828,\n",
- " 19.397447957052933\n",
- " ]\n",
- " ]\n",
- " ]\n",
- "}\n",
- "# Python Annotation\n",
- "bbox_with_free_text_subclass = lb_types.ObjectAnnotation(\n",
- " name=\"bbox_text_geo\",\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=-99.21019613742828, y=19.397447957052933), # Top left\n",
- " end=lb_types.Point(x=-99.20986354351044, y=19.39772119262215), # Bottom right\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"free_text_geo\",\n",
- " value=lb_types.Text(answer=\"sample text\")\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "bbox_with_free_text_subclass_ndjson = {\n",
- " \"name\":\"bbox_text_geo\",\n",
- " \"confidence\": 0.5,\n",
- " \"classifications\": [{\n",
- " \"name\": \"free_text_geo\",\n",
- " \"confidence\": 0.5,\n",
- " \"answer\": \"sample text\"\n",
- " }],\n",
- " \"bbox\": {\n",
- " 'top': coord_object_text[\"coordinates\"][0][1][1],\n",
- " 'left': coord_object_text[\"coordinates\"][0][1][0],\n",
- " 'height': coord_object_text[\"coordinates\"][0][3][1] - coord_object_text[\"coordinates\"][0][1][1],\n",
- " 'width': coord_object_text[\"coordinates\"][0][3][0] - coord_object_text[\"coordinates\"][0][1][0]\n",
- " }\n",
- "}"
- ],
+ "source": "####### Classification free form text with bbox #######\n\ncoord_object_text = {\n \"coordinates\": [[\n [-99.21019613742828, 19.397447957052933],\n [-99.21019613742828, 19.39772119262215],\n [-99.20986354351044, 19.39772119262215],\n [-99.20986354351044, 19.397447957052933],\n [-99.21019613742828, 19.397447957052933],\n ]]\n}\n# Python Annotation\nbbox_with_free_text_subclass = lb_types.ObjectAnnotation(\n name=\"bbox_text_geo\",\n value=lb_types.Rectangle(\n start=lb_types.Point(x=-99.21019613742828,\n y=19.397447957052933), # Top left\n end=lb_types.Point(x=-99.20986354351044,\n y=19.39772119262215), # Bottom right\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"free_text_geo\", value=lb_types.Text(answer=\"sample text\"))\n ],\n)\n\n# NDJSON\nbbox_with_free_text_subclass_ndjson = {\n \"name\": \"bbox_text_geo\",\n \"confidence\": 0.5,\n \"classifications\": [{\n \"name\": \"free_text_geo\",\n \"confidence\": 0.5,\n \"answer\": \"sample text\"\n }],\n \"bbox\": {\n \"top\":\n coord_object_text[\"coordinates\"][0][1][1],\n \"left\":\n coord_object_text[\"coordinates\"][0][1][0],\n \"height\":\n coord_object_text[\"coordinates\"][0][3][1] -\n coord_object_text[\"coordinates\"][0][1][1],\n \"width\":\n coord_object_text[\"coordinates\"][0][3][0] -\n coord_object_text[\"coordinates\"][0][1][0],\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "####### Classification - Checklist (multi-choice) #######\n",
- "\n",
- "# Python Annotation\n",
- "checklist_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question_geo\",\n",
- " value=lb_types.Checklist(answer = [\n",
- " lb_types.ClassificationAnswer(name = \"first_checklist_answer\", confidence = 0.5),\n",
- " lb_types.ClassificationAnswer(name = \"second_checklist_answer\", confidence = 0.5),\n",
- " lb_types.ClassificationAnswer(name = \"third_checklist_answer\", confidence = 0.5)\n",
- " ])\n",
- " )\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "checklist_prediction_ndjson = {\n",
- " 'name': 'checklist_question_geo',\n",
- " 'answer': [\n",
- " {'name': 'first_checklist_answer', \"confidence\": 0.5},\n",
- " {'name': 'second_checklist_answer', \"confidence\": 0.5},\n",
- " {'name': 'third_checklist_answer', \"confidence\": 0.5},\n",
- " ]\n",
- "}"
- ],
+ "source": "####### Classification - Checklist (multi-choice) #######\n\n# Python Annotation\nchecklist_prediction = lb_types.ClassificationAnnotation(\n name=\"checklist_question_geo\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\",\n confidence=0.5),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\",\n confidence=0.5),\n lb_types.ClassificationAnswer(name=\"third_checklist_answer\",\n confidence=0.5),\n ]),\n)\n\n# NDJSON\nchecklist_prediction_ndjson = {\n \"name\":\n \"checklist_question_geo\",\n \"answer\": [\n {\n \"name\": \"first_checklist_answer\",\n \"confidence\": 0.5\n },\n {\n \"name\": \"second_checklist_answer\",\n \"confidence\": 0.5\n },\n {\n \"name\": \"third_checklist_answer\",\n \"confidence\": 0.5\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "\n",
- "########## Classification - Radio and Checklist (with subclassifications) ##########\n",
- "\n",
- "nested_radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " confidence=0.5,\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\",\n",
- " confidence=0.2\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "# NDJSON\n",
- "nested_radio_prediction_ndjson= {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\",\n",
- " \"confidence\": 0.2,\n",
- " \"classifications\": [{\n",
- " \"name\":\"sub_radio_question\",\n",
- " \"answer\": { \"name\" : \"first_sub_radio_answer\", \"confidence\": 0.3}\n",
- " }]\n",
- " }\n",
- "}\n",
- "\n",
- "nested_checklist_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " confidence=0.5,\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\",\n",
- " confidence=0.5\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "nested_checklist_prediction_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"confidence\":0.5,\n",
- " \"classifications\" : [\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\"name\": \"first_sub_checklist_answer\", \"confidence\": 0.5}\n",
- " }\n",
- " ]\n",
- " }]\n",
- "}"
- ],
+ "source": "########## Classification - Radio and Checklist (with subclassifications) ##########\n\nnested_radio_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n confidence=0.5,\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\", confidence=0.2)),\n )\n ],\n )),\n)\n# NDJSON\nnested_radio_prediction_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"confidence\":\n 0.2,\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\",\n \"confidence\": 0.3\n },\n }],\n },\n}\n\nnested_checklist_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n confidence=0.5,\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\",\n confidence=0.5,\n )\n ]),\n )\n ],\n )\n ]),\n)\nnested_checklist_prediction_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"confidence\":\n 0.5,\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\",\n \"confidence\": 0.5,\n },\n }],\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -725,34 +168,7 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "top_left_bound = lb_types.Point(x=-99.21052827588443, y=19.400498983095076)\n",
- "bottom_right_bound = lb_types.Point(x=-99.20534818927473, y=19.39533555271248)\n",
- "\n",
- "epsg = lb_types.EPSG.EPSG4326\n",
- "bounds = lb_types.TiledBounds(epsg=epsg, bounds=[top_left_bound, bottom_right_bound])\n",
- "global_key = \"mexico_city\"\n",
- "\n",
- "tile_layer = lb_types.TileLayer(\n",
- " url=\"https://s3-us-west-1.amazonaws.com/lb-tiler-layers/mexico_city/{z}/{x}/{y}.png\"\n",
- ")\n",
- "\n",
- "tiled_image_data = lb_types.TiledImageData(tile_layer=tile_layer,\n",
- " tile_bounds=bounds,\n",
- " zoom_levels=[17, 23])\n",
- "\n",
- "asset = {\n",
- " \"row_data\": tiled_image_data.asdict(),\n",
- " \"global_key\": global_key,\n",
- " \"media_type\": \"TMS_GEO\"\n",
- "}\n",
- "\n",
- "dataset = client.create_dataset(name=\"geo_demo_dataset\")\n",
- "task= dataset.create_data_rows([asset])\n",
- "print(\"Errors:\",task.errors)\n",
- "print(\"Failed data rows:\", task.failed_data_rows)"
- ],
+ "source": "top_left_bound = lb_types.Point(x=-99.21052827588443, y=19.400498983095076)\nbottom_right_bound = lb_types.Point(x=-99.20534818927473, y=19.39533555271248)\n\nepsg = lb_types.EPSG.EPSG4326\nbounds = lb_types.TiledBounds(epsg=epsg,\n bounds=[top_left_bound, bottom_right_bound])\nglobal_key = \"mexico_city\"\n\ntile_layer = lb_types.TileLayer(\n url=\n \"https://s3-us-west-1.amazonaws.com/lb-tiler-layers/mexico_city/{z}/{x}/{y}.png\"\n)\n\ntiled_image_data = lb_types.TiledImageData(tile_layer=tile_layer,\n tile_bounds=bounds,\n zoom_levels=[17, 23])\n\nasset = {\n \"row_data\": tiled_image_data.asdict(),\n \"global_key\": global_key,\n \"media_type\": \"TMS_GEO\",\n}\n\ndataset = client.create_dataset(name=\"geo_demo_dataset\")\ntask = dataset.create_data_rows([asset])\nprint(\"Errors:\", task.errors)\nprint(\"Failed data rows:\", task.failed_data_rows)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -767,93 +183,7 @@
},
{
"metadata": {},
- "source": [
- "ontology_builder = lb.OntologyBuilder(\n",
- " tools=[\n",
- " lb.Tool(tool=lb.Tool.Type.POINT, name=\"point_geo\"),\n",
- " lb.Tool(tool=lb.Tool.Type.LINE, name=\"polyline_geo\"),\n",
- " lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"polygon_geo\"),\n",
- " lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"polygon_geo_2\"),\n",
- " lb.Tool(tool=lb.Tool.Type.BBOX, name=\"bbox_geo\"),\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.BBOX,\n",
- " name=\"bbox_checklist_geo\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_class_name\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " ]\n",
- " ),\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.BBOX,\n",
- " name=\"bbox_text_geo\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"free_text_geo\"\n",
- " ),\n",
- " ]\n",
- " )\n",
- " ],\n",
- " classifications = [\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_question_geo\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\"),\n",
- " lb.Option(value=\"third_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_question_geo\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\")\n",
- " ]\n",
- " ),\n",
- "\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_sub_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " ]\n",
- " ),\n",
- " ],\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Ontology Geospatial Annotations\", ontology_builder.asdict(), media_type=lb.MediaType.Geospatial_Tile)"
- ],
+ "source": "ontology_builder = lb.OntologyBuilder(\n tools=[\n lb.Tool(tool=lb.Tool.Type.POINT, name=\"point_geo\"),\n lb.Tool(tool=lb.Tool.Type.LINE, name=\"polyline_geo\"),\n lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"polygon_geo\"),\n lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"polygon_geo_2\"),\n lb.Tool(tool=lb.Tool.Type.BBOX, name=\"bbox_geo\"),\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"bbox_checklist_geo\",\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_class_name\",\n options=[lb.Option(value=\"first_checklist_answer\")],\n ),\n ],\n ),\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"bbox_text_geo\",\n classifications=[\n lb.Classification(class_type=lb.Classification.Type.TEXT,\n name=\"free_text_geo\"),\n ],\n ),\n ],\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_question_geo\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n lb.Option(value=\"third_checklist_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_question_geo\",\n options=[lb.Option(value=\"first_radio_answer\")],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n options=[\n lb.Option(\n value=\"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(value=\"first_sub_radio_answer\")],\n ),\n ],\n ),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n ],\n)\n\nontology = client.create_ontology(\n \"Ontology Geospatial Annotations\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Geospatial_Tile,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -867,13 +197,7 @@
},
{
"metadata": {},
- "source": [
- "# create Model\n",
- "model = client.create_model(name=\"geospatial_model_run_\" + str(uuid.uuid4()),\n",
- " ontology_id=ontology.uid)\n",
- "# create Model Run\n",
- "model_run = model.create_model_run(\"iteration 1\")"
- ],
+ "source": "# create Model\nmodel = client.create_model(name=\"geospatial_model_run_\" + str(uuid.uuid4()),\n ontology_id=ontology.uid)\n# create Model Run\nmodel_run = model.create_model_run(\"iteration 1\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -887,9 +211,7 @@
},
{
"metadata": {},
- "source": [
- "model_run.upsert_data_rows(global_keys=[global_key])"
- ],
+ "source": "model_run.upsert_data_rows(global_keys=[global_key])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -907,61 +229,14 @@
},
{
"metadata": {},
- "source": [
- " ## Lets create another polygon annotation with python annotation tools that draws the image using cv2 and PIL python libraries\n",
- "\n",
- "hsv = cv2.cvtColor(tiled_image_data.value, cv2.COLOR_RGB2HSV)\n",
- "mask = cv2.inRange(hsv, (25, 50, 25), (100, 150, 255))\n",
- "kernel = np.ones((15, 20), np.uint8)\n",
- "mask = cv2.erode(mask, kernel)\n",
- "mask = cv2.dilate(mask, kernel)\n",
- "mask_annotation = lb_types.MaskData.from_2D_arr(mask)\n",
- "mask_data = lb_types.Mask(mask=mask_annotation, color=[255, 255, 255])\n",
- "h, w, _ = tiled_image_data.value.shape\n",
- "pixel_bounds = lb_types.TiledBounds(epsg=lb_types.EPSG.SIMPLEPIXEL,\n",
- " bounds=[lb_types.Point(x=0, y=0),\n",
- " lb_types.Point(x=w, y=h)])\n",
- "transformer = lb_types.EPSGTransformer.create_pixel_to_geo_transformer(\n",
- " src_epsg=pixel_bounds.epsg,\n",
- " pixel_bounds=pixel_bounds,\n",
- " geo_bounds=tiled_image_data.tile_bounds,\n",
- " zoom=23)\n",
- "pixel_polygons = mask_data.shapely.simplify(3)\n",
- "list_of_polygons = [transformer(lb_types.Polygon.from_shapely(p)) for p in pixel_polygons.geoms]\n",
- "polygon_prediction_two = lb_types.ObjectAnnotation(value=list_of_polygons[0], name=\"polygon_geo_2\", confidence=0.5)\n"
- ],
+ "source": "## Lets create another polygon annotation with python annotation tools that draws the image using cv2 and PIL python libraries\n\nhsv = cv2.cvtColor(tiled_image_data.value, cv2.COLOR_RGB2HSV)\nmask = cv2.inRange(hsv, (25, 50, 25), (100, 150, 255))\nkernel = np.ones((15, 20), np.uint8)\nmask = cv2.erode(mask, kernel)\nmask = cv2.dilate(mask, kernel)\nmask_annotation = lb_types.MaskData.from_2D_arr(mask)\nmask_data = lb_types.Mask(mask=mask_annotation, color=[255, 255, 255])\nh, w, _ = tiled_image_data.value.shape\npixel_bounds = lb_types.TiledBounds(\n epsg=lb_types.EPSG.SIMPLEPIXEL,\n bounds=[lb_types.Point(x=0, y=0),\n lb_types.Point(x=w, y=h)],\n)\ntransformer = lb_types.EPSGTransformer.create_pixel_to_geo_transformer(\n src_epsg=pixel_bounds.epsg,\n pixel_bounds=pixel_bounds,\n geo_bounds=tiled_image_data.tile_bounds,\n zoom=23,\n)\npixel_polygons = mask_data.shapely.simplify(3)\nlist_of_polygons = [\n transformer(lb_types.Polygon.from_shapely(p)) for p in pixel_polygons.geoms\n]\npolygon_prediction_two = lb_types.ObjectAnnotation(value=list_of_polygons[0],\n name=\"polygon_geo_2\",\n confidence=0.5)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "labels =[]\n",
- "labels.append(\n",
- " lb_types.Label(\n",
- " data={\n",
- " \"global_key\": global_key,\n",
- " \"tile_layer\": tile_layer,\n",
- " \"tile_bounds\":bounds,\n",
- " \"zoom_levels\": [12, 20]\n",
- " },\n",
- " annotations = [\n",
- " point_prediction,\n",
- " polyline_prediction,\n",
- " polygon_prediction,\n",
- " bbox_prediction,\n",
- " radio_prediction,\n",
- " bbox_with_checklist_subclass,\n",
- " bbox_with_free_text_subclass,\n",
- " checklist_prediction,\n",
- " polygon_prediction_two,\n",
- " nested_checklist_prediction,\n",
- " nested_radio_prediction\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "labels = []\nlabels.append(\n lb_types.Label(\n data={\n \"global_key\": global_key,\n \"tile_layer\": tile_layer,\n \"tile_bounds\": bounds,\n \"zoom_levels\": [12, 20],\n },\n annotations=[\n point_prediction,\n polyline_prediction,\n polygon_prediction,\n bbox_prediction,\n radio_prediction,\n bbox_with_checklist_subclass,\n bbox_with_free_text_subclass,\n checklist_prediction,\n polygon_prediction_two,\n nested_checklist_prediction,\n nested_radio_prediction,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -975,25 +250,7 @@
},
{
"metadata": {},
- "source": [
- "label_ndjson = []\n",
- "for prediction in [\n",
- " radio_prediction_ndjson,\n",
- " checklist_prediction_ndjson,\n",
- " bbox_with_free_text_subclass_ndjson,\n",
- " bbox_with_checklist_subclass_ndjson,\n",
- " bbox_prediction_ndjson,\n",
- " point_prediction_ndjson,\n",
- " polyline_prediction_ndjson,\n",
- " polygon_prediction_ndjson,\n",
- " nested_checklist_prediction_ndjson,\n",
- " nested_radio_prediction_ndjson\n",
- "]:\n",
- " prediction.update({\n",
- " 'dataRow': {'globalKey': global_key},\n",
- " })\n",
- " label_ndjson.append(prediction)"
- ],
+ "source": "label_ndjson = []\nfor prediction in [\n radio_prediction_ndjson,\n checklist_prediction_ndjson,\n bbox_with_free_text_subclass_ndjson,\n bbox_with_checklist_subclass_ndjson,\n bbox_prediction_ndjson,\n point_prediction_ndjson,\n polyline_prediction_ndjson,\n polygon_prediction_ndjson,\n nested_checklist_prediction_ndjson,\n nested_radio_prediction_ndjson,\n]:\n prediction.update({\n \"dataRow\": {\n \"globalKey\": global_key\n },\n })\n label_ndjson.append(prediction)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1007,16 +264,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload the prediction label to the Model Run\n",
- "upload_job_prediction = model_run.add_predictions(\n",
- " name=\"prediction_upload_job\"+str(uuid.uuid4()),\n",
- " predictions=labels)\n",
- "\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_prediction.errors)\n",
- "print(\"Status of uploads: \", upload_job_prediction.statuses)"
- ],
+ "source": "# Upload the prediction label to the Model Run\nupload_job_prediction = model_run.add_predictions(name=\"prediction_upload_job\" +\n str(uuid.uuid4()),\n predictions=labels)\n\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_prediction.errors)\nprint(\"Status of uploads: \", upload_job_prediction.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1038,12 +286,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Labelbox project\n",
- "project = client.create_project(name=\"geospatial_prediction_demo\",\n",
- " media_type=lb.MediaType.Geospatial_Tile)\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "# Create a Labelbox project\nproject = client.create_project(name=\"geospatial_prediction_demo\",\n media_type=lb.MediaType.Geospatial_Tile)\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1057,13 +300,7 @@
},
{
"metadata": {},
- "source": [
- "project.create_batch(\n",
- " \"batch_geospatial_prediction_demo\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # A list of data rows or data row ids\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")"
- ],
+ "source": "project.create_batch(\n \"batch_geospatial_prediction_demo\", # Each batch in a project must have a unique name\n global_keys=[global_key], # A list of data rows or data row ids\n priority=5, # priority between 1(Highest) - 5(lowest)\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1077,139 +314,7 @@
},
{
"metadata": {},
- "source": [
- "####### Point #######\n",
- "\n",
- "# Python Annotation\n",
- "point_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"point_geo\",\n",
- " value = lb_types.Point(x=-99.20647859573366, y=19.40018029091072),\n",
- ")\n",
- "\n",
- "####### Polyline #######\n",
- "line_points = []\n",
- "line_points_ndjson = []\n",
- "\n",
- "for sub in coords:\n",
- " line_points.append(lb_types.Point(x=sub[0], y=sub[1]))\n",
- " line_points_ndjson.append({\"x\":sub[0], \"y\":sub[1]})\n",
- "\n",
- "# Python Annotation\n",
- "polyline_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"polyline_geo\",\n",
- " value = lb_types.Line(points=line_points),\n",
- ")\n",
- "\n",
- "\n",
- "\n",
- "polygon_points = []\n",
- "polygon_points_ndjson = []\n",
- "\n",
- "for sub in coords_polygon:\n",
- " polygon_points.append(lb_types.Point(x=sub[0], y=sub[1]))\n",
- " polygon_points_ndjson.append({\"x\":sub[0], \"y\":sub[1]})\n",
- "\n",
- "# Python Annotation\n",
- "polygon_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"polygon_geo\",\n",
- " value = lb_types.Polygon(points=polygon_points),\n",
- ")\n",
- "\n",
- "\n",
- "\n",
- "bbox_top_left = lb_types.Point(x= -99.20746564865112, y=19.39799442829336)\n",
- "bbox_bottom_right = lb_types.Point(x=-99.20568466186523, y=19.39925939999194)\n",
- "\n",
- "# Python Annotation\n",
- "bbox_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"bbox_geo\",\n",
- " value = lb_types.Rectangle(start=bbox_top_left, end=bbox_bottom_right)\n",
- ")\n",
- "\n",
- "# Python Annotation\n",
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question_geo\",\n",
- " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(name=\"first_radio_answer\"))\n",
- ")\n",
- "\n",
- "# Python Annotation\n",
- "bbox_with_checklist_subclass = lb_types.ObjectAnnotation(\n",
- " name=\"bbox_checklist_geo\",\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=-99.210266, y=19.39540372195134), # Top left\n",
- " end=lb_types.Point(x=-99.20621067903966, y=19.396901), # Bottom right\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_class_name\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(name=\"first_checklist_answer\")]\n",
- " )\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "bbox_with_free_text_subclass = lb_types.ObjectAnnotation(\n",
- " name=\"bbox_text_geo\",\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=-99.21019613742828, y=19.397447957052933), # Top left\n",
- " end=lb_types.Point(x=-99.20986354351044, y=19.39772119262215), # Bottom right\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"free_text_geo\",\n",
- " value=lb_types.Text(answer=\"sample text\")\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question_geo\",\n",
- " value=lb_types.Checklist(answer = [\n",
- " lb_types.ClassificationAnswer(name = \"first_checklist_answer\"),\n",
- " lb_types.ClassificationAnswer(name = \"second_checklist_answer\"),\n",
- " lb_types.ClassificationAnswer(name = \"third_checklist_answer\")\n",
- " ])\n",
- " )\n",
- "\n",
- "\n",
- "nested_radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "\n",
- "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\"\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")"
- ],
+ "source": "####### Point #######\n\n# Python Annotation\npoint_annotation = lb_types.ObjectAnnotation(\n name=\"point_geo\",\n value=lb_types.Point(x=-99.20647859573366, y=19.40018029091072),\n)\n\n####### Polyline #######\nline_points = []\nline_points_ndjson = []\n\nfor sub in coords:\n line_points.append(lb_types.Point(x=sub[0], y=sub[1]))\n line_points_ndjson.append({\"x\": sub[0], \"y\": sub[1]})\n\n# Python Annotation\npolyline_annotation = lb_types.ObjectAnnotation(\n name=\"polyline_geo\",\n value=lb_types.Line(points=line_points),\n)\n\npolygon_points = []\npolygon_points_ndjson = []\n\nfor sub in coords_polygon:\n polygon_points.append(lb_types.Point(x=sub[0], y=sub[1]))\n polygon_points_ndjson.append({\"x\": sub[0], \"y\": sub[1]})\n\n# Python Annotation\npolygon_annotation = lb_types.ObjectAnnotation(\n name=\"polygon_geo\",\n value=lb_types.Polygon(points=polygon_points),\n)\n\nbbox_top_left = lb_types.Point(x=-99.20746564865112, y=19.39799442829336)\nbbox_bottom_right = lb_types.Point(x=-99.20568466186523, y=19.39925939999194)\n\n# Python Annotation\nbbox_annotation = lb_types.ObjectAnnotation(\n name=\"bbox_geo\",\n value=lb_types.Rectangle(start=bbox_top_left, end=bbox_bottom_right),\n)\n\n# Python Annotation\nradio_annotation = lb_types.ClassificationAnnotation(\n name=\"radio_question_geo\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\")),\n)\n\n# Python Annotation\nbbox_with_checklist_subclass = lb_types.ObjectAnnotation(\n name=\"bbox_checklist_geo\",\n value=lb_types.Rectangle(\n start=lb_types.Point(x=-99.210266, y=19.39540372195134), # Top left\n end=lb_types.Point(x=-99.20621067903966, y=19.396901), # Bottom right\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"checklist_class_name\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\")\n ]),\n )\n ],\n)\n\nbbox_with_free_text_subclass = lb_types.ObjectAnnotation(\n name=\"bbox_text_geo\",\n value=lb_types.Rectangle(\n start=lb_types.Point(x=-99.21019613742828,\n y=19.397447957052933), # Top left\n end=lb_types.Point(x=-99.20986354351044,\n y=19.39772119262215), # Bottom right\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"free_text_geo\", value=lb_types.Text(answer=\"sample text\"))\n ],\n)\n\nchecklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_question_geo\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"third_checklist_answer\"),\n ]),\n)\n\nnested_radio_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n)\n\nnested_checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n )\n ]),\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1223,31 +328,7 @@
},
{
"metadata": {},
- "source": [
- "labels =[]\n",
- "labels.append(\n",
- " lb_types.Label(\n",
- " data=lb_types.TiledImageData(\n",
- " global_key=global_key,\n",
- " tile_layer=tile_layer,\n",
- " tile_bounds=bounds,\n",
- " zoom_levels=[12, 20]\n",
- " ),\n",
- " annotations = [\n",
- " point_annotation,\n",
- " polyline_annotation,\n",
- " polygon_annotation,\n",
- " bbox_annotation,\n",
- " radio_annotation,\n",
- " bbox_with_checklist_subclass,\n",
- " bbox_with_free_text_subclass,\n",
- " checklist_annotation,\n",
- " nested_checklist_annotation,\n",
- " nested_radio_annotation\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "labels = []\nlabels.append(\n lb_types.Label(\n data=lb_types.TiledImageData(\n global_key=global_key,\n tile_layer=tile_layer,\n tile_bounds=bounds,\n zoom_levels=[12, 20],\n ),\n annotations=[\n point_annotation,\n polyline_annotation,\n polygon_annotation,\n bbox_annotation,\n radio_annotation,\n bbox_with_checklist_subclass,\n bbox_with_free_text_subclass,\n checklist_annotation,\n nested_checklist_annotation,\n nested_radio_annotation,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1261,18 +342,7 @@
},
{
"metadata": {},
- "source": [
- "upload_job_annotation = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"geospatial_annotations_import_\" + str(uuid.uuid4()),\n",
- " labels=labels)\n",
- "\n",
- "upload_job_annotation.wait_until_done()\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_annotation.errors)\n",
- "print(\"Status of uploads: \", upload_job_annotation.statuses)"
- ],
+ "source": "upload_job_annotation = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"geospatial_annotations_import_\" + str(uuid.uuid4()),\n labels=labels,\n)\n\nupload_job_annotation.wait_until_done()\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_annotation.errors)\nprint(\"Status of uploads: \", upload_job_annotation.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1286,10 +356,7 @@
},
{
"metadata": {},
- "source": [
- "# get the labels id from the project\n",
- "model_run.upsert_labels(project_id=project.uid)"
- ],
+ "source": "# get the labels id from the project\nmodel_run.upsert_labels(project_id=project.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1303,11 +370,7 @@
},
{
"metadata": {},
- "source": [
- "#upload_job\n",
- "# project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# upload_job\n# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/prediction_upload/html_predictions.ipynb b/examples/prediction_upload/html_predictions.ipynb
index 7148cf06f..14e5510a1 100644
--- a/examples/prediction_upload/html_predictions.ipynb
+++ b/examples/prediction_upload/html_predictions.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -21,7 +21,7 @@
"\n",
"\n",
"\n",
- "![]() \n",
" | "
],
@@ -60,21 +60,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import labelbox.types as lb_types\n",
- "import uuid\n",
- "import numpy as np"
- ],
+ "source": "import labelbox as lb\nimport labelbox.types as lb_types\nimport uuid\nimport numpy as np",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -89,10 +82,7 @@
},
{
"metadata": {},
- "source": [
- "API_KEY = \"\"\n",
- "client = lb.Client(API_KEY)"
- ],
+ "source": "API_KEY = \"\"\nclient = lb.Client(API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -106,152 +96,28 @@
},
{
"metadata": {},
- "source": [
- "########### Radio Classification ###########\n",
- "radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question\", # Should match the name in the ontology\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(name = \"first_radio_answer\", confidence=0.5))\n",
- ")\n",
- "\n",
- "radio_prediction_ndjson = {\n",
- " \"name\": \"radio_question\",\n",
- " \"answer\": {\"name\": \"first_radio_answer\"}\n",
- "}"
- ],
+ "source": "########### Radio Classification ###########\nradio_prediction = lb_types.ClassificationAnnotation(\n name=\"radio_question\", # Should match the name in the ontology\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\", confidence=0.5)),\n)\n\nradio_prediction_ndjson = {\n \"name\": \"radio_question\",\n \"answer\": {\n \"name\": \"first_radio_answer\"\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "#### Nested Classifications ######\n",
- "\n",
- "# Python annotation\n",
- "nested_radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " confidence=0.5,# Confidence scores should be added to the answer\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\", confidence=0.5)\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "\n",
- "nested_radio_prediction_ndjson = {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\",\n",
- " \"confidence\": 0.5, # Confidence scores should be added to the answer\n",
- " \"classifications\": [{\n",
- " \"name\":\"sub_radio_question\",\n",
- " \"answer\": { \"name\" : \"first_sub_radio_answer\", \"confidence\": 0.5 }\n",
- " }]\n",
- " }\n",
- "}\n",
- "\n",
- "nested_checklist_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " confidence=0.5, # Confidence scores should be added to the answer\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\",\n",
- " confidence=0.5\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "\n",
- "nested_checklist_prediction_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"confidence\": 0.5, # Confidence scores should be added to the answer\n",
- " \"classifications\" : [\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\"name\": \"first_sub_checklist_answer\", \"confidence\": 0.5 }\n",
- " }\n",
- " ]\n",
- " }]\n",
- "}"
- ],
+ "source": "#### Nested Classifications ######\n\n# Python annotation\nnested_radio_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n confidence=0.5, # Confidence scores should be added to the answer\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\", confidence=0.5)),\n )\n ],\n )),\n)\n\nnested_radio_prediction_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"confidence\":\n 0.5, # Confidence scores should be added to the answer\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\",\n \"confidence\": 0.5\n },\n }],\n },\n}\n\nnested_checklist_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n confidence=0.5, # Confidence scores should be added to the answer\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\",\n confidence=0.5,\n )\n ]),\n )\n ],\n )\n ]),\n)\n\nnested_checklist_prediction_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"confidence\":\n 0.5, # Confidence scores should be added to the answer\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\",\n \"confidence\": 0.5,\n },\n }],\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########## Checklist ##########\n",
- "\n",
- "# Python annotation\n",
- "checklist_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\",\n",
- " confidence=0.5\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\",\n",
- " confidence=0.5\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"third_checklist_answer\",\n",
- " confidence=0.5\n",
- " )\n",
- " ])\n",
- " )\n",
- "\n",
- "# NDJSON\n",
- "checklist_prediction_ndjson = {\n",
- " \"name\": \"checklist_question\",\n",
- " \"answer\": [\n",
- " {\"name\": \"first_checklist_answer\", \"confidence\": 0.5}\n",
- " ]\n",
- "}\n"
- ],
+ "source": "########## Checklist ##########\n\n# Python annotation\nchecklist_prediction = lb_types.ClassificationAnnotation(\n name=\"checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\",\n confidence=0.5),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\",\n confidence=0.5),\n lb_types.ClassificationAnswer(name=\"third_checklist_answer\",\n confidence=0.5),\n ]),\n)\n\n# NDJSON\nchecklist_prediction_ndjson = {\n \"name\": \"checklist_question\",\n \"answer\": [{\n \"name\": \"first_checklist_answer\",\n \"confidence\": 0.5\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########## Classification Free-Form text ##########\n",
- "## Text classifications do not support confidence values\n",
- "# Python annotation\n",
- "text_prediction = lb_types.ClassificationAnnotation(\n",
- " name = \"free_text\",\n",
- " value = lb_types.Text(answer=\"sample text\", confidence=0.5)\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "text_prediction_ndjson = {\n",
- " \"name\": \"free_text\",\n",
- " \"answer\": \"sample text\",\n",
- " \"confidence\": 0.5\n",
- "}"
- ],
+ "source": "########## Classification Free-Form text ##########\n## Text classifications do not support confidence values\n# Python annotation\ntext_prediction = lb_types.ClassificationAnnotation(name=\"free_text\",\n value=lb_types.Text(\n answer=\"sample text\",\n confidence=0.5))\n\n# NDJSON\ntext_prediction_ndjson = {\n \"name\": \"free_text\",\n \"answer\": \"sample text\",\n \"confidence\": 0.5,\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -265,23 +131,7 @@
},
{
"metadata": {},
- "source": [
- "# send a sample image as batch to the project\n",
- "global_key =\"sample_html_2.html\"\n",
- "\n",
- "test_img_url = {\n",
- " \"row_data\": \"https://storage.googleapis.com/labelbox-datasets/html_sample_data/sample_html_2.html\",\n",
- " \"global_key\": global_key\n",
- "}\n",
- "dataset = client.create_dataset(\n",
- " name=\"html prediction demo dataset\",\n",
- " iam_integration=None # Removing this argument will default to the organziation's default iam integration\n",
- ")\n",
- "task = dataset.create_data_rows([test_img_url])\n",
- "task.wait_till_done()\n",
- "print(\"Errors:\",task.errors)\n",
- "print(\"Failed data rows:\", task.failed_data_rows)"
- ],
+ "source": "# send a sample image as batch to the project\nglobal_key = \"sample_html_2.html\"\n\ntest_img_url = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/html_sample_data/sample_html_2.html\",\n \"global_key\":\n global_key,\n}\ndataset = client.create_dataset(\n name=\"html prediction demo dataset\",\n iam_integration=\n None, # Removing this argument will default to the organziation's default iam integration\n)\ntask = dataset.create_data_rows([test_img_url])\ntask.wait_till_done()\nprint(\"Errors:\", task.errors)\nprint(\"Failed data rows:\", task.failed_data_rows)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -296,66 +146,7 @@
},
{
"metadata": {},
- "source": [
- "## Setup the ontology and link the tools created above.\n",
- "\n",
- "ontology_builder = lb.OntologyBuilder(\n",
- " classifications=[ # List of Classification objects\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_question\", # name matching the tool used in the annotation\n",
- " options=[lb.Option(value=\"first_radio_answer\")]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_sub_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " ]\n",
- " )\n",
- " ],\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\"),\n",
- " lb.Option(value=\"third_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"free_text\"\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Ontology HTML Predictions\", ontology_builder.asdict(), media_type=lb.MediaType.Html)\n"
- ],
+ "source": "## Setup the ontology and link the tools created above.\n\nontology_builder = lb.OntologyBuilder(\n classifications=[ # List of Classification objects\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\n \"radio_question\", # name matching the tool used in the annotation\n options=[lb.Option(value=\"first_radio_answer\")],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n options=[\n lb.Option(\n value=\"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(value=\"first_sub_radio_answer\")],\n ),\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_question\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n lb.Option(value=\"third_checklist_answer\"),\n ],\n ),\n lb.Classification(class_type=lb.Classification.Type.TEXT,\n name=\"free_text\"),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n ])\n\nontology = client.create_ontology(\n \"Ontology HTML Predictions\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Html,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -369,13 +160,7 @@
},
{
"metadata": {},
- "source": [
- "# create Model\n",
- "model = client.create_model(name=\"HTML_model_run_\" + str(uuid.uuid4()),\n",
- " ontology_id=ontology.uid)\n",
- "# create Model Run\n",
- "model_run = model.create_model_run(\"iteration 1\")"
- ],
+ "source": "# create Model\nmodel = client.create_model(name=\"HTML_model_run_\" + str(uuid.uuid4()),\n ontology_id=ontology.uid)\n# create Model Run\nmodel_run = model.create_model_run(\"iteration 1\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -389,9 +174,7 @@
},
{
"metadata": {},
- "source": [
- "model_run.upsert_data_rows(global_keys=[global_key])"
- ],
+ "source": "model_run.upsert_data_rows(global_keys=[global_key])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -411,22 +194,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Label for predictions\n",
- "label_prediction = []\n",
- "label_prediction.append(\n",
- " lb_types.Label(\n",
- " data=lb_types.HTMLData(global_key=global_key),\n",
- " annotations = [\n",
- " radio_prediction,\n",
- " checklist_prediction,\n",
- " text_prediction,\n",
- " nested_checklist_prediction,\n",
- " nested_radio_prediction\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "# Create a Label for predictions\nlabel_prediction = []\nlabel_prediction.append(\n lb_types.Label(\n data=lb_types.HTMLData(global_key=global_key),\n annotations=[\n radio_prediction,\n checklist_prediction,\n text_prediction,\n nested_checklist_prediction,\n nested_radio_prediction,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -440,21 +208,7 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "label_prediction_ndjson = []\n",
- "for annot in [\n",
- " radio_prediction_ndjson,\n",
- " nested_radio_prediction_ndjson,\n",
- " checklist_prediction_ndjson,\n",
- " text_prediction_ndjson,\n",
- " nested_checklist_prediction_ndjson\n",
- "]:\n",
- " annot.update({\n",
- " \"dataRow\": {\"globalKey\": global_key},\n",
- " })\n",
- " label_prediction_ndjson.append(annot)"
- ],
+ "source": "label_prediction_ndjson = []\nfor annot in [\n radio_prediction_ndjson,\n nested_radio_prediction_ndjson,\n checklist_prediction_ndjson,\n text_prediction_ndjson,\n nested_checklist_prediction_ndjson,\n]:\n annot.update({\n \"dataRow\": {\n \"globalKey\": global_key\n },\n })\n label_prediction_ndjson.append(annot)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -468,16 +222,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload the prediction label to the Model Run\n",
- "upload_job_prediction = model_run.add_predictions(\n",
- " name=\"prediction_upload_job\"+str(uuid.uuid4()),\n",
- " predictions=label_prediction)\n",
- "\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_prediction.errors)\n",
- "print(\"Status of uploads: \", upload_job_prediction.statuses)"
- ],
+ "source": "# Upload the prediction label to the Model Run\nupload_job_prediction = model_run.add_predictions(\n name=\"prediction_upload_job\" + str(uuid.uuid4()),\n predictions=label_prediction,\n)\n\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_prediction.errors)\nprint(\"Status of uploads: \", upload_job_prediction.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -499,12 +244,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Labelbox project\n",
- "project = client.create_project(name=\"HTML prediction import demo\",\n",
- " media_type=lb.MediaType.Html)\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "# Create a Labelbox project\nproject = client.create_project(name=\"HTML prediction import demo\",\n media_type=lb.MediaType.Html)\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -518,13 +258,7 @@
},
{
"metadata": {},
- "source": [
- "project.create_batch(\n",
- " \"batch_prediction_html\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")"
- ],
+ "source": "project.create_batch(\n \"batch_prediction_html\", # Each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # Paginated collection of data row objects, list of data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -538,71 +272,7 @@
},
{
"metadata": {},
- "source": [
- "###### Annotations ######\n",
- "\n",
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question\",\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(name = \"first_radio_answer\"))\n",
- ")\n",
- "\n",
- "nested_radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\")\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "\n",
- "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\",\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "\n",
- "checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\",\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\",\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"third_checklist_answer\",\n",
- " )\n",
- " ])\n",
- ")\n",
- "\n",
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name = \"free_text\",\n",
- " value = lb_types.Text(answer=\"sample text\")\n",
- ")"
- ],
+ "source": "###### Annotations ######\n\nradio_annotation = lb_types.ClassificationAnnotation(\n name=\"radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\")),\n)\n\nnested_radio_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n)\n\nnested_checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\",)\n ]),\n )\n ],\n )\n ]),\n)\n\nchecklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\",),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\",),\n lb_types.ClassificationAnswer(name=\"third_checklist_answer\",),\n ]),\n)\n\ntext_annotation = lb_types.ClassificationAnnotation(\n name=\"free_text\", value=lb_types.Text(answer=\"sample text\"))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -616,21 +286,7 @@
},
{
"metadata": {},
- "source": [
- "label = []\n",
- "label.append(\n",
- " lb_types.Label(\n",
- " data={\"global_key\" : global_key },\n",
- " annotations=[\n",
- " text_annotation,\n",
- " checklist_annotation,\n",
- " radio_annotation,\n",
- " nested_checklist_annotation,\n",
- " nested_radio_annotation\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "label = []\nlabel.append(\n lb_types.Label(\n data={\"global_key\": global_key},\n annotations=[\n text_annotation,\n checklist_annotation,\n radio_annotation,\n nested_checklist_annotation,\n nested_radio_annotation,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -644,18 +300,7 @@
},
{
"metadata": {},
- "source": [
- "upload_job_annotation = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"html_annotation_import\" + str(uuid.uuid4()),\n",
- " labels=label)\n",
- "\n",
- "upload_job_annotation.wait_until_done()\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_annotation.errors)\n",
- "print(\"Status of uploads: \", upload_job_annotation.statuses)\n"
- ],
+ "source": "upload_job_annotation = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"html_annotation_import\" + str(uuid.uuid4()),\n labels=label,\n)\n\nupload_job_annotation.wait_until_done()\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_annotation.errors)\nprint(\"Status of uploads: \", upload_job_annotation.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -669,10 +314,7 @@
},
{
"metadata": {},
- "source": [
- "# get the labels id from the project\n",
- "model_run.upsert_labels(project_id=project.uid)"
- ],
+ "source": "# get the labels id from the project\nmodel_run.upsert_labels(project_id=project.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -686,10 +328,7 @@
},
{
"metadata": {},
- "source": [
- "# project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/prediction_upload/image_predictions.ipynb b/examples/prediction_upload/image_predictions.ipynb
index f48ad559e..b28c9f78f 100644
--- a/examples/prediction_upload/image_predictions.ipynb
+++ b/examples/prediction_upload/image_predictions.ipynb
@@ -6,23 +6,22 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
{
"metadata": {},
"source": [
- "\n",
"\n",
" \n",
" | \n",
"\n",
"\n",
- "![]() \n",
" | "
],
@@ -70,21 +69,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import uuid\n",
- "import requests\n",
- "import labelbox as lb\n",
- "import labelbox.types as lb_types"
- ],
+ "source": "import uuid\nimport requests\nimport labelbox as lb\nimport labelbox.types as lb_types",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -99,10 +91,7 @@
},
{
"metadata": {},
- "source": [
- "API_KEY = \"\"\n",
- "client = lb.Client(API_KEY)"
- ],
+ "source": "API_KEY = \"\"\nclient = lb.Client(API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -123,19 +112,7 @@
},
{
"metadata": {},
- "source": [
- "# Python annotation\n",
- "radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question\",\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(name = \"second_radio_answer\", confidence=0.5))\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "radio_prediction_ndjson = {\n",
- " \"name\": \"radio_question\",\n",
- " \"answer\": {\"name\": \"second_radio_answer\", \"confidence\": 0.5}\n",
- "}"
- ],
+ "source": "# Python annotation\nradio_prediction = lb_types.ClassificationAnnotation(\n name=\"radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"second_radio_answer\", confidence=0.5)),\n)\n\n# NDJSON\nradio_prediction_ndjson = {\n \"name\": \"radio_question\",\n \"answer\": {\n \"name\": \"second_radio_answer\",\n \"confidence\": 0.5\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -149,79 +126,7 @@
},
{
"metadata": {},
- "source": [
- "nested_radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " confidence=0.5,\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\",\n",
- " confidence=0.5\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "\n",
- "nested_radio_prediction_ndjson = {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\",\n",
- " \"confidence\": 0.5,\n",
- " \"classifications\": [{\n",
- " \"name\": \"sub_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_sub_radio_answer\",\n",
- " \"confidence\": 0.5\n",
- " }\n",
- " }]\n",
- " }\n",
- "}\n",
- "\n",
- "\n",
- "nested_checklist_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " confidence=0.5,\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\",\n",
- " confidence=0.5\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "\n",
- "nested_checklist_prediction_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"confidence\": 0.5,\n",
- " \"classifications\": [{\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_sub_checklist_answer\",\n",
- " \"confidence\": 0.5\n",
- " }\n",
- " }]\n",
- " }]\n",
- "}"
- ],
+ "source": "nested_radio_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n confidence=0.5,\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\", confidence=0.5)),\n )\n ],\n )),\n)\n\nnested_radio_prediction_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"confidence\":\n 0.5,\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\",\n \"confidence\": 0.5\n },\n }],\n },\n}\n\nnested_checklist_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n confidence=0.5,\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\",\n confidence=0.5,\n )\n ]),\n )\n ],\n )\n ]),\n)\n\nnested_checklist_prediction_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"confidence\":\n 0.5,\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\",\n \"confidence\": 0.5,\n },\n }],\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -235,33 +140,7 @@
},
{
"metadata": {},
- "source": [
- "# Python Annotations\n",
- "checklist_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\",\n",
- " confidence=0.5\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\",\n",
- " confidence=0.5\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- "\n",
- "# NDJSON\n",
- "checklist_prediction_ndjson = {\n",
- " \"name\": \"checklist_question\",\n",
- " \"answer\": [\n",
- " {\"name\": \"first_checklist_answer\" , \"confidence\": 0.5},\n",
- " {\"name\": \"second_checklist_answer\", \"confidence\": 0.5}\n",
- " ]\n",
- "}"
- ],
+ "source": "# Python Annotations\nchecklist_prediction = lb_types.ClassificationAnnotation(\n name=\"checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\",\n confidence=0.5),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\",\n confidence=0.5),\n ]),\n)\n\n# NDJSON\nchecklist_prediction_ndjson = {\n \"name\":\n \"checklist_question\",\n \"answer\": [\n {\n \"name\": \"first_checklist_answer\",\n \"confidence\": 0.5\n },\n {\n \"name\": \"second_checklist_answer\",\n \"confidence\": 0.5\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -275,29 +154,7 @@
},
{
"metadata": {},
- "source": [
- "# Python Annotation\n",
- "bbox_prediction = lb_types.ObjectAnnotation(\n",
- " name = \"bounding_box\",\n",
- " confidence=0.5,\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=1690, y=977), # x = left, y = top\n",
- " end=lb_types.Point(x=1915, y=1307), # x= left + width , y = top + height\n",
- " )\n",
- ")\n",
- "\n",
- "#NDJSON\n",
- "bbox_prediction_ndjson = {\n",
- " \"name\": \"bounding_box\",\n",
- " \"confidence\": 0.5,\n",
- " \"bbox\": {\n",
- " \"top\": 977,\n",
- " \"left\": 1690,\n",
- " \"height\": 330,\n",
- " \"width\": 225\n",
- " }\n",
- "}\n"
- ],
+ "source": "# Python Annotation\nbbox_prediction = lb_types.ObjectAnnotation(\n name=\"bounding_box\",\n confidence=0.5,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=1690, y=977), # x = left, y = top\n end=lb_types.Point(x=1915,\n y=1307), # x= left + width , y = top + height\n ),\n)\n\n# NDJSON\nbbox_prediction_ndjson = {\n \"name\": \"bounding_box\",\n \"confidence\": 0.5,\n \"bbox\": {\n \"top\": 977,\n \"left\": 1690,\n \"height\": 330,\n \"width\": 225\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -311,42 +168,7 @@
},
{
"metadata": {},
- "source": [
- "####### Bounding box with nested classification #######\n",
- "bbox_with_radio_subclass_prediction = lb_types.ObjectAnnotation(\n",
- " name=\"bbox_with_radio_subclass\",\n",
- " confidence=0.5,\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=541, y=933), # x = left, y = top\n",
- " end=lb_types.Point(x=871, y=1124), # x= left + width , y = top + height\n",
- " ),\n",
- " classifications=[\n",
- " \tlb_types.ClassificationAnnotation(\n",
- " \tname=\"sub_radio_question\",\n",
- " \t\tvalue=lb_types.Radio(answer=lb_types.ClassificationAnswer(name=\"first_sub_radio_answer\", confidence=0.5))\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "\n",
- "## NDJSON\n",
- "bbox_with_radio_subclass_prediction_ndjson = {\n",
- " \"name\": \"bbox_with_radio_subclass\",\n",
- " \"confidence\": 0.5,\n",
- " \"classifications\": [{\n",
- " \"name\": \"sub_radio_question\",\n",
- " \"answer\":\n",
- " { \"name\":\"first_sub_radio_answer\", \"confidence\": 0.5}\n",
- "\n",
- " }],\n",
- " \"bbox\": {\n",
- " \"top\": 933,\n",
- " \"left\": 541,\n",
- " \"height\": 191,\n",
- " \"width\": 330\n",
- " }\n",
- "}"
- ],
+ "source": "####### Bounding box with nested classification #######\nbbox_with_radio_subclass_prediction = lb_types.ObjectAnnotation(\n name=\"bbox_with_radio_subclass\",\n confidence=0.5,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=541, y=933), # x = left, y = top\n end=lb_types.Point(x=871, y=1124), # x= left + width , y = top + height\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\", confidence=0.5)),\n )\n ],\n)\n\n## NDJSON\nbbox_with_radio_subclass_prediction_ndjson = {\n \"name\": \"bbox_with_radio_subclass\",\n \"confidence\": 0.5,\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\",\n \"confidence\": 0.5\n },\n }],\n \"bbox\": {\n \"top\": 933,\n \"left\": 541,\n \"height\": 191,\n \"width\": 330\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -360,45 +182,7 @@
},
{
"metadata": {},
- "source": [
- "# Python Anotation\n",
- "polygon_prediction = lb_types.ObjectAnnotation(\n",
- " name = \"polygon\",\n",
- " confidence = 0.5,\n",
- " value=lb_types.Polygon(\n",
- " points=[lb_types.Point(x=1489.581,y=183.934), lb_types.Point(x=2278.306,y=256.885), lb_types.Point(x=2428.197,y=200.437), lb_types.Point(x=2560.0,y=335.419),\n",
- " lb_types.Point(x=2557.386,y=503.165), lb_types.Point(x=2320.596,y=503.103), lb_types.Point(x=2156.083, y=628.943), lb_types.Point(x=2161.111,y=785.519),\n",
- " lb_types.Point(x=2002.115, y=894.647), lb_types.Point(x=1838.456,y=877.874), lb_types.Point(x=1436.53,y=874.636), lb_types.Point(x=1411.403,y=758.579),\n",
- " lb_types.Point(x=1353.853,y=751.74), lb_types.Point(x=1345.264, y=453.461), lb_types.Point(x=1426.011,y=421.129)]\n",
- " ),\n",
- ")\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "\n",
- "polygon_prediction_ndjson = {\n",
- " \"name\": \"polygon\",\n",
- " \"confidence\": 0.5,\n",
- " \"polygon\": [\n",
- " {\"x\": 1489.581, \"y\": 183.934},\n",
- " {\"x\": 2278.306, \"y\": 256.885},\n",
- " {\"x\": 2428.197, \"y\": 200.437},\n",
- " {\"x\": 2560.0, \"y\": 335.419},\n",
- " {\"x\": 2557.386, \"y\": 503.165},\n",
- " {\"x\": 2320.596, \"y\": 503.103},\n",
- " {\"x\": 2156.083, \"y\": 628.943},\n",
- " {\"x\": 2161.111, \"y\": 785.519},\n",
- " {\"x\": 2002.115, \"y\": 894.647},\n",
- " {\"x\": 1838.456, \"y\": 877.874},\n",
- " {\"x\": 1436.53, \"y\": 874.636},\n",
- " {\"x\": 1411.403, \"y\": 758.579},\n",
- " {\"x\": 1353.853, \"y\": 751.74},\n",
- " {\"x\": 1345.264, \"y\": 453.461},\n",
- " {\"x\": 1426.011, \"y\": 421.129},\n",
- " {\"x\": 1489.581, \"y\": 183.934}\n",
- " ]\n",
- "}"
- ],
+ "source": "# Python Anotation\npolygon_prediction = lb_types.ObjectAnnotation(\n name=\"polygon\",\n confidence=0.5,\n value=lb_types.Polygon(points=[\n lb_types.Point(x=1489.581, y=183.934),\n lb_types.Point(x=2278.306, y=256.885),\n lb_types.Point(x=2428.197, y=200.437),\n lb_types.Point(x=2560.0, y=335.419),\n lb_types.Point(x=2557.386, y=503.165),\n lb_types.Point(x=2320.596, y=503.103),\n lb_types.Point(x=2156.083, y=628.943),\n lb_types.Point(x=2161.111, y=785.519),\n lb_types.Point(x=2002.115, y=894.647),\n lb_types.Point(x=1838.456, y=877.874),\n lb_types.Point(x=1436.53, y=874.636),\n lb_types.Point(x=1411.403, y=758.579),\n lb_types.Point(x=1353.853, y=751.74),\n lb_types.Point(x=1345.264, y=453.461),\n lb_types.Point(x=1426.011, y=421.129),\n ]),\n)\n\n# NDJSON\n\npolygon_prediction_ndjson = {\n \"name\":\n \"polygon\",\n \"confidence\":\n 0.5,\n \"polygon\": [\n {\n \"x\": 1489.581,\n \"y\": 183.934\n },\n {\n \"x\": 2278.306,\n \"y\": 256.885\n },\n {\n \"x\": 2428.197,\n \"y\": 200.437\n },\n {\n \"x\": 2560.0,\n \"y\": 335.419\n },\n {\n \"x\": 2557.386,\n \"y\": 503.165\n },\n {\n \"x\": 2320.596,\n \"y\": 503.103\n },\n {\n \"x\": 2156.083,\n \"y\": 628.943\n },\n {\n \"x\": 2161.111,\n \"y\": 785.519\n },\n {\n \"x\": 2002.115,\n \"y\": 894.647\n },\n {\n \"x\": 1838.456,\n \"y\": 877.874\n },\n {\n \"x\": 1436.53,\n \"y\": 874.636\n },\n {\n \"x\": 1411.403,\n \"y\": 758.579\n },\n {\n \"x\": 1353.853,\n \"y\": 751.74\n },\n {\n \"x\": 1345.264,\n \"y\": 453.461\n },\n {\n \"x\": 1426.011,\n \"y\": 421.129\n },\n {\n \"x\": 1489.581,\n \"y\": 183.934\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -412,20 +196,7 @@
},
{
"metadata": {},
- "source": [
- "# Python annotation\n",
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"free_text\",\n",
- " value=lb_types.Text(answer=\"sample text\", confidence=0.5)\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "text_annotation_ndjson = {\n",
- " \"name\": \"free_text\",\n",
- " \"answer\": \"sample text\",\n",
- " \"confidence\": 0.5\n",
- "}"
- ],
+ "source": "# Python annotation\ntext_annotation = lb_types.ClassificationAnnotation(name=\"free_text\",\n value=lb_types.Text(\n answer=\"sample text\",\n confidence=0.5))\n\n# NDJSON\ntext_annotation_ndjson = {\n \"name\": \"free_text\",\n \"answer\": \"sample text\",\n \"confidence\": 0.5,\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -439,28 +210,7 @@
},
{
"metadata": {},
- "source": [
- "### Raster Segmentation (Byte string array)\n",
- "url = \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/raster_seg.png\"\n",
- "response = requests.get(url)\n",
- "\n",
- "mask_data = lb.types.MaskData(im_bytes=response.content) # You can also use \"url\" instead of img_bytes to pass the PNG mask url.\n",
- "mask_prediction = lb_types.ObjectAnnotation(\n",
- " name=\"mask\",\n",
- " value=lb_types.Mask(\n",
- " mask=mask_data,\n",
- " color=(255, 255, 255))\n",
- ")\n",
- "\n",
- "# NDJSON using instanceURI, bytes array is not fully supported.\n",
- "mask_prediction_ndjson = {\n",
- " \"name\": \"mask\",\n",
- " \"classifications\": [],\n",
- " \"mask\": {\"instanceURI\": url,\n",
- " \"colorRGB\": (255, 255, 255)}\n",
- "}\n",
- "\n"
- ],
+ "source": "### Raster Segmentation (Byte string array)\nurl = \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/raster_seg.png\"\nresponse = requests.get(url)\n\nmask_data = lb.types.MaskData(\n im_bytes=response.content\n) # You can also use \"url\" instead of img_bytes to pass the PNG mask url.\nmask_prediction = lb_types.ObjectAnnotation(name=\"mask\",\n value=lb_types.Mask(mask=mask_data,\n color=(255, 255,\n 255)))\n\n# NDJSON using instanceURI, bytes array is not fully supported.\nmask_prediction_ndjson = {\n \"name\": \"mask\",\n \"classifications\": [],\n \"mask\": {\n \"instanceURI\": url,\n \"colorRGB\": (255, 255, 255)\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -474,35 +224,7 @@
},
{
"metadata": {},
- "source": [
- "url_2 = \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/raster_seg_with_subclass.png\"\n",
- "response_2 = requests.get(url_2)\n",
- "mask_data_2 = lb_types.MaskData(im_bytes=response_2.content)\n",
- "\n",
- "# Python annotation\n",
- "mask_with_text_subclass_prediction = lb_types.ObjectAnnotation(\n",
- " name = \"mask_with_text_subclass\", # must match your ontology feature\"s name\n",
- " value=lb_types.Mask(\n",
- " mask=mask_data_2,\n",
- " color=(255, 255, 255)),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_free_text\",\n",
- " value=lb_types.Text(answer=\"free text answer\")\n",
- " )]\n",
- ")\n",
- "\n",
- "# NDJSON using instanceURI, bytes array is not fully supported.\n",
- "mask_with_text_subclass_prediction_ndjson = {\n",
- " \"name\": \"mask_with_text_subclass\",\n",
- " \"mask\": {\"instanceURI\": url_2,\n",
- " \"colorRGB\": (255, 255, 255)},\n",
- " \"classifications\":[{\n",
- " \"name\": \"sub_free_text\",\n",
- " \"answer\": \"free text answer\"\n",
- " }]\n",
- "}"
- ],
+ "source": "url_2 = \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/raster_seg_with_subclass.png\"\nresponse_2 = requests.get(url_2)\nmask_data_2 = lb_types.MaskData(im_bytes=response_2.content)\n\n# Python annotation\nmask_with_text_subclass_prediction = lb_types.ObjectAnnotation(\n name=\"mask_with_text_subclass\", # must match your ontology feature\"s name\n value=lb_types.Mask(mask=mask_data_2, color=(255, 255, 255)),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_free_text\",\n value=lb_types.Text(answer=\"free text answer\"))\n ],\n)\n\n# NDJSON using instanceURI, bytes array is not fully supported.\nmask_with_text_subclass_prediction_ndjson = {\n \"name\":\n \"mask_with_text_subclass\",\n \"mask\": {\n \"instanceURI\": url_2,\n \"colorRGB\": (255, 255, 255)\n },\n \"classifications\": [{\n \"name\": \"sub_free_text\",\n \"answer\": \"free text answer\"\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -516,23 +238,7 @@
},
{
"metadata": {},
- "source": [
- "# Python Annotation\n",
- "point_prediction = lb_types.ObjectAnnotation(\n",
- " name = \"point\",\n",
- " confidence=0.5,\n",
- " value = lb_types.Point(x=1166.606, y=1441.768),\n",
- ")\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "point_prediction_ndjson = {\n",
- " \"name\": \"point\",\n",
- " \"confidence\": 0.5,\n",
- " \"classifications\": [],\n",
- " \"point\": {\"x\": 1166.606, \"y\": 1441.768}\n",
- "}"
- ],
+ "source": "# Python Annotation\npoint_prediction = lb_types.ObjectAnnotation(\n name=\"point\",\n confidence=0.5,\n value=lb_types.Point(x=1166.606, y=1441.768),\n)\n\n# NDJSON\npoint_prediction_ndjson = {\n \"name\": \"point\",\n \"confidence\": 0.5,\n \"classifications\": [],\n \"point\": {\n \"x\": 1166.606,\n \"y\": 1441.768\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -546,51 +252,7 @@
},
{
"metadata": {},
- "source": [
- "# Python Annotation\n",
- "\n",
- "polyline_prediction = lb_types.ObjectAnnotation(\n",
- " name = \"polyline\",\n",
- " confidence=0.5,\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=2534.353, y=249.471), lb_types.Point(x=2429.492, y=182.092), lb_types.Point(x=2294.322, y=221.962), lb_types.Point(x=2224.491, y=180.463), lb_types.Point(x=2136.123, y=204.716),\n",
- " lb_types.Point(x=1712.247, y=173.949), lb_types.Point(x=1703.838, y=84.438), lb_types.Point(x=1579.772, y=82.61), lb_types.Point(x=1583.442, y=167.552),\n",
- " lb_types.Point(x=1478.869, y=164.903), lb_types.Point(x=1418.941, y=318.149), lb_types.Point(x=1243.128, y=400.815), lb_types.Point(x=1022.067, y=319.007),\n",
- " lb_types.Point(x=892.367, y=379.216), lb_types.Point(x=670.273, y=364.408), lb_types.Point(x=613.114, y=288.16), lb_types.Point(x=377.559, y=238.251),\n",
- " lb_types.Point(x=368.087, y=185.064), lb_types.Point(x=246.557, y=167.286), lb_types.Point(x=236.648, y=285.61), lb_types.Point(x=90.929, y=326.412)]\n",
- " ),\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "polyline_prediction_ndjson = {\n",
- " \"name\": \"polyline\",\n",
- " \"confidence\":0.5,\n",
- " \"classifications\": [],\n",
- " \"line\": [\n",
- " {\"x\": 2534.353, \"y\": 249.471},\n",
- " {\"x\": 2429.492, \"y\": 182.092},\n",
- " {\"x\": 2294.322, \"y\": 221.962},\n",
- " {\"x\": 2224.491, \"y\": 180.463},\n",
- " {\"x\": 2136.123, \"y\": 204.716},\n",
- " {\"x\": 1712.247, \"y\": 173.949},\n",
- " {\"x\": 1703.838, \"y\": 84.438},\n",
- " {\"x\": 1579.772, \"y\": 82.61},\n",
- " {\"x\": 1583.442, \"y\": 167.552},\n",
- " {\"x\": 1478.869, \"y\": 164.903},\n",
- " {\"x\": 1418.941, \"y\": 318.149},\n",
- " {\"x\": 1243.128, \"y\": 400.815},\n",
- " {\"x\": 1022.067, \"y\": 319.007},\n",
- " {\"x\": 892.367, \"y\": 379.216},\n",
- " {\"x\": 670.273, \"y\": 364.408},\n",
- " {\"x\": 613.114, \"y\": 288.16},\n",
- " {\"x\": 377.559, \"y\": 238.251},\n",
- " {\"x\": 368.087, \"y\": 185.064},\n",
- " {\"x\": 246.557, \"y\": 167.286},\n",
- " {\"x\": 236.648, \"y\": 285.61},\n",
- " {\"x\": 90.929, \"y\": 326.412}\n",
- " ]\n",
- "}\n"
- ],
+ "source": "# Python Annotation\n\npolyline_prediction = lb_types.ObjectAnnotation(\n name=\"polyline\",\n confidence=0.5,\n value=lb_types.Line(points=[\n lb_types.Point(x=2534.353, y=249.471),\n lb_types.Point(x=2429.492, y=182.092),\n lb_types.Point(x=2294.322, y=221.962),\n lb_types.Point(x=2224.491, y=180.463),\n lb_types.Point(x=2136.123, y=204.716),\n lb_types.Point(x=1712.247, y=173.949),\n lb_types.Point(x=1703.838, y=84.438),\n lb_types.Point(x=1579.772, y=82.61),\n lb_types.Point(x=1583.442, y=167.552),\n lb_types.Point(x=1478.869, y=164.903),\n lb_types.Point(x=1418.941, y=318.149),\n lb_types.Point(x=1243.128, y=400.815),\n lb_types.Point(x=1022.067, y=319.007),\n lb_types.Point(x=892.367, y=379.216),\n lb_types.Point(x=670.273, y=364.408),\n lb_types.Point(x=613.114, y=288.16),\n lb_types.Point(x=377.559, y=238.251),\n lb_types.Point(x=368.087, y=185.064),\n lb_types.Point(x=246.557, y=167.286),\n lb_types.Point(x=236.648, y=285.61),\n lb_types.Point(x=90.929, y=326.412),\n ]),\n)\n\n# NDJSON\npolyline_prediction_ndjson = {\n \"name\":\n \"polyline\",\n \"confidence\":\n 0.5,\n \"classifications\": [],\n \"line\": [\n {\n \"x\": 2534.353,\n \"y\": 249.471\n },\n {\n \"x\": 2429.492,\n \"y\": 182.092\n },\n {\n \"x\": 2294.322,\n \"y\": 221.962\n },\n {\n \"x\": 2224.491,\n \"y\": 180.463\n },\n {\n \"x\": 2136.123,\n \"y\": 204.716\n },\n {\n \"x\": 1712.247,\n \"y\": 173.949\n },\n {\n \"x\": 1703.838,\n \"y\": 84.438\n },\n {\n \"x\": 1579.772,\n \"y\": 82.61\n },\n {\n \"x\": 1583.442,\n \"y\": 167.552\n },\n {\n \"x\": 1478.869,\n \"y\": 164.903\n },\n {\n \"x\": 1418.941,\n \"y\": 318.149\n },\n {\n \"x\": 1243.128,\n \"y\": 400.815\n },\n {\n \"x\": 1022.067,\n \"y\": 319.007\n },\n {\n \"x\": 892.367,\n \"y\": 379.216\n },\n {\n \"x\": 670.273,\n \"y\": 364.408\n },\n {\n \"x\": 613.114,\n \"y\": 288.16\n },\n {\n \"x\": 377.559,\n \"y\": 238.251\n },\n {\n \"x\": 368.087,\n \"y\": 185.064\n },\n {\n \"x\": 246.557,\n \"y\": 167.286\n },\n {\n \"x\": 236.648,\n \"y\": 285.61\n },\n {\n \"x\": 90.929,\n \"y\": 326.412\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -604,18 +266,7 @@
},
{
"metadata": {},
- "source": [
- "# send a sample image as batch to the project\n",
- "global_key = \"2560px-Kitano_Street_Kobe01s.jpeg\"\n",
- "test_img_url = {\n",
- " \"row_data\": \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n",
- " \"global_key\": global_key\n",
- "}\n",
- "dataset = client.create_dataset(name=\"image_prediction_demo\")\n",
- "task = dataset.create_data_rows([test_img_url])\n",
- "print(\"Errors:\",task.errors)\n",
- "print(\"Failed data rows:\", task.failed_data_rows)"
- ],
+ "source": "# send a sample image as batch to the project\nglobal_key = \"2560px-Kitano_Street_Kobe01s.jpeg\"\ntest_img_url = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n}\ndataset = client.create_dataset(name=\"image_prediction_demo\")\ntask = dataset.create_data_rows([test_img_url])\nprint(\"Errors:\", task.errors)\nprint(\"Failed data rows:\", task.failed_data_rows)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -630,105 +281,7 @@
},
{
"metadata": {},
- "source": [
- "ontology_builder = lb.OntologyBuilder(\n",
- " classifications=[ # List of Classification objects\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\"),\n",
- " lb.Option(value=\"second_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"free_text\"\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " options=[\n",
- " lb.Option(\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[lb.Option(\"first_sub_radio_answer\")]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- " ),\n",
- " ],\n",
- " tools=[ # List of tools\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.BBOX,\n",
- " name=\"bounding_box\"),\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.BBOX,\n",
- " name=\"bbox_with_radio_subclass\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_sub_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " ]\n",
- " ),\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.POLYGON,\n",
- " name=\"polygon\"),\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.RASTER_SEGMENTATION,\n",
- " name=\"mask\"),\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.RASTER_SEGMENTATION,\n",
- " name=\"mask_with_text_subclass\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"sub_free_text\")\n",
- " ]\n",
- " ),\n",
- " \t lb.Tool(\n",
- " tool=lb.Tool.Type.POINT,\n",
- " name=\"point\"),\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.LINE,\n",
- " name=\"polyline\")]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Image Prediction Import Demo\",\n",
- " ontology_builder.asdict(),\n",
- " media_type=lb.MediaType.Image\n",
- " )"
- ],
+ "source": "ontology_builder = lb.OntologyBuilder(\n classifications=[ # List of Classification objects\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_question\",\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_question\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n ),\n lb.Classification(class_type=lb.Classification.Type.TEXT,\n name=\"free_text\"),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n options=[\n lb.Option(\n \"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(\"first_sub_radio_answer\")],\n )\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n ],\n tools=[ # List of tools\n lb.Tool(tool=lb.Tool.Type.BBOX, name=\"bounding_box\"),\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"bbox_with_radio_subclass\",\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(value=\"first_sub_radio_answer\")],\n ),\n ],\n ),\n lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"polygon\"),\n lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=\"mask\"),\n lb.Tool(\n tool=lb.Tool.Type.RASTER_SEGMENTATION,\n name=\"mask_with_text_subclass\",\n classifications=[\n lb.Classification(class_type=lb.Classification.Type.TEXT,\n name=\"sub_free_text\")\n ],\n ),\n lb.Tool(tool=lb.Tool.Type.POINT, name=\"point\"),\n lb.Tool(tool=lb.Tool.Type.LINE, name=\"polyline\"),\n ],\n)\n\nontology = client.create_ontology(\n \"Image Prediction Import Demo\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -742,13 +295,7 @@
},
{
"metadata": {},
- "source": [
- "# create Model\n",
- "model = client.create_model(name=\"image_model_run_\" + str(uuid.uuid4()),\n",
- " ontology_id=ontology.uid)\n",
- "# create Model Run\n",
- "model_run = model.create_model_run(\"iteration 1\")"
- ],
+ "source": "# create Model\nmodel = client.create_model(name=\"image_model_run_\" + str(uuid.uuid4()),\n ontology_id=ontology.uid)\n# create Model Run\nmodel_run = model.create_model_run(\"iteration 1\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -762,9 +309,7 @@
},
{
"metadata": {},
- "source": [
- "model_run.upsert_data_rows(global_keys=[global_key])"
- ],
+ "source": "model_run.upsert_data_rows(global_keys=[global_key])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -782,28 +327,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Label for predictions\n",
- "label_prediction = []\n",
- "label_prediction.append(lb_types.Label(\n",
- " data=lb_types.ImageData(global_key=global_key),\n",
- " annotations = [\n",
- " radio_prediction,\n",
- " nested_radio_prediction,\n",
- " checklist_prediction,\n",
- " nested_checklist_prediction,\n",
- " bbox_prediction,\n",
- " bbox_with_radio_subclass_prediction,\n",
- " polyline_prediction,\n",
- " polygon_prediction,\n",
- " mask_prediction,\n",
- " mask_with_text_subclass_prediction,\n",
- " point_prediction,\n",
- " text_annotation\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "# Create a Label for predictions\nlabel_prediction = []\nlabel_prediction.append(\n lb_types.Label(\n data=lb_types.ImageData(global_key=global_key),\n annotations=[\n radio_prediction,\n nested_radio_prediction,\n checklist_prediction,\n nested_checklist_prediction,\n bbox_prediction,\n bbox_with_radio_subclass_prediction,\n polyline_prediction,\n polygon_prediction,\n mask_prediction,\n mask_with_text_subclass_prediction,\n point_prediction,\n text_annotation,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -817,28 +341,7 @@
},
{
"metadata": {},
- "source": [
- "label_prediction_ndjson = []\n",
- "\n",
- "for annot in [\n",
- " radio_prediction_ndjson,\n",
- " checklist_prediction_ndjson,\n",
- " bbox_prediction_ndjson,\n",
- " bbox_with_radio_subclass_prediction_ndjson,\n",
- " polygon_prediction_ndjson,\n",
- " mask_prediction_ndjson,\n",
- " mask_with_text_subclass_prediction_ndjson,\n",
- " point_prediction_ndjson,\n",
- " polyline_prediction_ndjson,\n",
- " text_annotation_ndjson,\n",
- " nested_radio_prediction_ndjson,\n",
- " nested_checklist_prediction_ndjson\n",
- "]:\n",
- " annot.update({\n",
- " \"dataRow\": {\"globalKey\": global_key}\n",
- " })\n",
- " label_prediction_ndjson.append(annot)"
- ],
+ "source": "label_prediction_ndjson = []\n\nfor annot in [\n radio_prediction_ndjson,\n checklist_prediction_ndjson,\n bbox_prediction_ndjson,\n bbox_with_radio_subclass_prediction_ndjson,\n polygon_prediction_ndjson,\n mask_prediction_ndjson,\n mask_with_text_subclass_prediction_ndjson,\n point_prediction_ndjson,\n polyline_prediction_ndjson,\n text_annotation_ndjson,\n nested_radio_prediction_ndjson,\n nested_checklist_prediction_ndjson,\n]:\n annot.update({\"dataRow\": {\"globalKey\": global_key}})\n label_prediction_ndjson.append(annot)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -852,16 +355,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload the prediction label to the Model Run\n",
- "upload_job_prediction = model_run.add_predictions(\n",
- " name=\"prediction_upload_job\"+str(uuid.uuid4()),\n",
- " predictions=label_prediction)\n",
- "\n",
- "# Errors will appear for prediction uploads that failed.\n",
- "print(\"Errors:\", upload_job_prediction.errors)\n",
- "print(\"Status of uploads: \", upload_job_prediction.statuses)"
- ],
+ "source": "# Upload the prediction label to the Model Run\nupload_job_prediction = model_run.add_predictions(\n name=\"prediction_upload_job\" + str(uuid.uuid4()),\n predictions=label_prediction,\n)\n\n# Errors will appear for prediction uploads that failed.\nprint(\"Errors:\", upload_job_prediction.errors)\nprint(\"Status of uploads: \", upload_job_prediction.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -884,12 +378,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Labelbox project\n",
- "project = client.create_project(name=\"Image Prediction Demo\",\n",
- " media_type=lb.MediaType.Image)\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "# Create a Labelbox project\nproject = client.create_project(name=\"Image Prediction Demo\",\n media_type=lb.MediaType.Image)\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -903,13 +392,7 @@
},
{
"metadata": {},
- "source": [
- "project.create_batch(\n",
- " \"batch_predictions_demo\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")"
- ],
+ "source": "project.create_batch(\n \"batch_predictions_demo\", # Each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # Paginated collection of data row objects, list of data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -923,131 +406,7 @@
},
{
"metadata": {},
- "source": [
- "########### Annotations ###########\n",
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question\",\n",
- " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n",
- " name=\"second_radio_answer\"))\n",
- ")\n",
- "\n",
- "nested_radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "\n",
- "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\"\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "\n",
- "checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question\",\n",
- " value=lb_types.Checklist(answer=[\n",
- " lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n",
- " lb_types.ClassificationAnswer(name=\"second_checklist_answer\")\n",
- " ])\n",
- ")\n",
- "\n",
- "bbox_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"bounding_box\",\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=1690, y=977), # x = left, y = top\n",
- " end=lb_types.Point(x=1915, y=1307), # x= left + width , y = top + height\n",
- " )\n",
- ")\n",
- "\n",
- "bbox_with_radio_subclass_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"bbox_with_radio_subclass\",\n",
- " value=lb_types.Rectangle(\n",
- " start=lb_types.Point(x=541, y=933), # x = left, y = top\n",
- " end=lb_types.Point(x=871, y=1124), # x= left + width , y = top + height\n",
- " ),\n",
- " classifications=[\n",
- " \tlb_types.ClassificationAnnotation(\n",
- " \tname=\"sub_radio_question\",\n",
- " \t\tvalue=lb_types.Radio(answer=lb_types.ClassificationAnswer(name=\"first_sub_radio_answer\", confidence=0.5))\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "polygon_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"polygon\",\n",
- " value=lb_types.Polygon(\n",
- " points=[lb_types.Point(x=1489.581,y=183.934), lb_types.Point(x=2278.306,y=256.885), lb_types.Point(x=2428.197,y=200.437), lb_types.Point(x=2560.0,y=335.419),\n",
- " lb_types.Point(x=2557.386,y=503.165), lb_types.Point(x=2320.596,y=503.103), lb_types.Point(x=2156.083, y=628.943), lb_types.Point(x=2161.111,y=785.519),\n",
- " lb_types.Point(x=2002.115, y=894.647), lb_types.Point(x=1838.456,y=877.874), lb_types.Point(x=1436.53,y=874.636), lb_types.Point(x=1411.403,y=758.579),\n",
- " lb_types.Point(x=1353.853,y=751.74), lb_types.Point(x=1345.264, y=453.461), lb_types.Point(x=1426.011,y=421.129)]\n",
- " ),\n",
- ")\n",
- "\n",
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"free_text\",\n",
- " value=lb_types.Text(answer=\"sample text\")\n",
- ")\n",
- "\n",
- "mask_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"mask\",\n",
- " value=lb_types.Mask(\n",
- " mask=mask_data,\n",
- " color=(255, 255, 255))\n",
- ")\n",
- "\n",
- "mask_with_text_subclass_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"mask_with_text_subclass\", # must match your ontology feature\"s name\n",
- " value=lb_types.Mask(\n",
- " mask=mask_data_2,\n",
- " color=(255, 255, 255)),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_free_text\",\n",
- " value=lb_types.Text(answer=\"free text answer\")\n",
- " )]\n",
- ")\n",
- "\n",
- "point_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"point\",\n",
- " value = lb_types.Point(x=1166.606, y=1441.768),\n",
- ")\n",
- "\n",
- "polyline_annotation = lb_types.ObjectAnnotation(\n",
- " name = \"polyline\",\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=2534.353, y=249.471), lb_types.Point(x=2429.492, y=182.092), lb_types.Point(x=2294.322, y=221.962), lb_types.Point(x=2224.491, y=180.463), lb_types.Point(x=2136.123, y=204.716),\n",
- " lb_types.Point(x=1712.247, y=173.949), lb_types.Point(x=1703.838, y=84.438), lb_types.Point(x=1579.772, y=82.61), lb_types.Point(x=1583.442, y=167.552),\n",
- " lb_types.Point(x=1478.869, y=164.903), lb_types.Point(x=1418.941, y=318.149), lb_types.Point(x=1243.128, y=400.815), lb_types.Point(x=1022.067, y=319.007),\n",
- " lb_types.Point(x=892.367, y=379.216), lb_types.Point(x=670.273, y=364.408), lb_types.Point(x=613.114, y=288.16), lb_types.Point(x=377.559, y=238.251),\n",
- " lb_types.Point(x=368.087, y=185.064), lb_types.Point(x=246.557, y=167.286), lb_types.Point(x=236.648, y=285.61), lb_types.Point(x=90.929, y=326.412)]\n",
- " )\n",
- ")"
- ],
+ "source": "########### Annotations ###########\nradio_annotation = lb_types.ClassificationAnnotation(\n name=\"radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"second_radio_answer\")),\n)\n\nnested_radio_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n)\n\nnested_checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n )\n ]),\n)\n\nchecklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n ]),\n)\n\nbbox_annotation = lb_types.ObjectAnnotation(\n name=\"bounding_box\",\n value=lb_types.Rectangle(\n start=lb_types.Point(x=1690, y=977), # x = left, y = top\n end=lb_types.Point(x=1915,\n y=1307), # x= left + width , y = top + height\n ),\n)\n\nbbox_with_radio_subclass_annotation = lb_types.ObjectAnnotation(\n name=\"bbox_with_radio_subclass\",\n value=lb_types.Rectangle(\n start=lb_types.Point(x=541, y=933), # x = left, y = top\n end=lb_types.Point(x=871, y=1124), # x= left + width , y = top + height\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\", confidence=0.5)),\n )\n ],\n)\n\npolygon_annotation = lb_types.ObjectAnnotation(\n name=\"polygon\",\n value=lb_types.Polygon(points=[\n lb_types.Point(x=1489.581, y=183.934),\n lb_types.Point(x=2278.306, y=256.885),\n lb_types.Point(x=2428.197, y=200.437),\n lb_types.Point(x=2560.0, y=335.419),\n lb_types.Point(x=2557.386, y=503.165),\n lb_types.Point(x=2320.596, y=503.103),\n lb_types.Point(x=2156.083, y=628.943),\n lb_types.Point(x=2161.111, y=785.519),\n lb_types.Point(x=2002.115, y=894.647),\n lb_types.Point(x=1838.456, y=877.874),\n lb_types.Point(x=1436.53, y=874.636),\n lb_types.Point(x=1411.403, y=758.579),\n lb_types.Point(x=1353.853, y=751.74),\n lb_types.Point(x=1345.264, y=453.461),\n lb_types.Point(x=1426.011, y=421.129),\n ]),\n)\n\ntext_annotation = lb_types.ClassificationAnnotation(\n name=\"free_text\", value=lb_types.Text(answer=\"sample text\"))\n\nmask_annotation = lb_types.ObjectAnnotation(name=\"mask\",\n value=lb_types.Mask(mask=mask_data,\n color=(255, 255,\n 255)))\n\nmask_with_text_subclass_annotation = lb_types.ObjectAnnotation(\n name=\"mask_with_text_subclass\", # must match your ontology feature\"s name\n value=lb_types.Mask(mask=mask_data_2, color=(255, 255, 255)),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_free_text\",\n value=lb_types.Text(answer=\"free text answer\"))\n ],\n)\n\npoint_annotation = lb_types.ObjectAnnotation(\n name=\"point\",\n value=lb_types.Point(x=1166.606, y=1441.768),\n)\n\npolyline_annotation = lb_types.ObjectAnnotation(\n name=\"polyline\",\n value=lb_types.Line(points=[\n lb_types.Point(x=2534.353, y=249.471),\n lb_types.Point(x=2429.492, y=182.092),\n lb_types.Point(x=2294.322, y=221.962),\n lb_types.Point(x=2224.491, y=180.463),\n lb_types.Point(x=2136.123, y=204.716),\n lb_types.Point(x=1712.247, y=173.949),\n lb_types.Point(x=1703.838, y=84.438),\n lb_types.Point(x=1579.772, y=82.61),\n lb_types.Point(x=1583.442, y=167.552),\n lb_types.Point(x=1478.869, y=164.903),\n lb_types.Point(x=1418.941, y=318.149),\n lb_types.Point(x=1243.128, y=400.815),\n lb_types.Point(x=1022.067, y=319.007),\n lb_types.Point(x=892.367, y=379.216),\n lb_types.Point(x=670.273, y=364.408),\n lb_types.Point(x=613.114, y=288.16),\n lb_types.Point(x=377.559, y=238.251),\n lb_types.Point(x=368.087, y=185.064),\n lb_types.Point(x=246.557, y=167.286),\n lb_types.Point(x=236.648, y=285.61),\n lb_types.Point(x=90.929, y=326.412),\n ]),\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1061,28 +420,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Label object by identifying the applicable data row in Labelbox and providing a list of annotations\n",
- "label = []\n",
- "annotations = [\n",
- " radio_annotation,\n",
- " nested_radio_annotation,\n",
- " checklist_annotation,\n",
- " nested_checklist_annotation,\n",
- " text_annotation,\n",
- " bbox_annotation,\n",
- " bbox_with_radio_subclass_annotation,\n",
- " polygon_annotation,\n",
- " mask_annotation,\n",
- " mask_with_text_subclass_annotation,\n",
- " point_annotation,\n",
- " polyline_annotation\n",
- "]\n",
- "label.append(\n",
- " lb_types.Label(\n",
- " data={\"global_key\" : global_key },\n",
- " annotations=annotations))"
- ],
+ "source": "# Create a Label object by identifying the applicable data row in Labelbox and providing a list of annotations\nlabel = []\nannotations = [\n radio_annotation,\n nested_radio_annotation,\n checklist_annotation,\n nested_checklist_annotation,\n text_annotation,\n bbox_annotation,\n bbox_with_radio_subclass_annotation,\n polygon_annotation,\n mask_annotation,\n mask_with_text_subclass_annotation,\n point_annotation,\n polyline_annotation,\n]\nlabel.append(\n lb_types.Label(data={\"global_key\": global_key}, annotations=annotations))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1096,18 +434,7 @@
},
{
"metadata": {},
- "source": [
- "upload_job_annotation = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"annotation_import_\" + str(uuid.uuid4()),\n",
- " labels=label)\n",
- "\n",
- "upload_job_annotation.wait_until_done()\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_annotation.errors)\n",
- "print(\"Status of uploads: \", upload_job_annotation.statuses)"
- ],
+ "source": "upload_job_annotation = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"annotation_import_\" + str(uuid.uuid4()),\n labels=label,\n)\n\nupload_job_annotation.wait_until_done()\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_annotation.errors)\nprint(\"Status of uploads: \", upload_job_annotation.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1121,10 +448,7 @@
},
{
"metadata": {},
- "source": [
- "# get the annotations from the project and add them to the model\n",
- "model_run.upsert_labels(project_id=project.uid)"
- ],
+ "source": "# get the annotations from the project and add them to the model\nmodel_run.upsert_labels(project_id=project.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1138,10 +462,7 @@
},
{
"metadata": {},
- "source": [
- "# project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/prediction_upload/pdf_predictions.ipynb b/examples/prediction_upload/pdf_predictions.ipynb
index 665498879..82d9f05cb 100644
--- a/examples/prediction_upload/pdf_predictions.ipynb
+++ b/examples/prediction_upload/pdf_predictions.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -65,22 +65,14 @@
},
{
"metadata": {},
- "source": [
- " !pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import uuid\n",
- "import json\n",
- "import requests\n",
- "import labelbox as lb\n",
- "import labelbox.types as lb_types"
- ],
+ "source": "import uuid\nimport json\nimport requests\nimport labelbox as lb\nimport labelbox.types as lb_types",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -94,10 +86,7 @@
},
{
"metadata": {},
- "source": [
- "API_KEY= \"\"\n",
- "client = lb.Client(API_KEY)"
- ],
+ "source": "API_KEY = \"\"\nclient = lb.Client(API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -111,352 +100,56 @@
},
{
"metadata": {},
- "source": [
- "########## Entity ##########\n",
- "\n",
- "# Annotation Types\n",
- "entities_prediction = lb_types.ObjectAnnotation(\n",
- " name=\"named_entity\",\n",
- " confidence=0.5,\n",
- " value= lb_types.DocumentEntity(\n",
- " name=\"named_entity\",\n",
- " textSelections=[\n",
- " lb_types.DocumentTextSelection(\n",
- " token_ids=[],\n",
- " group_id=\"\",\n",
- " page=1\n",
- " )\n",
- " ]\n",
- " )\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "entities_prediction_ndjson = {\n",
- " \"name\": \"named_entity\",\n",
- " \"confidence\": 0.5,\n",
- " \"textSelections\": [\n",
- " {\n",
- " \"tokenIds\": [\n",
- " \"\",\n",
- " ],\n",
- " \"groupId\": \"\",\n",
- " \"page\": 1,\n",
- " }\n",
- " ]\n",
- "}"
- ],
+ "source": "########## Entity ##########\n\n# Annotation Types\nentities_prediction = lb_types.ObjectAnnotation(\n name=\"named_entity\",\n confidence=0.5,\n value=lb_types.DocumentEntity(\n name=\"named_entity\",\n textSelections=[\n lb_types.DocumentTextSelection(token_ids=[], group_id=\"\", page=1)\n ],\n ),\n)\n\n# NDJSON\nentities_prediction_ndjson = {\n \"name\":\n \"named_entity\",\n \"confidence\":\n 0.5,\n \"textSelections\": [{\n \"tokenIds\": [\"\",],\n \"groupId\": \"\",\n \"page\": 1,\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########### Radio Classification #########\n",
- "\n",
- "# Annotation types\n",
- "radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question\",\n",
- " value=lb_types.Radio(answer =\n",
- " lb_types.ClassificationAnswer(name = \"first_radio_answer\", confidence=0.5)\n",
- " )\n",
- ")\n",
- "# NDJSON\n",
- "radio_prediction_ndjson = {\n",
- " \"name\": \"radio_question\",\n",
- " \"answer\": {\"name\": \"first_radio_answer\", \"confidence\":0.5}\n",
- "}"
- ],
+ "source": "########### Radio Classification #########\n\n# Annotation types\nradio_prediction = lb_types.ClassificationAnnotation(\n name=\"radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\", confidence=0.5)),\n)\n# NDJSON\nradio_prediction_ndjson = {\n \"name\": \"radio_question\",\n \"answer\": {\n \"name\": \"first_radio_answer\",\n \"confidence\": 0.5\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "############ Checklist Classification ###########\n",
- "\n",
- "# Annotation types\n",
- "checklist_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question\",\n",
- " value=lb_types.Checklist(answer = [\n",
- " lb_types.ClassificationAnswer(name = \"first_checklist_answer\", confidence=0.5),\n",
- " lb_types.ClassificationAnswer(name = \"second_checklist_answer\", confidence=0.5)\n",
- " ])\n",
- " )\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "checklist_prediction_ndjson = {\n",
- " \"name\": \"checklist_question\",\n",
- " \"answer\": [\n",
- " {\"name\": \"first_checklist_answer\", \"confidence\":0.5},\n",
- " {\"name\": \"second_checklist_answer\", \"confidence\":0.5}\n",
- " ]\n",
- "}"
- ],
+ "source": "############ Checklist Classification ###########\n\n# Annotation types\nchecklist_prediction = lb_types.ClassificationAnnotation(\n name=\"checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\",\n confidence=0.5),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\",\n confidence=0.5),\n ]),\n)\n\n# NDJSON\nchecklist_prediction_ndjson = {\n \"name\":\n \"checklist_question\",\n \"answer\": [\n {\n \"name\": \"first_checklist_answer\",\n \"confidence\": 0.5\n },\n {\n \"name\": \"second_checklist_answer\",\n \"confidence\": 0.5\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "############ Bounding Box ###########\n",
- "\n",
- "bbox_dim_1 = {\n",
- " \"top\": 135.3,\n",
- " \"left\": 102.771,\n",
- " \"height\": 109.843,\n",
- " \"width\": 415.8\n",
- " }\n",
- "bbox_prediction = lb_types.ObjectAnnotation(\n",
- " name=\"bounding_box\", # must match your ontology feature\"s name\n",
- " value=lb_types.DocumentRectangle(\n",
- " start=lb_types.Point(x=bbox_dim_1[\"left\"], y=bbox_dim_1[\"top\"]), # x = left, y = top\n",
- " end=lb_types.Point(x=bbox_dim_1[\"left\"] + bbox_dim_1[\"width\"], y=bbox_dim_1[\"top\"]+ bbox_dim_1[\"height\"]), # x= left + width , y = top + height\n",
- " page=0,\n",
- " unit=lb_types.RectangleUnit.POINTS\n",
- " )\n",
- " )\n",
- "\n",
- "bbox_prediction_ndjson = {\n",
- " \"name\": \"bounding_box\",\n",
- " \"bbox\": bbox_dim_1,\n",
- " \"page\": 0,\n",
- " \"unit\": \"POINTS\"\n",
- "}"
- ],
+ "source": "############ Bounding Box ###########\n\nbbox_dim_1 = {\"top\": 135.3, \"left\": 102.771, \"height\": 109.843, \"width\": 415.8}\nbbox_prediction = lb_types.ObjectAnnotation(\n name=\"bounding_box\", # must match your ontology feature\"s name\n value=lb_types.DocumentRectangle(\n start=lb_types.Point(x=bbox_dim_1[\"left\"],\n y=bbox_dim_1[\"top\"]), # x = left, y = top\n end=lb_types.Point(\n x=bbox_dim_1[\"left\"] + bbox_dim_1[\"width\"],\n y=bbox_dim_1[\"top\"] + bbox_dim_1[\"height\"],\n ), # x= left + width , y = top + height\n page=0,\n unit=lb_types.RectangleUnit.POINTS,\n ),\n)\n\nbbox_prediction_ndjson = {\n \"name\": \"bounding_box\",\n \"bbox\": bbox_dim_1,\n \"page\": 0,\n \"unit\": \"POINTS\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# ############ global nested classifications ###########\n",
- "\n",
- "nested_checklist_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " confidence=0.5, # Confidence scores should be added to the answer\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\",\n",
- " confidence=0.5 # Confidence scores should be added to the answer\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "\n",
- "nested_checklist_prediction_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"confidence\": 0.5, # Confidence scores should be added to the answer\n",
- " \"classifications\" : [\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_sub_checklist_answer\",\n",
- " \"confidence\": 0.5, # Confidence scores should be added to the answer\n",
- " }\n",
- " }\n",
- " ]\n",
- " }]\n",
- "}\n",
- "\n",
- "nested_radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " confidence=0.5, # Confidence scores should be added to the answer\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\",\n",
- " confidence=0.5 # Confidence scores should be added to the answer\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "\n",
- "\n",
- "nested_radio_prediction_ndjson = {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\",\n",
- " \"confidence\": 0.5,\n",
- " \"classifications\": [{\n",
- " \"name\":\"sub_radio_question\",\n",
- " \"answer\": { \"name\" : \"first_sub_radio_answer\",\n",
- " \"confidence\": 0.5}\n",
- " }]\n",
- " }\n",
- "}\n",
- "\n"
- ],
+ "source": "# ############ global nested classifications ###########\n\nnested_checklist_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n confidence=0.5, # Confidence scores should be added to the answer\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\",\n confidence=\n 0.5, # Confidence scores should be added to the answer\n )\n ]),\n )\n ],\n )\n ]),\n)\n\nnested_checklist_prediction_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"confidence\":\n 0.5, # Confidence scores should be added to the answer\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\",\n \"confidence\":\n 0.5, # Confidence scores should be added to the answer\n },\n }],\n }],\n}\n\nnested_radio_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n confidence=0.5, # Confidence scores should be added to the answer\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\",\n confidence=\n 0.5, # Confidence scores should be added to the answer\n )),\n )\n ],\n )),\n)\n\nnested_radio_prediction_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"confidence\":\n 0.5,\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\",\n \"confidence\": 0.5\n },\n }],\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "############## Classification Free-form text ##############\n",
- "\n",
- "text_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"free_text\", # must match your ontology feature\"s name\n",
- " value=lb_types.Text(answer=\"sample text\", confidence=0.5)\n",
- ")\n",
- "\n",
- "\n",
- "text_prediction_ndjson = {\n",
- " \"name\": \"free_text\",\n",
- " \"answer\": \"sample text\",\n",
- " \"confidence\": 0.5\n",
- "}"
- ],
+ "source": "############## Classification Free-form text ##############\n\ntext_prediction = lb_types.ClassificationAnnotation(\n name=\"free_text\", # must match your ontology feature\"s name\n value=lb_types.Text(answer=\"sample text\", confidence=0.5),\n)\n\ntext_prediction_ndjson = {\n \"name\": \"free_text\",\n \"answer\": \"sample text\",\n \"confidence\": 0.5,\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "######### BBOX with nested classifications #########\n",
- "\n",
- "bbox_dim = {\n",
- " \"top\": 226.757,\n",
- " \"left\": 317.271,\n",
- " \"height\": 194.229,\n",
- " \"width\": 249.386\n",
- " }\n",
- "\n",
- "bbox_with_radio_subclass_prediction = lb_types.ObjectAnnotation(\n",
- " name=\"bbox_with_radio_subclass\",\n",
- " confidence=0.5,\n",
- " value=lb_types.DocumentRectangle(\n",
- " start=lb_types.Point(x=bbox_dim[\"left\"], y=bbox_dim[\"top\"]), # x = left, y = top\n",
- " end=lb_types.Point(x=bbox_dim[\"left\"] + bbox_dim[\"width\"], y=bbox_dim[\"top\"] + bbox_dim[\"height\"]), # x= left + width , y = top + height\n",
- " unit=lb_types.RectangleUnit.POINTS,\n",
- " page=1\n",
- " ),\n",
- " classifications=[\n",
- " \tlb_types.ClassificationAnnotation(\n",
- " \tname=\"sub_radio_question\",\n",
- " \t\tvalue=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\",\n",
- " confidence=0.5,\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"second_sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"second_sub_radio_answer\",\n",
- " confidence=0.5\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "bbox_with_radio_subclass_prediction_ndjson = {\n",
- " \"name\": \"bbox_with_radio_subclass\",\n",
- " \"classifications\": [\n",
- " {\n",
- " \"name\": \"sub_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_sub_radio_answer\",\n",
- " \"confidence\": 0.5,\n",
- " \"classifications\": [\n",
- " {\n",
- " \"name\": \"second_sub_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"second_sub_radio_answer\", \"confidence\": 0.5}\n",
- " }\n",
- " ]\n",
- " }\n",
- " }\n",
- " ],\n",
- " \"bbox\":bbox_dim,\n",
- " \"page\": 1,\n",
- " \"unit\": \"POINTS\"\n",
- "}"
- ],
+ "source": "######### BBOX with nested classifications #########\n\nbbox_dim = {\n \"top\": 226.757,\n \"left\": 317.271,\n \"height\": 194.229,\n \"width\": 249.386,\n}\n\nbbox_with_radio_subclass_prediction = lb_types.ObjectAnnotation(\n name=\"bbox_with_radio_subclass\",\n confidence=0.5,\n value=lb_types.DocumentRectangle(\n start=lb_types.Point(x=bbox_dim[\"left\"],\n y=bbox_dim[\"top\"]), # x = left, y = top\n end=lb_types.Point(\n x=bbox_dim[\"left\"] + bbox_dim[\"width\"],\n y=bbox_dim[\"top\"] + bbox_dim[\"height\"],\n ), # x= left + width , y = top + height\n unit=lb_types.RectangleUnit.POINTS,\n page=1,\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\",\n confidence=0.5,\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"second_sub_radio_question\",\n value=lb_types.Radio(\n answer=lb_types.ClassificationAnswer(\n name=\"second_sub_radio_answer\",\n confidence=0.5,\n )),\n )\n ],\n )),\n )\n ],\n)\n\nbbox_with_radio_subclass_prediction_ndjson = {\n \"name\": \"bbox_with_radio_subclass\",\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\":\n \"first_sub_radio_answer\",\n \"confidence\":\n 0.5,\n \"classifications\": [{\n \"name\": \"second_sub_radio_question\",\n \"answer\": {\n \"name\": \"second_sub_radio_answer\",\n \"confidence\": 0.5,\n },\n }],\n },\n }],\n \"bbox\": bbox_dim,\n \"page\": 1,\n \"unit\": \"POINTS\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "\n",
- "############ NER with nested classifications ########\n",
- "\n",
- "\n",
- "ner_with_checklist_subclass_prediction = lb_types.ObjectAnnotation(\n",
- " name=\"ner_with_checklist_subclass\",\n",
- " confidence=0.5,\n",
- " value=lb_types.DocumentEntity(\n",
- " name=\"ner_with_checklist_subclass\",\n",
- " text_selections=[\n",
- " lb_types.DocumentTextSelection(\n",
- " token_ids=[],\n",
- " group_id=\"\",\n",
- " page=1\n",
- " )\n",
- " ]\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(name=\"first_sub_checklist_answer\", confidence=0.5)]\n",
- " )\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "\n",
- "ner_with_checklist_subclass_prediction_ndjson = {\n",
- " \"name\": \"ner_with_checklist_subclass\",\n",
- " \"classifications\":[\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": [{\"name\": \"first_sub_checklist_answer\", \"confidence\":0.5 }]\n",
- " }\n",
- " ],\n",
- " \"textSelections\": [\n",
- " {\n",
- " \"tokenIds\": [\n",
- " \"\"\n",
- " ],\n",
- " \"groupId\": \"\",\n",
- " \"page\": 1\n",
- " }\n",
- " ]\n",
- "}\n",
- "\n"
- ],
+ "source": "############ NER with nested classifications ########\n\nner_with_checklist_subclass_prediction = lb_types.ObjectAnnotation(\n name=\"ner_with_checklist_subclass\",\n confidence=0.5,\n value=lb_types.DocumentEntity(\n name=\"ner_with_checklist_subclass\",\n text_selections=[\n lb_types.DocumentTextSelection(token_ids=[], group_id=\"\", page=1)\n ],\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_sub_checklist_answer\",\n confidence=0.5)\n ]),\n )\n ],\n)\n\nner_with_checklist_subclass_prediction_ndjson = {\n \"name\":\n \"ner_with_checklist_subclass\",\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": [{\n \"name\": \"first_sub_checklist_answer\",\n \"confidence\": 0.5\n }],\n }],\n \"textSelections\": [{\n \"tokenIds\": [\"\"],\n \"groupId\": \"\",\n \"page\": 1\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -487,29 +180,7 @@
},
{
"metadata": {},
- "source": [
- "global_key = \"0801.3483.pdf\"\n",
- "img_url = {\n",
- " \"row_data\": {\n",
- " \"pdf_url\": \"https://storage.googleapis.com/labelbox-datasets/arxiv-pdf/data/99-word-token-pdfs/0801.3483.pdf\"\n",
- " },\n",
- " \"global_key\": global_key\n",
- "}\n",
- "\n",
- "\n",
- "dataset = client.create_dataset(name=\"pdf_demo_dataset\")\n",
- "task = dataset.create_data_rows([img_url])\n",
- "task.wait_till_done()\n",
- "print(f\"Failed data rows: {task.failed_data_rows}\")\n",
- "print(f\"Errors: {task.errors}\")\n",
- "\n",
- "if task.errors:\n",
- " for error in task.errors:\n",
- " if 'Duplicate global key' in error['message'] and dataset.row_count == 0:\n",
- " # If the global key already exists in the workspace the dataset will be created empty, so we can delete it.\n",
- " print(f\"Deleting empty dataset: {dataset}\")\n",
- " dataset.delete()"
- ],
+ "source": "global_key = \"0801.3483.pdf\"\nimg_url = {\n \"row_data\": {\n \"pdf_url\":\n \"https://storage.googleapis.com/labelbox-datasets/arxiv-pdf/data/99-word-token-pdfs/0801.3483.pdf\"\n },\n \"global_key\": global_key,\n}\n\ndataset = client.create_dataset(name=\"pdf_demo_dataset\")\ntask = dataset.create_data_rows([img_url])\ntask.wait_till_done()\nprint(f\"Failed data rows: {task.failed_data_rows}\")\nprint(f\"Errors: {task.errors}\")\n\nif task.errors:\n for error in task.errors:\n if (\"Duplicate global key\" in error[\"message\"] and\n dataset.row_count == 0):\n # If the global key already exists in the workspace the dataset will be created empty, so we can delete it.\n print(f\"Deleting empty dataset: {dataset}\")\n dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -524,103 +195,7 @@
},
{
"metadata": {},
- "source": [
- "## Setup the ontology and link the tools created above.\n",
- "\n",
- "ontology_builder = lb.OntologyBuilder(\n",
- " classifications=[ # List of Classification objects\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_question\",\n",
- " scope = lb.Classification.Scope.GLOBAL,\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\"),\n",
- " lb.Option(value=\"second_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_question\",\n",
- " scope = lb.Classification.Scope.GLOBAL,\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"free_text\",\n",
- " scope = lb.Classification.Scope.GLOBAL\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " scope = lb.Classification.Scope.GLOBAL,\n",
- " options=[\n",
- " lb.Option(\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[lb.Option(\"first_sub_radio_answer\")]\n",
- " )\n",
- " ])\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " scope = lb.Classification.Scope.GLOBAL,\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ])\n",
- " ]\n",
- " ),\n",
- " ],\n",
- " tools=[ # List of Tool objects\n",
- " lb.Tool( tool=lb.Tool.Type.BBOX,name=\"bounding_box\"),\n",
- " lb.Tool(tool=lb.Tool.Type.NER, name=\"named_entity\"),\n",
- " lb.Tool(tool=lb.Tool.Type.NER,\n",
- " name=\"ner_with_checklist_subclass\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_sub_checklist_answer\")\n",
- " ]\n",
- " )\n",
- " ]),\n",
- " lb.Tool( tool=lb.Tool.Type.BBOX,\n",
- " name=\"bbox_with_radio_subclass\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[\n",
- " lb.Option(\n",
- " value=\"first_sub_radio_answer\" ,\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"second_sub_radio_question\",\n",
- " options=[lb.Option(\"second_sub_radio_answer\")]\n",
- " )]\n",
- " )]\n",
- " )]\n",
- " )]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Document Annotation Import Demo\",\n",
- " ontology_builder.asdict(),\n",
- " media_type=lb.MediaType.Document)"
- ],
+ "source": "## Setup the ontology and link the tools created above.\n\nontology_builder = lb.OntologyBuilder(\n classifications=[ # List of Classification objects\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_question\",\n scope=lb.Classification.Scope.GLOBAL,\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_question\",\n scope=lb.Classification.Scope.GLOBAL,\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.TEXT,\n name=\"free_text\",\n scope=lb.Classification.Scope.GLOBAL,\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n scope=lb.Classification.Scope.GLOBAL,\n options=[\n lb.Option(\n \"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(\"first_sub_radio_answer\")],\n )\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n scope=lb.Classification.Scope.GLOBAL,\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n ],\n tools=[ # List of Tool objects\n lb.Tool(tool=lb.Tool.Type.BBOX, name=\"bounding_box\"),\n lb.Tool(tool=lb.Tool.Type.NER, name=\"named_entity\"),\n lb.Tool(\n tool=lb.Tool.Type.NER,\n name=\"ner_with_checklist_subclass\",\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(value=\"first_sub_checklist_answer\")],\n )\n ],\n ),\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"bbox_with_radio_subclass\",\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[\n lb.Option(\n value=\"first_sub_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"second_sub_radio_question\",\n options=[\n lb.Option(\"second_sub_radio_answer\")\n ],\n )\n ],\n )\n ],\n )\n ],\n ),\n ],\n)\n\nontology = client.create_ontology(\n \"Document Annotation Import Demo\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Document,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -634,13 +209,7 @@
},
{
"metadata": {},
- "source": [
- "# create Model\n",
- "model = client.create_model(name=\"PDF_model_run_\"+ str(uuid.uuid4()),\n",
- " ontology_id=ontology.uid)\n",
- "# create Model Run\n",
- "model_run = model.create_model_run(\"iteration 1\")"
- ],
+ "source": "# create Model\nmodel = client.create_model(name=\"PDF_model_run_\" + str(uuid.uuid4()),\n ontology_id=ontology.uid)\n# create Model Run\nmodel_run = model.create_model_run(\"iteration 1\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -654,9 +223,7 @@
},
{
"metadata": {},
- "source": [
- "model_run.upsert_data_rows(global_keys=[global_key])"
- ],
+ "source": "model_run.upsert_data_rows(global_keys=[global_key])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -689,100 +256,14 @@
},
{
"metadata": {},
- "source": [
- "client.enable_experimental = True\n",
- "task = lb.DataRow.export(client=client,global_keys=[global_key])\n",
- "task.wait_till_done()\n",
- "stream = task.get_stream()\n",
- "\n",
- "text_layer = \"\"\n",
- "for output in stream:\n",
- " output_json = json.loads(output.json_str)\n",
- " text_layer = output_json['media_attributes']['text_layer_url']\n",
- "print(text_layer)"
- ],
+ "source": "client.enable_experimental = True\ntask = lb.DataRow.export(client=client, global_keys=[global_key])\ntask.wait_till_done()\nstream = task.get_stream()\n\ntext_layer = \"\"\nfor output in stream:\n output_json = json.loads(output.json_str)\n text_layer = output_json[\"media_attributes\"][\"text_layer_url\"]\nprint(text_layer)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Helper method\n",
- "def update_text_selections(annotation, group_id, list_tokens, page):\n",
- " return annotation.update({\n",
- " \"textSelections\": [\n",
- " {\n",
- " \"groupId\": group_id,\n",
- " \"tokenIds\": list_tokens,\n",
- " \"page\": page\n",
- " }\n",
- " ]\n",
- " })\n",
- "\n",
- "\n",
- "# Fetch the content of the text layer\n",
- "res = requests.get(text_layer)\n",
- "\n",
- "# Phrases that we want to annotation obtained from the text layer url\n",
- "content_phrases = [\"Metal-insulator (MI) transitions have been one of the\",\n",
- " \"T. Sasaki, N. Yoneyama, and N. Kobayashi\"]\n",
- "\n",
- "# Parse the text layer\n",
- "text_selections = []\n",
- "text_selections_ner = []\n",
- "\n",
- "\n",
- "for obj in json.loads(res.text):\n",
- " for group in obj[\"groups\"]:\n",
- " if group[\"content\"] == content_phrases[0]:\n",
- " list_tokens = [x[\"id\"] for x in group[\"tokens\"]]\n",
- " # build text selections for Python Annotation Types\n",
- " document_text_selection = lb_types.DocumentTextSelection(groupId=group[\"id\"], tokenIds=list_tokens, page=1)\n",
- " text_selections.append(document_text_selection)\n",
- " # build text selection for the NDJson annotations\n",
- " update_text_selections(annotation=entities_prediction_ndjson,\n",
- " group_id=group[\"id\"], # id representing group of words\n",
- " list_tokens=list_tokens, # ids representing individual words from the group\n",
- " page=1)\n",
- " if group[\"content\"] == content_phrases[1]:\n",
- " list_tokens_2 = [x[\"id\"] for x in group[\"tokens\"]]\n",
- " # build text selections for Python Annotation Types\n",
- " ner_text_selection = lb_types.DocumentTextSelection(groupId=group[\"id\"], tokenIds=list_tokens_2, page=1)\n",
- " text_selections_ner.append(ner_text_selection)\n",
- " # build text selection for the NDJson annotations\n",
- " update_text_selections(annotation=ner_with_checklist_subclass_prediction_ndjson,\n",
- " group_id=group[\"id\"], # id representing group of words\n",
- " list_tokens=list_tokens_2, # ids representing individual words from the group\n",
- " page=1)\n",
- "\n",
- "\n",
- "#re-write the entity annotation with text selections\n",
- "entities_prediction_document_entity = lb_types.DocumentEntity(name=\"named_entity\",confidence=0.5, textSelections = text_selections)\n",
- "entities_prediction = lb_types.ObjectAnnotation(name=\"named_entity\",value=entities_prediction_document_entity)\n",
- "\n",
- "\n",
- "# re-write the entity annotation + subclassification with text selections\n",
- "classifications = [\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(name=\"first_sub_checklist_answer\", confidence=0.5)]\n",
- " )\n",
- " )\n",
- " ]\n",
- "ner_annotation_with_subclass = lb_types.DocumentEntity(name=\"ner_with_checklist_subclass\",confidence=0.5, textSelections= text_selections_ner)\n",
- "ner_with_checklist_subclass_annotation = lb_types.ObjectAnnotation(name=\"ner_with_checklist_subclass\",\n",
- " confidence=0.5,\n",
- " value=ner_annotation_with_subclass,\n",
- " classifications=classifications)\n",
- "\n",
- "# Final NDJSON and python annotations\n",
- "print(f\"entities_annotations_ndjson={entities_prediction_ndjson}\")\n",
- "print(f\"entities_annotation={entities_prediction}\")\n",
- "print(f\"nested_entities_annotation_ndjson={ner_with_checklist_subclass_prediction_ndjson}\")\n",
- "print(f\"nested_entities_annotation={ner_with_checklist_subclass_annotation}\")"
- ],
+ "source": "# Helper method\ndef update_text_selections(annotation, group_id, list_tokens, page):\n return annotation.update({\n \"textSelections\": [{\n \"groupId\": group_id,\n \"tokenIds\": list_tokens,\n \"page\": page\n }]\n })\n\n\n# Fetch the content of the text layer\nres = requests.get(text_layer)\n\n# Phrases that we want to annotation obtained from the text layer url\ncontent_phrases = [\n \"Metal-insulator (MI) transitions have been one of the\",\n \"T. Sasaki, N. Yoneyama, and N. Kobayashi\",\n]\n\n# Parse the text layer\ntext_selections = []\ntext_selections_ner = []\n\nfor obj in json.loads(res.text):\n for group in obj[\"groups\"]:\n if group[\"content\"] == content_phrases[0]:\n list_tokens = [x[\"id\"] for x in group[\"tokens\"]]\n # build text selections for Python Annotation Types\n document_text_selection = lb_types.DocumentTextSelection(\n groupId=group[\"id\"], tokenIds=list_tokens, page=1)\n text_selections.append(document_text_selection)\n # build text selection for the NDJson annotations\n update_text_selections(\n annotation=entities_prediction_ndjson,\n group_id=group[\"id\"], # id representing group of words\n list_tokens=\n list_tokens, # ids representing individual words from the group\n page=1,\n )\n if group[\"content\"] == content_phrases[1]:\n list_tokens_2 = [x[\"id\"] for x in group[\"tokens\"]]\n # build text selections for Python Annotation Types\n ner_text_selection = lb_types.DocumentTextSelection(\n groupId=group[\"id\"], tokenIds=list_tokens_2, page=1)\n text_selections_ner.append(ner_text_selection)\n # build text selection for the NDJson annotations\n update_text_selections(\n annotation=ner_with_checklist_subclass_prediction_ndjson,\n group_id=group[\"id\"], # id representing group of words\n list_tokens=\n list_tokens_2, # ids representing individual words from the group\n page=1,\n )\n\n# re-write the entity annotation with text selections\nentities_prediction_document_entity = lb_types.DocumentEntity(\n name=\"named_entity\", confidence=0.5, textSelections=text_selections)\nentities_prediction = lb_types.ObjectAnnotation(\n name=\"named_entity\", value=entities_prediction_document_entity)\n\n# re-write the entity annotation + subclassification with text selections\nclassifications = [\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_sub_checklist_answer\",\n confidence=0.5)\n ]),\n )\n]\nner_annotation_with_subclass = lb_types.DocumentEntity(\n name=\"ner_with_checklist_subclass\",\n confidence=0.5,\n textSelections=text_selections_ner,\n)\nner_with_checklist_subclass_annotation = lb_types.ObjectAnnotation(\n name=\"ner_with_checklist_subclass\",\n confidence=0.5,\n value=ner_annotation_with_subclass,\n classifications=classifications,\n)\n\n# Final NDJSON and python annotations\nprint(f\"entities_annotations_ndjson={entities_prediction_ndjson}\")\nprint(f\"entities_annotation={entities_prediction}\")\nprint(\n f\"nested_entities_annotation_ndjson={ner_with_checklist_subclass_prediction_ndjson}\"\n)\nprint(f\"nested_entities_annotation={ner_with_checklist_subclass_annotation}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -796,27 +277,7 @@
},
{
"metadata": {},
- "source": [
- "label_predictions = []\n",
- "\n",
- "label_predictions.append(\n",
- " lb_types.Label(\n",
- " data=lb_types.DocumentData(\n",
- " global_key=global_key),\n",
- " annotations = [\n",
- " entities_prediction,\n",
- " checklist_prediction,\n",
- " nested_checklist_prediction,\n",
- " text_prediction,\n",
- " radio_prediction,\n",
- " nested_radio_prediction,\n",
- " bbox_prediction,\n",
- " bbox_with_radio_subclass_prediction,\n",
- " ner_with_checklist_subclass_prediction\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "label_predictions = []\n\nlabel_predictions.append(\n lb_types.Label(\n data=lb_types.DocumentData(global_key=global_key),\n annotations=[\n entities_prediction,\n checklist_prediction,\n nested_checklist_prediction,\n text_prediction,\n radio_prediction,\n nested_radio_prediction,\n bbox_prediction,\n bbox_with_radio_subclass_prediction,\n ner_with_checklist_subclass_prediction,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -830,26 +291,7 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "label_predictions_ndjson = []\n",
- "for annot in [\n",
- " entities_prediction_ndjson,\n",
- " checklist_prediction_ndjson,\n",
- " nested_checklist_prediction_ndjson,\n",
- " text_prediction_ndjson,\n",
- " radio_prediction_ndjson,\n",
- " nested_radio_prediction_ndjson,\n",
- " bbox_prediction_ndjson,\n",
- " bbox_with_radio_subclass_prediction_ndjson,\n",
- " ner_with_checklist_subclass_prediction_ndjson\n",
- " ]:\n",
- " annot.update({\n",
- " \"dataRow\": {\"globalKey\": global_key},\n",
- " })\n",
- " label_predictions_ndjson.append(annot)\n",
- "\n"
- ],
+ "source": "label_predictions_ndjson = []\nfor annot in [\n entities_prediction_ndjson,\n checklist_prediction_ndjson,\n nested_checklist_prediction_ndjson,\n text_prediction_ndjson,\n radio_prediction_ndjson,\n nested_radio_prediction_ndjson,\n bbox_prediction_ndjson,\n bbox_with_radio_subclass_prediction_ndjson,\n ner_with_checklist_subclass_prediction_ndjson,\n]:\n annot.update({\n \"dataRow\": {\n \"globalKey\": global_key\n },\n })\n label_predictions_ndjson.append(annot)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -863,16 +305,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload the prediction label to the Model Run\n",
- "upload_job_prediction = model_run.add_predictions(\n",
- " name=\"prediction_upload_job\"+str(uuid.uuid4()),\n",
- " predictions=label_predictions)\n",
- "\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_prediction.errors)\n",
- "print(\"Status of uploads: \", upload_job_prediction.statuses)"
- ],
+ "source": "# Upload the prediction label to the Model Run\nupload_job_prediction = model_run.add_predictions(\n name=\"prediction_upload_job\" + str(uuid.uuid4()),\n predictions=label_predictions,\n)\n\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_prediction.errors)\nprint(\"Status of uploads: \", upload_job_prediction.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -894,11 +327,7 @@
},
{
"metadata": {},
- "source": [
- "project = client.create_project(name=\"Document Prediction Import Demo\",\n",
- " media_type=lb.MediaType.Document)\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "project = client.create_project(name=\"Document Prediction Import Demo\",\n media_type=lb.MediaType.Document)\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -912,13 +341,7 @@
},
{
"metadata": {},
- "source": [
- "project.create_batch(\n",
- " \"batch_text_prediction_demo\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")"
- ],
+ "source": "project.create_batch(\n \"batch_text_prediction_demo\", # Each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # Paginated collection of data row objects, list of data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -932,144 +355,7 @@
},
{
"metadata": {},
- "source": [
- "entities_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"named_entity\",\n",
- " value= lb_types.DocumentEntity(\n",
- " name=\"named_entity\",\n",
- " textSelections=text_selections\n",
- " )\n",
- ")\n",
- "\n",
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question\",\n",
- " value=lb_types.Radio(answer =\n",
- " lb_types.ClassificationAnswer(name = \"first_radio_answer\")\n",
- " )\n",
- ")\n",
- "\n",
- "checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question\",\n",
- " value=lb_types.Checklist(answer = [\n",
- " lb_types.ClassificationAnswer(name = \"first_checklist_answer\"),\n",
- " lb_types.ClassificationAnswer(name = \"second_checklist_answer\"),\n",
- " ])\n",
- " )\n",
- "\n",
- "bbox_dim_1 = {\n",
- " \"top\": 135.3,\n",
- " \"left\": 102.771,\n",
- " \"height\": 109.843,\n",
- " \"width\": 415.8\n",
- " }\n",
- "bbox_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"bounding_box\", # must match your ontology feature\"s name\n",
- " value=lb_types.DocumentRectangle(\n",
- " start=lb_types.Point(x=bbox_dim_1[\"left\"], y=bbox_dim_1[\"top\"]), # x = left, y = top\n",
- " end=lb_types.Point(x=bbox_dim_1[\"left\"] + bbox_dim_1[\"width\"], y=bbox_dim_1[\"top\"]+ bbox_dim_1[\"height\"]), # x= left + width , y = top + height\n",
- " page=0,\n",
- " unit=lb_types.RectangleUnit.POINTS\n",
- " )\n",
- " )\n",
- "\n",
- "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\",\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "\n",
- "nested_radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\",\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "\n",
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"free_text\",\n",
- " value=lb_types.Text(answer=\"sample text\")\n",
- ")\n",
- "\n",
- "bbox_dim = {\n",
- " \"top\": 226.757,\n",
- " \"left\": 317.271,\n",
- " \"height\": 194.229,\n",
- " \"width\": 249.386\n",
- " }\n",
- "\n",
- "bbox_with_radio_subclass_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"bbox_with_radio_subclass\",\n",
- "\n",
- " value=lb_types.DocumentRectangle(\n",
- " start=lb_types.Point(x=bbox_dim[\"left\"], y=bbox_dim[\"top\"]), # x = left, y = top\n",
- " end=lb_types.Point(x=bbox_dim[\"left\"] + bbox_dim[\"width\"], y=bbox_dim[\"top\"] + bbox_dim[\"height\"]), # x= left + width , y = top + height\n",
- " unit=lb_types.RectangleUnit.POINTS,\n",
- " page=1\n",
- " ),\n",
- " classifications=[\n",
- " \tlb_types.ClassificationAnnotation(\n",
- " \tname=\"sub_radio_question\",\n",
- " \t\tvalue=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\",\n",
- "\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"second_sub_radio_question\",\n",
- "\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"second_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "ner_with_checklist_subclass_annotation = lb_types.ObjectAnnotation(\n",
- " name=\"ner_with_checklist_subclass\",\n",
- " value=lb_types.DocumentEntity(\n",
- " name=\"ner_with_checklist_subclass\",\n",
- " text_selections=text_selections_ner\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(name=\"first_sub_checklist_answer\")]\n",
- " )\n",
- " )\n",
- " ]\n",
- ")\n"
- ],
+ "source": "entities_annotation = lb_types.ObjectAnnotation(\n name=\"named_entity\",\n value=lb_types.DocumentEntity(name=\"named_entity\",\n textSelections=text_selections),\n)\n\nradio_annotation = lb_types.ClassificationAnnotation(\n name=\"radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\")),\n)\n\nchecklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n ]),\n)\n\nbbox_dim_1 = {\"top\": 135.3, \"left\": 102.771, \"height\": 109.843, \"width\": 415.8}\nbbox_annotation = lb_types.ObjectAnnotation(\n name=\"bounding_box\", # must match your ontology feature\"s name\n value=lb_types.DocumentRectangle(\n start=lb_types.Point(x=bbox_dim_1[\"left\"],\n y=bbox_dim_1[\"top\"]), # x = left, y = top\n end=lb_types.Point(\n x=bbox_dim_1[\"left\"] + bbox_dim_1[\"width\"],\n y=bbox_dim_1[\"top\"] + bbox_dim_1[\"height\"],\n ), # x= left + width , y = top + height\n page=0,\n unit=lb_types.RectangleUnit.POINTS,\n ),\n)\n\nnested_checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\",)\n ]),\n )\n ],\n )\n ]),\n)\n\nnested_radio_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\",)),\n )\n ],\n )),\n)\n\ntext_annotation = lb_types.ClassificationAnnotation(\n name=\"free_text\", value=lb_types.Text(answer=\"sample text\"))\n\nbbox_dim = {\n \"top\": 226.757,\n \"left\": 317.271,\n \"height\": 194.229,\n \"width\": 249.386,\n}\n\nbbox_with_radio_subclass_annotation = lb_types.ObjectAnnotation(\n name=\"bbox_with_radio_subclass\",\n value=lb_types.DocumentRectangle(\n start=lb_types.Point(x=bbox_dim[\"left\"],\n y=bbox_dim[\"top\"]), # x = left, y = top\n end=lb_types.Point(\n x=bbox_dim[\"left\"] + bbox_dim[\"width\"],\n y=bbox_dim[\"top\"] + bbox_dim[\"height\"],\n ), # x= left + width , y = top + height\n unit=lb_types.RectangleUnit.POINTS,\n page=1,\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"second_sub_radio_question\",\n value=lb_types.Radio(\n answer=lb_types.ClassificationAnswer(\n name=\"second_sub_radio_answer\")),\n )\n ],\n )),\n )\n ],\n)\n\nner_with_checklist_subclass_annotation = lb_types.ObjectAnnotation(\n name=\"ner_with_checklist_subclass\",\n value=lb_types.DocumentEntity(name=\"ner_with_checklist_subclass\",\n text_selections=text_selections_ner),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1083,26 +369,7 @@
},
{
"metadata": {},
- "source": [
- "labels = []\n",
- "\n",
- "labels.append(\n",
- " lb_types.Label(\n",
- " data={\"global_key\" : global_key },\n",
- " annotations = [\n",
- " entities_annotation,\n",
- " checklist_annotation,\n",
- " nested_checklist_annotation,\n",
- " text_annotation,\n",
- " radio_annotation,\n",
- " nested_radio_annotation,\n",
- " bbox_annotation,\n",
- " bbox_with_radio_subclass_annotation,\n",
- " ner_with_checklist_subclass_annotation\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "labels = []\n\nlabels.append(\n lb_types.Label(\n data={\"global_key\": global_key},\n annotations=[\n entities_annotation,\n checklist_annotation,\n nested_checklist_annotation,\n text_annotation,\n radio_annotation,\n nested_radio_annotation,\n bbox_annotation,\n bbox_with_radio_subclass_annotation,\n ner_with_checklist_subclass_annotation,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1116,18 +383,7 @@
},
{
"metadata": {},
- "source": [
- "upload_job_annotation = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"text_label_import_job\"+ str(uuid.uuid4()),\n",
- " labels=labels)\n",
- "\n",
- "upload_job_annotation.wait_until_done()\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_annotation.errors)\n",
- "print(\"Status of uploads: \", upload_job_annotation.statuses)"
- ],
+ "source": "upload_job_annotation = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"text_label_import_job\" + str(uuid.uuid4()),\n labels=labels,\n)\n\nupload_job_annotation.wait_until_done()\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_annotation.errors)\nprint(\"Status of uploads: \", upload_job_annotation.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1141,10 +397,7 @@
},
{
"metadata": {},
- "source": [
- "# get the labels id from the project\n",
- "model_run.upsert_labels(project_id=project.uid)"
- ],
+ "source": "# get the labels id from the project\nmodel_run.upsert_labels(project_id=project.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1158,10 +411,7 @@
},
{
"metadata": {},
- "source": [
- "# project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/prediction_upload/text_predictions.ipynb b/examples/prediction_upload/text_predictions.ipynb
index 96ec0445a..8943ca17b 100644
--- a/examples/prediction_upload/text_predictions.ipynb
+++ b/examples/prediction_upload/text_predictions.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -21,7 +21,7 @@
"\n",
"\n",
"\n",
- "![]() \n",
" | "
],
@@ -62,20 +62,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import labelbox.types as lb_types\n",
- "import uuid"
- ],
+ "source": "import labelbox as lb\nimport labelbox.types as lb_types\nimport uuid",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -90,10 +84,7 @@
},
{
"metadata": {},
- "source": [
- "API_KEY= \"\"\n",
- "client = lb.Client(API_KEY)"
- ],
+ "source": "API_KEY = \"\"\nclient = lb.Client(API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -107,185 +98,35 @@
},
{
"metadata": {},
- "source": [
- "########## Entities ##########\n",
- "\n",
- "# Python annotation\n",
- "named_entity = lb_types.TextEntity(start=10, end=20)\n",
- "entities_prediction = lb_types.ObjectAnnotation(value=named_entity, name = \"named_entity\", confidence=0.5)\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "entities_prediction_ndjson = {\n",
- " \"name\": \"named_entity\",\n",
- " \"confidence\": 0.5,\n",
- " \"location\": {\n",
- " \"start\": 10,\n",
- " \"end\": 20\n",
- " }\n",
- "}"
- ],
+ "source": "########## Entities ##########\n\n# Python annotation\nnamed_entity = lb_types.TextEntity(start=10, end=20)\nentities_prediction = lb_types.ObjectAnnotation(value=named_entity,\n name=\"named_entity\",\n confidence=0.5)\n\n# NDJSON\nentities_prediction_ndjson = {\n \"name\": \"named_entity\",\n \"confidence\": 0.5,\n \"location\": {\n \"start\": 10,\n \"end\": 20\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########## Classification - Radio (single choice ) ##########\n",
- "\n",
- "# Python annotation\n",
- "radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question\",\n",
- " value=lb_types.Radio(answer =\n",
- " lb_types.ClassificationAnswer(name = \"first_radio_answer\", confidence=0.5)\n",
- " )\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "radio_prediction_ndjson = {\n",
- " \"name\": \"radio_question\",\n",
- " \"answer\": {\"name\": \"first_radio_answer\", \"confidence\": 0.5}\n",
- "}"
- ],
+ "source": "########## Classification - Radio (single choice ) ##########\n\n# Python annotation\nradio_prediction = lb_types.ClassificationAnnotation(\n name=\"radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\", confidence=0.5)),\n)\n\n# NDJSON\nradio_prediction_ndjson = {\n \"name\": \"radio_question\",\n \"answer\": {\n \"name\": \"first_radio_answer\",\n \"confidence\": 0.5\n },\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########## Classification - Radio and Checklist (with subclassifcations) ##########\n",
- "\n",
- "nested_radio_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " confidence=0.5, # Confidence scores should be added to the answer\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\",\n",
- " confidence=0.5\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "\n",
- "nested_radio_prediction_ndjson= {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\n",
- " \"name\": \"first_radio_answer\",\n",
- " \"confidence\": 0.5, # Confidence scores should be added to the answer\n",
- " \"classifications\": [{\n",
- " \"name\":\"sub_radio_question\",\n",
- " \"answer\": { \"name\" : \"first_sub_radio_answer\",\n",
- " \"confidence\": 0.5}\n",
- " }]\n",
- " }\n",
- "}\n",
- "\n",
- "nested_checklist_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " confidence=0.5, # Confidence scores should be added to the answer\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\",\n",
- " confidence=0.5,\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "\n",
- "nested_checklist_prediction_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"confidence\": 0.5, # Confidence scores should be added to the answer\n",
- " \"classifications\" : [\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\"name\": \"first_sub_checklist_answer\",\n",
- " \"confidence\": 0.5}\n",
- " }\n",
- " ]\n",
- " }]\n",
- "}"
- ],
+ "source": "########## Classification - Radio and Checklist (with subclassifcations) ##########\n\nnested_radio_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n confidence=0.5, # Confidence scores should be added to the answer\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\", confidence=0.5)),\n )\n ],\n )),\n)\n\nnested_radio_prediction_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"confidence\":\n 0.5, # Confidence scores should be added to the answer\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\",\n \"confidence\": 0.5\n },\n }],\n },\n}\n\nnested_checklist_prediction = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n confidence=0.5, # Confidence scores should be added to the answer\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\",\n confidence=0.5,\n )\n ]),\n )\n ],\n )\n ]),\n)\n\nnested_checklist_prediction_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"confidence\":\n 0.5, # Confidence scores should be added to the answer\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\",\n \"confidence\": 0.5,\n },\n }],\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########## Checklist ##########\n",
- "\n",
- "# Python annotation\n",
- "checklist_prediction = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\",\n",
- " confidence=0.5\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\",\n",
- " confidence=0.5\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"third_checklist_answer\",\n",
- " confidence=0.5\n",
- " )\n",
- " ])\n",
- " )\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "checklist_prediction_ndjson = {\n",
- " \"name\": \"checklist_question\",\n",
- " \"answer\": [\n",
- " {\"name\": \"first_checklist_answer\", \"confidence\": 0.5}\n",
- " ]\n",
- "}"
- ],
+ "source": "########## Checklist ##########\n\n# Python annotation\nchecklist_prediction = lb_types.ClassificationAnnotation(\n name=\"checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\",\n confidence=0.5),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\",\n confidence=0.5),\n lb_types.ClassificationAnswer(name=\"third_checklist_answer\",\n confidence=0.5),\n ]),\n)\n\n# NDJSON\nchecklist_prediction_ndjson = {\n \"name\": \"checklist_question\",\n \"answer\": [{\n \"name\": \"first_checklist_answer\",\n \"confidence\": 0.5\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########## Classification Free-Form text ##########\n",
- "\n",
- "# Python annotation\n",
- "text_prediction = lb_types.ClassificationAnnotation(\n",
- " name = \"free_text\",\n",
- " value = lb_types.Text(answer=\"sample text\", confidence=0.5)\n",
- ")\n",
- "\n",
- "# NDJSON\n",
- "text_prediction_ndjson = {\n",
- " \"name\": \"free_text\",\n",
- " \"answer\": \"sample text\",\n",
- " \"confidence\": 0.5\n",
- "}"
- ],
+ "source": "########## Classification Free-Form text ##########\n\n# Python annotation\ntext_prediction = lb_types.ClassificationAnnotation(name=\"free_text\",\n value=lb_types.Text(\n answer=\"sample text\",\n confidence=0.5))\n\n# NDJSON\ntext_prediction_ndjson = {\n \"name\": \"free_text\",\n \"answer\": \"sample text\",\n \"confidence\": 0.5,\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -299,22 +140,7 @@
},
{
"metadata": {},
- "source": [
- "# send a sample image as batch to the project\n",
- "global_key = \"lorem-ipsum.txt\"\n",
- "test_img_url = {\n",
- " \"row_data\": \"https://storage.googleapis.com/labelbox-sample-datasets/nlp/lorem-ipsum.txt\",\n",
- " \"global_key\": global_key\n",
- "}\n",
- "dataset = client.create_dataset(\n",
- " name=\"text prediction demo dataset\",\n",
- " iam_integration=None # Removing this argument will default to the organziation's default iam integration\n",
- " )\n",
- "task = dataset.create_data_rows([test_img_url])\n",
- "task.wait_till_done()\n",
- "print(\"Errors:\",task.errors)\n",
- "print(\"Failed data rows:\", task.failed_data_rows)"
- ],
+ "source": "# send a sample image as batch to the project\nglobal_key = \"lorem-ipsum.txt\"\ntest_img_url = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-sample-datasets/nlp/lorem-ipsum.txt\",\n \"global_key\":\n global_key,\n}\ndataset = client.create_dataset(\n name=\"text prediction demo dataset\",\n iam_integration=\n None, # Removing this argument will default to the organziation's default iam integration\n)\ntask = dataset.create_data_rows([test_img_url])\ntask.wait_till_done()\nprint(\"Errors:\", task.errors)\nprint(\"Failed data rows:\", task.failed_data_rows)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -329,70 +155,7 @@
},
{
"metadata": {},
- "source": [
- "## Setup the ontology and link the tools created above.\n",
- "\n",
- "ontology_builder = lb.OntologyBuilder(\n",
- " classifications=[ # List of Classification objects\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_question\",\n",
- " options=[lb.Option(value=\"first_radio_answer\")]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_sub_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " ]\n",
- " )\n",
- " ],\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_question\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\"),\n",
- " lb.Option(value=\"third_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"free_text\"\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ],\n",
- " tools=[ # List of Tool objects\n",
- " lb.Tool(tool=lb.Tool.Type.NER,\n",
- " name=\"named_entity\")\n",
- " ]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Ontology Text Predictions\", ontology_builder.asdict() , media_type=lb.MediaType.Text)\n"
- ],
+ "source": "## Setup the ontology and link the tools created above.\n\nontology_builder = lb.OntologyBuilder(\n classifications=[ # List of Classification objects\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_question\",\n options=[lb.Option(value=\"first_radio_answer\")],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n options=[\n lb.Option(\n value=\"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(value=\"first_sub_radio_answer\")],\n ),\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_question\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n lb.Option(value=\"third_checklist_answer\"),\n ],\n ),\n lb.Classification(class_type=lb.Classification.Type.TEXT,\n name=\"free_text\"),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n ],\n tools=[ # List of Tool objects\n lb.Tool(tool=lb.Tool.Type.NER, name=\"named_entity\")\n ],\n)\n\nontology = client.create_ontology(\n \"Ontology Text Predictions\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Text,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -406,13 +169,7 @@
},
{
"metadata": {},
- "source": [
- "# create Model\n",
- "model = client.create_model(name=\"text_model_run_\"+ str(uuid.uuid4()),\n",
- " ontology_id=ontology.uid)\n",
- "# create Model Run\n",
- "model_run = model.create_model_run(\"iteration 1\")"
- ],
+ "source": "# create Model\nmodel = client.create_model(name=\"text_model_run_\" + str(uuid.uuid4()),\n ontology_id=ontology.uid)\n# create Model Run\nmodel_run = model.create_model_run(\"iteration 1\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -426,9 +183,7 @@
},
{
"metadata": {},
- "source": [
- "model_run.upsert_data_rows(global_keys=[global_key])"
- ],
+ "source": "model_run.upsert_data_rows(global_keys=[global_key])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -448,23 +203,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Label for predictions\n",
- "label_predictions = []\n",
- "label_predictions.append(\n",
- " lb_types.Label(\n",
- " data={\"global_key\" : global_key },\n",
- " annotations = [\n",
- " entities_prediction,\n",
- " nested_radio_prediction,\n",
- " radio_prediction,\n",
- " checklist_prediction,\n",
- " nested_checklist_prediction,\n",
- " text_prediction,\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "# Create a Label for predictions\nlabel_predictions = []\nlabel_predictions.append(\n lb_types.Label(\n data={\"global_key\": global_key},\n annotations=[\n entities_prediction,\n nested_radio_prediction,\n radio_prediction,\n checklist_prediction,\n nested_checklist_prediction,\n text_prediction,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -478,21 +217,7 @@
},
{
"metadata": {},
- "source": [
- "label_ndjson_predictions= []\n",
- "for annot in [\n",
- " entities_prediction_ndjson,\n",
- " radio_prediction_ndjson,\n",
- " checklist_prediction_ndjson,\n",
- " text_prediction_ndjson,\n",
- " nested_radio_prediction_ndjson,\n",
- " nested_checklist_prediction_ndjson\n",
- " ]:\n",
- " annot.update({\n",
- " \"dataRow\": {\"globalKey\": global_key}\n",
- " })\n",
- " label_ndjson_predictions.append(annot)"
- ],
+ "source": "label_ndjson_predictions = []\nfor annot in [\n entities_prediction_ndjson,\n radio_prediction_ndjson,\n checklist_prediction_ndjson,\n text_prediction_ndjson,\n nested_radio_prediction_ndjson,\n nested_checklist_prediction_ndjson,\n]:\n annot.update({\"dataRow\": {\"globalKey\": global_key}})\n label_ndjson_predictions.append(annot)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -506,16 +231,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload the prediction label to the Model Run\n",
- "upload_job_prediction = model_run.add_predictions(\n",
- " name=\"prediction_upload_job\"+str(uuid.uuid4()),\n",
- " predictions=label_predictions)\n",
- "\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_prediction.errors)\n",
- "print(\"Status of uploads: \", upload_job_prediction.statuses)"
- ],
+ "source": "# Upload the prediction label to the Model Run\nupload_job_prediction = model_run.add_predictions(\n name=\"prediction_upload_job\" + str(uuid.uuid4()),\n predictions=label_predictions,\n)\n\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_prediction.errors)\nprint(\"Status of uploads: \", upload_job_prediction.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -537,12 +253,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Labelbox project\n",
- "project = client.create_project(name=\"Text Prediction Import Demo\",\n",
- " media_type=lb.MediaType.Text)\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "# Create a Labelbox project\nproject = client.create_project(name=\"Text Prediction Import Demo\",\n media_type=lb.MediaType.Text)\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -556,13 +267,7 @@
},
{
"metadata": {},
- "source": [
- "project.create_batch(\n",
- " \"batch_text_prediction_demo\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")"
- ],
+ "source": "project.create_batch(\n \"batch_text_prediction_demo\", # Each batch in a project must have a unique name\n global_keys=[\n global_key\n ], # Paginated collection of data row objects, list of data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -576,76 +281,7 @@
},
{
"metadata": {},
- "source": [
- "named_entity = lb_types.TextEntity(start=10, end=20)\n",
- "entities_annotation = lb_types.ObjectAnnotation(value=named_entity, name = \"named_entity\")\n",
- "\n",
- "\n",
- "radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"radio_question\",\n",
- " value=lb_types.Radio(answer =\n",
- " lb_types.ClassificationAnswer(name = \"first_radio_answer\")\n",
- " )\n",
- ")\n",
- "\n",
- "nested_radio_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")\n",
- "\n",
- "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\"\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")\n",
- "\n",
- "checklist_annotation = lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\"\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\"\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"third_checklist_answer\"\n",
- " )\n",
- " ])\n",
- " )\n",
- "\n",
- "text_annotation = lb_types.ClassificationAnnotation(\n",
- " name = \"free_text\",\n",
- " value = lb_types.Text(answer=\"sample text\")\n",
- ")"
- ],
+ "source": "named_entity = lb_types.TextEntity(start=10, end=20)\nentities_annotation = lb_types.ObjectAnnotation(value=named_entity,\n name=\"named_entity\")\n\nradio_annotation = lb_types.ClassificationAnnotation(\n name=\"radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\")),\n)\n\nnested_radio_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n)\n\nnested_checklist_annotation = lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n )\n ]),\n)\n\nchecklist_annotation = lb_types.ClassificationAnnotation(\n name=\"checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"third_checklist_answer\"),\n ]),\n)\n\ntext_annotation = lb_types.ClassificationAnnotation(\n name=\"free_text\", value=lb_types.Text(answer=\"sample text\"))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -659,24 +295,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Label object by identifying the applicable data row in Labelbox and providing a list of annotations\n",
- "# Create a Label for predictions\n",
- "label = []\n",
- "label.append(\n",
- " lb_types.Label(\n",
- " data=lb_types.TextData(global_key=global_key),\n",
- " annotations = [\n",
- " entities_annotation,\n",
- " nested_radio_annotation,\n",
- " radio_annotation,\n",
- " checklist_annotation,\n",
- " nested_checklist_annotation,\n",
- " text_annotation,\n",
- " ]\n",
- " )\n",
- ")"
- ],
+ "source": "# Create a Label object by identifying the applicable data row in Labelbox and providing a list of annotations\n# Create a Label for predictions\nlabel = []\nlabel.append(\n lb_types.Label(\n data=lb_types.TextData(global_key=global_key),\n annotations=[\n entities_annotation,\n nested_radio_annotation,\n radio_annotation,\n checklist_annotation,\n nested_checklist_annotation,\n text_annotation,\n ],\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -690,18 +309,7 @@
},
{
"metadata": {},
- "source": [
- "upload_job_annotation = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"text_label_import_job\"+ str(uuid.uuid4()),\n",
- " labels=label)\n",
- "\n",
- "upload_job_annotation.wait_until_done()\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_annotation.errors)\n",
- "print(\"Status of uploads: \", upload_job_annotation.statuses)"
- ],
+ "source": "upload_job_annotation = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"text_label_import_job\" + str(uuid.uuid4()),\n labels=label,\n)\n\nupload_job_annotation.wait_until_done()\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_annotation.errors)\nprint(\"Status of uploads: \", upload_job_annotation.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -715,10 +323,7 @@
},
{
"metadata": {},
- "source": [
- "# get the labels id from the project\n",
- "model_run.upsert_labels(project_id=project.uid)"
- ],
+ "source": "# get the labels id from the project\nmodel_run.upsert_labels(project_id=project.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -732,10 +337,7 @@
},
{
"metadata": {},
- "source": [
- "# project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/prediction_upload/video_predictions.ipynb b/examples/prediction_upload/video_predictions.ipynb
index 46e57a2bc..b4a7a5cd4 100644
--- a/examples/prediction_upload/video_predictions.ipynb
+++ b/examples/prediction_upload/video_predictions.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -21,7 +21,7 @@
"\n",
"\n",
"\n",
- "![]() \n",
" | "
],
@@ -61,20 +61,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install -q \"labelbox[data]\""
- ],
+ "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "import labelbox.types as lb_types\n",
- "import uuid"
- ],
+ "source": "import labelbox as lb\nimport labelbox.types as lb_types\nimport uuid",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -89,10 +83,7 @@
},
{
"metadata": {},
- "source": [
- "API_KEY=\"\"\n",
- "client = lb.Client(API_KEY)"
- ],
+ "source": "API_KEY = \"\"\nclient = lb.Client(API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -107,596 +98,56 @@
},
{
"metadata": {},
- "source": [
- "####### Bounding box (frame specific) ###########\n",
- "\n",
- "# Confidence scores are not supported for frame specific bounding box annotations and VideoObjectAnnotation\n",
- "\n",
- "# bbox dimensions\n",
- "bbox_dm = {\n",
- " \"top\":617,\n",
- " \"left\":1371,\n",
- " \"height\":419,\n",
- " \"width\":505\n",
- "}\n",
- "\n",
- "# Python Annotation\n",
- "bbox_prediction = [\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_video\",\n",
- " keyframe=True,\n",
- " frame=13,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]), # x = left, y = top\n",
- " end=lb_types.Point(x=bbox_dm[\"left\"] + bbox_dm[\"width\"], y=bbox_dm[\"top\"] + bbox_dm[\"height\"]), # x= left + width , y = top + height\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_video\",\n",
- " keyframe=True,\n",
- " frame=15,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]),\n",
- " end=lb_types.Point(x=bbox_dm[\"left\"] + bbox_dm[\"width\"], y=bbox_dm[\"top\"] + bbox_dm[\"height\"]),\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_video\",\n",
- " keyframe=True,\n",
- " frame=19,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]),\n",
- " end=lb_types.Point(x=bbox_dm[\"left\"] + bbox_dm[\"width\"], y=bbox_dm[\"top\"] + bbox_dm[\"height\"]),\n",
- " )\n",
- " )\n",
- "]\n",
- "\n",
- "\n",
- "# NDJSON\n",
- "bbox_prediction_ndjson = {\n",
- " \"name\" : \"bbox_video\",\n",
- " \"segments\" : [{\n",
- " \"keyframes\" : [\n",
- " {\n",
- " \"frame\": 13,\n",
- " \"bbox\" : bbox_dm\n",
- " },\n",
- " {\n",
- " \"frame\": 15,\n",
- " \"bbox\" : bbox_dm\n",
- " },\n",
- " {\n",
- " \"frame\": 19,\n",
- " \"bbox\" : bbox_dm\n",
- " }\n",
- " ]\n",
- " }\n",
- " ]\n",
- "}"
- ],
+ "source": "####### Bounding box (frame specific) ###########\n\n# Confidence scores are not supported for frame specific bounding box annotations and VideoObjectAnnotation\n\n# bbox dimensions\nbbox_dm = {\"top\": 617, \"left\": 1371, \"height\": 419, \"width\": 505}\n\n# Python Annotation\nbbox_prediction = [\n lb_types.VideoObjectAnnotation(\n name=\"bbox_video\",\n keyframe=True,\n frame=13,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm[\"left\"],\n y=bbox_dm[\"top\"]), # x = left, y = top\n end=lb_types.Point(\n x=bbox_dm[\"left\"] + bbox_dm[\"width\"],\n y=bbox_dm[\"top\"] + bbox_dm[\"height\"],\n ), # x= left + width , y = top + height\n ),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"bbox_video\",\n keyframe=True,\n frame=15,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]),\n end=lb_types.Point(\n x=bbox_dm[\"left\"] + bbox_dm[\"width\"],\n y=bbox_dm[\"top\"] + bbox_dm[\"height\"],\n ),\n ),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"bbox_video\",\n keyframe=True,\n frame=19,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]),\n end=lb_types.Point(\n x=bbox_dm[\"left\"] + bbox_dm[\"width\"],\n y=bbox_dm[\"top\"] + bbox_dm[\"height\"],\n ),\n ),\n ),\n]\n\n# NDJSON\nbbox_prediction_ndjson = {\n \"name\":\n \"bbox_video\",\n \"segments\": [{\n \"keyframes\": [\n {\n \"frame\": 13,\n \"bbox\": bbox_dm\n },\n {\n \"frame\": 15,\n \"bbox\": bbox_dm\n },\n {\n \"frame\": 19,\n \"bbox\": bbox_dm\n },\n ]\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "######## Point ########\n",
- "# Confidence score is not supported for VideoObjectAnnotation\n",
- "# Python Annotation\n",
- "point_prediction = [\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"point_video\",\n",
- " keyframe=True,\n",
- " frame=17,\n",
- " value = lb_types.Point(x=660.134, y=407.926),\n",
- " )\n",
- "]\n",
- "\n",
- "# NDJSON\n",
- "point_prediction_ndjson = {\n",
- " \"name\": \"point_video\",\n",
- " \"confidence\": 0.5,\n",
- " \"segments\": [{\n",
- " \"keyframes\": [{\n",
- " \"frame\": 17,\n",
- " \"point\" : {\n",
- " \"x\": 660.134 ,\n",
- " \"y\": 407.926\n",
- " }\n",
- " }]\n",
- " }]\n",
- "}"
- ],
+ "source": "######## Point ########\n# Confidence score is not supported for VideoObjectAnnotation\n# Python Annotation\npoint_prediction = [\n lb_types.VideoObjectAnnotation(\n name=\"point_video\",\n keyframe=True,\n frame=17,\n value=lb_types.Point(x=660.134, y=407.926),\n )\n]\n\n# NDJSON\npoint_prediction_ndjson = {\n \"name\":\n \"point_video\",\n \"confidence\":\n 0.5,\n \"segments\": [{\n \"keyframes\": [{\n \"frame\": 17,\n \"point\": {\n \"x\": 660.134,\n \"y\": 407.926\n }\n }]\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "######## Polyline (frame specific) ########\n",
- "# confidence scores are not supported in polyline annotations\n",
- "\n",
- "# Python Annotation\n",
- "polyline_prediction = [\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"line_video_frame\",\n",
- " keyframe=True,\n",
- " frame=5,\n",
- " segment_index=0,\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=680, y=100), lb_types.Point(x=100, y=190)]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"line_video_frame\",\n",
- " keyframe=True,\n",
- " frame=12,\n",
- " segment_index=0,\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=680, y=100), lb_types.Point(x=100, y=190)]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"line_video_frame\",\n",
- " keyframe=True,\n",
- " frame=20,\n",
- " segment_index=0,\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=680, y=100), lb_types.Point(x=100, y=190)]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"line_video_frame\",\n",
- " keyframe=True,\n",
- " frame=24,\n",
- " segment_index=1,\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=680, y=100), lb_types.Point(x=100, y=190)]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"line_video_frame\",\n",
- " keyframe=True,\n",
- " frame=45,\n",
- " segment_index=1,\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=680, y=100), lb_types.Point(x=100, y=190)]\n",
- " )\n",
- " )\n",
- "\n",
- "]\n",
- "\n",
- "# NDJSON\n",
- "polyline_prediction_ndjson = {\n",
- " \"name\": \"line_video_frame\",\n",
- " \"segments\": [\n",
- " {\n",
- " \"keyframes\": [\n",
- " {\n",
- " \"frame\": 5,\n",
- " \"line\": [{\n",
- " \"x\": 680,\n",
- " \"y\": 100\n",
- " },{\n",
- " \"x\": 100,\n",
- " \"y\": 190\n",
- " },{\n",
- " \"x\": 190,\n",
- " \"y\": 220\n",
- " }]\n",
- " },\n",
- " {\n",
- " \"frame\": 12,\n",
- " \"line\": [{\n",
- " \"x\": 680,\n",
- " \"y\": 280\n",
- " },{\n",
- " \"x\": 300,\n",
- " \"y\": 380\n",
- " },{\n",
- " \"x\": 400,\n",
- " \"y\": 460\n",
- " }]\n",
- " },\n",
- " {\n",
- " \"frame\": 20,\n",
- " \"line\": [{\n",
- " \"x\": 680,\n",
- " \"y\": 180\n",
- " },{\n",
- " \"x\": 100,\n",
- " \"y\": 200\n",
- " },{\n",
- " \"x\": 200,\n",
- " \"y\": 260\n",
- " }]\n",
- " }\n",
- " ]\n",
- " },\n",
- " {\n",
- " \"keyframes\": [\n",
- " {\n",
- " \"frame\": 24,\n",
- " \"line\": [{\n",
- " \"x\": 300,\n",
- " \"y\": 310\n",
- " },{\n",
- " \"x\": 330,\n",
- " \"y\": 430\n",
- " }]\n",
- " },\n",
- " {\n",
- " \"frame\": 45,\n",
- " \"line\": [{\n",
- " \"x\": 600,\n",
- " \"y\": 810\n",
- " },{\n",
- " \"x\": 900,\n",
- " \"y\": 930\n",
- " }]\n",
- " }\n",
- " ]\n",
- " }\n",
- " ]\n",
- "}"
- ],
+ "source": "######## Polyline (frame specific) ########\n# confidence scores are not supported in polyline annotations\n\n# Python Annotation\npolyline_prediction = [\n lb_types.VideoObjectAnnotation(\n name=\"line_video_frame\",\n keyframe=True,\n frame=5,\n segment_index=0,\n value=lb_types.Line(\n points=[lb_types.Point(x=680, y=100),\n lb_types.Point(x=100, y=190)]),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"line_video_frame\",\n keyframe=True,\n frame=12,\n segment_index=0,\n value=lb_types.Line(\n points=[lb_types.Point(x=680, y=100),\n lb_types.Point(x=100, y=190)]),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"line_video_frame\",\n keyframe=True,\n frame=20,\n segment_index=0,\n value=lb_types.Line(\n points=[lb_types.Point(x=680, y=100),\n lb_types.Point(x=100, y=190)]),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"line_video_frame\",\n keyframe=True,\n frame=24,\n segment_index=1,\n value=lb_types.Line(\n points=[lb_types.Point(x=680, y=100),\n lb_types.Point(x=100, y=190)]),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"line_video_frame\",\n keyframe=True,\n frame=45,\n segment_index=1,\n value=lb_types.Line(\n points=[lb_types.Point(x=680, y=100),\n lb_types.Point(x=100, y=190)]),\n ),\n]\n\n# NDJSON\npolyline_prediction_ndjson = {\n \"name\":\n \"line_video_frame\",\n \"segments\": [\n {\n \"keyframes\": [\n {\n \"frame\":\n 5,\n \"line\": [\n {\n \"x\": 680,\n \"y\": 100\n },\n {\n \"x\": 100,\n \"y\": 190\n },\n {\n \"x\": 190,\n \"y\": 220\n },\n ],\n },\n {\n \"frame\":\n 12,\n \"line\": [\n {\n \"x\": 680,\n \"y\": 280\n },\n {\n \"x\": 300,\n \"y\": 380\n },\n {\n \"x\": 400,\n \"y\": 460\n },\n ],\n },\n {\n \"frame\":\n 20,\n \"line\": [\n {\n \"x\": 680,\n \"y\": 180\n },\n {\n \"x\": 100,\n \"y\": 200\n },\n {\n \"x\": 200,\n \"y\": 260\n },\n ],\n },\n ]\n },\n {\n \"keyframes\": [\n {\n \"frame\": 24,\n \"line\": [{\n \"x\": 300,\n \"y\": 310\n }, {\n \"x\": 330,\n \"y\": 430\n }],\n },\n {\n \"frame\": 45,\n \"line\": [{\n \"x\": 600,\n \"y\": 810\n }, {\n \"x\": 900,\n \"y\": 930\n }],\n },\n ]\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "######## Frame base classifications ########\n",
- "\n",
- "# Python Annotation\n",
- "radio_prediction = [\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"radio_class\",\n",
- " frame=9,\n",
- " segment_index=0,\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(\n",
- " name = \"first_radio_answer\",\n",
- " confidence=0.5\n",
- " ))\n",
- " ),\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"radio_class\",\n",
- " frame=15,\n",
- " segment_index=0,\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(\n",
- " name = \"first_radio_answer\",\n",
- " confidence=0.5\n",
- " ))\n",
- " )\n",
- "]\n",
- "\n",
- "checklist_prediction= [\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"checklist_class\",\n",
- " frame=29,\n",
- " segment_index=0,\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\",\n",
- " confidence=0.5\n",
- " )\n",
- " ]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"checklist_class\",\n",
- " frame=35,\n",
- " segment_index=0,\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\",\n",
- " confidence=0.5\n",
- " )\n",
- " ]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"checklist_class\",\n",
- " frame=39,\n",
- " segment_index=1,\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\",\n",
- " confidence=0.5\n",
- " )\n",
- " ]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"checklist_class\",\n",
- " frame=45,\n",
- " segment_index=1,\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- "\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\",\n",
- " confidence=0.5\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- "]\n",
- "\n",
- "\n",
- "## NDJSON\n",
- "frame_radio_classification_prediction_ndjson = {\n",
- " \"name\": \"radio_class\",\n",
- " \"answer\": { \"name\": \"first_radio_answer\", \"frames\": [{\"start\": 9, \"end\": 15}]}\n",
- "}\n",
- "\n",
- "## frame specific\n",
- "frame_checklist_classification_prediction_ndjson = {\n",
- " \"name\": \"checklist_class\",\n",
- " \"answer\": [\n",
- " { \"name\": \"first_checklist_answer\" , \"frames\": [{\"start\": 29, \"end\": 35 }]},\n",
- " { \"name\": \"second_checklist_answer\", \"frames\": [{\"start\": 39, \"end\": 45 }]}\n",
- " ]\n",
- "}"
- ],
+ "source": "######## Frame base classifications ########\n\n# Python Annotation\nradio_prediction = [\n lb_types.VideoClassificationAnnotation(\n name=\"radio_class\",\n frame=9,\n segment_index=0,\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\", confidence=0.5)),\n ),\n lb_types.VideoClassificationAnnotation(\n name=\"radio_class\",\n frame=15,\n segment_index=0,\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\", confidence=0.5)),\n ),\n]\n\nchecklist_prediction = [\n lb_types.VideoClassificationAnnotation(\n name=\"checklist_class\",\n frame=29,\n segment_index=0,\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\",\n confidence=0.5)\n ]),\n ),\n lb_types.VideoClassificationAnnotation(\n name=\"checklist_class\",\n frame=35,\n segment_index=0,\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\",\n confidence=0.5)\n ]),\n ),\n lb_types.VideoClassificationAnnotation(\n name=\"checklist_class\",\n frame=39,\n segment_index=1,\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\",\n confidence=0.5)\n ]),\n ),\n lb_types.VideoClassificationAnnotation(\n name=\"checklist_class\",\n frame=45,\n segment_index=1,\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\",\n confidence=0.5)\n ]),\n ),\n]\n\n## NDJSON\nframe_radio_classification_prediction_ndjson = {\n \"name\": \"radio_class\",\n \"answer\": {\n \"name\": \"first_radio_answer\",\n \"frames\": [{\n \"start\": 9,\n \"end\": 15\n }],\n },\n}\n\n## frame specific\nframe_checklist_classification_prediction_ndjson = {\n \"name\":\n \"checklist_class\",\n \"answer\": [\n {\n \"name\": \"first_checklist_answer\",\n \"frames\": [{\n \"start\": 29,\n \"end\": 35\n }],\n },\n {\n \"name\": \"second_checklist_answer\",\n \"frames\": [{\n \"start\": 39,\n \"end\": 45\n }],\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "####### Global Classifications #########\n",
- "\n",
- "# Python Annotation\n",
- "## For global classifications use ClassificationAnnotation\n",
- "global_radio_prediction = [lb_types.ClassificationAnnotation(\n",
- " name=\"radio_class_global\",\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(\n",
- " name = \"first_radio_answer\",\n",
- " confidence=0.5\n",
- " ))\n",
- ")]\n",
- "\n",
- "global_checklist_prediction=[lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_class_global\",\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\",\n",
- " confidence=0.5\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\",\n",
- " confidence=0.5\n",
- " )\n",
- " ]\n",
- " )\n",
- " )]\n",
- "\n",
- "# NDJSON\n",
- "global_radio_classification_ndjson = {\n",
- " \"name\": \"radio_class_global\",\n",
- " \"answer\": { \"name\": \"first_radio_answer\", \"confidence\": 0.5}\n",
- "}\n",
- "\n",
- "\n",
- "global_checklist_classification_ndjson = {\n",
- " \"name\": \"checklist_class_global\",\n",
- " \"answer\": [\n",
- " { \"name\": \"first_checklist_answer\" , \"confidence\": 0.5},\n",
- " { \"name\": \"second_checklist_answer\", \"confidence\": 0.5}\n",
- " ]\n",
- "}"
- ],
+ "source": "####### Global Classifications #########\n\n# Python Annotation\n## For global classifications use ClassificationAnnotation\nglobal_radio_prediction = [\n lb_types.ClassificationAnnotation(\n name=\"radio_class_global\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\", confidence=0.5)),\n )\n]\n\nglobal_checklist_prediction = [\n lb_types.ClassificationAnnotation(\n name=\"checklist_class_global\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\",\n confidence=0.5),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\",\n confidence=0.5),\n ]),\n )\n]\n\n# NDJSON\nglobal_radio_classification_ndjson = {\n \"name\": \"radio_class_global\",\n \"answer\": {\n \"name\": \"first_radio_answer\",\n \"confidence\": 0.5\n },\n}\n\nglobal_checklist_classification_ndjson = {\n \"name\":\n \"checklist_class_global\",\n \"answer\": [\n {\n \"name\": \"first_checklist_answer\",\n \"confidence\": 0.5\n },\n {\n \"name\": \"second_checklist_answer\",\n \"confidence\": 0.5\n },\n ],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########## Nested Global Classification ###########\n",
- "\n",
- "# Python Annotation\n",
- "nested_radio_prediction =[lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " confidence=0.5 ,\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\",\n",
- " confidence=0.5\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")]\n",
- "\n",
- "# NDJSON\n",
- "nested_radio_prediction_ndjson = {\n",
- " \"name\": \"nested_radio_question\",\n",
- " \"answer\": {\"name\": \"first_radio_answer\", \"confidence\": 0.5,\n",
- " \"classifications\" : [\n",
- " {\"name\": \"sub_radio_question\", \"answer\": {\"name\": \"first_sub_radio_answer\", \"confidence\": 0.5}}\n",
- " ]\n",
- " }\n",
- "}\n",
- "\n",
- "# Python Annotation\n",
- "nested_checklist_prediction = [lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " confidence=0.5 ,\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\",\n",
- " confidence=0.5\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")]\n",
- "\n",
- "# NDJSON\n",
- "nested_checklist_prediction_ndjson = {\n",
- " \"name\": \"nested_checklist_question\",\n",
- " \"answer\": [{\n",
- " \"name\": \"first_checklist_answer\",\n",
- " \"confidence\": 0.5,\n",
- " \"classifications\" : [\n",
- " {\n",
- " \"name\": \"sub_checklist_question\",\n",
- " \"answer\": {\"name\": \"first_sub_checklist_answer\", \"confidence\": 0.5}\n",
- " }\n",
- " ]\n",
- " }]\n",
- "}"
- ],
+ "source": "########## Nested Global Classification ###########\n\n# Python Annotation\nnested_radio_prediction = [\n lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n confidence=0.5,\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\", confidence=0.5)),\n )\n ],\n )),\n )\n]\n\n# NDJSON\nnested_radio_prediction_ndjson = {\n \"name\": \"nested_radio_question\",\n \"answer\": {\n \"name\":\n \"first_radio_answer\",\n \"confidence\":\n 0.5,\n \"classifications\": [{\n \"name\": \"sub_radio_question\",\n \"answer\": {\n \"name\": \"first_sub_radio_answer\",\n \"confidence\": 0.5\n },\n }],\n },\n}\n\n# Python Annotation\nnested_checklist_prediction = [\n lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n confidence=0.5,\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\",\n confidence=0.5,\n )\n ]),\n )\n ],\n )\n ]),\n )\n]\n\n# NDJSON\nnested_checklist_prediction_ndjson = {\n \"name\":\n \"nested_checklist_question\",\n \"answer\": [{\n \"name\":\n \"first_checklist_answer\",\n \"confidence\":\n 0.5,\n \"classifications\": [{\n \"name\": \"sub_checklist_question\",\n \"answer\": {\n \"name\": \"first_sub_checklist_answer\",\n \"confidence\": 0.5,\n },\n }],\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "########## Classifications under frame base tools ##########\n",
- "# Confidence scores are not supported for frame specific bounding box annotations with sub-classifications\n",
- "\n",
- "# bounding box dimensions\n",
- "bbox_dm2 = {\n",
- " \"top\": 146.0,\n",
- " \"left\": 98.0,\n",
- " \"height\": 382.0,\n",
- " \"width\": 341.0\n",
- "}\n",
- "\n",
- "# Python Annotation\n",
- "frame_bbox_with_checklist_subclass_prediction = [\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_class\",\n",
- " keyframe=True,\n",
- " frame=10,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]), # x = left, y = top\n",
- " end=lb_types.Point(x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"], y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"]), # x= left + width , y = top + height\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_class\",\n",
- " keyframe=True,\n",
- " frame=11,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]),\n",
- " end=lb_types.Point(x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"], y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"]),\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name='checklist_class',\n",
- " value=lb_types.Checklist(answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " confidence=0.5\n",
- " )])\n",
- " )\n",
- " ]\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_class\",\n",
- " keyframe=True,\n",
- " frame=13,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]),\n",
- " end=lb_types.Point(x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"], y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"]),\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name='checklist_class',\n",
- " value=lb_types.Checklist(answer=[lb_types.ClassificationAnswer(\n",
- " name=\"second_checklist_answer\",\n",
- " confidence=0.5\n",
- " )])\n",
- " )\n",
- " ]\n",
- " )\n",
- "]\n",
- "\n",
- "frame_bbox_with_checklist_subclass_prediction_ndjson = {\n",
- " \"name\": \"bbox_class\",\n",
- " \"segments\": [{\n",
- " \"keyframes\": [\n",
- " {\n",
- " \"frame\": 10,\n",
- " \"bbox\": bbox_dm2\n",
- " },\n",
- " {\n",
- " \"frame\": 11,\n",
- " \"bbox\": bbox_dm2,\n",
- " \"classifications\": [\n",
- " {\n",
- " \"name\": \"bbox_radio\",\n",
- " \"answer\": [{\"name\": \"first_checklist_answer\", \"confidence\": 0.5}]\n",
- " }\n",
- " ]\n",
- " },\n",
- " {\n",
- " \"frame\": 13,\n",
- " \"bbox\": bbox_dm2,\n",
- " \"classifications\": [\n",
- " {\n",
- " \"name\": \"bbox_radio\",\n",
- " \"answer\": [{\"name\": \"second_checklist_answer\", \"confidence\": 0.5}]\n",
- " }\n",
- " ]\n",
- " }\n",
- " ]\n",
- " }\n",
- " ]\n",
- "}"
- ],
+ "source": "########## Classifications under frame base tools ##########\n# Confidence scores are not supported for frame specific bounding box annotations with sub-classifications\n\n# bounding box dimensions\nbbox_dm2 = {\"top\": 146.0, \"left\": 98.0, \"height\": 382.0, \"width\": 341.0}\n\n# Python Annotation\nframe_bbox_with_checklist_subclass_prediction = [\n lb_types.VideoObjectAnnotation(\n name=\"bbox_class\",\n keyframe=True,\n frame=10,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm2[\"left\"],\n y=bbox_dm2[\"top\"]), # x = left, y = top\n end=lb_types.Point(\n x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"],\n y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"],\n ), # x= left + width , y = top + height\n ),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"bbox_class\",\n keyframe=True,\n frame=11,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]),\n end=lb_types.Point(\n x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"],\n y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"],\n ),\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"checklist_class\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\",\n confidence=0.5)\n ]),\n )\n ],\n ),\n lb_types.VideoObjectAnnotation(\n name=\"bbox_class\",\n keyframe=True,\n frame=13,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]),\n end=lb_types.Point(\n x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"],\n y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"],\n ),\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"checklist_class\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"second_checklist_answer\", confidence=0.5)\n ]),\n )\n ],\n ),\n]\n\nframe_bbox_with_checklist_subclass_prediction_ndjson = {\n \"name\":\n \"bbox_class\",\n \"segments\": [{\n \"keyframes\": [\n {\n \"frame\": 10,\n \"bbox\": bbox_dm2\n },\n {\n \"frame\":\n 11,\n \"bbox\":\n bbox_dm2,\n \"classifications\": [{\n \"name\":\n \"bbox_radio\",\n \"answer\": [{\n \"name\": \"first_checklist_answer\",\n \"confidence\": 0.5,\n }],\n }],\n },\n {\n \"frame\":\n 13,\n \"bbox\":\n bbox_dm2,\n \"classifications\": [{\n \"name\":\n \"bbox_radio\",\n \"answer\": [{\n \"name\": \"second_checklist_answer\",\n \"confidence\": 0.5,\n }],\n }],\n },\n ]\n }],\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "######### Free text classification ###########\n",
- "text_prediction = [lb_types.ClassificationAnnotation(\n",
- " name=\"free_text\", # must match your ontology feature's name\n",
- " value=lb_types.Text(answer=\"sample text\", confidence=0.5)\n",
- ")]\n",
- "\n",
- "text_prediction_ndjson = {\n",
- " 'name': 'free_text',\n",
- " 'confidence': 0.5,\n",
- " 'answer': 'sample text',\n",
- "}"
- ],
+ "source": "######### Free text classification ###########\ntext_prediction = [\n lb_types.ClassificationAnnotation(\n name=\"free_text\", # must match your ontology feature's name\n value=lb_types.Text(answer=\"sample text\", confidence=0.5),\n )\n]\n\ntext_prediction_ndjson = {\n \"name\": \"free_text\",\n \"confidence\": 0.5,\n \"answer\": \"sample text\",\n}",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -710,22 +161,7 @@
},
{
"metadata": {},
- "source": [
- "# send a sample image as batch to the project\n",
- "global_key = \"sample-video-2.mp4\"\n",
- "test_img_url = {\n",
- " \"row_data\": \"https://storage.googleapis.com/labelbox-datasets/video-sample-data/sample-video-2.mp4\",\n",
- " \"global_key\": global_key\n",
- "}\n",
- "dataset = client.create_dataset(\n",
- " name=\"Video prediction demo\",\n",
- " iam_integration=None # Removing this argument will default to the organziation's default iam integration\n",
- ")\n",
- "task = dataset.create_data_rows([test_img_url])\n",
- "task.wait_till_done()\n",
- "print(\"Errors: \",task.errors)\n",
- "print(\"Failed data rows: \",task.failed_data_rows)"
- ],
+ "source": "# send a sample image as batch to the project\nglobal_key = \"sample-video-2.mp4\"\ntest_img_url = {\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/video-sample-data/sample-video-2.mp4\",\n \"global_key\":\n global_key,\n}\ndataset = client.create_dataset(\n name=\"Video prediction demo\",\n iam_integration=\n None, # Removing this argument will default to the organziation's default iam integration\n)\ntask = dataset.create_data_rows([test_img_url])\ntask.wait_till_done()\nprint(\"Errors: \", task.errors)\nprint(\"Failed data rows: \", task.failed_data_rows)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -740,105 +176,7 @@
},
{
"metadata": {},
- "source": [
- "ontology_builder = lb.OntologyBuilder(\n",
- " tools=[\n",
- " lb.Tool(tool=lb.Tool.Type.BBOX, name=\"bbox_video\"),\n",
- " lb.Tool(tool=lb.Tool.Type.POINT, name=\"point_video\"),\n",
- " lb.Tool(tool=lb.Tool.Type.LINE, name=\"line_video_frame\"),\n",
- " lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=\"video_mask\"),\n",
- " lb.Tool(\n",
- " tool=lb.Tool.Type.BBOX, name=\"bbox_class\",\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_class\",\n",
- " scope = lb.Classification.Scope.INDEX, ## defined scope for frame classifications\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ],\n",
- " classifications=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_class\",\n",
- " scope = lb.Classification.Scope.INDEX, ## defined scope for frame classifications\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_class\",\n",
- " scope = lb.Classification.Scope.INDEX,\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\"),\n",
- " lb.Option(value=\"second_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"nested_radio_question\",\n",
- " options=[\n",
- " lb.Option(\"first_radio_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"sub_radio_question\",\n",
- " options=[lb.Option(\"first_sub_radio_answer\")]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"nested_checklist_question\",\n",
- " options=[\n",
- " lb.Option(\"first_checklist_answer\",\n",
- " options=[\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"sub_checklist_question\",\n",
- " options=[lb.Option(\"first_sub_checklist_answer\")]\n",
- " )\n",
- " ]\n",
- " )\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.RADIO,\n",
- " name=\"radio_class_global\",\n",
- " options=[\n",
- " lb.Option(value=\"first_radio_answer\"),\n",
- " lb.Option(value=\"second_radio_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"checklist_class_global\",\n",
- " options=[\n",
- " lb.Option(value=\"first_checklist_answer\"),\n",
- " lb.Option(value=\"second_checklist_answer\")\n",
- " ]\n",
- " ),\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.TEXT,\n",
- " name=\"free_text\"\n",
- " )\n",
- " ]\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\"Ontology Video Annotations\",\n",
- " ontology_builder.asdict(),\n",
- " media_type=lb.MediaType.Video\n",
- " )"
- ],
+ "source": "ontology_builder = lb.OntologyBuilder(\n tools=[\n lb.Tool(tool=lb.Tool.Type.BBOX, name=\"bbox_video\"),\n lb.Tool(tool=lb.Tool.Type.POINT, name=\"point_video\"),\n lb.Tool(tool=lb.Tool.Type.LINE, name=\"line_video_frame\"),\n lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=\"video_mask\"),\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"bbox_class\",\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_class\",\n scope=lb.Classification.Scope.\n INDEX, ## defined scope for frame classifications\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n )\n ],\n ),\n ],\n classifications=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_class\",\n scope=lb.Classification.Scope.\n INDEX, ## defined scope for frame classifications\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_class\",\n scope=lb.Classification.Scope.INDEX,\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"nested_radio_question\",\n options=[\n lb.Option(\n \"first_radio_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"sub_radio_question\",\n options=[lb.Option(\"first_sub_radio_answer\")],\n )\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"nested_checklist_question\",\n options=[\n lb.Option(\n \"first_checklist_answer\",\n options=[\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"sub_checklist_question\",\n options=[lb.Option(\"first_sub_checklist_answer\")],\n )\n ],\n )\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.RADIO,\n name=\"radio_class_global\",\n options=[\n lb.Option(value=\"first_radio_answer\"),\n lb.Option(value=\"second_radio_answer\"),\n ],\n ),\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"checklist_class_global\",\n options=[\n lb.Option(value=\"first_checklist_answer\"),\n lb.Option(value=\"second_checklist_answer\"),\n ],\n ),\n lb.Classification(class_type=lb.Classification.Type.TEXT,\n name=\"free_text\"),\n ],\n)\n\nontology = client.create_ontology(\n \"Ontology Video Annotations\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Video,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -852,13 +190,7 @@
},
{
"metadata": {},
- "source": [
- "# create Model\n",
- "model = client.create_model(name=\"video_model_run_\" + str(uuid.uuid4()),\n",
- " ontology_id=ontology.uid)\n",
- "# create Model Run\n",
- "model_run = model.create_model_run(\"iteration 1\")"
- ],
+ "source": "# create Model\nmodel = client.create_model(name=\"video_model_run_\" + str(uuid.uuid4()),\n ontology_id=ontology.uid)\n# create Model Run\nmodel_run = model.create_model_run(\"iteration 1\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -872,9 +204,7 @@
},
{
"metadata": {},
- "source": [
- "model_run.upsert_data_rows(global_keys=[global_key])"
- ],
+ "source": "model_run.upsert_data_rows(global_keys=[global_key])",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -898,31 +228,7 @@
},
{
"metadata": {},
- "source": [
- "label_predictions = []\n",
- "annotations_list = [\n",
- " point_prediction,\n",
- " bbox_prediction,\n",
- " polyline_prediction,\n",
- " checklist_prediction,\n",
- " radio_prediction,\n",
- " nested_radio_prediction,\n",
- " nested_checklist_prediction,\n",
- " frame_bbox_with_checklist_subclass_prediction,\n",
- " global_radio_prediction,\n",
- " global_checklist_prediction,\n",
- " text_prediction\n",
- " ]\n",
- "\n",
- "flatten_list_annotations = [ann for ann_sublist in annotations_list for ann in ann_sublist]\n",
- "\n",
- "label_predictions.append(\n",
- " lb_types.Label(\n",
- " data={\"global_key\" : global_key },\n",
- " annotations = flatten_list_annotations\n",
- " )\n",
- ")"
- ],
+ "source": "label_predictions = []\nannotations_list = [\n point_prediction,\n bbox_prediction,\n polyline_prediction,\n checklist_prediction,\n radio_prediction,\n nested_radio_prediction,\n nested_checklist_prediction,\n frame_bbox_with_checklist_subclass_prediction,\n global_radio_prediction,\n global_checklist_prediction,\n text_prediction,\n]\n\nflatten_list_annotations = [\n ann for ann_sublist in annotations_list for ann in ann_sublist\n]\n\nlabel_predictions.append(\n lb_types.Label(data={\"global_key\": global_key},\n annotations=flatten_list_annotations))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -936,30 +242,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Label object by identifying the applicable data row in Labelbox and providing a list of annotations\n",
- "label_prediction_ndjson = []\n",
- "\n",
- "for annotation in [\n",
- " point_prediction_ndjson,\n",
- " bbox_prediction_ndjson,\n",
- " polyline_prediction_ndjson,\n",
- " frame_checklist_classification_prediction_ndjson,\n",
- " frame_radio_classification_prediction_ndjson,\n",
- " nested_radio_prediction_ndjson,\n",
- " nested_checklist_prediction_ndjson,\n",
- " frame_bbox_with_checklist_subclass_prediction_ndjson,\n",
- " global_radio_classification_ndjson,\n",
- " global_checklist_classification_ndjson,\n",
- " text_prediction_ndjson\n",
- "]:\n",
- " annotation.update({\n",
- " \"dataRow\": {\n",
- " \"globalKey\": global_key\n",
- " }\n",
- " })\n",
- " label_prediction_ndjson.append(annotation)"
- ],
+ "source": "# Create a Label object by identifying the applicable data row in Labelbox and providing a list of annotations\nlabel_prediction_ndjson = []\n\nfor annotation in [\n point_prediction_ndjson,\n bbox_prediction_ndjson,\n polyline_prediction_ndjson,\n frame_checklist_classification_prediction_ndjson,\n frame_radio_classification_prediction_ndjson,\n nested_radio_prediction_ndjson,\n nested_checklist_prediction_ndjson,\n frame_bbox_with_checklist_subclass_prediction_ndjson,\n global_radio_classification_ndjson,\n global_checklist_classification_ndjson,\n text_prediction_ndjson,\n]:\n annotation.update({\"dataRow\": {\"globalKey\": global_key}})\n label_prediction_ndjson.append(annotation)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -973,16 +256,7 @@
},
{
"metadata": {},
- "source": [
- "# Upload the prediction label to the Model Run\n",
- "upload_job_prediction = model_run.add_predictions(\n",
- " name=\"prediction_upload_job\"+str(uuid.uuid4()),\n",
- " predictions=label_predictions)\n",
- "\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_prediction.errors)\n",
- "print(\"Status of uploads: \", upload_job_prediction.statuses)"
- ],
+ "source": "# Upload the prediction label to the Model Run\nupload_job_prediction = model_run.add_predictions(\n name=\"prediction_upload_job\" + str(uuid.uuid4()),\n predictions=label_predictions,\n)\n\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_prediction.errors)\nprint(\"Status of uploads: \", upload_job_prediction.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1004,12 +278,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Labelbox project\n",
- "project = client.create_project(name=\"video_prediction_demo\",\n",
- " media_type=lb.MediaType.Video)\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "# Create a Labelbox project\nproject = client.create_project(name=\"video_prediction_demo\",\n media_type=lb.MediaType.Video)\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1023,13 +292,7 @@
},
{
"metadata": {},
- "source": [
- "project.create_batch(\n",
- " \"batch_video_prediction_demo\", # Each batch in a project must have a unique name\n",
- " global_keys=[global_key], # A list of data rows, data row ids or global keys\n",
- " priority=5 # priority between 1(Highest) - 5(lowest)\n",
- ")"
- ],
+ "source": "project.create_batch(\n \"batch_video_prediction_demo\", # Each batch in a project must have a unique name\n global_keys=[global_key\n ], # A list of data rows, data row ids or global keys\n priority=5, # priority between 1(Highest) - 5(lowest)\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1043,295 +306,7 @@
},
{
"metadata": {},
- "source": [
- "# Python Annotation\n",
- "point_annotation = [\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"point_video\",\n",
- " keyframe=True,\n",
- " frame=17,\n",
- " value = lb_types.Point(x=660.134, y=407.926),\n",
- " )\n",
- "]\n",
- "\n",
- "\n",
- "######## Polyline ########\n",
- "\n",
- "# Python Annotation\n",
- "polyline_annotation = [\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"line_video_frame\",\n",
- " keyframe=True,\n",
- " frame=5,\n",
- " segment_index=0,\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=680, y=100), lb_types.Point(x=100, y=190)]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"line_video_frame\",\n",
- " keyframe=True,\n",
- " frame=12,\n",
- " segment_index=0,\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=680, y=100), lb_types.Point(x=100, y=190)]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"line_video_frame\",\n",
- " keyframe=True,\n",
- " frame=20,\n",
- " segment_index=0,\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=680, y=100), lb_types.Point(x=100, y=190)]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"line_video_frame\",\n",
- " keyframe=True,\n",
- " frame=24,\n",
- " segment_index=1,\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=680, y=100), lb_types.Point(x=100, y=190)]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"line_video_frame\",\n",
- " keyframe=True,\n",
- " frame=45,\n",
- " segment_index=1,\n",
- " value=lb_types.Line(\n",
- " points=[lb_types.Point(x=680, y=100), lb_types.Point(x=100, y=190)]\n",
- " )\n",
- " )\n",
- "\n",
- "]\n",
- "\n",
- "radio_annotation = [\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"radio_class\",\n",
- " frame=9,\n",
- " segment_index=0,\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(name = \"first_radio_answer\"))\n",
- " ),\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"radio_class\",\n",
- " frame=15,\n",
- " segment_index=0,\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(name = \"first_radio_answer\"))\n",
- " )\n",
- "]\n",
- "\n",
- "checklist_annotation= [\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"checklist_class\",\n",
- " frame=29,\n",
- " segment_index=0,\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\"\n",
- " )\n",
- " ]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"checklist_class\",\n",
- " frame=35,\n",
- " segment_index=0,\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\"\n",
- " )\n",
- " ]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"checklist_class\",\n",
- " frame=39,\n",
- " segment_index=1,\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\"\n",
- " )\n",
- " ]\n",
- " )\n",
- " ),\n",
- " lb_types.VideoClassificationAnnotation(\n",
- " name=\"checklist_class\",\n",
- " frame=45,\n",
- " segment_index=1,\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- "\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\"\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- "]\n",
- "\n",
- "global_radio_annotation = [lb_types.ClassificationAnnotation(\n",
- " name=\"radio_class_global\",\n",
- " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(name = \"first_radio_answer\"))\n",
- ")]\n",
- "\n",
- "global_checklist_annotation=[lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_class_global\",\n",
- " value=lb_types.Checklist(\n",
- " answer = [\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"first_checklist_answer\"\n",
- " ),\n",
- " lb_types.ClassificationAnswer(\n",
- " name = \"second_checklist_answer\"\n",
- " )\n",
- " ]\n",
- " )\n",
- " )]\n",
- "\n",
- "nested_radio_annotation =[lb_types.ClassificationAnnotation(\n",
- " name=\"nested_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_radio_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_radio_question\",\n",
- " value=lb_types.Radio(\n",
- " answer=lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_radio_answer\"\n",
- " )\n",
- " )\n",
- " )\n",
- " ]\n",
- " )\n",
- " )\n",
- ")]\n",
- "\n",
- "nested_checklist_annotation = [lb_types.ClassificationAnnotation(\n",
- " name=\"nested_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\",\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"sub_checklist_question\",\n",
- " value=lb_types.Checklist(\n",
- " answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_sub_checklist_answer\"\n",
- " )]\n",
- " ))\n",
- " ]\n",
- " )]\n",
- " )\n",
- ")]\n",
- "\n",
- "bbox_dm2 = {\n",
- " \"top\": 146.0,\n",
- " \"left\": 98.0,\n",
- " \"height\": 382.0,\n",
- " \"width\": 341.0\n",
- "}\n",
- "frame_bbox_with_checklist_subclass = [\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_class\",\n",
- " keyframe=True,\n",
- " frame=10,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]), # x = left, y = top\n",
- " end=lb_types.Point(x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"], y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"]), # x= left + width , y = top + height\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_class\",\n",
- " keyframe=True,\n",
- " frame=11,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]), # x = left, y = top\n",
- " end=lb_types.Point(x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"], y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"]), # x= left + width , y = top + height\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_class\",\n",
- " value=lb_types.Checklist(answer=[lb_types.ClassificationAnswer(\n",
- " name=\"first_checklist_answer\"\n",
- " )])\n",
- " )\n",
- " ]\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_class\",\n",
- " keyframe=True,\n",
- " frame=13,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm2[\"left\"], y=bbox_dm2[\"top\"]), # x = left, y = top\n",
- " end=lb_types.Point(x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"], y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"]), # x= left + width , y = top + height\n",
- " ),\n",
- " classifications=[\n",
- " lb_types.ClassificationAnnotation(\n",
- " name=\"checklist_class\",\n",
- " value=lb_types.Checklist(answer=[lb_types.ClassificationAnswer(\n",
- " name=\"second_checklist_answer\"\n",
- " )])\n",
- " )\n",
- " ]\n",
- " )\n",
- "]\n",
- "\n",
- "\n",
- "bbox_dm = {\n",
- " \"top\":617,\n",
- " \"left\":1371,\n",
- " \"height\":419,\n",
- " \"width\":505\n",
- "}\n",
- "bbox_annotation = [\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_video\",\n",
- " keyframe=True,\n",
- " frame=13,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]), # x = left, y = top\n",
- " end=lb_types.Point(x=bbox_dm[\"left\"] + bbox_dm[\"width\"], y=bbox_dm[\"top\"] + bbox_dm[\"height\"]), # x= left + width , y = top + height\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_video\",\n",
- " keyframe=True,\n",
- " frame=15,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]),\n",
- " end=lb_types.Point(x=bbox_dm[\"left\"] + bbox_dm[\"width\"], y=bbox_dm[\"top\"] + bbox_dm[\"height\"]),\n",
- " )\n",
- " ),\n",
- " lb_types.VideoObjectAnnotation(\n",
- " name = \"bbox_video\",\n",
- " keyframe=True,\n",
- " frame=19,\n",
- " segment_index=0,\n",
- " value = lb_types.Rectangle(\n",
- " start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]),\n",
- " end=lb_types.Point(x=bbox_dm[\"left\"] + bbox_dm[\"width\"], y=bbox_dm[\"top\"] + bbox_dm[\"height\"]),\n",
- " )\n",
- " )\n",
- "]\n",
- "\n",
- "\n",
- "text_annotation = [lb_types.ClassificationAnnotation(\n",
- " name=\"free_text\", # must match your ontology feature's name\n",
- " value=lb_types.Text(answer=\"sample text\")\n",
- ")]\n",
- "\n"
- ],
+ "source": "# Python Annotation\npoint_annotation = [\n lb_types.VideoObjectAnnotation(\n name=\"point_video\",\n keyframe=True,\n frame=17,\n value=lb_types.Point(x=660.134, y=407.926),\n )\n]\n\n######## Polyline ########\n\n# Python Annotation\npolyline_annotation = [\n lb_types.VideoObjectAnnotation(\n name=\"line_video_frame\",\n keyframe=True,\n frame=5,\n segment_index=0,\n value=lb_types.Line(\n points=[lb_types.Point(x=680, y=100),\n lb_types.Point(x=100, y=190)]),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"line_video_frame\",\n keyframe=True,\n frame=12,\n segment_index=0,\n value=lb_types.Line(\n points=[lb_types.Point(x=680, y=100),\n lb_types.Point(x=100, y=190)]),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"line_video_frame\",\n keyframe=True,\n frame=20,\n segment_index=0,\n value=lb_types.Line(\n points=[lb_types.Point(x=680, y=100),\n lb_types.Point(x=100, y=190)]),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"line_video_frame\",\n keyframe=True,\n frame=24,\n segment_index=1,\n value=lb_types.Line(\n points=[lb_types.Point(x=680, y=100),\n lb_types.Point(x=100, y=190)]),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"line_video_frame\",\n keyframe=True,\n frame=45,\n segment_index=1,\n value=lb_types.Line(\n points=[lb_types.Point(x=680, y=100),\n lb_types.Point(x=100, y=190)]),\n ),\n]\n\nradio_annotation = [\n lb_types.VideoClassificationAnnotation(\n name=\"radio_class\",\n frame=9,\n segment_index=0,\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\")),\n ),\n lb_types.VideoClassificationAnnotation(\n name=\"radio_class\",\n frame=15,\n segment_index=0,\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\")),\n ),\n]\n\nchecklist_annotation = [\n lb_types.VideoClassificationAnnotation(\n name=\"checklist_class\",\n frame=29,\n segment_index=0,\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\")\n ]),\n ),\n lb_types.VideoClassificationAnnotation(\n name=\"checklist_class\",\n frame=35,\n segment_index=0,\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\")\n ]),\n ),\n lb_types.VideoClassificationAnnotation(\n name=\"checklist_class\",\n frame=39,\n segment_index=1,\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\")\n ]),\n ),\n lb_types.VideoClassificationAnnotation(\n name=\"checklist_class\",\n frame=45,\n segment_index=1,\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\")\n ]),\n ),\n]\n\nglobal_radio_annotation = [\n lb_types.ClassificationAnnotation(\n name=\"radio_class_global\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\")),\n )\n]\n\nglobal_checklist_annotation = [\n lb_types.ClassificationAnnotation(\n name=\"checklist_class_global\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n lb_types.ClassificationAnswer(name=\"second_checklist_answer\"),\n ]),\n )\n]\n\nnested_radio_annotation = [\n lb_types.ClassificationAnnotation(\n name=\"nested_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_radio_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_radio_question\",\n value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n name=\"first_sub_radio_answer\")),\n )\n ],\n )),\n )\n]\n\nnested_checklist_annotation = [\n lb_types.ClassificationAnnotation(\n name=\"nested_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_checklist_answer\",\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"sub_checklist_question\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"first_sub_checklist_answer\")\n ]),\n )\n ],\n )\n ]),\n )\n]\n\nbbox_dm2 = {\"top\": 146.0, \"left\": 98.0, \"height\": 382.0, \"width\": 341.0}\nframe_bbox_with_checklist_subclass = [\n lb_types.VideoObjectAnnotation(\n name=\"bbox_class\",\n keyframe=True,\n frame=10,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm2[\"left\"],\n y=bbox_dm2[\"top\"]), # x = left, y = top\n end=lb_types.Point(\n x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"],\n y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"],\n ), # x= left + width , y = top + height\n ),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"bbox_class\",\n keyframe=True,\n frame=11,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm2[\"left\"],\n y=bbox_dm2[\"top\"]), # x = left, y = top\n end=lb_types.Point(\n x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"],\n y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"],\n ), # x= left + width , y = top + height\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"checklist_class\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(name=\"first_checklist_answer\")\n ]),\n )\n ],\n ),\n lb_types.VideoObjectAnnotation(\n name=\"bbox_class\",\n keyframe=True,\n frame=13,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm2[\"left\"],\n y=bbox_dm2[\"top\"]), # x = left, y = top\n end=lb_types.Point(\n x=bbox_dm2[\"left\"] + bbox_dm2[\"width\"],\n y=bbox_dm2[\"top\"] + bbox_dm2[\"height\"],\n ), # x= left + width , y = top + height\n ),\n classifications=[\n lb_types.ClassificationAnnotation(\n name=\"checklist_class\",\n value=lb_types.Checklist(answer=[\n lb_types.ClassificationAnswer(\n name=\"second_checklist_answer\")\n ]),\n )\n ],\n ),\n]\n\nbbox_dm = {\"top\": 617, \"left\": 1371, \"height\": 419, \"width\": 505}\nbbox_annotation = [\n lb_types.VideoObjectAnnotation(\n name=\"bbox_video\",\n keyframe=True,\n frame=13,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm[\"left\"],\n y=bbox_dm[\"top\"]), # x = left, y = top\n end=lb_types.Point(\n x=bbox_dm[\"left\"] + bbox_dm[\"width\"],\n y=bbox_dm[\"top\"] + bbox_dm[\"height\"],\n ), # x= left + width , y = top + height\n ),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"bbox_video\",\n keyframe=True,\n frame=15,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]),\n end=lb_types.Point(\n x=bbox_dm[\"left\"] + bbox_dm[\"width\"],\n y=bbox_dm[\"top\"] + bbox_dm[\"height\"],\n ),\n ),\n ),\n lb_types.VideoObjectAnnotation(\n name=\"bbox_video\",\n keyframe=True,\n frame=19,\n segment_index=0,\n value=lb_types.Rectangle(\n start=lb_types.Point(x=bbox_dm[\"left\"], y=bbox_dm[\"top\"]),\n end=lb_types.Point(\n x=bbox_dm[\"left\"] + bbox_dm[\"width\"],\n y=bbox_dm[\"top\"] + bbox_dm[\"height\"],\n ),\n ),\n ),\n]\n\ntext_annotation = [\n lb_types.ClassificationAnnotation(\n name=\"free_text\", # must match your ontology feature's name\n value=lb_types.Text(answer=\"sample text\"),\n )\n]",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1350,33 +325,7 @@
},
{
"metadata": {},
- "source": [
- "# Create a Label object by identifying the applicable data row in Labelbox and providing a list of annotations\n",
- "\n",
- "labels = []\n",
- "annotations_list = [\n",
- " checklist_annotation,\n",
- " radio_annotation,\n",
- " bbox_annotation,\n",
- " frame_bbox_with_checklist_subclass,\n",
- " point_annotation,\n",
- " polyline_annotation,\n",
- " global_checklist_annotation,\n",
- " global_radio_annotation,\n",
- " nested_checklist_annotation,\n",
- " nested_radio_annotation,\n",
- " text_annotation\n",
- " ]\n",
- "\n",
- "flatten_list_annotations = [ann for ann_sublist in annotations_list for ann in ann_sublist]\n",
- "\n",
- "labels.append(\n",
- " lb_types.Label(\n",
- " data=lb_types.VideoData(global_key=global_key),\n",
- " annotations = flatten_list_annotations\n",
- " )\n",
- ")"
- ],
+ "source": "# Create a Label object by identifying the applicable data row in Labelbox and providing a list of annotations\n\nlabels = []\nannotations_list = [\n checklist_annotation,\n radio_annotation,\n bbox_annotation,\n frame_bbox_with_checklist_subclass,\n point_annotation,\n polyline_annotation,\n global_checklist_annotation,\n global_radio_annotation,\n nested_checklist_annotation,\n nested_radio_annotation,\n text_annotation,\n]\n\nflatten_list_annotations = [\n ann for ann_sublist in annotations_list for ann in ann_sublist\n]\n\nlabels.append(\n lb_types.Label(\n data=lb_types.VideoData(global_key=global_key),\n annotations=flatten_list_annotations,\n ))",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1390,18 +339,7 @@
},
{
"metadata": {},
- "source": [
- "upload_job_annotation = lb.LabelImport.create_from_objects(\n",
- " client = client,\n",
- " project_id = project.uid,\n",
- " name=\"video_annotations_import_\" + str(uuid.uuid4()),\n",
- " labels=labels)\n",
- "\n",
- "upload_job_annotation.wait_until_done()\n",
- "# Errors will appear for annotation uploads that failed.\n",
- "print(\"Errors:\", upload_job_annotation.errors)\n",
- "print(\"Status of uploads: \", upload_job_annotation.statuses)"
- ],
+ "source": "upload_job_annotation = lb.LabelImport.create_from_objects(\n client=client,\n project_id=project.uid,\n name=\"video_annotations_import_\" + str(uuid.uuid4()),\n labels=labels,\n)\n\nupload_job_annotation.wait_until_done()\n# Errors will appear for annotation uploads that failed.\nprint(\"Errors:\", upload_job_annotation.errors)\nprint(\"Status of uploads: \", upload_job_annotation.statuses)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1415,10 +353,7 @@
},
{
"metadata": {},
- "source": [
- "# get the labels id from the project\n",
- "model_run.upsert_labels(project_id=project.uid)"
- ],
+ "source": "# get the labels id from the project\nmodel_run.upsert_labels(project_id=project.uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -1432,10 +367,7 @@
},
{
"metadata": {},
- "source": [
- "# project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/project_configuration/README.md b/examples/project_configuration/README.md
deleted file mode 100644
index a907bd5ce..000000000
--- a/examples/project_configuration/README.md
+++ /dev/null
@@ -1,2 +0,0 @@
-- This section describes advanced usage of project configuration.
-- Make sure you are comfortable with the basics/project section first.
diff --git a/examples/project_configuration/project_setup.ipynb b/examples/project_configuration/project_setup.ipynb
index 19538c905..2733332b1 100644
--- a/examples/project_configuration/project_setup.ipynb
+++ b/examples/project_configuration/project_setup.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -47,20 +47,14 @@
},
{
"metadata": {},
- "source": [
- "!pip install labelbox[data]"
- ],
+ "source": "%pip install \"labelbox[data]\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "from labelbox.schema.quality_mode import QualityMode\n",
- "import uuid"
- ],
+ "source": "import labelbox as lb\nfrom labelbox.schema.quality_mode import QualityMode",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -75,11 +69,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your api key\n",
- "API_KEY=\"\"\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your api key\nAPI_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -95,22 +85,7 @@
},
{
"metadata": {},
- "source": [
- "dataset = client.create_dataset(name=\"project_setup_demo\")\n",
- "global_keys = [\"id1\", \"id2\", \"id3\", \"id4\"]\n",
- "## Example image\n",
- "uploads = []\n",
- "# Generate data rows\n",
- "for i in range(1,5):\n",
- " uploads.append({\n",
- " 'row_data': f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n",
- " \"global_key\": global_keys[i-1]\n",
- " })\n",
- "task = dataset.create_data_rows(uploads)\n",
- "task.wait_till_done()\n",
- "print(\"ERRORS: \" , task.errors)\n",
- "print(\"RESULT URL: \", task.result_url)"
- ],
+ "source": "dataset = client.create_dataset(name=\"project_setup_demo\")\nglobal_keys = [\"id1\", \"id2\", \"id3\", \"id4\"]\n## Example image\nuploads = []\n# Generate data rows\nfor i in range(1, 5):\n uploads.append({\n \"row_data\":\n f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n \"global_key\":\n global_keys[i - 1],\n })\ntask = dataset.create_data_rows(uploads)\ntask.wait_till_done()\nprint(\"ERRORS: \", task.errors)\nprint(\"RESULT URL: \", task.result_url)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -127,16 +102,7 @@
},
{
"metadata": {},
- "source": [
- "# Create\n",
- "ontology_builder = lb.OntologyBuilder(\n",
- " tools=[lb.Tool(name=\"cat\", tool=lb.Tool.Type.BBOX)])\n",
- "ontology = client.create_ontology(\"project-setup-demo-ontology\",\n",
- " ontology_builder.asdict())\n",
- "# Select existing ontology\n",
- "#ontology = client.get_ontology(\"\")\n",
- "#ontology = existing_project.ontology()"
- ],
+ "source": "# Create\nontology_builder = lb.OntologyBuilder(\n tools=[lb.Tool(name=\"cat\", tool=lb.Tool.Type.BBOX)])\nontology = client.create_ontology(\"project-setup-demo-ontology\",\n ontology_builder.asdict())\n# Select existing ontology\n# ontology = client.get_ontology(\"\")\n# ontology = existing_project.ontology()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -152,15 +118,7 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "batch_project = client.create_project(name=\"Project Setup Demo\",\n",
- " quality_mode=QualityMode.Consensus, # For benchmarks use quality_mode = QualityMode.Benchmark\n",
- " media_type=lb.MediaType.Image)\n",
- "\n",
- "\n",
- "batch_project.setup_editor(ontology)\n"
- ],
+ "source": "batch_project = client.create_project(\n name=\"Project Setup Demo\",\n quality_mode=QualityMode.\n Consensus, # For benchmarks use quality_mode = QualityMode.Benchmark\n media_type=lb.MediaType.Image,\n)\n\nbatch_project.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -174,20 +132,7 @@
},
{
"metadata": {},
- "source": [
- "\n",
- "## When creating a batch you can also setup the data rows priority\n",
- "batch = batch_project.create_batch(\n",
- " \"batch-demo-4\", # Each batch in a project must have a unique name\n",
- " global_keys=global_keys, # A list of data rows or data row ids\n",
- " priority=5, # priority between 1(Highest) - 5(lowest)\n",
- " consensus_settings={\n",
- " \"number_of_labels\": 2,\n",
- " \"coverage_percentage\": 1\n",
- " }\n",
- ")\n",
- "print(\"Batch: \", batch)"
- ],
+ "source": "## When creating a batch you can also setup the data rows priority\nbatch = batch_project.create_batch(\n \"batch-demo-4\", # Each batch in a project must have a unique name\n global_keys=global_keys, # A list of data rows or data row ids\n priority=5, # priority between 1(Highest) - 5(lowest)\n consensus_settings={\n \"number_of_labels\": 2,\n \"coverage_percentage\": 1\n },\n)\nprint(\"Batch: \", batch)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -201,21 +146,14 @@
},
{
"metadata": {},
- "source": [
- "# Note setup_complete will be None if it fails.\n",
- "print(batch_project.setup_complete)\n",
- "print(batch_project.ontology())\n",
- "print([ds.name for ds in batch_project.batches()])\n"
- ],
+ "source": "# Note setup_complete will be None if it fails.\nprint(batch_project.setup_complete)\nprint(batch_project.ontology())\nprint([ds.name for ds in batch_project.batches()])",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "print(f\"https://app.labelbox.com/projects/{batch_project.uid}\")"
- ],
+ "source": "print(f\"https://app.labelbox.com/projects/{batch_project.uid}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -229,11 +167,7 @@
},
{
"metadata": {},
- "source": [
- "# batch_project.delete()\n",
- "# dataset_project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# batch_project.delete()\n# dataset_project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/project_configuration/queue_management.ipynb b/examples/project_configuration/queue_management.ipynb
index 26a03b14c..3ee993dd0 100644
--- a/examples/project_configuration/queue_management.ipynb
+++ b/examples/project_configuration/queue_management.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -47,22 +47,14 @@
},
{
"metadata": {},
- "source": [
- "%pip install -q \"labelbox[data]\"\n",
- "%pip install -q numpy"
- ],
+ "source": "%pip install -q \"labelbox[data]\"\n%pip install -q numpy",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "from labelbox.schema.quality_mode import QualityMode\n",
- "from uuid import uuid4\n",
- "import json"
- ],
+ "source": "import labelbox as lb\nfrom labelbox.schema.quality_mode import QualityMode\nfrom uuid import uuid4\nimport json",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -77,11 +69,7 @@
},
{
"metadata": {},
- "source": [
- "# Add your API key\n",
- "API_KEY = \"\"\n",
- "client = lb.Client(api_key=API_KEY)"
- ],
+ "source": "# Add your API key\nAPI_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -102,19 +90,7 @@
},
{
"metadata": {},
- "source": [
- "# Create Labelbox project\n",
- "\n",
- "project = client.create_project(\n",
- " name=\"batch-test-project\",\n",
- " description=\"a description\",\n",
- " quality_mode=QualityMode.\n",
- " Benchmark, # For Consensus projects use quality_mode = QualityMode.Consensus\n",
- " media_type=lb.MediaType.Image,\n",
- ")\n",
- "\n",
- "dataset = client.create_dataset(name=\"queue_dataset\")"
- ],
+ "source": "# Create Labelbox project\n\nproject = client.create_project(\n name=\"batch-test-project\",\n description=\"a description\",\n quality_mode=QualityMode.\n Benchmark, # For Consensus projects use quality_mode = QualityMode.Consensus\n media_type=lb.MediaType.Image,\n)\n\ndataset = client.create_dataset(name=\"queue_dataset\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -128,30 +104,7 @@
},
{
"metadata": {},
- "source": [
- "classification_features = [\n",
- " lb.Classification(\n",
- " class_type=lb.Classification.Type.CHECKLIST,\n",
- " name=\"Quality Issues\",\n",
- " options=[\n",
- " lb.Option(value=\"blurry\", label=\"Blurry\"),\n",
- " lb.Option(value=\"distorted\", label=\"Distorted\"),\n",
- " ],\n",
- " )\n",
- "]\n",
- "\n",
- "ontology_builder = lb.OntologyBuilder(\n",
- " tools=[], classifications=classification_features\n",
- ")\n",
- "\n",
- "ontology = client.create_ontology(\n",
- " \"Ontology from new features\",\n",
- " ontology_builder.asdict(),\n",
- " media_type=lb.MediaType.Image,\n",
- ")\n",
- "\n",
- "project.setup_editor(ontology)"
- ],
+ "source": "classification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\nontology_builder = lb.OntologyBuilder(tools=[],\n classifications=classification_features)\n\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)\n\nproject.setup_editor(ontology)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -165,27 +118,7 @@
},
{
"metadata": {},
- "source": [
- "## Example image\n",
- "uploads = []\n",
- "global_keys = []\n",
- "# Generate data rows\n",
- "for i in range(1, 5):\n",
- " global_key = str(uuid4())\n",
- " row = {\n",
- " \"row_data\":\n",
- " f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n",
- " \"global_key\":\n",
- " global_key,\n",
- " }\n",
- " global_keys.append(global_key)\n",
- " uploads.append(row)\n",
- "\n",
- "data_rows = dataset.create_data_rows(uploads)\n",
- "data_rows.wait_till_done()\n",
- "print(\"Errors\", data_rows.errors)\n",
- "print(\"Dataset status: \", data_rows.status)"
- ],
+ "source": "## Example image\nuploads = []\nglobal_keys = []\n# Generate data rows\nfor i in range(1, 5):\n global_key = str(uuid4())\n row = {\n \"row_data\":\n f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n \"global_key\":\n global_key,\n }\n global_keys.append(global_key)\n uploads.append(row)\n\ndata_rows = dataset.create_data_rows(uploads)\ndata_rows.wait_till_done()\nprint(\"Errors\", data_rows.errors)\nprint(\"Dataset status: \", data_rows.status)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -199,43 +132,14 @@
},
{
"metadata": {},
- "source": [
- "######## Create batches\n",
- "\n",
- "# Create the batch\n",
- "\n",
- "batch = project.create_batch(\n",
- " \"batch-demo\", # Each batch in a project must have a unique name\n",
- " global_keys=global_keys[\n",
- " 0:2], # A list of data rows, data row ids or global keys\n",
- " priority=\n",
- " 5, # priority between 1(Highest) - 5(lowest) 5 is the max priority that can be set\n",
- ")\n",
- "\n",
- "batch2 = project.create_batch(\n",
- " \"batch-demo-2\", # Each batch in a project must have a unique name\n",
- " # Provide a slice of the data since you can't import assets with global keys that already exist in the project.\n",
- " global_keys=global_keys[\n",
- " 2:4], # A list of data rows, data row ids or global keys\n",
- " priority=\n",
- " 1, # priority between 1(Highest) - 5(lowest) 5 is the max priority that can be set\n",
- ")\n",
- "\n",
- "print(\"Batch: \", batch)\n",
- "print(\"Batch2: \", batch2)"
- ],
+ "source": "######## Create batches\n\n# Create the batch\n\nbatch = project.create_batch(\n \"batch-demo\", # Each batch in a project must have a unique name\n global_keys=global_keys[\n 0:2], # A list of data rows, data row ids or global keys\n priority=\n 5, # priority between 1(Highest) - 5(lowest) 5 is the max priority that can be set\n)\n\nbatch2 = project.create_batch(\n \"batch-demo-2\", # Each batch in a project must have a unique name\n # Provide a slice of the data since you can't import assets with global keys that already exist in the project.\n global_keys=global_keys[\n 2:4], # A list of data rows, data row ids or global keys\n priority=\n 1, # priority between 1(Highest) - 5(lowest) 5 is the max priority that can be set\n)\n\nprint(\"Batch: \", batch)\nprint(\"Batch2: \", batch2)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "print(\n",
- " \"View the results here:\", f\"https://app.labelbox.com/projects/{project.uid}\"\n",
- ")\n",
- "# Click `start labeling` to see the images in order"
- ],
+ "source": "print(\"View the results here:\",\n f\"https://app.labelbox.com/projects/{project.uid}\")\n# Click `start labeling` to see the images in order",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -251,96 +155,35 @@
},
{
"metadata": {},
- "source": [
- "export_task = project.export()\n",
- "export_task.wait_till_done()"
- ],
+ "source": "export_task = project.export()\nexport_task.wait_till_done()",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Get data rows from project\n",
- "data_rows = []\n",
- "\n",
- "\n",
- "def json_stream_handler(output: lb.JsonConverterOutput):\n",
- " data_row = json.loads(output.json_str)\n",
- " data_rows.append(\n",
- " lb.GlobalKey(data_row[\"data_row\"][\"global_key\"])\n",
- " ) # Convert json data row into data row identifier object\n",
- "\n",
- "\n",
- "if export_task.has_errors():\n",
- " export_task.get_stream(\n",
- " converter=lb.JsonConverter(), stream_type=lb.StreamType.ERRORS\n",
- " ).start(stream_handler=lambda error: print(error))\n",
- "\n",
- "if export_task.has_result():\n",
- " export_json = export_task.get_stream(\n",
- " converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT\n",
- " ).start(stream_handler=json_stream_handler)"
- ],
+ "source": "# Get data rows from project\ndata_rows = []\n\n\ndef json_stream_handler(output: lb.JsonConverterOutput):\n data_row = json.loads(output.json_str)\n data_rows.append(lb.GlobalKey(data_row[\"data_row\"][\"global_key\"])\n ) # Convert json data row into data row identifier object\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Get label parameter overrides (LPOs)\n",
- "project_lpos = project.labeling_parameter_overrides()\n",
- "\n",
- "for lpo in project_lpos:\n",
- " print(lpo)\n",
- " print(\"Data row:\", lpo.data_row().uid)"
- ],
+ "source": "# Get label parameter overrides (LPOs)\nproject_lpos = project.labeling_parameter_overrides()\n\nfor lpo in project_lpos:\n print(lpo)\n print(\"Data row:\", lpo.data_row().uid)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Add LPOs\n",
- "lpos = []\n",
- "priority = 1\n",
- "for data_row in data_rows:\n",
- " lpos.append((data_row, priority))\n",
- " priority += 1\n",
- "\n",
- "project.set_labeling_parameter_overrides(lpos)\n",
- "\n",
- "# Check results\n",
- "project_lpos = list(project.labeling_parameter_overrides())\n",
- "\n",
- "for lpo in project_lpos:\n",
- " print(lpo)"
- ],
+ "source": "# Add LPOs\nlpos = []\npriority = 1\nfor data_row in data_rows:\n lpos.append((data_row, priority))\n priority += 1\n\nproject.set_labeling_parameter_overrides(lpos)\n\n# Check results\nproject_lpos = list(project.labeling_parameter_overrides())\n\nfor lpo in project_lpos:\n print(lpo)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Update LPOs\n",
- "global_keys = []\n",
- "for data_row in data_rows:\n",
- " global_keys.append(data_row.key)\n",
- "\n",
- "project.update_data_row_labeling_priority(\n",
- " data_rows=lb.GlobalKeys(global_keys), priority=1\n",
- ")\n",
- "\n",
- "# Check results\n",
- "project_lpos = list(project.labeling_parameter_overrides())\n",
- "\n",
- "for lpo in project_lpos:\n",
- " print(lpo)"
- ],
+ "source": "# Update LPOs\nglobal_keys = []\nfor data_row in data_rows:\n global_keys.append(data_row.key)\n\nproject.update_data_row_labeling_priority(data_rows=lb.GlobalKeys(global_keys),\n priority=1)\n\n# Check results\nproject_lpos = list(project.labeling_parameter_overrides())\n\nfor lpo in project_lpos:\n print(lpo)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -354,10 +197,7 @@
},
{
"metadata": {},
- "source": [
- "# project.delete()\n",
- "# dataset.delete()"
- ],
+ "source": "# project.delete()\n# dataset.delete()",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/project_configuration/webhooks.ipynb b/examples/project_configuration/webhooks.ipynb
index ec54de860..36b6f977b 100644
--- a/examples/project_configuration/webhooks.ipynb
+++ b/examples/project_configuration/webhooks.ipynb
@@ -6,9 +6,9 @@
{
"metadata": {},
"source": [
- "\n",
- " \n",
- " | "
+ "",
+ " ",
+ " | \n"
],
"cell_type": "markdown"
},
@@ -16,12 +16,12 @@
"metadata": {},
"source": [
"\n",
- "![]() \n",
" | \n",
"\n",
"\n",
- "![]() \n",
" | "
],
@@ -46,88 +46,42 @@
},
{
"metadata": {},
- "source": [
- "!pip install labelbox\n",
- "!pip install requests\n",
- "!pip install hmac\n",
- "!pip install hashlib\n",
- "!pip install flask\n",
- "!pip install Werkzeug"
- ],
+ "source": "%pip install -q \"labelbox[data]\"\n%pip install -q requests\n%pip install -q hmac\n%pip install -q hashlib\n%pip install -q flask\n%pip install -q Werkzeug",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "import labelbox as lb\n",
- "from flask import Flask, request\n",
- "import hmac\n",
- "import hashlib\n",
- "import threading\n",
- "from werkzeug.serving import run_simple\n",
- "import json\n",
- "import requests\n",
- "import os\n",
- "from getpass import getpass\n",
- "import socket"
- ],
+ "source": "import labelbox as lb\nfrom flask import Flask, request\nimport hmac\nimport hashlib\nimport threading\nfrom werkzeug.serving import run_simple\nimport json\nimport requests\nimport os\nfrom getpass import getpass\nimport socket",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# If you don't want to give google access to drive you can skip this cell\n",
- "# and manually set `API_KEY` below.\n",
- "\n",
- "COLAB = \"google.colab\" in str(get_ipython())\n",
- "if COLAB:\n",
- " !pip install colab-env -qU\n",
- " from colab_env import envvar_handler\n",
- "\n",
- " envvar_handler.envload()\n",
- "\n",
- "API_KEY = os.environ.get(\"LABELBOX_API_KEY\")\n",
- "if not os.environ.get(\"LABELBOX_API_KEY\"):\n",
- " API_KEY = getpass(\"Please enter your labelbox api key\")\n",
- " if COLAB:\n",
- " envvar_handler.add_env(\"LABELBOX_API_KEY\", API_KEY)"
- ],
+ "source": "# If you don\"t want to give google access to drive you can skip this cell\n# and manually set `API_KEY` below.\n\nCOLAB = \"google.colab\" in str(get_ipython())\nif COLAB:\n %pip install colab-env -qU\n from colab_env import envvar_handler\n\n envvar_handler.envload()\n\nAPI_KEY = os.environ.get(\"LABELBOX_API_KEY\")\nif not os.environ.get(\"LABELBOX_API_KEY\"):\n API_KEY = getpass(\"Please enter your labelbox api key\")\n if COLAB:\n envvar_handler.add_env(\"LABELBOX_API_KEY\", API_KEY)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Set this to a project that you want to use for the webhook\n",
- "PROJECT_ID = \"\"\n",
- "# Only update this if you have an on-prem deployment\n",
- "ENDPOINT = \"https://api.labelbox.com/graphql\""
- ],
+ "source": "# Set this to a project that you want to use for the webhook\nPROJECT_ID = \"\"\n# Only update this if you have an on-prem deployment\nENDPOINT = \"https://api.labelbox.com/graphql\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "client = lb.Client(api_key=API_KEY, endpoint=ENDPOINT)"
- ],
+ "source": "client = lb.Client(api_key=API_KEY, endpoint=ENDPOINT)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# We are using port 3001 for this example.\n",
- "# Feel free to set to whatever port you want\n",
- "WH_PORT = 3001"
- ],
+ "source": "# We are using port 3001 for this example.\n# Feel free to set to whatever port you want\nWH_PORT = 3001",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -148,10 +102,7 @@
},
{
"metadata": {},
- "source": [
- "if not COLAB:\n",
- " os.system(f\"ngrok http {WH_PORT} &\")"
- ],
+ "source": "if not COLAB:\n os.system(f\"ngrok http {WH_PORT} &\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -165,47 +116,14 @@
},
{
"metadata": {},
- "source": [
- "# This can be any secret that matches your webhook config (we will set later)\n",
- "secret = b\"example_secret\""
- ],
+ "source": "# This can be any secret that matches your webhook config (we will set later)\nsecret = b\"example_secret\"",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "app = Flask(__name__)\n",
- "\n",
- "\n",
- "@app.route(\"/\")\n",
- "def hello_world():\n",
- " return \"Hello, World!\"\n",
- "\n",
- "\n",
- "@app.route(\"/webhook-endpoint\", methods=[\"POST\"])\n",
- "def print_webhook_info():\n",
- " payload = request.data\n",
- " computed_signature = hmac.new(secret, msg=payload,\n",
- " digestmod=hashlib.sha1).hexdigest()\n",
- " if request.headers[\"X-Hub-Signature\"] != \"sha1=\" + computed_signature:\n",
- " print(\n",
- " \"Error: computed_signature does not match signature provided in the headers\"\n",
- " )\n",
- " return \"Error\", 500, 200\n",
- "\n",
- " print(\"=========== New Webhook Delivery ============\")\n",
- " print(\"Delivery ID: %s\" % request.headers[\"X-Labelbox-Id\"])\n",
- " print(\"Event: %s\" % request.headers[\"X-Labelbox-Event\"])\n",
- " print(\"Payload: %s\" %\n",
- " json.dumps(json.loads(payload.decode(\"utf8\")), indent=4))\n",
- " return \"Success\"\n",
- "\n",
- "\n",
- "thread = threading.Thread(target=lambda: run_simple(\"0.0.0.0\", WH_PORT, app))\n",
- "thread.start()"
- ],
+ "source": "app = Flask(__name__)\n\n\n@app.route(\"/\")\ndef hello_world():\n return \"Hello, World!\"\n\n\n@app.route(\"/webhook-endpoint\", methods=[\"POST\"])\ndef print_webhook_info():\n payload = request.data\n computed_signature = hmac.new(secret, msg=payload,\n digestmod=hashlib.sha1).hexdigest()\n if request.headers[\"X-Hub-Signature\"] != \"sha1=\" + computed_signature:\n print(\n \"Error: computed_signature does not match signature provided in the headers\"\n )\n return \"Error\", 500, 200\n\n print(\"=========== New Webhook Delivery ============\")\n print(\"Delivery ID: %s\" % request.headers[\"X-Labelbox-Id\"])\n print(\"Event: %s\" % request.headers[\"X-Labelbox-Event\"])\n print(\"Payload: %s\" %\n json.dumps(json.loads(payload.decode(\"utf8\")), indent=4))\n return \"Success\"\n\n\nthread = threading.Thread(target=lambda: run_simple(\"0.0.0.0\", WH_PORT, app))\nthread.start()",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -219,9 +137,7 @@
},
{
"metadata": {},
- "source": [
- "print(requests.get(\"http://localhost:3001\").text)"
- ],
+ "source": "print(requests.get(\"http://localhost:3001\").text)",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -243,49 +159,21 @@
},
{
"metadata": {},
- "source": [
- "if not COLAB:\n",
- " res = requests.get(\"http://localhost:4040/api/tunnels\")\n",
- " assert (res.status_code == 200\n",
- " ), f\"ngrok probably isn't running. {res.status_code}, {res.text}\"\n",
- " tunnels = res.json()[\"tunnels\"]\n",
- " tunnel = [\n",
- " t for t in tunnels if t[\"config\"][\"addr\"].split(\":\")[-1] == str(WH_PORT)\n",
- " ]\n",
- " tunnel = tunnel[0] # Should only be one..\n",
- " public_url = tunnel[\"public_url\"]\n",
- "else:\n",
- " public_url = f\"http://{socket.gethostbyname(socket.getfqdn(socket.gethostname()))}\"\n",
- "print(public_url)"
- ],
+ "source": "if not COLAB:\n res = requests.get(\"http://localhost:4040/api/tunnels\")\n assert (res.status_code == 200\n ), f\"ngrok probably isn't running. {res.status_code}, {res.text}\"\n tunnels = res.json()[\"tunnels\"]\n tunnel = [\n t for t in tunnels if t[\"config\"][\"addr\"].split(\":\")[-1] == str(WH_PORT)\n ]\n tunnel = tunnel[0] # Should only be one..\n public_url = tunnel[\"public_url\"]\nelse:\n public_url = (\n f\"http://{socket.gethostbyname(socket.getfqdn(socket.gethostname()))}\")\nprint(public_url)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Set project to limit the scope to a single project\n",
- "project = client.get_project(PROJECT_ID)\n",
- "topics = {topic.value for topic in lb.Webhook.Topic}\n",
- "# For Global Webhooks (Global = per workspace) project = None\n",
- "webhook = lb.Webhook.create(client,\n",
- " topics=topics,\n",
- " url=public_url,\n",
- " secret=secret.decode(),\n",
- " project=project)"
- ],
+ "source": "# Set project to limit the scope to a single project\nproject = client.get_project(PROJECT_ID)\ntopics = {topic.value for topic in lb.Webhook.Topic}\n# For Global Webhooks (Global = per workspace) project = None\nwebhook = lb.Webhook.create(\n client,\n topics=topics,\n url=public_url,\n secret=secret.decode(),\n project=project,\n)",
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
- "source": [
- "# Ok so we should be configured assuming everything is setup correctly.\n",
- "# Go to the following url and make a new label to see if it works\n",
- "print(f\"https://app.labelbox.com/projects/{PROJECT_ID}\")"
- ],
+ "source": "# Ok so we should be configured assuming everything is setup correctly.\n# Go to the following url and make a new label to see if it works\nprint(f\"https://app.labelbox.com/projects/{PROJECT_ID}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -299,15 +187,7 @@
},
{
"metadata": {},
- "source": [
- "# url, topics, and status can all be updated\n",
- "updated_url = f\"{public_url}/webhook-endpoint\"\n",
- "print(updated_url)\n",
- "webhook.update(url=updated_url)\n",
- "# Go to the following url and try one last time.\n",
- "# Any supported action should work (create, delete, or update a label)\n",
- "print(f\"https://app.labelbox.com/projects/{PROJECT_ID}\")"
- ],
+ "source": "# url, topics, and status can all be updated\nupdated_url = f\"{public_url}/webhook-endpoint\"\nprint(updated_url)\nwebhook.update(url=updated_url)\n# Go to the following url and try one last time.\n# Any supported action should work (create, delete, or update a label)\nprint(f\"https://app.labelbox.com/projects/{PROJECT_ID}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
@@ -321,21 +201,7 @@
},
{
"metadata": {},
- "source": [
- "# DELETE:\n",
- "webhook.update(status=lb.Webhook.Status.INACTIVE.value)\n",
- "\n",
- "# FETCH ALL WEBHOOKS:\n",
- "org = client.get_organization()\n",
- "webhooks = org.webhooks()\n",
- "\n",
- "# Run this to clear all.\n",
- "# WARNING!!! THIS WILL DELETE ALL WEBHOOKS FOR YOUR ORG\n",
- "# ONLY RUN THIS IS YOU KNOW WHAT YOU ARE DOING.\n",
- "# for webhook in webhooks:\n",
- "# print(webhook)\n",
- "# webhook.update(status = lb.Webhook.Status.INACTIVE.value)"
- ],
+ "source": "# DELETE:\nwebhook.update(status=lb.Webhook.Status.INACTIVE.value)\n\n# FETCH ALL WEBHOOKS:\norg = client.get_organization()\nwebhooks = org.webhooks()\n\n# Run this to clear all.\n# WARNING!!! THIS WILL DELETE ALL WEBHOOKS FOR YOUR ORG\n# ONLY RUN THIS IS YOU KNOW WHAT YOU ARE DOING.\n# for webhook in webhooks:\n# print(webhook)\n# webhook.update(status = lb.Webhook.Status.INACTIVE.value)",
"cell_type": "code",
"outputs": [],
"execution_count": null
diff --git a/examples/pyproject.toml b/examples/pyproject.toml
new file mode 100644
index 000000000..05b4ed0af
--- /dev/null
+++ b/examples/pyproject.toml
@@ -0,0 +1,35 @@
+[project]
+name = "examples"
+version = "0.1.0"
+description = "Labelbox Python Example Notebooks"
+authors = [{ name = "Labelbox", email = "docs@labelbox.com" }]
+readme = "README.md"
+# Python version matches labelbox SDK
+requires-python = ">=3."
+dependencies = []
+
+[project.urls]
+Homepage = "https://labelbox.com/"
+Documentation = "https://docs.labelbox.com/"
+Tutorials = "https://docs.labelbox.com/page/tutorials"
+Repository = "https://github.com/Labelbox/labelbox-python/examples"
+Issues = "https://github.com/Labelbox/labelbox-python/issues"
+
+[tool.rye]
+managed = true
+virtual = true
+dev-dependencies = [
+ "yapf>=0.40.2",
+ "black[jupyter]>=24.4.2",
+ "databooks>=1.3.10",
+ # higher versions dont support python 3.8
+ "pandas>=1.5.3",
+]
+
+[tool.rye.scripts]
+clean = { chain = ["clean:black", "clean:format", "clean:databooks"] }
+"clean:databooks" = 'databooks meta --rm-outs . --yes'
+"clean:black" = 'black --line-length 80 . --quiet'
+"clean:format" = { call = "scripts.format_notebooks" }
+"create-readme" = { call = "scripts.generate_readme:main(True)" }
+"create-doc-readme" = { call = "scripts.generate_readme:main(False)" }
diff --git a/examples/scripts/config.json b/examples/scripts/config.json
deleted file mode 100644
index 6f0a0e91c..000000000
--- a/examples/scripts/config.json
+++ /dev/null
@@ -1,32 +0,0 @@
-[
- {
- "dir": "basics",
- "title": "Getting started",
- "order": 0
- },
- {
- "dir": "project_configuration",
- "title": "Project configuration",
- "order": 1
- },
- {
- "dir": "annotation_types",
- "title": "Annotation types",
- "order": 2
- },
- {
- "dir": "annotation_import",
- "title": "Annotation import (Ground Truth & MAL)",
- "order": 3
- },
- {
- "dir": "label_export",
- "title": "Label export",
- "order": 4
- },
- {
- "dir": "model_diagnostics",
- "title": "Model diagnostics",
- "order": 5
- }
-]
\ No newline at end of file
diff --git a/examples/format_notebooks.py b/examples/scripts/format_notebooks.py
similarity index 67%
rename from examples/format_notebooks.py
rename to examples/scripts/format_notebooks.py
index 11b63f999..36972e96a 100644
--- a/examples/format_notebooks.py
+++ b/examples/scripts/format_notebooks.py
@@ -1,9 +1,13 @@
import glob
import json
from copy import deepcopy
-
+from concurrent.futures import ProcessPoolExecutor
from yapf.yapflib.yapf_api import FormatCode
+"""
+Script used to format notebooks. To mass change any links or headers cells change the variables below. Hooks into github action CI tools.
+"""
+
BANNER_CELL = {
"cell_type": "markdown",
"id": "db768cda",
@@ -11,41 +15,38 @@
"source": [
"",
' ',
- " | ",
+ "\n",
],
}
-
LINK_CELL = {
"cell_type": "markdown",
"id": "cb5611d0",
"metadata": {},
"source": [
- "",
- ' ',
- " | ",
+ "\n",
+ ' \n',
+ " | \n",
"\n",
- "",
- ' ',
+ " | \n",
+ ' \n',
" | ",
],
}
COLAB_TEMPLATE = "https://colab.research.google.com/github/Labelbox/labelbox-python/blob/develop/examples/{filename}"
-GITHUB_TEMPLATE = (
- "https://github.com/Labelbox/labelbox-python/tree/develop/examples/{filename}"
-)
+GITHUB_TEMPLATE = "https://github.com/Labelbox/labelbox-python/tree/develop/examples/{filename}"
def format_cell(source):
for line in source.split("\n"):
if line.strip().startswith(("!", "%")):
- return source
+ return source.replace("!", "%").replace("'", '"')
return FormatCode(source, style_config="google")[0]
-def add_headers(file_name):
+def format_file(file_name):
with open(file_name, "r") as file:
data = json.load(file)
@@ -57,34 +58,22 @@ def add_headers(file_name):
link_cell["source"][1] = link_cell["source"][1].format(colab=colab_path)
link_cell["source"][6] = link_cell["source"][6].format(github=github_path)
- data["cells"] = [BANNER_CELL, link_cell] + data["cells"]
-
- with open(file_name, "w") as file:
- file.write(json.dumps(data, indent=4))
-
- print("Formatted", file_name)
-
-
-def format_file(file_name):
- with open(file_name, "r") as file:
- data = json.load(file)
+ data["cells"] = [BANNER_CELL, link_cell] + data["cells"][2:]
- idx = 1
for cell in data["cells"]:
if cell["cell_type"] == "code":
- cell["execution_count"] = idx
if isinstance(cell["source"], list):
cell["source"] = "".join(cell["source"])
cell["source"] = format_cell(cell["source"])
- idx += 1
if cell["source"].endswith("\n"):
cell["source"] = cell["source"][:-1]
with open(file_name, "w") as file:
file.write(json.dumps(data, indent=4))
- print("Formatted", file_name)
if __name__ == "__main__":
- for file in glob.glob("**/*.ipynb", recursive=True):
- format_file(file)
+ files = [file for file in glob.glob("**/*.ipynb", recursive=True)]
+ with ProcessPoolExecutor(10) as pool:
+ pool.map(format_file, files)
+ print("Cleaning Completed! 🍻 ")
diff --git a/examples/scripts/generate_readme.py b/examples/scripts/generate_readme.py
index a12f8176c..80939acfc 100644
--- a/examples/scripts/generate_readme.py
+++ b/examples/scripts/generate_readme.py
@@ -1,22 +1,39 @@
import pandas
import glob
from collections import defaultdict
+from pprint import pprint
"""
Script used to generate readme programmatically works by taking the links of all the notebooks
then dividing them to different tables based on directory name. Pandas is used to make the tables. Using inline HTML to support our doc page.
"""
+IGNORE = ["template.ipynb"]
+
+ORDER = [
+ "basics",
+ "exports",
+ "project_configuration",
+ "annotation_import",
+ "integrations",
+ "model_experiments",
+ "prediction_upload",
+]
+
SDK_EXAMPLE_HEADER = """
# Labelbox SDK Examples\n
- Learn how to use the SDK by following along\n
- Run in google colab, view the notebooks on github, or clone the repo and run locally\n
"""
+README_EXAMPLE_HEADER = """---
+title: Python tutorials
+---
+
+"""
+
COLAB_TEMPLATE = "https://colab.research.google.com/github/Labelbox/labelbox-python/blob/develop/examples/{filename}"
-GITHUB_TEMPLATE = (
- "https://github.com/Labelbox/labelbox-python/tree/develop/examples/{filename}"
-)
+GITHUB_TEMPLATE = "https://github.com/Labelbox/labelbox-python/tree/develop/examples/{filename}"
def create_header(link: str) -> str:
@@ -29,7 +46,7 @@ def create_header(link: str) -> str:
str: formatted file path for header
"""
# Splits up link uses directory name
- split_link = link.split("/")[1].replace("_", " ").split(" ")
+ split_link = link.split("/")[0].replace("_", " ").split(" ")
header = []
# Capitalize first letter of each word
@@ -75,10 +92,10 @@ def make_link(link: str, photo: str, link_type: str) -> str:
Returns:
str: anchor tag with image
"""
- return f'
'
+ return f'
'
-def make_links_dict(links: str) -> defaultdict[list]:
+def make_links_dict(links: str):
"""Creates dictionary needed for pandas to generate the table takes all the links and makes each directory its own table
Args:
@@ -88,13 +105,18 @@ def make_links_dict(links: str) -> defaultdict[list]:
defaultdict[list]: returns dict that is in pandas dataFrame format
"""
link_dict = defaultdict(list)
+ for section in ORDER:
+ link_dict[section] = []
for link in links:
- split_link = link.split("/")[1]
- link_dict[split_link].append(link)
+ if link.split("/")[-1] in IGNORE:
+ continue
+ else:
+ split_link = link.split("/")[0]
+ link_dict[split_link].append(link)
return link_dict
-def make_table(base: str = "") -> str:
+def make_table(base: str) -> str:
"""main function to make table
Args:
@@ -103,7 +125,7 @@ def make_table(base: str = "") -> str:
Returns:
str: markdown string file
"""
- link_dict = make_links_dict(glob.glob("**/examples/**/*.ipynb", recursive=True))
+ link_dict = make_links_dict(glob.glob("**/*.ipynb", recursive=True))
generated_markdown = base
for link_list in link_dict.values():
pandas_dict = {"Notebook": [], "Github": [], "Google Colab": []}
@@ -112,23 +134,35 @@ def make_table(base: str = "") -> str:
pandas_dict["Notebook"].append(create_title(link))
pandas_dict["Github"].append(
make_link(
- GITHUB_TEMPLATE.format(filename="/".join(link.split("/")[1:])),
+ GITHUB_TEMPLATE.format(filename="/".join(link.split("/"))),
"https://img.shields.io/badge/GitHub-100000?logo=github&logoColor=white",
"Github",
)
)
pandas_dict["Google Colab"].append(
make_link(
- COLAB_TEMPLATE.format(filename="/".join(link.split("/")[1:])),
+ COLAB_TEMPLATE.format(filename="/".join(link.split("/"))),
"https://colab.research.google.com/assets/colab-badge.svg",
"Colab",
)
)
df = pandas.DataFrame(pandas_dict)
generated_markdown += f"{df.to_html(col_space={'Notebook':400}, index=False, escape=False, justify='left')}\n\n"
- return generated_markdown
+ return f"{generated_markdown.rstrip()}\n"
+
+
+def main(github: bool):
+ """
+ Args:
+ github (bool): if this is the readme for github.
+ """
+ if github:
+ with open("./README.md", "w") as readme:
+ readme.write(make_table(SDK_EXAMPLE_HEADER))
+ else:
+ with open("./tutorials.html", "w") as readme:
+ readme.write(make_table(README_EXAMPLE_HEADER))
if __name__ == "__main__":
- with open("./examples/README.md", "w") as readme:
- readme.write(f"{make_table(SDK_EXAMPLE_HEADER).rstrip()}\n")
+ main(True)
diff --git a/examples/scripts/upload_documentation.py b/examples/scripts/upload_documentation.py
deleted file mode 100644
index ea987f6b7..000000000
--- a/examples/scripts/upload_documentation.py
+++ /dev/null
@@ -1,127 +0,0 @@
-import glob
-import json
-import os
-
-import click
-import nbformat
-import requests
-from nbconvert import MarkdownExporter
-
-README_AUTH = os.getenv('README_AUTH')
-README_ENDPOINT = "https://dash.readme.com/api/v1/docs"
-README_DOC_ENDPOINT = "https://dash.readme.com/api/v1/docs/"
-CATEGORY_ID = '61fb645198ad91004246bd5f'
-CATEGORY_SLUG = 'tutorials'
-
-
-def upload_doc(path, section):
- title = path.split('/')[-1].replace(".ipynb",
- '').capitalize().replace('_', ' ')
-
- with open(path) as fb:
- nb = nbformat.reads(json.dumps(json.load(fb)), as_version=4)
-
- nb.cells = [nb.cells[1]] + nb.cells[3:]
- nb.cells[0]['source'] += '\n'
- exporter = MarkdownExporter()
-
- body, resources = exporter.from_notebook_node(nb)
-
- payload = {
- "hidden":
- True,
- "title":
- f'{section["slug"]}-' + title.replace(' ', '-').replace("(", ''),
- "category":
- CATEGORY_ID,
- "parentDoc":
- section['id'],
- "body":
- body
- }
-
- headers = {
- "Accept": "application/json",
- "Content-Type": "application/json",
- "Authorization": README_AUTH
- }
-
- response = requests.post(README_ENDPOINT, json=payload, headers=headers)
- response.raise_for_status()
- data = response.json()
- change_name(data['slug'], title, headers, hidden=False)
-
-
-def make_sections(sections):
- for section in sections:
- print(section)
- payload = {
- "hidden": True,
- "order": section['order'],
- "title": 'section-' + section['dir'] + '-notebooks',
- "category": CATEGORY_ID
- }
- headers = {
- "Accept": "application/json",
- "Content-Type": "application/json",
- "Authorization": README_AUTH
- }
-
- response = requests.post(README_ENDPOINT, json=payload, headers=headers)
- data = response.json()
-
- section['id'] = data['id']
- section['slug'] = data['slug']
-
- change_name(data["slug"], section['title'], headers, False)
-
- return sections
-
-
-def change_name(slug, title, headers, hidden=True):
- resp = requests.put(f'{README_DOC_ENDPOINT}/{slug}',
- json={
- "hidden": hidden,
- "title": title,
- "category": CATEGORY_ID
- },
- headers=headers)
- resp.raise_for_status()
-
-
-def erase_category_docs(cat_slug):
- headers = {"Accept": "application/json", "Authorization": README_AUTH}
-
- response = requests.request(
- "GET",
- f'https://dash.readme.com/api/v1/categories/{cat_slug}/docs',
- headers=headers)
- docs = response.json()
- for doc in docs:
- for child in doc["children"]:
- resp = requests.delete(f'{README_DOC_ENDPOINT}/{child["slug"]}',
- headers=headers)
- resp = requests.delete(f'{README_DOC_ENDPOINT}/{doc["slug"]}',
- headers=headers)
-
-
-@click.command()
-@click.option('--config-path')
-# @click.option('--output-path')
-def main(config_path):
- # print(input_path)
- erase_category_docs(CATEGORY_SLUG)
- with open(config_path) as fb:
- config = json.load(fb)
- config = make_sections(config)
-
- for section in config:
- print(section, '\n------')
- for path in glob.glob(f'{section["dir"]}/**.ipynb'):
- print('*', path)
- upload_doc(path, section)
- print('-------')
-
-
-if __name__ == '__main__':
- main()
diff --git a/examples/template.ipynb b/examples/template.ipynb
new file mode 100644
index 000000000..6a052a9b6
--- /dev/null
+++ b/examples/template.ipynb
@@ -0,0 +1,133 @@
+{
+ "nbformat": 4,
+ "nbformat_minor": 2,
+ "metadata": {},
+ "cells": [
+ {
+ "metadata": {},
+ "source": [
+ "",
+ " ",
+ " | \n"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "\n",
+ " \n",
+ " | \n",
+ "\n",
+ "\n",
+ " \n",
+ " | "
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "%pip install -q \"labelbox[data]\"\n# Always install \"labelbox[data]\" over labelbox to ensure dependencies are installed correctly\n# Include other installs in this block with similar format: \"%pip install -q \"",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": "import labelbox as lb\n\n# Include other imports in this block try grouping similar imports together",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "## API key and client\n",
+ "Provide a valid API key below in order to properly connect to the Labelbox client. Please review [Create API key guide](https://docs.labelbox.com/reference/create-api-key) for more information."
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "# Add your API key\nAPI_KEY = None\n# To get your API key go to: Workspace settings -> API -> Create API Key\nclient = lb.Client(api_key=API_KEY)",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "## Main section header\n",
+ "\n",
+ "* Include information on what section discusses"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "### Sub section header\n",
+ "\n",
+ "* Include information on what sub section discusses\n",
+ "* If parameters are needed specify they need included"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "DATASET_ID = None\n# Inline Parameters should be all caps with a default value typically None",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "metadata": {},
+ "source": [
+ "## Notebook section with steps\n",
+ "\n",
+ "* For long winded processes step headers should be included"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "### Step \"step number\""
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "* Include information on step"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "#### \"step number.sub step number\"\n",
+ "\n",
+ "* Some steps need sub steps and should be labeled like above. For example, 7.1, 7.2, etc."
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": [
+ "## Clean up\n",
+ "Uncomment and run the cell below to optionally delete Labelbox objects created"
+ ],
+ "cell_type": "markdown"
+ },
+ {
+ "metadata": {},
+ "source": "# batch.delete()\n# project.delete()\n# dataset.delete()\n\n## Include other objects that were created",
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null
+ }
+ ]
+}
\ No newline at end of file
diff --git a/examples/test_notebooks.py b/examples/test_notebooks.py
deleted file mode 100644
index 96ec06c78..000000000
--- a/examples/test_notebooks.py
+++ /dev/null
@@ -1,74 +0,0 @@
-"""
-Runs example notebooks to ensure that they are not throwing an error.
-"""
-
-import pathlib
-import pytest
-
-import nbformat
-from nbconvert.preprocessors import ExecutePreprocessor
-
-examples_path = pathlib.Path(__file__).parent
-notebook_paths = examples_path.glob('**/*.ipynb')
-filtered_notebook_paths = [
- path for path in notebook_paths if '.ipynb_checkpoints' not in str(path)
-]
-relative_notebook_paths = [
- str(p.relative_to(examples_path)) for p in filtered_notebook_paths
-]
-
-
-def run_notebook(filename):
- with open(filename) as ff:
- nb_in = nbformat.read(ff, nbformat.NO_CONVERT)
-
- ep = ExecutePreprocessor(timeout=1200, kernel_name='python3')
-
- ep.preprocess(nb_in)
-
-
-SKIP_LIST = [
- 'extras/classification-confusion-matrix.ipynb',
- 'label_export/images.ipynb',
- 'label_export/text.ipynb',
- 'label_export/video.ipynb',
- 'annotation_types/converters.ipynb',
- 'integrations/detectron2/coco_panoptic.ipynb',
- 'integrations/tlt/detectnet_v2_bounding_box.ipynb',
- 'basics/datasets.ipynb',
- 'basics/data_rows.ipynb',
- 'basics/labels.ipynb',
- 'basics/data_row_metadata.ipynb',
- 'model_diagnostics/custom_metrics_basics.ipynb',
- 'basics/user_management.ipynb',
- 'integrations/tlt/labelbox_upload.ipynb',
- 'model_diagnostics/custom_metrics_demo.ipynb',
- 'model_diagnostics/model_diagnostics_demo.ipynb',
- 'integrations/databricks/',
- 'integrations/detectron2/coco_object.ipynb',
- 'project_configuration/webhooks.ipynb',
- 'basics/projects.ipynb',
- 'model_diagnostics/model_diagnostics_guide.ipynb',
-]
-
-
-def skip_notebook(notebook_path):
- for skip_path in SKIP_LIST:
- if notebook_path.startswith(skip_path):
- return True
- return False
-
-
-run_notebook_paths = [
- path for path in relative_notebook_paths if not skip_notebook(path)
-]
-
-
-@pytest.mark.skip(
- 'Need some more work to run reliably, e.g. figuring out how to deal with '
- 'max number of models per org, therefore skipping from CI. However, this '
- 'test can be run locally after updating notebooks to ensure notebooks '
- 'are working.')
-@pytest.mark.parametrize("notebook_path", run_notebook_paths)
-def test_notebooks_run_without_errors(notebook_path):
- run_notebook(examples_path / notebook_path)
diff --git a/pyproject.toml b/pyproject.toml
index ecd80c176..82c6d2f71 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -2,9 +2,7 @@
name = "labelbox-python"
version = "0.1.0"
description = "Labelbox Python API"
-authors = [
- { name = "Labelbox", email = "engineering@labelbox.com" }
-]
+authors = [{ name = "Labelbox", email = "engineering@labelbox.com" }]
dependencies = [
"sphinx-multiproject>=1.0.0rc1",
"sphinx>=7.1.2",
@@ -29,7 +27,7 @@ dev-dependencies = [
]
[tool.rye.workspace]
-members = ["libs/*"]
+members = ["libs/*", "examples"]
[tool.pytest.ini_options]
addopts = "-rP -vvv --reruns 2 --reruns-delay 10 --durations=20 -n auto --cov=labelbox --import-mode=importlib"
@@ -38,4 +36,4 @@ markers = """
"""
[tool.rye.scripts]
-docs = "sphinx-build ./docs ./dist"
\ No newline at end of file
+docs = "sphinx-build ./docs ./dist"
diff --git a/requirements-dev.lock b/requirements-dev.lock
index 0a5d5ae48..a90e24e44 100644
--- a/requirements-dev.lock
+++ b/requirements-dev.lock
@@ -6,20 +6,26 @@
# features: []
# all-features: false
# with-sources: false
-# generate-hashes: false
-e file:libs/labelbox
alabaster==0.7.13
# via sphinx
annotated-types==0.7.0
# via pydantic
+appnope==0.1.4
+ # via ipython
+asttokens==2.4.1
+ # via stack-data
attrs==23.2.0
# via jsonschema
# via referencing
babel==2.15.0
# via sphinx
+backcall==0.2.0
+ # via ipython
beautifulsoup4==4.12.3
# via nbconvert
+black==24.4.2
bleach==6.1.0
# via nbconvert
cachetools==5.3.3
@@ -29,11 +35,17 @@ certifi==2024.2.2
charset-normalizer==3.3.2
# via requests
click==8.1.7
+ # via black
# via typer
+commonmark==0.9.1
+ # via rich
coverage==7.5.1
# via pytest-cov
+databooks==1.3.10
decopatch==1.4.10
# via pytest-cases
+decorator==5.1.1
+ # via ipython
defusedxml==0.7.1
# via nbconvert
docutils==0.20.1
@@ -43,10 +55,16 @@ exceptiongroup==1.2.1
# via pytest
execnet==2.1.1
# via pytest-xdist
+executing==2.0.1
+ # via stack-data
fastjsonschema==2.19.1
# via nbformat
geojson==3.1.0
# via labelbox
+gitdb==4.0.11
+ # via gitpython
+gitpython==3.1.43
+ # via databooks
google-api-core==2.19.0
# via labelbox
google-auth==2.29.0
@@ -67,6 +85,10 @@ importlib-resources==6.4.0
# via jsonschema-specifications
iniconfig==2.0.0
# via pytest
+ipython==8.12.3
+ # via black
+jedi==0.19.1
+ # via ipython
jinja2==3.1.4
# via nbconvert
# via sphinx
@@ -86,17 +108,16 @@ jupyterlab-pygments==0.3.0
makefun==1.15.2
# via decopatch
# via pytest-cases
-markdown-it-py==3.0.0
- # via rich
markupsafe==2.1.5
# via jinja2
# via nbconvert
-mdurl==0.1.2
- # via markdown-it-py
+matplotlib-inline==0.1.7
+ # via ipython
mistune==3.0.2
# via nbconvert
mypy==1.10.0
mypy-extensions==1.0.0
+ # via black
# via mypy
nbclient==0.10.0
# via nbconvert
@@ -104,37 +125,58 @@ nbconvert==7.16.4
nbformat==5.10.4
# via nbclient
# via nbconvert
+numpy==1.24.4
+ # via pandas
packaging==24.0
+ # via black
# via nbconvert
# via pytest
# via pytest-cases
# via pytest-rerunfailures
# via sphinx
+pandas==1.5.3
pandocfilters==1.5.1
# via nbconvert
+parso==0.8.4
+ # via jedi
+pathspec==0.12.1
+ # via black
+pexpect==4.9.0
+ # via ipython
+pickleshare==0.7.5
+ # via ipython
pkgutil-resolve-name==1.3.10
# via jsonschema
platformdirs==4.2.2
+ # via black
# via jupyter-core
# via yapf
pluggy==1.5.0
# via pytest
+prompt-toolkit==3.0.43
+ # via ipython
proto-plus==1.23.0
# via google-api-core
protobuf==4.25.3
# via google-api-core
# via googleapis-common-protos
# via proto-plus
+ptyprocess==0.7.0
+ # via pexpect
+pure-eval==0.2.2
+ # via stack-data
pyasn1==0.6.0
# via pyasn1-modules
# via rsa
pyasn1-modules==0.4.0
# via google-auth
pydantic==2.7.1
+ # via databooks
# via labelbox
pydantic-core==2.18.2
# via pydantic
pygments==2.18.0
+ # via ipython
# via nbconvert
# via rich
# via sphinx
@@ -151,8 +193,10 @@ pytest-xdist==3.6.1
python-dateutil==2.8.2
# via jupyter-client
# via labelbox
+ # via pandas
pytz==2024.1
# via babel
+ # via pandas
pyzmq==26.0.3
# via jupyter-client
referencing==0.35.1
@@ -164,7 +208,8 @@ requests==2.32.2
# via google-api-core
# via labelbox
# via sphinx
-rich==13.7.1
+rich==12.6.0
+ # via databooks
# via typer
rpds-py==0.18.1
# via jsonschema
@@ -174,8 +219,11 @@ rsa==4.9
shellingham==1.5.4
# via typer
six==1.16.0
+ # via asttokens
# via bleach
# via python-dateutil
+smmap==5.0.1
+ # via gitdb
snowballstemmer==2.2.0
# via sphinx
soupsieve==2.5
@@ -199,13 +247,19 @@ sphinxcontrib-qthelp==1.0.3
# via sphinx
sphinxcontrib-serializinghtml==1.1.5
# via sphinx
+stack-data==0.6.3
+ # via ipython
strenum==0.4.15
# via labelbox
tinycss2==1.3.0
# via nbconvert
+tokenize-rt==5.2.0
+ # via black
toml-cli==0.6.1
tomli==2.0.1
+ # via black
# via coverage
+ # via databooks
# via mypy
# via pytest
# via yapf
@@ -216,12 +270,15 @@ tornado==6.4
tqdm==4.66.4
# via labelbox
traitlets==5.14.3
+ # via ipython
# via jupyter-client
# via jupyter-core
+ # via matplotlib-inline
# via nbclient
# via nbconvert
# via nbformat
typer==0.12.3
+ # via databooks
# via toml-cli
types-pillow==10.2.0.20240520
types-python-dateutil==2.9.0.20240316
@@ -229,6 +286,9 @@ types-requests==2.32.0.20240523
types-tqdm==4.66.0.20240417
typing-extensions==4.11.0
# via annotated-types
+ # via black
+ # via databooks
+ # via ipython
# via mypy
# via pydantic
# via pydantic-core
@@ -237,6 +297,8 @@ typing-extensions==4.11.0
urllib3==2.2.1
# via requests
# via types-requests
+wcwidth==0.2.13
+ # via prompt-toolkit
webencodings==0.5.1
# via bleach
# via tinycss2