-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make 1.4rc0 * Update frontend (#1721) * Update frontend * Pull latest changes from LSF Co-authored-by: Nick <[email protected]> * Update frontend scripts * Update LSF * Update frontend * Bump 1.4rc1 * Temporary disable py3.9 tests * [fix] [dm] onlyVirtualTabs of undefined * [fix] db naming * [fix] Empty annotations and predictions in DM TaskSerializer (#1733) * [fix] Serializer with empty annotations and predictions * Update serializers.py * Fix tests * [fix] Update LSF build with ctrl+z and not working label hotkey (DEV-1121) (#1748) * Fix quickstart example (#1726) * Fix brush mask to rle description (#1728) * Docs for custom agreement metric for private cloud LSE (#1729) * Update to add perms notes * Finish updating custom metric doc for perms * fixing link * updating custom metric doc for review feedback - restructured create policy steps - added a bunch of links to aws docs for creating roles - clarified order and links for things * Configure ssl certs in nginx (#1707) * [docs] Usecase with blocked internet access (#1732) * [docs] Usecase with blocked internet access * update k8s install for proxy/airgapped internet added more links and keywords and clarity Co-authored-by: smoreface <[email protected]> * Add docs how to enable tls on pgsql (#1737) * Update LSF build with ctrl+z and not working label hotkeys Co-authored-by: smoreface <[email protected]> Co-authored-by: Sergey Zhuk <[email protected]> * DEV-1154: Rotation fixes (#1756) * Update LSF * Update LSF to master Co-authored-by: 4iGAN <[email protected]> * DEV-438: SDK tutorial (#1711) * Create sdk.md * Update sdk.md * Update sdk.md * Update sdk.md * Add some fixes * review feedback on sdk doc * Update docs header with SDK reference link * Add more prediction examples * Update sdk.md * Update header.ejs * fix imports in doc * fix links to jupyter notebooks * [docs] update filters header per review feedback Co-authored-by: Max Tkachenko <[email protected]> Co-authored-by: nik <[email protected]> * DEV-819: Fix image size problems with appearance of scrollbar (#1758) * Make get-build works with long branch names (cherry picked from commit 4c8329e) (cherry picked from commit 56d42da) * [fix] [lsf] Add observing of image size for special cases * Update LSF Co-authored-by: makseq-ubnt <[email protected]> * Update DM from master commit * Update LS version * Update converter and LS version * Update converter to 0.0.36 * Add verify flag to sqlite download * Fix --ml-backend option * [fix] fix code editor vertical scroll after #1669 (#1765) * Fix changing avatar permission (DEV-1183) (#1764) * Get only task ids via drf-flexfields (DEV-1102) (#1747) * Change version to rc6 * Change version to 1.4 Co-authored-by: nik <[email protected]> Co-authored-by: Nick <[email protected]> Co-authored-by: hlomzik <[email protected]> Co-authored-by: makseq-ubnt <[email protected]> Co-authored-by: smoreface <[email protected]> Co-authored-by: Sergey Zhuk <[email protected]> Co-authored-by: Nick Skriabin <[email protected]> Co-authored-by: 4iGAN <[email protected]> Co-authored-by: Sergey <[email protected]> Co-authored-by: Sergei Ivashchenko <[email protected]>
- Loading branch information
1 parent
d4c4fc9
commit 3e28c16
Showing
31 changed files
with
248 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
--- | ||
title: Python SDK Tutorial for Label Studio | ||
short: Python SDK Tutorial | ||
type: guide | ||
order: 675 | ||
meta_title: Label Studio Python SDK Tutorial | ||
meta_description: Tutorial documentation for the Label Studio Python SDK that covers how and why to use the SDK to easily include data labeling project creation and annotated task parsing in your data pipeline python scripts for data science and machine learning projects. | ||
--- | ||
|
||
You can use the Label Studio Python SDK to make annotating data a more integrated part of your data science and machine learning pipelines. This software development kit (SDK) lets you call the Label Studio API directly from scripts using predefined classes and methods. | ||
|
||
With the Label Studio Python SDK, you can perform the following tasks in a Python script: | ||
- [Authenticate to the Label Studio API](#Start-using-the-Label-Studio-Python-SDK) | ||
- [Create a Label Studio project](#Create-a-project-with-the-Label-Studio-Python-SDK), including setting up a labeling configuration. | ||
- [Import tasks](#Import-tasks-with-the-Label-Studio-Python-SDK). | ||
- [Manage pre-annotated tasks and model predictions](#Add-predictions-to-existing-tasks-with-the-Label-Studio-Python-SDK). | ||
- [Connect to a cloud storage provider](https://github.com/heartexlabs/label-studio-sdk/blob/master/examples/annotate_data_from_gcs/annotate_data_from_gcs.ipynb), such as Amazon S3, Microsoft Azure, or Google Cloud Services (GCS), to retrieve unlabeled tasks and store annotated tasks. | ||
- [Modify project settings](/sdk/project.html#label_studio_sdk.project.Project.set_params), such as task sampling or the model version used to display predictions. | ||
|
||
See the [full SDK reference documentation for all available modules](/sdk/index.html), or review the available [API endpoints](/api) for any tasks that the SDK does not cover. | ||
|
||
## Start using the Label Studio Python SDK | ||
|
||
1. Install the SDK: | ||
`pip install label-studio-sdk` | ||
2. In your Python script, do the following: | ||
1. Import the SDK. | ||
2. Define your API key and Label Studio URL (API key is available at _Account_ page). | ||
3. Connect to the API. | ||
```python | ||
# Define the URL where Label Studio is accessible and the API key for your user account | ||
LABEL_STUDIO_URL = 'http://localhost:8080' | ||
API_KEY = 'd6f8a2622d39e9d89ff0dfef1a80ad877f4ee9e3' | ||
|
||
# Import the SDK and the client module | ||
from label_studio_sdk import Client | ||
|
||
# Connect to the Label Studio API and check the connection | ||
ls = Client(url=LABEL_STUDIO_URL, api_key=API_KEY) | ||
ls.check_connection() | ||
``` | ||
|
||
## Create a project with the Label Studio Python SDK | ||
|
||
Create a project in Label Studio using the SDK. Specify the project title and the labeling configuration. Choose your labeling configuration based on the type of labeling that you wish to perform. See the available [templates for Label Studio projects](/templates), or set a blank configuration with `<View></View>`. | ||
|
||
For example, create an audio transcription project in your Python code: | ||
```python | ||
project = ls.start_project( | ||
title='Audio Transcription Project', | ||
label_config=''' | ||
<View> | ||
<Header value="Listen to the audio" /> | ||
<Audio name="audio" value="$audio" /> | ||
<Header value="Write the transcription" /> | ||
<TextArea name="transcription" toName="audio" | ||
rows="4" editable="true" maxSubmissions="1" /> | ||
</View> | ||
''' | ||
) | ||
``` | ||
|
||
For more about what you can do with the project module of the SDK, see the [project module SDK reference](/sdk/project.html). | ||
|
||
## Import tasks with the Label Studio Python SDK | ||
|
||
You can import tasks from your script using the Label Studio Python SDK. | ||
|
||
For a specific project, you can import tasks in [Label Studio JSON format](tasks.html#Basic-Label-Studio-JSON-format) or [connect to cloud storage providers](https://github.com/heartexlabs/label-studio-sdk/blob/master/examples/annotate_data_from_gcs/annotate_data_from_gcs.ipynb) and import image, audio, or video files directly. | ||
|
||
```python | ||
project.import_tasks( | ||
[ | ||
{'image': 'https://data.heartex.net/open-images/train_0/mini/0045dd96bf73936c.jpg'}, | ||
{'image': 'https://data.heartex.net/open-images/train_0/mini/0083d02f6ad18b38.jpg'} | ||
] | ||
) | ||
``` | ||
|
||
You can also import predictions: | ||
- [Add predictions to an existing task](#Add-predictions-to-existing-tasks-with-the-Label-Studio-Python-SDK) | ||
- [Import pre-annotated tasks](#Import-pre-annotated-tasks-into-Label-Studio) | ||
|
||
### Add predictions to existing tasks with the Label Studio Python SDK | ||
|
||
You can add predictions to existing tasks in Label Studio in your Python script. | ||
|
||
For an existing simple image classification project, you can do the following to add predictions of "Dog" for image tasks that you retrieve: | ||
```python | ||
task_ids = project.get_tasks_ids() | ||
project.create_prediction(task_ids[0], result='Dog', score=0.9) | ||
``` | ||
|
||
For complex cases, such as object detection with bounding boxes, you can specify structured results: | ||
```python | ||
project.create_prediction(task_ids[1], result={"x": 10, "y": 20, "width": 30, "height": 40, "label": ["Dog"]}, score=0.9) | ||
``` | ||
|
||
For another example, see the [Jupyter notebook example of importing pre-annotated data](https://github.com/heartexlabs/label-studio-sdk/blob/master/examples/import_preannotations/import_preannotations.ipynb). | ||
|
||
### Import pre-annotated tasks into Label Studio | ||
|
||
You can also import predictions together with tasks as pre-annotated tasks. The SDK offers several ways that you can import pre-annotations into Label Studio. | ||
|
||
One way is to import tasks in a simple JSON format, where one key in the JSON identifies the data object being labeled, and the other is the key containing the prediction. | ||
|
||
In this example, import predictions for an image classification task: | ||
```python | ||
project.import_tasks( | ||
[{'image': f'https://data.heartex.net/open-images/train_0/mini/0045dd96bf73936c.jpg', 'pet': 'Dog'}, | ||
{'image': f'https://data.heartex.net/open-images/train_0/mini/0083d02f6ad18b38.jpg', 'pet': 'Cat'}], | ||
preannotated_from_fields=['pet'] | ||
) | ||
``` | ||
The image is specified in the `image` key using a public URL, and the prediction is referenced in an arbitrary `pet` key, which is then specified in the `preannotated_from_fields()` method. | ||
|
||
For more examples, see the [Jupyter notebook example of importing pre-annotated data](https://github.com/heartexlabs/label-studio-sdk/blob/master/examples/import_preannotations/import_preannotations.ipynb). | ||
|
||
## Prepare and manage data with filters | ||
|
||
You can also use the SDK to control how tasks appear in the data manager to annotators or reviewers. You can create custom filters and ordering for the tasks based on parameters that you specify with the SDK. This lets you have more granular control over which tasks in your dataset get labeled or reviewed, and in which order. | ||
|
||
### Prepare unlabeled data with filters | ||
|
||
For example, you can create a filter to prepare tasks to be annotated. For example, if you want annotators to focus on tasks in the first 1000 tasks in a dataset that contain the word "possum" in the field "text" in the task data, do the following: | ||
```python | ||
from label_studio_sdk.data_manager import Filters, Column, Type, Operator | ||
|
||
Filters.create(Filters.AND, [ | ||
Filters.item( | ||
Column.id, | ||
Operator.GREATER_OR_EQUAL, | ||
Type.Number, | ||
Filters.value(1) | ||
), | ||
Filters.item( | ||
Column.id, | ||
Operator.LESS_OR_EQUAL, | ||
Type.Number, | ||
Filters.value(1000) | ||
), | ||
Filters.item( | ||
Column.data(text), | ||
Operator.CONTAINS, | ||
Type.String, | ||
Filters.value("possum") | ||
) | ||
]) | ||
``` | ||
|
||
### Manage annotations with filters | ||
|
||
For example, to create a filter that displays only tasks with an ID greater than 42 or that were annotated between November 1, 2021, and now, do the following: | ||
```python | ||
from label_studio_sdk.data_manager import Filters, Column, Type, Operator | ||
|
||
Filters.create(Filters.OR, [ | ||
Filters.item( | ||
Column.id, | ||
Operator.GREATER, | ||
Type.Number, | ||
Filters.value(42) | ||
), | ||
Filters.item( | ||
Column.completed_at, | ||
Operator.IN, | ||
Type.Datetime, | ||
Filters.value( | ||
datetime(2021, 11, 1), | ||
datetime.now() | ||
) | ||
) | ||
]) | ||
``` | ||
You can use this example filter to prepare completed tasks for review in Label Studio Enterprise. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"message": "Merge branch 'feature/dev-609/source-from-server' of github.com:heartexlabs/dm2 into feature/dev-609/source-from-server", | ||
"commit": "e52959c02510bf31bfae8e7c3e336135097570e0", | ||
"branch": "feature/dev-609/source-from-server", | ||
"date": "2021-11-16T16:51:40Z" | ||
"message": "DEV-609: Load task data from server (#22)\n\n* Load task data from server\r\n\r\n* Load task data from server\r\n\r\n* Run actions on branch\r\n\r\nCo-authored-by: Sergey <[email protected]>", | ||
"commit": "feb9f1db923039b098fd0122f3d6a87bdc224a79", | ||
"branch": "master", | ||
"date": "2021-11-18T20:01:55Z" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"message": "[fix] Linter issues", | ||
"commit": "d0261d7362eaee235f6ab1f2d7f64ac17e7226c6", | ||
"message": "[fix] Add observing of image size for special cases (#340)\n\n* [fix] Add observing of image size for special cases\r\n\r\n* Add ResizeObserver fallback\r\n\r\n* Run actions on sub-branches\r\n\r\n(cherry picked from commit c1f1744ecf68c32db8adcbae0ae1ca62fba92780)\r\n(cherry picked from commit 862e7d58476ad169457b68224b09301d04e067d1)\r\n\r\n* Fix tests\r\n\r\nCo-authored-by: Nick Skriabin <[email protected]>\r\nCo-authored-by: Nick <[email protected]>\r\nCo-authored-by: Max Tkachenko <[email protected]>\r\nCo-authored-by: niklub <[email protected]>", | ||
"commit": "cb2fd37cda67dd456700f95e64947b00319dc8b8", | ||
"branch": "master", | ||
"date": "2021-10-26T12:28:02Z" | ||
"date": "2021-11-18T15:41:46Z" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.