Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ dist
build
fastlabel.egg-info
test*.py
annotation.json
annotation.json
*.jpg
*.jpeg
*.png
183 changes: 88 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# FastLabel Python SDK

_If you are using FastLabel prototype, please install version 0.2.2._

## Installation

```bash
Expand All @@ -13,7 +15,7 @@ $ pip install --upgrade fastlabel
Configure API Key in environment variable.

```bash
export FASTLABEL_API_KEY="YOUR_API_KEY"
export FASTLABEL_ACCESS_TOKEN="YOUR_ACCESS_TOKEN"
```

Initialize fastlabel client.
Expand All @@ -25,7 +27,7 @@ client = fastlabel.Client()

## Limitation

API is allowed to call 5000 times per hour. If you create/delete a large size of tasks, please wait a second for every requests.
API is allowed to call 1000 times per 10 minutes. If you create/delete a large size of tasks, please wait a second for every requests.

## Task

Expand All @@ -34,34 +36,66 @@ API is allowed to call 5000 times per hour. If you create/delete a large size of
- Create a new task.

```python
task = client.create_image_task(
project_id="YOUR_PROJECT_ID",
key="sample.jpg",
url="https://sample.com/sample.jpg"
task = client.create_task(
project="YOUR_PROJECT_SLUG",
name="sample.jpg",
file_path="./sample.jpg"
)
```

- Create a new task with pre-defined labels. (Class should be configured on your project in advance)
- Create a new task with pre-defined annotations. (Class should be configured on your project in advance)

```python
task = client.create_image_task(
project_id="YOUR_PROJECT_ID",
key="sample.jpg",
url="https://sample.com/sample.jpg",
labels=[
{
"type": "bbox",
"value": "bbox",
"points": [
{ "x": 100, "y": 100}, # top-left
{ "x": 200, "y": 200} # bottom-right
]
}
]
task = client.create_task(
project="YOUR_PROJECT_SLUG",
name="sample.jpg",
file_path="./sample.jpg",
annotations=[{
"value": "annotation-value",
"attributes": [
{
"key": "attribute-key",
"value": "attribute-value"
}
],
"points": [
100, # top-left x
100, # top-left y
200, # bottom-right x
200 # bottom-right y
]
}]
)
```

> Check [examples/create_image_task.py](/examples/create_image_task.py) for other label types, such as line, keyPoint and polygon.
> Check [examples/create_task.py](/examples/create_task.py).

### Update Task

- Update a single task status, tags, and annotations.

```python
task = client.update_task(
task_id="YOUR_TASK_ID",
status="approved",
tags=["tag1", "tag2"],
annotations=[{
"value": "annotation-value",
"attributes": [
{
"key": "attribute-key",
"value": "attribute-value"
}
],
"points": [
100, # top-left x
100, # top-left y
200, # bottom-right x
200 # bottom-right y
]
}]
)
```

### Find Task

Expand All @@ -73,38 +107,39 @@ task = client.find_task(task_id="YOUR_TASK_ID")

### Get Tasks

- Get tasks. (Up to 100 tasks)
- Get tasks. (Up to 1000 tasks)

```python
tasks = client.get_tasks(project_id="YOUR_PROJECT_ID")
tasks = client.get_tasks(project="YOUR_PROJECT_SLUG")
```

- Filter and Get tasks. (Up to 100 tasks)
- Filter and Get tasks. (Up to 1000 tasks)

```python
tasks = client.get_tasks(
project_id="YOUR_PROJECT_ID",
status="submitted", # status can be 'registered', 'registered', 'submitted' or 'skipped'
review_status="accepted" # review_status can be 'notReviewed', 'inProgress', 'accepted' or 'declined'
project="YOUR_PROJECT_SLUG",
status="approved", # status can be 'registered', 'in_progress', 'completed', 'skipped', 'in_review', 'send_backed', 'approved', 'customer_in_review', 'customer_send_backed', 'customer_approved'
tags=["tag1", "tag2"] # up to 10 tags
)
```

- Get a large size of tasks. (Over 100 tasks)
- Get a large size of tasks. (Over 1000 tasks)

```python
import time

# Iterate pages until new tasks are empty.
all_tasks = []
start_after = None
offset = None
while True:
time.sleep(1)

tasks = client.get_tasks(project_id="YOUR_PROJECT_ID", start_after=start_after)
tasks = client.get_tasks(
project="YOUR_PROJECT_SLUG", offset=offset)
all_tasks.extend(tasks)

if len(tasks) > 0:
start_after = tasks[-1]["id"] # Set the last task id to start_after
offset = len(all_tasks) # Set the offset
else:
break
```
Expand All @@ -113,6 +148,8 @@ while True:

### Delete Task

- Delete a single task.

```python
client.delete_task(task_id="YOUR_TASK_ID")
```
Expand All @@ -124,76 +161,32 @@ client.delete_task(task_id="YOUR_TASK_ID")
```python
{
"id": "YOUR_TASK_ID",
"key": "sample.png",
"assigneeId": null,
"assigneeName": null,
"name": "cat.jpg",
"url": "YOUR_TASK_URL",
"status": "registered",
"reviewAssigneeId": null,
"reviewAssigneeName": null,
"reviewStatus": "notReviewed",
"projectId": "YOUR_PROJECT_ID",
"datasetId": "YOUR_DATASET_ID",
"labels": [
"tags": [],
"annotations": [
{
"id": "YOUR_LABEL_ID",
"type": "bbox",
"value": "window",
"title": "窓",
"color": "#d9713e",
"metadata": [],
"attributes": [
{ "key": "kind", "name": "猫の種類", "type": "text", "value": "三毛猫" }
],
"color": "#b36d18",
"points": [
{ "x": 100, "y": 100}, # top-left
{ "x": 200, "y": 200} # bottom-right
]
100, # top-left x
100, # top-left y
200, # bottom-right x
200 # bottom-right y
],
"title": "Cat",
"type": "bbox",
"value": "cat"
}
],
"duration": 0,
"image": {
"width": 1500,
"height": 1200
},
"createdAt": "2020-12-25T15:02:00.513",
"updatedAt": "2020-12-25T15:02:00.513"
"createdAt": "2021-02-22T11:25:27.158Z",
"updatedAt": "2021-02-22T11:25:27.158Z"
}
```

## Model Analysis

### Upload Predictions

```python
# Create your model predictions
predictions = [
{
"fileKey": "sample.jpg", # file name exists in your project
"labels": [
{
"value": "bbox_a", # class value exists in your project
"points": [
{ "x": 10, "y": 10 }, # top-left
{ "x": 20, "y": 20 }, # botom-right
]
},
{
"value": "bbox_b",
"points": [
{ "x": 30, "y": 30 },
{ "x": 40, "y": 40 },
]
}
]
}
]

# Upload predictions
client.upload_predictions(
project_id="YOUR_PROJECT_ID", # your fastlabel project id
analysis_type="bbox", # annotation type to be analyze (Only "bbox" or "line" are supported)
threshold=80, # IoU percentage/pixel distance to check labels are correct. (Ex: 0 - 100)
predictions=predictions
)
```

## API Docs

Check [this](https://api-fastlabel-production.web.app/api/doc/) for further information.
Check [this](https://api.fastlabel.ai/docs/) for further information.
61 changes: 0 additions & 61 deletions examples/create_image_task.py

This file was deleted.

33 changes: 33 additions & 0 deletions examples/create_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pprint import pprint

import fastlabel

# Initialize client
client = fastlabel.Client()

project = "YOUR_PROJECT_SLUG"
name = "YOUR_DATA_NAME"
file_path = "YOUR_DATA_FILE_PATH" # e.g.) ./cat.jpg
annotations = [{
"value": "cat",
"attributes": [
{
"key": "kind",
"value": "三毛猫"
}
],
"points": [
100, # top-left x
100, # top-left y
200, # bottom-right x
200 # bottom-right y
]
}]

task = client.create_task(
project=project,
name=name,
file_path=file_path,
annotations=annotations
)
pprint(task)
Loading