From 260db430be8e068b436f8cd3780654df3a0108e9 Mon Sep 17 00:00:00 2001
From: Andrea Ovalle <74880762+ovalle15@users.noreply.github.com>
Date: Fri, 28 Oct 2022 09:30:05 -0400
Subject: [PATCH 1/3] Update basics / basic project setup
---
examples/basics/basics.ipynb | 881 ++++++++++++++++++-----------------
1 file changed, 454 insertions(+), 427 deletions(-)
diff --git a/examples/basics/basics.ipynb b/examples/basics/basics.ipynb
index dcfe1d51a..f9e1089a7 100644
--- a/examples/basics/basics.ipynb
+++ b/examples/basics/basics.ipynb
@@ -1,441 +1,468 @@
{
- "cells": [
- {
- "cell_type": "markdown",
- "id": "db768cda",
- "metadata": {},
- "source": [
- "
\n",
- " \n",
- " | "
- ]
- },
- {
- "cell_type": "markdown",
- "id": "cb5611d0",
- "metadata": {},
- "source": [
- "\n",
- " \n",
- " | \n",
- "\n",
- "\n",
- " \n",
- " | "
- ]
- },
- {
- "cell_type": "markdown",
- "id": "complimentary-passing",
- "metadata": {},
- "source": [
- "# Basics\n"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "smaller-syndication",
- "metadata": {},
- "source": [
- "### Quick install instructions\n",
- "The quick version is basically just\n",
- "1. `!pip install labelbox`\n",
- "2. `export LABELBOX_API_KEY=\"\"`\n",
- "* Get this from the UI under (Workspace settings -> API -> Create API Key)\n",
- "* You can also set the api_key below in the notebook.\n",
- "\n",
- "This only works for cloud deployments.\n",
- "* For more details : https://docs.labelbox.com/python-sdk/en/index-en#labelbox-python-sdk\n"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "cheap-damages",
- "metadata": {},
- "source": [
- "#### The remainder of this notebook is an interactive version of the fundamental concepts docs.\n",
- "* For more details you can read the docs here: \n",
- " * https://docs.labelbox.com/python-sdk/en/index-en#fundamental-concepts"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "id": "indie-bracket",
- "metadata": {},
- "outputs": [],
- "source": [
- "!pip install labelbox"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "id": "everyday-street",
- "metadata": {},
- "outputs": [],
- "source": [
- "from labelbox import Project, Dataset, Client\n",
- "import os"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "committed-matthew",
- "metadata": {},
- "source": [
- "### Main takeaways:\n",
- "* All interactions with labelbox happen through the client\n",
- "* all attributes that are labelbox.orm.Fields can be accessed via object.field_name\n",
- "* all attributes that are labelbox.orm.Relationships can be accessed via object.relationship()\n",
- "----\n",
- "* To use on your own data you need to plug in the following:\n",
- "1. Project and Dataset ids (go to the web ui and you can find these in the url)\n",
- " * (https://app.labelbox.com/projects/\n",
- " * https://app.labelbox.com/dataset/\n",
- "2. A project name and a dataset name\n",
- " * Select any project names from here: https://app.labelbox.com/projects\n",
- " * Select any dataset names from here: https://app.labelbox.com/data"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "id": "instructional-reply",
- "metadata": {},
- "outputs": [],
- "source": [
- "PROJECT_ID = \"ckk4q1viuc0w20704eh69u28h\"\n",
- "DATASET_ID = \"ckk4q1vjznyhu087203wlghfr\"\n",
- "PROJECT_NAME = \"Sample Project\"\n",
- "DATASET_NAME = \"Example Jellyfish Dataset\"\n",
- "# Only update this if you have an on-prem deployment\n",
- "ENDPOINT = \"https://api.labelbox.com/graphql\""
- ]
- },
- {
- "cell_type": "markdown",
- "id": "chinese-playing",
- "metadata": {},
- "source": [
- "### Client\n",
- "* Starting point for all db interactions"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "485451ad",
- "metadata": {},
- "source": [
- "# API Key and Client\n",
- "Provide a valid api key below in order to properly connect to the Labelbox Client."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "id": "thick-gasoline",
- "metadata": {},
- "outputs": [],
- "source": [
- "# Add your api key\n",
- "API_KEY = None\n",
- "client = Client(api_key=API_KEY)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "id": "victorian-consumer",
- "metadata": {},
- "outputs": [],
- "source": [
- "#Client can be used to fetch by id:\n",
- "project = client.get_project(PROJECT_ID)\n",
- "dataset = client.get_dataset(DATASET_ID)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "id": "industrial-onion",
- "metadata": {},
- "outputs": [
+ "cells": [
{
- "data": {
- "text/plain": [
- ""
+ "cell_type": "markdown",
+ "id": "db768cda",
+ "metadata": {
+ "id": "db768cda"
+ },
+ "source": [
+ "\n",
+ " \n",
+ " | "
]
- },
- "execution_count": 9,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "project"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "popular-nylon",
- "metadata": {},
- "source": [
- "### Fields\n",
- "* All db objects have fields (look at the source code to see them https://github.com/Labelbox/labelbox-python/blob/develop/labelbox/schema/project.py)\n",
- "* These fields are attributes of the object"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "id": "guided-institute",
- "metadata": {},
- "outputs": [
+ },
{
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Sample Project\n",
- "Demonstrating image segmentation and object detection\n",
- "Example Jellyfish Dataset\n"
- ]
- }
- ],
- "source": [
- "print(project.name)\n",
- "print(project.description)\n",
- "print(dataset.name)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "protective-multimedia",
- "metadata": {},
- "source": [
- "* Fields can be updated. This will be reflected server side (you will see it in labelbox) "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "id": "according-subdivision",
- "metadata": {},
- "outputs": [],
- "source": [
- "project.update(description=\"new description field\")\n",
- "print(project.description)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "viral-power",
- "metadata": {},
- "source": [
- "### Pagination\n",
- "* Queries that return a list of database objects return them as a PaginatedCollection\n",
- "* The goal here is to limit the data being returned to only the necessary data."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "id": "ideal-processing",
- "metadata": {},
- "outputs": [
+ "cell_type": "markdown",
+ "id": "cb5611d0",
+ "metadata": {
+ "id": "cb5611d0"
+ },
+ "source": [
+ "\n",
+ " \n",
+ " | \n",
+ "\n",
+ "\n",
+ " \n",
+ " | "
+ ]
+ },
{
- "data": {
- "text/plain": [
- ""
+ "cell_type": "markdown",
+ "id": "complimentary-passing",
+ "metadata": {
+ "id": "complimentary-passing"
+ },
+ "source": [
+ "# Basic project setup\n",
+ "\n",
+ "This notebook is used to go over the basic of the Python SDK, what a db object is, and how to interact with it. \n",
+ "\n"
]
- },
- "execution_count": 17,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "labels_paginated_collection = project.labels()\n",
- "labels_paginated_collection"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "id": "convinced-force",
- "metadata": {},
- "outputs": [],
- "source": [
- "# Note that if you selected a `project_id` without any labels this will raise `StopIteration`\n",
- "# Iterate over them to get the items out.\n",
- "next(labels_paginated_collection)\n",
- "# list(paginated...) should be avoided for queries that could return more than a dozen results"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "widespread-startup",
- "metadata": {},
- "source": [
- "### Query parameters\n",
- "* Query with the following conventions:\n",
- " * `DbObject.Field`"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "id": "cubic-joint",
- "metadata": {},
- "outputs": [
+ },
{
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "\n",
- "\n",
- "None\n",
- "None\n"
- ]
- }
- ],
- "source": [
- "datasets = client.get_datasets(where=Dataset.name == DATASET_NAME)\n",
- "\n",
- "projects = client.get_projects(\n",
- " where=((Project.name == PROJECT_NAME) &\n",
- " (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."
- ]
- },
- {
- "cell_type": "markdown",
- "id": "french-toner",
- "metadata": {},
- "source": [
- "### Querying Limitations\n",
- "* The DbObject used for the query must be the same as the DbObject returned by the querying function. \n",
- "* eg. is not valid since get_project returns a Project but we are filtering on a Dataset\n",
- "> `>>> projects = client.get_projects(where = Dataset.name == \"dataset_name\")`\n"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "defensive-bidder",
- "metadata": {},
- "source": [
- "### Relationship\n",
- "* Relationships can be used to query for related objects (solves the limitation outlined above)\n",
- " * E.g. if a user wants all projects that have a specific dataset attached, then can run the code below.\n",
- "* You can find all realtionships of a DB object in the source code\n",
- " * E.g. for a Project ( https://github.com/Labelbox/labelbox-python/blob/develop/labelbox/schema/project.py))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "id": "handmade-yugoslavia",
- "metadata": {},
- "outputs": [
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "indie-bracket",
+ "metadata": {
+ "id": "indie-bracket"
+ },
+ "outputs": [],
+ "source": [
+ "!pip install labelbox"
+ ]
+ },
{
- "data": {
- "text/plain": [
- "[]"
+ "cell_type": "code",
+ "execution_count": 2,
+ "id": "everyday-street",
+ "metadata": {
+ "id": "everyday-street"
+ },
+ "outputs": [],
+ "source": [
+ "from labelbox import Project, Dataset, Client, DataRow\n",
+ "from labelbox.schema.queue_mode import QueueMode\n",
+ "from labelbox.schema.media_type import MediaType\n",
+ "import random\n",
+ "import uuid\n",
+ "import os"
]
- },
- "execution_count": 31,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Dataset has a Relationship to a Project so we can use the following\n",
- "list(dataset.projects())\n",
- "# This will return all projects that are attached to this dataset"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "id": "future-bargain",
- "metadata": {},
- "outputs": [
+ },
+ {
+ "cell_type": "markdown",
+ "id": "485451ad",
+ "metadata": {
+ "id": "485451ad"
+ },
+ "source": [
+ "# API Key and Client\n",
+ "Provide a valid api key below in order to properly connect to the Labelbox Client."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "id": "thick-gasoline",
+ "metadata": {
+ "id": "thick-gasoline"
+ },
+ "outputs": [],
+ "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 = Client(api_key=API_KEY)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "# For the purpose of this demo get a single project/dataset id from your organization\n",
+ "\n",
+ "# Get a single Project id\n",
+ "projects = client.get_projects()\n",
+ "project_id=list(projects)[0].uid\n",
+ "project_name=list(projects)[0].name\n",
+ "print(\"Project ID: \", project_id)\n",
+ "print(\"Project Name:\", project_name)\n",
+ "print(\"Number of projects in your org:\", len(list(projects)))\n",
+ "\n",
+ "print(\"-\" * 40)\n",
+ "\n",
+ "# Get a single dataset id\n",
+ "datasets = client.get_datasets()\n",
+ "dataset_id = list(datasets)[0].uid\n",
+ "dataset_name = list(datasets)[0].name\n",
+ "print(\"Dataset ID: \", dataset_id)\n",
+ "print(\"Dataset Name:\" , dataset_name)\n",
+ "print(\"Number of datasets in your org:\", len(list(datasets)))"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "F_payZKCiX56",
+ "outputId": "45123f80-6d04-4c83-8390-ec1d2f82ff3f"
+ },
+ "id": "F_payZKCiX56",
+ "execution_count": 4,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Project ID: cl9rmkr5a4hiy07v5ey34ahtk\n",
+ "Project Name: label_import_project_demo\n",
+ "Number of projects in your org: 88\n",
+ "----------------------------------------\n",
+ "Dataset ID: cl9rmksvo3wv207y6h158giqo\n",
+ "Dataset Name: annotation_import_demo_dataset\n",
+ "Number of datasets in your org: 78\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "id": "victorian-consumer",
+ "metadata": {
+ "id": "victorian-consumer"
+ },
+ "outputs": [],
+ "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)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "id": "industrial-onion",
+ "metadata": {
+ "id": "industrial-onion",
+ "outputId": "340c857a-8aba-428c-ae0e-04d5565ccb8f",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ }
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Project: , 'name': 'label_import_project_demo', 'queue_mode': , 'setup_complete': datetime.datetime(2022, 10, 27, 22, 16, 45, tzinfo=datetime.timezone.utc), 'uid': 'cl9rmkr5a4hiy07v5ey34ahtk', 'updated_at': datetime.datetime(2022, 10, 27, 22, 16, 46, tzinfo=datetime.timezone.utc)}>\n",
+ "Dataset: \n"
+ ]
+ }
+ ],
+ "source": [
+ "print(\"Project: \", project)\n",
+ "print(\"Dataset: \", dataset)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "popular-nylon",
+ "metadata": {
+ "id": "popular-nylon"
+ },
+ "source": [
+ "### Fields\n",
+ "* All db objects have fields (look at the source code to see them https://github.com/Labelbox/labelbox-python/blob/develop/labelbox/schema/project.py)\n",
+ "* These fields are attributes of the object"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "id": "guided-institute",
+ "metadata": {
+ "id": "guided-institute",
+ "outputId": "9fe66adc-8336-431a-cea1-91942e4939bc",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ }
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "label_import_project_demo\n",
+ "annotation_import_demo_dataset\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(project.name)\n",
+ "print(dataset.name)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "protective-multimedia",
+ "metadata": {
+ "id": "protective-multimedia"
+ },
+ "source": [
+ "* Fields can be updated. This will be reflected server side (you will see it in labelbox) "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "id": "according-subdivision",
+ "metadata": {
+ "id": "according-subdivision",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "9bc9e80d-3bce-43f5-a18d-554174fb8a7a"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "new description field\n"
+ ]
+ }
+ ],
+ "source": [
+ "project.update(description=\"new description field\")\n",
+ "print(project.description)"
+ ]
+ },
{
- "data": {
- "text/plain": [
- "[]"
+ "cell_type": "markdown",
+ "id": "viral-power",
+ "metadata": {
+ "id": "viral-power"
+ },
+ "source": [
+ "### Pagination\n",
+ "* Queries that return a list of database objects are return as a PaginatedCollection\n",
+ "* Limits the data that is being returned for better performance"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "id": "ideal-processing",
+ "metadata": {
+ "id": "ideal-processing",
+ "outputId": "c1d7ac49-31d4-4949-896d-8765f5954436",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ }
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Type of collection: \n",
+ "Number of labels : 0\n"
+ ]
+ }
+ ],
+ "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)))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "id": "convinced-force",
+ "metadata": {
+ "id": "convinced-force",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "3aff953b-efc4-4f1e-f2cd-575c3e78c01a"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Project has no labels !\n"
+ ]
+ }
+ ],
+ "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 !\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "widespread-startup",
+ "metadata": {
+ "id": "widespread-startup"
+ },
+ "source": [
+ "### Query parameters\n",
+ "* Query with the following conventions:\n",
+ " * `DbObject.Field`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "id": "cubic-joint",
+ "metadata": {
+ "id": "cubic-joint",
+ "outputId": "f02e5758-6db7-44a3-cf2b-937164e18bda",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ }
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "\n",
+ ", 'name': 'label_import_project_demo', 'queue_mode': , 'setup_complete': datetime.datetime(2022, 10, 27, 22, 16, 45, tzinfo=datetime.timezone.utc), 'uid': 'cl9rmkr5a4hiy07v5ey34ahtk', 'updated_at': datetime.datetime(2022, 10, 28, 13, 20, 59, tzinfo=datetime.timezone.utc)}>\n",
+ "None\n",
+ "None\n"
+ ]
+ }
+ ],
+ "source": [
+ "datasets = client.get_datasets(where=Dataset.name == dataset_name)\n",
+ "\n",
+ "projects = client.get_projects(\n",
+ " where=((Project.name == project_name) &\n",
+ " (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."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "french-toner",
+ "metadata": {
+ "id": "french-toner"
+ },
+ "source": [
+ "### Querying Limitations\n",
+ "* The DbObject used for the query must be the same as the DbObject returned by the querying function. \n",
+ "* The below query is not valid since get_project returns a project not a dataset\n",
+ "> `>>> projects = client.get_projects(where = Dataset.name == \"dataset_name\")`\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "# Relationships between projects and batches/datasets\n",
+ "\n"
+ ],
+ "metadata": {
+ "id": "PtEddH7nq7qy"
+ },
+ "id": "PtEddH7nq7qy"
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "id": "future-bargain",
+ "metadata": {
+ "id": "future-bargain",
+ "outputId": "f4c2980b-9b06-41c9-be36-7dfb5b4429bf",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ }
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ " Name of project : label_import_project_demo\n",
+ " Name of batches in project: first-batch-LI-demo\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Since the project we created only has batches, we can't query for datasets. \n",
+ "# sample_project_datasets = project.datasets() --> Run if project is in dataset mode\n",
+ "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}\")"
]
- },
- "execution_count": 32,
- "metadata": {},
- "output_type": "execute_result"
}
- ],
- "source": [
- "sample_project_datasets = project.datasets()\n",
- "list(sample_project_datasets)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "metric-speaker",
- "metadata": {},
- "source": [
- "### Delete\n",
- "* Most DBObjects support deletion"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 15,
- "id": "persistent-briefs",
- "metadata": {},
- "outputs": [],
- "source": [
- "#Eg.\n",
- "##### project.delete()\n",
- "##### dataset.delete()\n",
- "##### data_row.delete()"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "confused-peace",
- "metadata": {},
- "source": [
- "* We reccomend using bulk operations where possible.\n",
- "* You can find specific deletion instructions in tutorials on each object."
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.8.2"
+ },
+ "colab": {
+ "provenance": [],
+ "collapsed_sections": []
+ }
},
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.8.2"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 5
+ "nbformat": 4,
+ "nbformat_minor": 5
}
From 8ad4756f56b9bc92f2db21134bea41ecddd254b1 Mon Sep 17 00:00:00 2001
From: Andrea Ovalle <74880762+ovalle15@users.noreply.github.com>
Date: Tue, 1 Nov 2022 15:21:52 -0400
Subject: [PATCH 2/3] Latest updates
1. Remove unnecessary imports
2. updated methods for fetching projects/datasets.
---
examples/basics/basics.ipynb | 82 +++++++++++++++++-------------------
1 file changed, 39 insertions(+), 43 deletions(-)
diff --git a/examples/basics/basics.ipynb b/examples/basics/basics.ipynb
index f9e1089a7..ab75c30a4 100644
--- a/examples/basics/basics.ipynb
+++ b/examples/basics/basics.ipynb
@@ -57,7 +57,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 9,
"id": "everyday-street",
"metadata": {
"id": "everyday-street"
@@ -65,8 +65,6 @@
"outputs": [],
"source": [
"from labelbox import Project, Dataset, Client, DataRow\n",
- "from labelbox.schema.queue_mode import QueueMode\n",
- "from labelbox.schema.media_type import MediaType\n",
"import random\n",
"import uuid\n",
"import os"
@@ -85,7 +83,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 10,
"id": "thick-gasoline",
"metadata": {
"id": "thick-gasoline"
@@ -104,51 +102,49 @@
"# For the purpose of this demo get a single project/dataset id from your organization\n",
"\n",
"# Get a single Project id\n",
- "projects = client.get_projects()\n",
- "project_id=list(projects)[0].uid\n",
- "project_name=list(projects)[0].name\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",
- "print(\"Number of projects in your org:\", len(list(projects)))\n",
"\n",
"print(\"-\" * 40)\n",
"\n",
"# Get a single dataset id\n",
- "datasets = client.get_datasets()\n",
- "dataset_id = list(datasets)[0].uid\n",
- "dataset_name = list(datasets)[0].name\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)\n",
- "print(\"Number of datasets in your org:\", len(list(datasets)))"
+ "print(\"Dataset Name:\" , dataset_name)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "F_payZKCiX56",
- "outputId": "45123f80-6d04-4c83-8390-ec1d2f82ff3f"
+ "outputId": "d8334a02-a62f-4b8b-a63c-5f43512fede4"
},
"id": "F_payZKCiX56",
- "execution_count": 4,
+ "execution_count": 13,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
- "Project ID: cl9rmkr5a4hiy07v5ey34ahtk\n",
- "Project Name: label_import_project_demo\n",
- "Number of projects in your org: 88\n",
+ "Project ID: cl9smiqo23hk307y27k42cajv\n",
+ "Project Name: html-editor\n",
"----------------------------------------\n",
- "Dataset ID: cl9rmksvo3wv207y6h158giqo\n",
- "Dataset Name: annotation_import_demo_dataset\n",
- "Number of datasets in your org: 78\n"
+ "Dataset ID: cl9sywtkj2gsv07vk2isaeadj\n",
+ "Dataset Name: text_test.json\n"
]
}
]
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 14,
"id": "victorian-consumer",
"metadata": {
"id": "victorian-consumer"
@@ -162,11 +158,11 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 15,
"id": "industrial-onion",
"metadata": {
"id": "industrial-onion",
- "outputId": "340c857a-8aba-428c-ae0e-04d5565ccb8f",
+ "outputId": "965cb071-45bf-458e-edd4-e82781c58e7a",
"colab": {
"base_uri": "https://localhost:8080/"
}
@@ -176,8 +172,8 @@
"output_type": "stream",
"name": "stdout",
"text": [
- "Project: , 'name': 'label_import_project_demo', 'queue_mode': , 'setup_complete': datetime.datetime(2022, 10, 27, 22, 16, 45, tzinfo=datetime.timezone.utc), 'uid': 'cl9rmkr5a4hiy07v5ey34ahtk', 'updated_at': datetime.datetime(2022, 10, 27, 22, 16, 46, tzinfo=datetime.timezone.utc)}>\n",
- "Dataset: \n"
+ "Project: , 'name': 'html-editor', 'queue_mode': , 'setup_complete': None, 'uid': 'cl9smiqo23hk307y27k42cajv', 'updated_at': datetime.datetime(2022, 10, 28, 15, 47, 41, tzinfo=datetime.timezone.utc)}>\n",
+ "Dataset: \n"
]
}
],
@@ -200,11 +196,11 @@
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 16,
"id": "guided-institute",
"metadata": {
"id": "guided-institute",
- "outputId": "9fe66adc-8336-431a-cea1-91942e4939bc",
+ "outputId": "7805c5e3-ba99-4c91-98f8-fc69575f64fc",
"colab": {
"base_uri": "https://localhost:8080/"
}
@@ -214,8 +210,8 @@
"output_type": "stream",
"name": "stdout",
"text": [
- "label_import_project_demo\n",
- "annotation_import_demo_dataset\n"
+ "html-editor\n",
+ "text_test.json\n"
]
}
],
@@ -236,14 +232,14 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": 17,
"id": "according-subdivision",
"metadata": {
"id": "according-subdivision",
"colab": {
"base_uri": "https://localhost:8080/"
},
- "outputId": "9bc9e80d-3bce-43f5-a18d-554174fb8a7a"
+ "outputId": "18faa683-fbd5-48ce-abb5-6a6c93464b23"
},
"outputs": [
{
@@ -273,11 +269,11 @@
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 18,
"id": "ideal-processing",
"metadata": {
"id": "ideal-processing",
- "outputId": "c1d7ac49-31d4-4949-896d-8765f5954436",
+ "outputId": "ea10e564-fe27-47f1-8993-1d03d2be26a7",
"colab": {
"base_uri": "https://localhost:8080/"
}
@@ -303,14 +299,14 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 19,
"id": "convinced-force",
"metadata": {
"id": "convinced-force",
"colab": {
"base_uri": "https://localhost:8080/"
},
- "outputId": "3aff953b-efc4-4f1e-f2cd-575c3e78c01a"
+ "outputId": "b6afc495-fd71-4ac1-9e42-3fcaa6fa1802"
},
"outputs": [
{
@@ -345,11 +341,11 @@
},
{
"cell_type": "code",
- "execution_count": 11,
+ "execution_count": 20,
"id": "cubic-joint",
"metadata": {
"id": "cubic-joint",
- "outputId": "f02e5758-6db7-44a3-cf2b-937164e18bda",
+ "outputId": "b4ac9639-a362-4f6e-cbef-7c0a032b3b1f",
"colab": {
"base_uri": "https://localhost:8080/"
}
@@ -359,8 +355,8 @@
"output_type": "stream",
"name": "stdout",
"text": [
- "\n",
- ", 'name': 'label_import_project_demo', 'queue_mode': , 'setup_complete': datetime.datetime(2022, 10, 27, 22, 16, 45, tzinfo=datetime.timezone.utc), 'uid': 'cl9rmkr5a4hiy07v5ey34ahtk', 'updated_at': datetime.datetime(2022, 10, 28, 13, 20, 59, tzinfo=datetime.timezone.utc)}>\n",
+ "\n",
+ ", 'name': 'html-editor', 'queue_mode': , 'setup_complete': None, 'uid': 'cl9smiqo23hk307y27k42cajv', 'updated_at': datetime.datetime(2022, 11, 1, 19, 18, 21, tzinfo=datetime.timezone.utc)}>\n",
"None\n",
"None\n"
]
@@ -412,7 +408,7 @@
"id": "future-bargain",
"metadata": {
"id": "future-bargain",
- "outputId": "f4c2980b-9b06-41c9-be36-7dfb5b4429bf",
+ "outputId": "a2e32b99-8bd7-4b24-ce5a-171b3a2c6441",
"colab": {
"base_uri": "https://localhost:8080/"
}
@@ -422,8 +418,8 @@
"output_type": "stream",
"name": "stdout",
"text": [
- " Name of project : label_import_project_demo\n",
- " Name of batches in project: first-batch-LI-demo\n"
+ " Name of project : html-editor\n",
+ " Name of batches in project: testsss\n"
]
}
],
From 651a9ecb3d906d85959778c5a72e35e504bdc9c1 Mon Sep 17 00:00:00 2001
From: Andrea Ovalle <74880762+ovalle15@users.noreply.github.com>
Date: Tue, 1 Nov 2022 15:25:10 -0400
Subject: [PATCH 3/3] Changes to title and removed unused imports
---
examples/basics/basics.ipynb | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/examples/basics/basics.ipynb b/examples/basics/basics.ipynb
index ab75c30a4..0fb8d242d 100644
--- a/examples/basics/basics.ipynb
+++ b/examples/basics/basics.ipynb
@@ -37,9 +37,9 @@
"id": "complimentary-passing"
},
"source": [
- "# Basic project setup\n",
+ "# Basic project/datasets overview\n",
"\n",
- "This notebook is used to go over the basic of the Python SDK, what a db object is, and how to interact with it. \n",
+ "This notebook is used to go over the basic of the Python SDK, such as what a db object is, and how to interact with it. \n",
"\n"
]
},
@@ -65,9 +65,7 @@
"outputs": [],
"source": [
"from labelbox import Project, Dataset, Client, DataRow\n",
- "import random\n",
- "import uuid\n",
- "import os"
+ "import random"
]
},
{