|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "complimentary-passing", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Basics" |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "cell_type": "markdown", |
| 13 | + "id": "smaller-syndication", |
| 14 | + "metadata": {}, |
| 15 | + "source": [ |
| 16 | + "#### Quick install instructions\n", |
| 17 | + "The quick version is basically just\n", |
| 18 | + "1. `!pip install labelbox`\n", |
| 19 | + "2. `export LABELBOX_API_KEY=\"<your_api_key>\"`\n", |
| 20 | + "* Get this from the UI under (Account -> API -> Create API Key)\n", |
| 21 | + "\n", |
| 22 | + "\n", |
| 23 | + "This only works for cloud deployments.\n", |
| 24 | + "* For more details : https://docs.labelbox.com/python-sdk/en/index-en#labelbox-python-sdk" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "code", |
| 29 | + "execution_count": 1, |
| 30 | + "id": "everyday-street", |
| 31 | + "metadata": {}, |
| 32 | + "outputs": [], |
| 33 | + "source": [ |
| 34 | + "from labelbox import Client\n", |
| 35 | + "from labelbox import Project, Dataset" |
| 36 | + ] |
| 37 | + }, |
| 38 | + { |
| 39 | + "cell_type": "markdown", |
| 40 | + "id": "committed-matthew", |
| 41 | + "metadata": {}, |
| 42 | + "source": [ |
| 43 | + "### Main takeaways:\n", |
| 44 | + "* All interactions with labelbox happen through the client\n", |
| 45 | + "* all attributes that are labelbox.orm.Fields can be accessed via object.field_name\n", |
| 46 | + "* all attributes that are labelbox.orm.Relationships can be accessed via object.relationship()\n", |
| 47 | + "----\n", |
| 48 | + "* To use on your own data you need to plug in the following:\n", |
| 49 | + "1. Project and Dataset ids (go to the web ui and you can find these in the url)\n", |
| 50 | + " * (https://app.labelbox.com/projects/<project_id>\n", |
| 51 | + " * https://app.labelbox.com/dataset/<dataset_id>\n", |
| 52 | + "2. A project name and a dataset name\n", |
| 53 | + " * Select any project names from here: https://app.labelbox.com/projects\n", |
| 54 | + " * Select any dataset names from here: https://app.labelbox.com/data" |
| 55 | + ] |
| 56 | + }, |
| 57 | + { |
| 58 | + "cell_type": "code", |
| 59 | + "execution_count": 9, |
| 60 | + "id": "instructional-reply", |
| 61 | + "metadata": {}, |
| 62 | + "outputs": [], |
| 63 | + "source": [ |
| 64 | + "PROJECT_ID = \"ckk4q1viuc0w20704eh69u28h\"\n", |
| 65 | + "DATASET_ID = \"ckk4q1vjznyhu087203wlghfr\"\n", |
| 66 | + "PROJECT_NAME = \"Sample Project\"\n", |
| 67 | + "DATASET_NAME = \"Example Jellyfish Dataset\"" |
| 68 | + ] |
| 69 | + }, |
| 70 | + { |
| 71 | + "cell_type": "code", |
| 72 | + "execution_count": 10, |
| 73 | + "id": "thick-gasoline", |
| 74 | + "metadata": {}, |
| 75 | + "outputs": [], |
| 76 | + "source": [ |
| 77 | + "#Client is used for all DB interactions.\n", |
| 78 | + "#This is usually the starting point for all usage.\n", |
| 79 | + "client = Client()" |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "cell_type": "code", |
| 84 | + "execution_count": 11, |
| 85 | + "id": "victorian-consumer", |
| 86 | + "metadata": {}, |
| 87 | + "outputs": [], |
| 88 | + "source": [ |
| 89 | + "#Client can be used to fetch by id:\n", |
| 90 | + "project = client.get_project(PROJECT_ID)\n", |
| 91 | + "dataset = client.get_dataset(DATASET_ID)" |
| 92 | + ] |
| 93 | + }, |
| 94 | + { |
| 95 | + "cell_type": "code", |
| 96 | + "execution_count": 12, |
| 97 | + "id": "industrial-onion", |
| 98 | + "metadata": {}, |
| 99 | + "outputs": [ |
| 100 | + { |
| 101 | + "data": { |
| 102 | + "text/plain": [ |
| 103 | + "<Project ID: ckk4q1viuc0w20704eh69u28h>" |
| 104 | + ] |
| 105 | + }, |
| 106 | + "execution_count": 12, |
| 107 | + "metadata": {}, |
| 108 | + "output_type": "execute_result" |
| 109 | + } |
| 110 | + ], |
| 111 | + "source": [ |
| 112 | + "project" |
| 113 | + ] |
| 114 | + }, |
| 115 | + { |
| 116 | + "cell_type": "code", |
| 117 | + "execution_count": null, |
| 118 | + "id": "superb-revolution", |
| 119 | + "metadata": {}, |
| 120 | + "outputs": [], |
| 121 | + "source": [] |
| 122 | + }, |
| 123 | + { |
| 124 | + "cell_type": "code", |
| 125 | + "execution_count": 13, |
| 126 | + "id": "cubic-joint", |
| 127 | + "metadata": {}, |
| 128 | + "outputs": [ |
| 129 | + { |
| 130 | + "data": { |
| 131 | + "text/plain": [ |
| 132 | + "<labelbox.pagination.PaginatedCollection at 0x10caa6160>" |
| 133 | + ] |
| 134 | + }, |
| 135 | + "execution_count": 13, |
| 136 | + "metadata": {}, |
| 137 | + "output_type": "execute_result" |
| 138 | + } |
| 139 | + ], |
| 140 | + "source": [ |
| 141 | + "#Or you can fetch all based on a condition\n", |
| 142 | + "projects = client.get_projects(where = Project.name == PROJECT_NAME)\n", |
| 143 | + "datasets = client.get_datasets(where = Dataset.name == DATASET_NAME)\n", |
| 144 | + "projects" |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "code", |
| 149 | + "execution_count": 14, |
| 150 | + "id": "adapted-parish", |
| 151 | + "metadata": {}, |
| 152 | + "outputs": [ |
| 153 | + { |
| 154 | + "data": { |
| 155 | + "text/plain": [ |
| 156 | + "<Project ID: ckk4q1viuc0w20704eh69u28h>" |
| 157 | + ] |
| 158 | + }, |
| 159 | + "execution_count": 14, |
| 160 | + "metadata": {}, |
| 161 | + "output_type": "execute_result" |
| 162 | + } |
| 163 | + ], |
| 164 | + "source": [ |
| 165 | + "#The above two queries return PaginatedCollections because the filter parameters aren't guarenteed to be unique.\n", |
| 166 | + "#This object is an iterable containing the query results\n", |
| 167 | + "next(projects)" |
| 168 | + ] |
| 169 | + }, |
| 170 | + { |
| 171 | + "cell_type": "code", |
| 172 | + "execution_count": 15, |
| 173 | + "id": "future-bargain", |
| 174 | + "metadata": {}, |
| 175 | + "outputs": [ |
| 176 | + { |
| 177 | + "data": { |
| 178 | + "text/plain": [ |
| 179 | + "[<Dataset ID: cklv1qzlv1oqn0y9ne7b9gtpb>]" |
| 180 | + ] |
| 181 | + }, |
| 182 | + "execution_count": 15, |
| 183 | + "metadata": {}, |
| 184 | + "output_type": "execute_result" |
| 185 | + } |
| 186 | + ], |
| 187 | + "source": [ |
| 188 | + "# If you are interested in the relationship between objects then \n", |
| 189 | + "#You can only filter on attributes of either a dataset or a project.\n", |
| 190 | + "#If you want all datasets that belongs to a particular project then you can do that with the following query.\n", |
| 191 | + "sample_project_datasets = project.datasets()\n", |
| 192 | + "list(sample_project_datasets)" |
| 193 | + ] |
| 194 | + }, |
| 195 | + { |
| 196 | + "cell_type": "code", |
| 197 | + "execution_count": null, |
| 198 | + "id": "bacterial-yield", |
| 199 | + "metadata": {}, |
| 200 | + "outputs": [], |
| 201 | + "source": [] |
| 202 | + } |
| 203 | + ], |
| 204 | + "metadata": { |
| 205 | + "kernelspec": { |
| 206 | + "display_name": "Python 3", |
| 207 | + "language": "python", |
| 208 | + "name": "python3" |
| 209 | + }, |
| 210 | + "language_info": { |
| 211 | + "codemirror_mode": { |
| 212 | + "name": "ipython", |
| 213 | + "version": 3 |
| 214 | + }, |
| 215 | + "file_extension": ".py", |
| 216 | + "mimetype": "text/x-python", |
| 217 | + "name": "python", |
| 218 | + "nbconvert_exporter": "python", |
| 219 | + "pygments_lexer": "ipython3", |
| 220 | + "version": "3.8.2" |
| 221 | + } |
| 222 | + }, |
| 223 | + "nbformat": 4, |
| 224 | + "nbformat_minor": 5 |
| 225 | +} |
0 commit comments