No project description provided
Project description
title: Python SDK Tutorial for WowDAO short: Python SDK Tutorial type: guide order: 675 meta_title: WowDAO Python SDK Tutorial meta_description: Tutorial documentation for the WowDAO 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 WowDAO 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 WowDAO API directly from scripts using predefined classes and methods.
With the WowDAO Python SDK, you can perform the following tasks in a Python script:
- Authenticate to the WowDAO API
- Create a WowDAO project, including setting up a labeling configuration.
- Import tasks.
- Manage pre-annotated tasks and model predictions.
- Connect to a cloud storage provider, such as Amazon S3, Microsoft Azure, or Google Cloud Services (GCS), to retrieve unlabeled tasks and store annotated tasks.
- Modify project settings, such as task sampling or the model version used to display predictions.
See the full SDK reference documentation for all available modules, or review the available API endpoints for any tasks that the SDK does not cover.
Start using the WowDAO Python SDK
- Install the SDK:
pip install wow-ai-sdk
- In your Python script, do the following:
- Import the SDK.
- Define your API key and WowDAO URL (API key is available at Account page).
- Connect to the API.
# Define the URL where WowDAO is accessible and the API key for your user account
WOWAI_URL = 'http://localhost:8080'
API_KEY = 'd6f8a2622d39e9d89ff0dfef1a80ad877f4ee9e3'
# Import the SDK and the client module
from wow_ai_sdk import Client
# Connect to the WowDAO API and check the connection
ls = Client(url=WOWAI_URL, api_key=API_KEY)
ls.check_connection()
Create a project with the WowDAO Python SDK
Create a project in WowDAO 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 WowDAO projects, or set a blank configuration with <View></View>
.
For example, create an audio transcription project in your Python code:
project = ls.start_project(
title='Object Detection with Bounding Boxes Project',
label_config='''
<View>\n <Image name=\"image\" value=\"$image\"/>\n <RectangleLabels name=\"label\" toName=\"image\">\n <Label value=\"Airplane\" background=\"green\"/>\n <Label value=\"Car\" background=\"blue\"/>\n </RectangleLabels>\n</View>\n
'''
)
For more about what you can do with the project module of the SDK, see the project module SDK reference.
Import tasks with the WowDAO Python SDK
You can import tasks from your script using the WowDAO Python SDK.
For a specific project, you can import tasks in WowDAO JSON format or connect to cloud storage providers and import image, audio, or video files directly.
project.import_tasks(
[
{'image': 'https://i.imgur.com/HaR6pIZ.jpeg'},
{'image': 'https://i.imgur.com/WbISHgK.jpeg'}
]
)
You can also import predictions:
Add predictions to existing tasks with the WowDAO Python SDK
You can add predictions to existing tasks in WowDAO 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:
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:
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.
Import pre-annotated tasks into WowDAO
You can also import predictions together with tasks as pre-annotated tasks. The SDK offers several ways that you can import pre-annotations into WowDAO.
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:
project.import_tasks(
[{'image': f'https://i.imgur.com/WbISHgK.jpeg', 'label': 'Car'},
{'image': f'https://i.imgur.com/HaR6pIZ.jpeg', 'label': 'Car'}],
preannotated_from_fields=['label']
)
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.
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:
from wow_ai_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:
from wow_ai_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 WowDAO.ai
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for wow_ai_sdk-0.1.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 595c0002c68fbc1e29ec938fb4d106a7ab52bbfb360c9763fb0b8320495ebeb1 |
|
MD5 | 0a44135ef90c8bfd1ddfaf958b48cf7c |
|
BLAKE2b-256 | b46f9e6a5e1712167bac2d8028aacc2c9a7b07448f9f4e51e6ceafd7c0e8a27c |