Skip to content

Commit f87fff8

Browse files
authored
Merge pull request #3 from fastlabel/feature/add-task-apis
add task api
2 parents 4e99cd2 + ba41813 commit f87fff8

File tree

10 files changed

+380
-35
lines changed

10 files changed

+380
-35
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
.pytest_cache
66
dist
77
build
8-
fastlabel.egg-info
8+
fastlabel.egg-info
9+
test*.py
10+
annotation.json

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
all: black isort
2+
3+
black:
4+
black .
5+
6+
isort:
7+
isort .

README.md

Lines changed: 143 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,159 @@ import fastlabel
2323
client = fastlabel.Client()
2424
```
2525

26-
## Model Analysis
26+
## Limitation
2727

28-
### Upload Predictions
28+
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.
29+
30+
## Task
31+
32+
### Create Task
33+
34+
- Create a new task.
2935

3036
```python
31-
import fastlabel
37+
task = client.create_image_task(
38+
project_id="YOUR_PROJECT_ID",
39+
key="sample.jpg",
40+
url="https://sample.com/sample.jpg"
41+
)
42+
```
3243

33-
# Initialize client
34-
client = fastlabel.Client()
44+
- Create a new task with pre-defined labels. (Class should be configured on your project in advance)
45+
46+
```python
47+
task = client.create_image_task(
48+
project_id="YOUR_PROJECT_ID",
49+
key="sample.jpg",
50+
url="https://sample.com/sample.jpg",
51+
labels=[
52+
{
53+
"type": "bbox",
54+
"value": "bbox",
55+
"points": [
56+
{ "x": 100, "y": 100}, # top-left
57+
{ "x": 200, "y": 200} # bottom-right
58+
]
59+
}
60+
]
61+
)
62+
```
3563

36-
# Create predictions
64+
> Check [examples/create_image_task.py](/examples/create_image_task.py) for other label types, such as line, keyPoint and polygon.
65+
66+
### Find Task
67+
68+
- Find a single task.
69+
70+
```python
71+
task = client.find_task(task_id="YOUR_TASK_ID")
72+
```
73+
74+
### Get Tasks
75+
76+
- Get tasks. (Up to 100 tasks)
77+
78+
```python
79+
tasks = client.get_tasks(project_id="YOUR_PROJECT_ID")
80+
```
81+
82+
- Filter and Get tasks. (Up to 100 tasks)
83+
84+
```python
85+
tasks = client.get_tasks(
86+
project_id="YOUR_PROJECT_ID",
87+
status="submitted", # status can be 'registered', 'registered', 'submitted' or 'skipped'
88+
review_status="accepted" # review_status can be 'notReviewed', 'inProgress', 'accepted' or 'declined'
89+
)
90+
```
91+
92+
- Get a large size of tasks. (Over 100 tasks)
93+
94+
```python
95+
import time
96+
97+
# Iterate pages until new tasks are empty.
98+
all_tasks = []
99+
start_after = None
100+
while True:
101+
time.sleep(1)
102+
103+
tasks = client.get_tasks(project_id="YOUR_PROJECT_ID", start_after=start_after)
104+
all_tasks.extend(tasks)
105+
106+
if len(tasks) > 0:
107+
start_after = tasks[-1]["id"] # Set the last task id to start_after
108+
else:
109+
break
110+
```
111+
112+
> Please wait a second before sending another requests!
113+
114+
### Delete Task
115+
116+
```python
117+
client.delete_task(task_id="YOUR_TASK_ID")
118+
```
119+
120+
### Task Response
121+
122+
- Example of a single task object
123+
124+
```python
125+
{
126+
"id": "YOUR_TASK_ID",
127+
"key": "sample.png",
128+
"assigneeId": null,
129+
"assigneeName": null,
130+
"status": "registered",
131+
"reviewAssigneeId": null,
132+
"reviewAssigneeName": null,
133+
"reviewStatus": "notReviewed",
134+
"projectId": "YOUR_PROJECT_ID",
135+
"datasetId": "YOUR_DATASET_ID",
136+
"labels": [
137+
{
138+
"id": "YOUR_LABEL_ID",
139+
"type": "bbox",
140+
"value": "window",
141+
"title": "",
142+
"color": "#d9713e",
143+
"metadata": [],
144+
"points": [
145+
{ "x": 100, "y": 100}, # top-left
146+
{ "x": 200, "y": 200} # bottom-right
147+
]
148+
}
149+
],
150+
"duration": 0,
151+
"image": {
152+
"width": 1500,
153+
"height": 1200
154+
},
155+
"createdAt": "2020-12-25T15:02:00.513",
156+
"updatedAt": "2020-12-25T15:02:00.513"
157+
}
158+
```
159+
160+
## Model Analysis
161+
162+
### Upload Predictions
163+
164+
```python
165+
# Create your model predictions
37166
predictions = [
38167
{
39-
"fileKey": "sample1.jpg", # file name exists in your project
168+
"fileKey": "sample.jpg", # file name exists in your project
40169
"labels": [
41170
{
42-
"value": "line_a", # class value exists in your project
171+
"value": "bbox_a", # class value exists in your project
43172
"points": [
44-
{ "x": 10, "y": 10 },
45-
{ "x": 20, "y": 20 },
173+
{ "x": 10, "y": 10 }, # top-left
174+
{ "x": 20, "y": 20 }, # botom-right
46175
]
47176
},
48177
{
49-
"value": "line_b",
178+
"value": "bbox_b",
50179
"points": [
51180
{ "x": 30, "y": 30 },
52181
{ "x": 40, "y": 40 },
@@ -58,9 +187,9 @@ predictions = [
58187

59188
# Upload predictions
60189
client.upload_predictions(
61-
project_id="project_id", # your fastlabel project id
62-
analysis_type="line", # annotation type to be analyze ("bbox" or "line" are supported)
63-
threshold=25, # IoU percentage/pixel to analyze labels. (Ex: 0 - 100)
190+
project_id="YOUR_PROJECT_ID", # your fastlabel project id
191+
analysis_type="bbox", # annotation type to be analyze (Only "bbox" or "line" are supported)
192+
threshold=80, # IoU percentage/pixel distance to check labels are correct. (Ex: 0 - 100)
64193
predictions=predictions
65194
)
66195
```

contributing/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Contributing Guideline
2+
3+
## Pull Request Checklist
4+
5+
Before sending your pull requests, make sure you followed this list.
6+
7+
- Read Contributing Guideline
8+
- Run formatter and linter
9+
10+
## Formatter and Linter
11+
12+
### Installation
13+
14+
```bash
15+
$ pip install -r contributing/requirements.txt
16+
```
17+
18+
### Run Formatter and Linter
19+
20+
```bash
21+
make all
22+
```

contributing/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
black==20.8b1
2+
flake8==3.8.4
3+
isort==5.6.4

examples/create_image_task.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from pprint import pprint
2+
3+
import fastlabel
4+
5+
# Initialize client
6+
client = fastlabel.Client()
7+
8+
project_id = "YOUR_PROJECT_ID"
9+
key = "YOUR_IMAGE_KEY" # Should be an unique in your project
10+
url = "YOUR_IMAGE_URL"
11+
labels = [
12+
{
13+
"type": "bbox",
14+
"value": "bbox",
15+
"points": [
16+
{"x": 100, "y": 100}, # top-left
17+
{"x": 200, "y": 200}, # bottom-right
18+
],
19+
},
20+
{
21+
"type": "line",
22+
"value": "line",
23+
"points": [{"x": 200, "y": 200}, {"x": 250, "y": 250}],
24+
},
25+
{"type": "keyPoint", "value": "keyPoint", "points": {"x": 10, "y": 10}},
26+
{
27+
"type": "polygon",
28+
"value": "polygon",
29+
"points": [
30+
{"x": 300, "y": 300},
31+
{"x": 320, "y": 320},
32+
{"x": 340, "y": 220},
33+
{"x": 310, "y": 200},
34+
],
35+
},
36+
{
37+
"type": "polyline",
38+
"value": "polyline",
39+
"points": [
40+
{"x": 100, "y": 300},
41+
{"x": 120, "y": 320},
42+
{"x": 140, "y": 220},
43+
{"x": 110, "y": 200},
44+
],
45+
},
46+
{
47+
"type": "segmentation",
48+
"value": "segmentation",
49+
"points": [
50+
[
51+
{"x": 400, "y": 400},
52+
{"x": 420, "y": 420},
53+
{"x": 440, "y": 420},
54+
{"x": 410, "y": 400},
55+
]
56+
],
57+
},
58+
]
59+
60+
task = client.create_image_task(project_id=project_id, key=key, url=url, labels=labels)
61+
pprint(task)

0 commit comments

Comments
 (0)