Skip to content

Commit c8ef314

Browse files
Merge pull request #225 from fastlabel/add/github-workflow(formatter)
add CI
2 parents a29f8c5 + f7f4c2f commit c8ef314

File tree

3 files changed

+61
-15
lines changed

3 files changed

+61
-15
lines changed

.github/workflows/test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: SDK Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
sdk-test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
18+
19+
- name: Setup Python
20+
uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5
21+
with:
22+
cache: pip
23+
python-version: "3.10.11"
24+
25+
- name: Install dependencies
26+
run: |
27+
pip install -r requirements.txt
28+
29+
- name: Install Python tools
30+
run: |
31+
pip install black==22.10.0 flake8==5.0.4 isort==5.11.5
32+
33+
- name: Run black
34+
run: black --check .
35+
36+
- name: Run flake8
37+
run: flake8 .
38+
39+
- name: Run isort
40+
run: isort --check .

fastlabel/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ def find_image_classification_task(self, task_id: str) -> dict:
7070
"""
7171
endpoint = "tasks/image/classification/" + task_id
7272
return self.api.get_request(endpoint)
73-
73+
7474
def find_multi_image_classification_task(self, task_id: str) -> dict:
7575
"""
7676
Find a single multi image classification task.
7777
"""
7878
endpoint = "tasks/multi-image/classification/" + task_id
7979
return self.api.get_request(endpoint)
80-
80+
8181
def find_multi_image_classification_task_by_name(
8282
self, project: str, task_name: str
8383
) -> dict:
@@ -432,9 +432,9 @@ def get_image_classification_tasks(
432432
if limit:
433433
params["limit"] = limit
434434
return self.api.get_request(endpoint, params=params)
435-
435+
436436
def get_multi_image_classification_tasks(
437-
self,
437+
self,
438438
project: str,
439439
status: str = None,
440440
external_status: str = None,
@@ -1197,7 +1197,7 @@ def create_integrated_image_classification_task(
11971197
self.__fill_assign_users(payload, **kwargs)
11981198

11991199
return self.api.post_request(endpoint, payload=payload)
1200-
1200+
12011201
def create_multi_image_classification_task(
12021202
self,
12031203
project: str,
@@ -2135,7 +2135,7 @@ def update_image_classification_task(
21352135
self.__fill_assign_users(payload, **kwargs)
21362136

21372137
return self.api.put_request(endpoint, payload=payload)
2138-
2138+
21392139
def update_multi_image_classification_task(
21402140
self,
21412141
task_id: str,
@@ -4300,7 +4300,7 @@ def download_dataset_objects(
43004300
"annotations": obj["annotations"],
43014301
"customMetadata": obj["customMetadata"],
43024302
"tags": obj["tags"],
4303-
"object_type": obj["type"]
4303+
"object_type": obj["type"],
43044304
}
43054305
for obj in objects
43064306
]

fastlabel/converters.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from operator import itemgetter
99
from pathlib import Path
1010
from tempfile import NamedTemporaryFile
11-
from typing import List, Dict, Optional
11+
from typing import Dict, List, Optional
1212

1313
import cv2
1414
import geojson
@@ -239,7 +239,7 @@ def __to_coco_annotation(data: dict) -> dict:
239239
image_id,
240240
annotation_type,
241241
annotation_attributes,
242-
rotation
242+
rotation,
243243
)
244244

245245

@@ -254,7 +254,11 @@ def __get_coco_category_by_name(categories: list, name: str) -> Optional[dict]:
254254

255255
def __get_coco_annotation_keypoints(keypoints: list, category_keypoints: list) -> list:
256256
coco_annotation_keypoints = []
257-
keypoint_values = {keypoint["key"]: keypoint["value"] for keypoint in keypoints if keypoint["value"]}
257+
keypoint_values = {
258+
keypoint["key"]: keypoint["value"]
259+
for keypoint in keypoints
260+
if keypoint["value"]
261+
}
258262
for category_key in category_keypoints:
259263
value = keypoint_values.get(category_key, [0, 0, 0])
260264
# Adjust fastlabel data definition to coco format
@@ -271,20 +275,22 @@ def __get_coco_annotation(
271275
image_id: str,
272276
annotation_type: str,
273277
annotation_attributes: Dict[str, AttributeValue],
274-
rotation: int
278+
rotation: int,
275279
) -> dict:
276280
annotation = {}
277281
annotation["num_keypoints"] = len(keypoints) if keypoints else 0
278282
annotation["keypoints"] = (
279-
__get_coco_annotation_keypoints(keypoints, category["keypoints"]) if keypoints else []
283+
__get_coco_annotation_keypoints(keypoints, category["keypoints"])
284+
if keypoints
285+
else []
280286
)
281287
annotation["segmentation"] = __to_coco_segmentation(annotation_type, points)
282288
annotation["iscrowd"] = 0
283289
annotation["area"] = __to_area(annotation_type, points)
284290
annotation["image_id"] = image_id
285291
annotation["bbox"] = (
286-
__get_coco_bbox(points, rotation)
287-
if annotation_type == AnnotationType.bbox
292+
__get_coco_bbox(points, rotation)
293+
if annotation_type == AnnotationType.bbox
288294
else __to_bbox(annotation_type, points)
289295
)
290296
annotation["rotation"] = rotation
@@ -329,6 +335,7 @@ def __get_rotated_rectangle_coordinates(
329335

330336
return rotated_corners
331337

338+
332339
def __get_coco_bbox(
333340
points: list,
334341
rotation: int,
@@ -1209,4 +1216,3 @@ def _get_coco_annotation_attributes(annotation: dict) -> Dict[str, AttributeValu
12091216
for attribute in attributes:
12101217
coco_attributes[attribute["key"]] = attribute["value"]
12111218
return coco_attributes
1212-

0 commit comments

Comments
 (0)