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
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: SDK Test

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
sdk-test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4

- name: Setup Python
uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5
with:
cache: pip
python-version: "3.10.11"

- name: Install dependencies
run: |
pip install -r requirements.txt

- name: Install Python tools
run: |
pip install black==22.10.0 flake8==5.0.4 isort==5.11.5

- name: Run black
run: black --check .

- name: Run flake8
run: flake8 .

- name: Run isort
run: isort --check .
14 changes: 7 additions & 7 deletions fastlabel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ def find_image_classification_task(self, task_id: str) -> dict:
"""
endpoint = "tasks/image/classification/" + task_id
return self.api.get_request(endpoint)

def find_multi_image_classification_task(self, task_id: str) -> dict:
"""
Find a single multi image classification task.
"""
endpoint = "tasks/multi-image/classification/" + task_id
return self.api.get_request(endpoint)

def find_multi_image_classification_task_by_name(
self, project: str, task_name: str
) -> dict:
Expand Down Expand Up @@ -432,9 +432,9 @@ def get_image_classification_tasks(
if limit:
params["limit"] = limit
return self.api.get_request(endpoint, params=params)

def get_multi_image_classification_tasks(
self,
self,
project: str,
status: str = None,
external_status: str = None,
Expand Down Expand Up @@ -1197,7 +1197,7 @@ def create_integrated_image_classification_task(
self.__fill_assign_users(payload, **kwargs)

return self.api.post_request(endpoint, payload=payload)

def create_multi_image_classification_task(
self,
project: str,
Expand Down Expand Up @@ -2135,7 +2135,7 @@ def update_image_classification_task(
self.__fill_assign_users(payload, **kwargs)

return self.api.put_request(endpoint, payload=payload)

def update_multi_image_classification_task(
self,
task_id: str,
Expand Down Expand Up @@ -4300,7 +4300,7 @@ def download_dataset_objects(
"annotations": obj["annotations"],
"customMetadata": obj["customMetadata"],
"tags": obj["tags"],
"object_type": obj["type"]
"object_type": obj["type"],
}
for obj in objects
]
Expand Down
22 changes: 14 additions & 8 deletions fastlabel/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from operator import itemgetter
from pathlib import Path
from tempfile import NamedTemporaryFile
from typing import List, Dict, Optional
from typing import Dict, List, Optional

import cv2
import geojson
Expand Down Expand Up @@ -239,7 +239,7 @@ def __to_coco_annotation(data: dict) -> dict:
image_id,
annotation_type,
annotation_attributes,
rotation
rotation,
)


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

def __get_coco_annotation_keypoints(keypoints: list, category_keypoints: list) -> list:
coco_annotation_keypoints = []
keypoint_values = {keypoint["key"]: keypoint["value"] for keypoint in keypoints if keypoint["value"]}
keypoint_values = {
keypoint["key"]: keypoint["value"]
for keypoint in keypoints
if keypoint["value"]
}
for category_key in category_keypoints:
value = keypoint_values.get(category_key, [0, 0, 0])
# Adjust fastlabel data definition to coco format
Expand All @@ -271,20 +275,22 @@ def __get_coco_annotation(
image_id: str,
annotation_type: str,
annotation_attributes: Dict[str, AttributeValue],
rotation: int
rotation: int,
) -> dict:
annotation = {}
annotation["num_keypoints"] = len(keypoints) if keypoints else 0
annotation["keypoints"] = (
__get_coco_annotation_keypoints(keypoints, category["keypoints"]) if keypoints else []
__get_coco_annotation_keypoints(keypoints, category["keypoints"])
if keypoints
else []
)
annotation["segmentation"] = __to_coco_segmentation(annotation_type, points)
annotation["iscrowd"] = 0
annotation["area"] = __to_area(annotation_type, points)
annotation["image_id"] = image_id
annotation["bbox"] = (
__get_coco_bbox(points, rotation)
if annotation_type == AnnotationType.bbox
__get_coco_bbox(points, rotation)
if annotation_type == AnnotationType.bbox
else __to_bbox(annotation_type, points)
)
annotation["rotation"] = rotation
Expand Down Expand Up @@ -329,6 +335,7 @@ def __get_rotated_rectangle_coordinates(

return rotated_corners


def __get_coco_bbox(
points: list,
rotation: int,
Expand Down Expand Up @@ -1209,4 +1216,3 @@ def _get_coco_annotation_attributes(annotation: dict) -> Dict[str, AttributeValu
for attribute in attributes:
coco_attributes[attribute["key"]] = attribute["value"]
return coco_attributes