From dc32a12d44680bfed3468a99e4bcec10b07624cf Mon Sep 17 00:00:00 2001 From: hukurou0 Date: Fri, 30 Aug 2024 14:45:14 +0900 Subject: [PATCH 1/3] add test.yml --- .github/workflows/test.yml | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..2a07797 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 flake8 isort + + - name: Run black + run: black --check . + + - name: Run flake8 + run: flake8 . + + - name: Run isort + run: isort --check . \ No newline at end of file From 837384fdc64f4fca7a9f83b2d8c4a1a98441b104 Mon Sep 17 00:00:00 2001 From: hukurou0 Date: Fri, 30 Aug 2024 14:52:54 +0900 Subject: [PATCH 2/3] change version --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2a07797..6c97a2d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,7 +28,7 @@ jobs: - name: Install Python tools run: | - pip install black flake8 isort + pip install black==22.10.0 flake8==5.0.4 isort==5.11.5 - name: Run black run: black --check . From f7f4c2f2aeab950d0a310b04ca71933adc0ad23f Mon Sep 17 00:00:00 2001 From: hukurou0 Date: Fri, 30 Aug 2024 14:59:49 +0900 Subject: [PATCH 3/3] run black, flake8, isort --- fastlabel/__init__.py | 14 +++++++------- fastlabel/converters.py | 22 ++++++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/fastlabel/__init__.py b/fastlabel/__init__.py index fdcdebd..7ab7291 100644 --- a/fastlabel/__init__.py +++ b/fastlabel/__init__.py @@ -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: @@ -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, @@ -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, @@ -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, @@ -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 ] diff --git a/fastlabel/converters.py b/fastlabel/converters.py index 2c7a98b..9b60598 100644 --- a/fastlabel/converters.py +++ b/fastlabel/converters.py @@ -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 @@ -239,7 +239,7 @@ def __to_coco_annotation(data: dict) -> dict: image_id, annotation_type, annotation_attributes, - rotation + rotation, ) @@ -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 @@ -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 @@ -329,6 +335,7 @@ def __get_rotated_rectangle_coordinates( return rotated_corners + def __get_coco_bbox( points: list, rotation: int, @@ -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 -