|
6 | 6 | "metadata": {},
|
7 | 7 | "source": [
|
8 | 8 | "# Project Setup\n",
|
9 |
| - "* This section describes how to create and configure a project\n", |
| 9 | + "* This notebok describes how to create and configure a project\n", |
10 | 10 | "* This is the same as creating a new project in the editor and going through all of the steps."
|
11 | 11 | ]
|
12 | 12 | },
|
|
22 | 22 | },
|
23 | 23 | {
|
24 | 24 | "cell_type": "code",
|
25 |
| - "execution_count": 1, |
| 25 | + "execution_count": null, |
26 | 26 | "id": "contemporary-banking",
|
27 | 27 | "metadata": {},
|
28 | 28 | "outputs": [],
|
|
32 | 32 | },
|
33 | 33 | {
|
34 | 34 | "cell_type": "code",
|
35 |
| - "execution_count": 2, |
| 35 | + "execution_count": null, |
36 | 36 | "id": "ordered-notice",
|
37 | 37 | "metadata": {},
|
38 | 38 | "outputs": [],
|
39 | 39 | "source": [
|
40 |
| - "from labelbox import Client, Project, LabelingFrontend\n", |
41 |
| - "from labelbox.schema.ontology import Tool, OntologyBuilder\n", |
42 |
| - "from getpass import getpass\n", |
43 |
| - "import os" |
| 40 | + "from labelbox import Client, Project, Tool, OntologyBuilder" |
44 | 41 | ]
|
45 | 42 | },
|
46 | 43 | {
|
47 | 44 | "cell_type": "code",
|
48 |
| - "execution_count": 3, |
49 |
| - "id": "alert-train", |
50 |
| - "metadata": {}, |
51 |
| - "outputs": [], |
52 |
| - "source": [ |
53 |
| - "# If you don't want to give google access to drive you can skip this cell\n", |
54 |
| - "# and manually set `API_KEY` below.\n", |
55 |
| - "\n", |
56 |
| - "COLAB = \"google.colab\" in str(get_ipython())\n", |
57 |
| - "if COLAB:\n", |
58 |
| - " !pip install colab-env -qU\n", |
59 |
| - " from colab_env import envvar_handler\n", |
60 |
| - " envvar_handler.envload()\n", |
61 |
| - "\n", |
62 |
| - "API_KEY = os.environ.get(\"LABELBOX_API_KEY\")\n", |
63 |
| - "if not os.environ.get(\"LABELBOX_API_KEY\"):\n", |
64 |
| - " API_KEY = getpass(\"Please enter your labelbox api key\")\n", |
65 |
| - " if COLAB:\n", |
66 |
| - " envvar_handler.add_env(\"LABELBOX_API_KEY\", API_KEY)" |
67 |
| - ] |
68 |
| - }, |
69 |
| - { |
70 |
| - "cell_type": "code", |
71 |
| - "execution_count": 4, |
| 45 | + "execution_count": null, |
72 | 46 | "id": "royal-algeria",
|
73 | 47 | "metadata": {},
|
74 | 48 | "outputs": [],
|
75 | 49 | "source": [
|
76 |
| - "# Set this to a project that is already set up\n", |
77 |
| - "PROJECT_ID = \"ckm4xyfncfgja0760vpfdxoro\"\n", |
78 |
| - "# Only update this if you have an on-prem deployment\n", |
79 |
| - "ENDPOINT = \"https://api.labelbox.com/graphql\"" |
80 |
| - ] |
81 |
| - }, |
82 |
| - { |
83 |
| - "cell_type": "code", |
84 |
| - "execution_count": 5, |
85 |
| - "id": "welsh-maker", |
86 |
| - "metadata": {}, |
87 |
| - "outputs": [], |
88 |
| - "source": [ |
| 50 | + "# Add your api key\n", |
| 51 | + "API_KEY = None\n", |
| 52 | + "ENDPOINT = \"https://api.labelbox.com/graphql\"\n", |
89 | 53 | "client = Client(api_key=API_KEY, endpoint=ENDPOINT)"
|
90 | 54 | ]
|
91 | 55 | },
|
|
94 | 58 | "id": "least-stone",
|
95 | 59 | "metadata": {},
|
96 | 60 | "source": [
|
97 |
| - "### Identify project, dataset, and ontology\n", |
98 |
| - "* Pick the project to setup\n", |
99 |
| - "* Dataset(s) to attach to that project\n", |
100 |
| - "* Configure the ontology for the project" |
| 61 | + "### Create Dataset\n", |
| 62 | + "* Create dataset and attach data\n", |
| 63 | + "* More details on attaching data can be found [here](https://github.com/Labelbox/labelbox-python/blob/develop/examples/basics/data_rows.ipynb)" |
101 | 64 | ]
|
102 | 65 | },
|
103 | 66 | {
|
104 | 67 | "cell_type": "code",
|
105 |
| - "execution_count": 6, |
106 |
| - "id": "mobile-south", |
| 68 | + "execution_count": null, |
| 69 | + "id": "0c195add", |
107 | 70 | "metadata": {},
|
108 | 71 | "outputs": [],
|
109 | 72 | "source": [
|
110 |
| - "# Use bounding boxes to label cats\n", |
111 |
| - "ontology_builder = OntologyBuilder(\n", |
112 |
| - " tools=[Tool(name=\"cat\", tool=Tool.Type.BBOX)])\n", |
113 |
| - "project = client.create_project(name=\"my_new_project\")\n", |
114 | 73 | "dataset = client.create_dataset(name=\"my_new_dataset\")\n",
|
115 | 74 | "# Add data_rows since this is a new dataset (see basics/data_rows.ipynb for more information on this)\n",
|
116 | 75 | "test_img_url = \"https://raw.githubusercontent.com/Labelbox/labelbox-python/develop/examples/assets/2560px-Kitano_Street_Kobe01s5s4110.jpg\"\n",
|
117 | 76 | "dataset.create_data_row(row_data=test_img_url)"
|
118 | 77 | ]
|
119 | 78 | },
|
120 | 79 | {
|
121 |
| - "cell_type": "code", |
122 |
| - "execution_count": 7, |
123 |
| - "id": "neural-scanning", |
| 80 | + "cell_type": "markdown", |
| 81 | + "id": "e4f8b7f7", |
124 | 82 | "metadata": {},
|
125 |
| - "outputs": [], |
126 | 83 | "source": [
|
127 |
| - "# Unless you are using a custom editor you should always use the following editor:\n", |
128 |
| - "editor = next(\n", |
129 |
| - " client.get_labeling_frontends(where=LabelingFrontend.name == \"Editor\"))" |
| 84 | + "### Create Or Select an Ontology\n", |
| 85 | + "* Optionally create an ontology or select from an existing one.\n", |
| 86 | + "* More details on ontology management can be found [here](https://github.com/Labelbox/labelbox-python/blob/develop/examples/basics/ontologies.ipynb)\n", |
| 87 | + " " |
130 | 88 | ]
|
131 | 89 | },
|
132 | 90 | {
|
133 | 91 | "cell_type": "code",
|
134 |
| - "execution_count": 8, |
135 |
| - "id": "attended-twist", |
| 92 | + "execution_count": null, |
| 93 | + "id": "a9e4738c", |
136 | 94 | "metadata": {},
|
137 | 95 | "outputs": [],
|
138 | 96 | "source": [
|
139 |
| - "# Note that you can use any dataset or ontology even if they already exist.\n", |
140 |
| - "existing_project = client.get_project(PROJECT_ID)\n", |
141 |
| - "# We are not using this, but it is possible to copy the ontology to the new project\n", |
142 |
| - "ontology = existing_project.ontology()" |
| 97 | + "# Create\n", |
| 98 | + "ontology_builder = OntologyBuilder(\n", |
| 99 | + " tools=[Tool(name=\"cat\", tool=Tool.Type.BBOX)])\n", |
| 100 | + "ontology = client.create_ontology(\"project-setup-demo-ontology\", ontology_builder.asdict())\n", |
| 101 | + "# Select existing ontology\n", |
| 102 | + "#ontology = client.get_ontology(\"<ontology_id>\")\n", |
| 103 | + "#ontology = existing_project.ontology()\n" |
143 | 104 | ]
|
144 | 105 | },
|
145 | 106 | {
|
146 | 107 | "cell_type": "markdown",
|
147 | 108 | "id": "limiting-bleeding",
|
148 | 109 | "metadata": {},
|
149 | 110 | "source": [
|
150 |
| - "### Setup and attach dataset\n", |
| 111 | + "### Create Project and Setup the Editor\n", |
151 | 112 | "* Setting up a project will add an ontology and will enable labeling to begin\n",
|
152 | 113 | "* Attaching dataset(s) will add all data_rows belonging to the dataset to the queue."
|
153 | 114 | ]
|
154 | 115 | },
|
155 | 116 | {
|
156 | 117 | "cell_type": "code",
|
157 |
| - "execution_count": 9, |
| 118 | + "execution_count": null, |
158 | 119 | "id": "reserved-vietnam",
|
159 | 120 | "metadata": {},
|
160 | 121 | "outputs": [],
|
161 | 122 | "source": [
|
162 |
| - "project.setup(editor, ontology_builder.asdict())\n", |
163 |
| - "# Could also do if ontology is a normalized ontology\n", |
164 |
| - "# project.setup(editor, ontology.normalized)" |
165 |
| - ] |
166 |
| - }, |
167 |
| - { |
168 |
| - "cell_type": "code", |
169 |
| - "execution_count": 10, |
170 |
| - "id": "unexpected-vegetarian", |
171 |
| - "metadata": {}, |
172 |
| - "outputs": [], |
173 |
| - "source": [ |
174 |
| - "# Run this for each dataset we want to attach\n", |
175 |
| - "project.datasets.connect(dataset)\n", |
176 |
| - "# project.datasets.connect(another_dataset)" |
| 123 | + "project = client.create_project(name=\"my_new_project\")\n", |
| 124 | + "project.setup_editor(ontology)\n", |
| 125 | + "project.datasets.connect(dataset)" |
177 | 126 | ]
|
178 | 127 | },
|
179 | 128 | {
|
|
186 | 135 | },
|
187 | 136 | {
|
188 | 137 | "cell_type": "code",
|
189 |
| - "execution_count": 11, |
| 138 | + "execution_count": null, |
190 | 139 | "id": "vanilla-diamond",
|
191 | 140 | "metadata": {},
|
192 |
| - "outputs": [ |
193 |
| - { |
194 |
| - "name": "stdout", |
195 |
| - "output_type": "stream", |
196 |
| - "text": [ |
197 |
| - "2021-03-17 12:35:00+00:00\n", |
198 |
| - "<labelbox.orm.db_object.RelationshipManager object at 0x1046030d0>\n", |
199 |
| - "['my_new_dataset']\n" |
200 |
| - ] |
201 |
| - } |
202 |
| - ], |
| 141 | + "outputs": [], |
203 | 142 | "source": [
|
204 | 143 | "# Note setup_complete will be None if it fails.\n",
|
205 | 144 | "print(project.setup_complete)\n",
|
206 |
| - "print(project.ontology)\n", |
| 145 | + "print(project.ontology())\n", |
207 | 146 | "print([ds.name for ds in project.datasets()])"
|
208 | 147 | ]
|
209 | 148 | },
|
210 | 149 | {
|
211 | 150 | "cell_type": "code",
|
212 |
| - "execution_count": 12, |
| 151 | + "execution_count": null, |
213 | 152 | "id": "alpha-dayton",
|
214 | 153 | "metadata": {},
|
215 | 154 | "outputs": [],
|
216 | 155 | "source": [
|
217 | 156 | "print(f\"https://app.labelbox.com/projects/{project.uid}\")"
|
218 | 157 | ]
|
| 158 | + }, |
| 159 | + { |
| 160 | + "cell_type": "code", |
| 161 | + "execution_count": null, |
| 162 | + "id": "dec2f4c9", |
| 163 | + "metadata": {}, |
| 164 | + "outputs": [], |
| 165 | + "source": [] |
219 | 166 | }
|
220 | 167 | ],
|
221 | 168 | "metadata": {
|
222 | 169 | "kernelspec": {
|
223 |
| - "display_name": "Python 3", |
| 170 | + "display_name": "Python 3 (ipykernel)", |
224 | 171 | "language": "python",
|
225 | 172 | "name": "python3"
|
226 | 173 | },
|
|
234 | 181 | "name": "python",
|
235 | 182 | "nbconvert_exporter": "python",
|
236 | 183 | "pygments_lexer": "ipython3",
|
237 |
| - "version": "3.8.8" |
| 184 | + "version": "3.8.2" |
238 | 185 | }
|
239 | 186 | },
|
240 | 187 | "nbformat": 4,
|
|
0 commit comments