Skip to content

Commit a39f153

Browse files
authored
Merge pull request #37 from fastlabel/develop
Merge to main
2 parents 4ce78ab + 6a7026e commit a39f153

File tree

3 files changed

+215
-6
lines changed

3 files changed

+215
-6
lines changed

README.md

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ _If you are using FastLabel prototype, please install version 0.2.2._
1414
- [Video](#video)
1515
- [Common](#common)
1616
- [Annotation](#annotation)
17+
- [Project](#project)
1718
- [Converter](#converter)
1819
- [COCO](#coco)
1920
- [YOLO](#yolo)
@@ -547,19 +548,19 @@ annotation_id = client.create_classification_annotation(
547548
- Find an annotation.
548549

549550
```python
550-
annotaion = client.find_annotation(annotation_id="YOUR_ANNOTATIPN_ID")
551+
annotation = client.find_annotation(annotation_id="YOUR_ANNOTATION_ID")
551552
```
552553

553554
- Find an annotation by value.
554555

555556
```python
556-
annotaion = client.find_annotation_by_value(project="YOUR_PROJECT_SLUG", value="cat")
557+
annotation = client.find_annotation_by_value(project="YOUR_PROJECT_SLUG", value="cat")
557558
```
558559

559560
- Find an annotation by value in classification project.
560561

561562
```python
562-
annotaion = client.find_annotation_by_value(
563+
annotation = client.find_annotation_by_value(
563564
project="YOUR_PROJECT_SLUG", value="classification") # "classification" is fixed value
564565
```
565566

@@ -568,7 +569,7 @@ annotaion = client.find_annotation_by_value(
568569
- Get annotations. (Up to 1000 annotations)
569570

570571
```python
571-
annotatios = client.get_annotations(project="YOUR_PROJECT_SLUG")
572+
annotations = client.get_annotations(project="YOUR_PROJECT_SLUG")
572573
```
573574

574575
### Response
@@ -660,7 +661,76 @@ annotation_id = client.update_classification_annotation(
660661
- Delete an annotation.
661662

662663
```python
663-
client.delete_annotation(annotation_id="YOUR_ANNOTATIPN_ID")
664+
client.delete_annotation(annotation_id="YOUR_ANNOTATION_ID")
665+
```
666+
667+
## Project
668+
669+
### Create Project
670+
671+
- Create a new project.
672+
673+
```python
674+
project_id = client.create_project(
675+
type="image_bbox", name="ImageNet", slug="image-net")
676+
```
677+
678+
### Find Project
679+
680+
- Find a project.
681+
682+
```python
683+
project = client.find_project(project_id="YOUR_PROJECT_ID")
684+
```
685+
686+
- Find a project by slug.
687+
688+
```python
689+
project = client.find_project_by_slug(slug="YOUR_PROJECT_SLUG")
690+
```
691+
692+
### Get Projects
693+
694+
- Get projects. (Up to 1000 projects)
695+
696+
```python
697+
projects = client.get_projects()
698+
```
699+
700+
### Response
701+
702+
- Example of a project object
703+
704+
```python
705+
{
706+
"id": "YOUR_PROJECT_ID",
707+
"type": "image_bbox",
708+
"slug": "YOUR_PROJECT_SLUG",
709+
"name": "YOUR_PROJECT_NAME",
710+
"isBitmap": False,
711+
"jobSize": 10,
712+
"useAnnotationService": False,
713+
"status": "active",
714+
"createdAt": "2021-04-20T03:20:41.427Z",
715+
"updatedAt": "2021-04-20T03:20:41.427Z",
716+
}
717+
```
718+
719+
### Update Project
720+
721+
- Update a project.
722+
723+
```python
724+
project_id = client.update_project(
725+
project_id="YOUR_PROJECT_ID", name="NewImageNet", slug="new-image-net", job_size=20)
726+
```
727+
728+
### Delete Project
729+
730+
- Delete a project.
731+
732+
```python
733+
client.delete_project(project_id="YOUR_PROJECT_ID")
664734
```
665735

666736
## Converter

fastlabel/__init__.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,3 +647,142 @@ def delete_annotation(self, annotation_id: str) -> None:
647647
"""
648648
endpoint = "annotations/" + annotation_id
649649
self.api.delete_request(endpoint)
650+
651+
# Project
652+
653+
def find_project(self, project_id: str) -> dict:
654+
"""
655+
Find a project.
656+
"""
657+
endpoint = "projects/" + project_id
658+
return self.api.get_request(endpoint)
659+
660+
def find_project_by_slug(self, slug: str) -> dict:
661+
"""
662+
Find a project by slug.
663+
664+
slug is slug of your project. (Required)
665+
"""
666+
projects = self.get_projects(slug=slug)
667+
if not projects:
668+
return None
669+
return projects[0]
670+
671+
def get_projects(
672+
self,
673+
slug: str = None,
674+
offset: int = None,
675+
limit: int = 100,
676+
) -> list:
677+
"""
678+
Returns a list of projects.
679+
Returns up to 1000 at a time, to get more, set offset as the starting position to fetch.
680+
681+
slug is slug of your project. (Optional)
682+
offset is the starting position number to fetch. (Optional)
683+
limit is the max number to fetch. (Optional)
684+
"""
685+
if limit > 1000:
686+
raise FastLabelInvalidException(
687+
"Limit must be less than or equal to 1000.", 422)
688+
endpoint = "projects"
689+
params = {}
690+
if slug:
691+
params["slug"] = slug
692+
if offset:
693+
params["offset"] = offset
694+
if limit:
695+
params["limit"] = limit
696+
return self.api.get_request(endpoint, params=params)
697+
698+
def get_project_id_slug_map(
699+
self,
700+
offset: int = None,
701+
limit: int = 1000,
702+
) -> dict:
703+
"""
704+
Returns a map of project ids and slugs.
705+
e.g.) {
706+
"88e74507-07b5-4607-a130-cb6316ca872c", "image-bbox-slug",
707+
"fe2c24a4-8270-46eb-9c78-bb7281c8bdgs", "image-video-slug"
708+
}
709+
Returns up to 1000 at a time, to get more, set offset as the starting position to fetch.
710+
711+
offset is the starting position number to fetch. (Optional)
712+
limit is the max number to fetch. (Optional)
713+
"""
714+
if limit > 1000:
715+
raise FastLabelInvalidException(
716+
"Limit must be less than or equal to 1000.", 422)
717+
endpoint = "projects/map/id-slug"
718+
params = {}
719+
if offset:
720+
params["offset"] = offset
721+
if limit:
722+
params["limit"] = limit
723+
return self.api.get_request(endpoint, params=params)
724+
725+
def create_project(
726+
self,
727+
type: str,
728+
name: str,
729+
slug: str,
730+
is_bitmap: bool = False,
731+
job_size: int = 10,
732+
use_annotation_service: bool = False
733+
) -> str:
734+
"""
735+
Create a project.
736+
737+
type can be 'image_bbox', 'image_polygon', 'image_keypoint', 'image_line', 'image_segmentation', 'image_classification', 'image_all', 'multi_image_bbox', 'multi_image_polygon', 'multi_image_keypoint', 'multi_image_line', 'multi_image_segmentation', 'video_bbox', 'video_single_classification'. (Required)
738+
name is name of your project. (Required)
739+
slug is slug of your project. (Required)
740+
is_bitmap is whether to be annotated by pixel. (Optional)
741+
job_size is the number of tasks the annotator gets at one time. (Optional)
742+
use_annotation_service is whether to request FastLabel to provide annotation service or not. (Optional)
743+
"""
744+
endpoint = "projects"
745+
payload = {
746+
"type": type,
747+
"name": name,
748+
"slug": slug,
749+
}
750+
if is_bitmap:
751+
payload["isBitmap"] = is_bitmap
752+
if job_size:
753+
payload["jobSize"] = job_size
754+
if use_annotation_service:
755+
payload["useAnnotationService"] = use_annotation_service
756+
return self.api.post_request(endpoint, payload=payload)
757+
758+
def update_project(
759+
self,
760+
project_id: str,
761+
name: str = None,
762+
slug: str = None,
763+
job_size: int = None,
764+
) -> str:
765+
"""
766+
Update a project.
767+
768+
project_id is an id of the project. (Required)
769+
name is name of your project. (Optional)
770+
slug is slug of your project. (Optional)
771+
job_size is the number of tasks the annotator gets at one time. (Optional)
772+
"""
773+
endpoint = "projects/" + project_id
774+
payload = {}
775+
if name:
776+
payload["name"] = name
777+
if slug:
778+
payload["slug"] = slug
779+
if job_size:
780+
payload["jobSize"] = job_size
781+
return self.api.put_request(endpoint, payload=payload)
782+
783+
def delete_project(self, project_id: str) -> None:
784+
"""
785+
Delete a project.
786+
"""
787+
endpoint = "projects/" + project_id
788+
self.api.delete_request(endpoint)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setuptools.setup(
1010
name="fastlabel",
11-
version="0.8.1",
11+
version="0.9.0",
1212
author="eisuke-ueta",
1313
author_email="eisuke.ueta@fastlabel.ai",
1414
description="The official Python SDK for FastLabel API, the Data Platform for AI",

0 commit comments

Comments
 (0)