From 2c7eeb5a650bede786281b5f1de441091616c896 Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Fri, 21 Jun 2024 13:19:36 +0200 Subject: [PATCH 1/9] Fix most mypy errors --- roboflow/adapters/rfapi.py | 4 +-- roboflow/core/project.py | 40 ++++++++++++------------ roboflow/core/version.py | 8 +++-- roboflow/core/workspace.py | 9 ++++-- roboflow/models/classification.py | 10 +++--- roboflow/models/inference.py | 4 +-- roboflow/models/instance_segmentation.py | 4 +-- roboflow/models/keypoint_detection.py | 6 ++-- roboflow/models/video.py | 9 ++++-- roboflow/util/prediction.py | 5 +-- setup.py | 4 ++- 11 files changed, 56 insertions(+), 47 deletions(-) diff --git a/roboflow/adapters/rfapi.py b/roboflow/adapters/rfapi.py index 01de1fd6..c3c6f86d 100644 --- a/roboflow/adapters/rfapi.py +++ b/roboflow/adapters/rfapi.py @@ -43,8 +43,8 @@ def upload_image( split: str = "train", batch_name: str = DEFAULT_BATCH_NAME, tag_names: list = [], - sequence_number: int = None, - sequence_size: int = None, + sequence_number: int | None = None, + sequence_size: int | None = None, **kwargs, ): """ diff --git a/roboflow/core/project.py b/roboflow/core/project.py index ccec7a7e..d32f7a0b 100644 --- a/roboflow/core/project.py +++ b/roboflow/core/project.py @@ -22,7 +22,7 @@ def custom_formatwarning(msg, *args, **kwargs): return str(msg) + "\n" -warnings.formatwarning = custom_formatwarning +warnings.formatwarning = custom_formatwarning # type: ignore[assignment] class Project: @@ -30,7 +30,7 @@ class Project: A Roboflow Project. """ - def __init__(self, api_key: str, a_project: str, model_format: str = None): + def __init__(self, api_key: str, a_project: dict, model_format: str | None = None): """ Create a Project object that represents a Project associated with a Workspace. @@ -283,7 +283,7 @@ def train( return new_model - def version(self, version_number: int, local: str = None): + def version(self, version_number: int, local: str | None = None): """ Retrieves information about a specific version and returns a Version() object. @@ -357,13 +357,13 @@ def check_valid_image(self, image_path: str): def upload( self, - image_path: str = None, - annotation_path: str = None, + image_path: str, + annotation_path: str | None = None, hosted_image: bool = False, - image_id: str = None, + image_id: str | None = None, split: str = "train", num_retry_uploads: int = 0, - batch_name: str = None, + batch_name: str | None = None, tag_names: list = [], is_prediction: bool = False, **kwargs, @@ -549,15 +549,15 @@ def _annotation_params(self, annotation_path): def search( self, - like_image: str = None, - prompt: str = None, + like_image: str | None = None, + prompt: str | None = None, offset: int = 0, limit: int = 100, - tag: str = None, - class_name: str = None, - in_dataset: str = None, + tag: str | None = None, + class_name: str | None = None, + in_dataset: str | None = None, batch: bool = False, - batch_id: str = None, + batch_id: str | None = None, fields: list = ["id", "created", "name", "labels"], ): """ @@ -587,7 +587,7 @@ def search( >>> results = project.search(query="cat", limit=10) """ # noqa: E501 // docs - payload = {} + payload: dict[str, str | int | list[str]] = {} if like_image is not None: payload["like_image"] = like_image @@ -627,15 +627,15 @@ def search( def search_all( self, - like_image: str = None, - prompt: str = None, + like_image: str | None = None, + prompt: str | None = None, offset: int = 0, limit: int = 100, - tag: str = None, - class_name: str = None, - in_dataset: str = None, + tag: str | None = None, + class_name: str | None = None, + in_dataset: str | None = None, batch: bool = False, - batch_id: str = None, + batch_id: str | None = None, fields: list = ["id", "created"], ): """ diff --git a/roboflow/core/version.py b/roboflow/core/version.py index f6ffa95f..4eb1dfd1 100644 --- a/roboflow/core/version.py +++ b/roboflow/core/version.py @@ -359,7 +359,7 @@ def live_plot(epochs, mAP, loss, title=""): plt.show() first_graph_write = False - previous_epochs = [] + previous_epochs: np.ndarray | list = [] num_machine_spin_dots = [] while status == "training" or status == "running": @@ -381,6 +381,10 @@ def live_plot(epochs, mAP, loss, title=""): write_line(line="Training failed") break + epochs: np.ndarray | list + mAP: np.ndarray | list + loss: np.ndarray | list + if "roboflow-train" in models.keys(): # training has started epochs = np.array([int(epoch["epoch"]) for epoch in models["roboflow-train"]["epochs"]]) @@ -452,7 +456,7 @@ def deploy(self, model_type: str, model_path: str, filename: str = "weights/best import ultralytics except ImportError: - raise RuntimeError( + raise RuntimeErrorException( "The ultralytics python package is required to deploy yolov8" " models. Please install it with `pip install ultralytics`" ) diff --git a/roboflow/core/workspace.py b/roboflow/core/workspace.py index 9fa00f90..922b8aad 100644 --- a/roboflow/core/workspace.py +++ b/roboflow/core/workspace.py @@ -117,7 +117,7 @@ def create_project(self, project_name, project_type, project_license, annotation return self.project(r.json()["id"].split("/")[-1]) - def clip_compare(self, dir: str = "", image_ext: str = ".png", target_image: str = "") -> dict: + def clip_compare(self, dir: str = "", image_ext: str = ".png", target_image: str = "") -> list[dict]: """ Compare all images in a directory to a target image using CLIP @@ -127,6 +127,7 @@ def clip_compare(self, dir: str = "", image_ext: str = ".png", target_image: str target_image (str): name reference for target image to compare individual images from directory against Returns: + # TODO: fix docs dict: a key:value mapping of image_name:comparison_score_to_target """ # noqa: E501 // docs @@ -148,7 +149,7 @@ def two_stage( first_stage_model_version: int = 0, second_stage_model_name: str = "", second_stage_model_version: int = 0, - ) -> dict: + ) -> list[dict]: """ For each prediction in a first stage detection, perform detection with the second stage model @@ -160,6 +161,7 @@ def two_stage( second_stage_model_version (int): version number for the second stage model Returns: + # TODO: fix docs dict: a json obj containing the results of the second stage detection """ # noqa: E501 // docs results = [] @@ -218,7 +220,7 @@ def two_stage_ocr( image: str = "", first_stage_model_name: str = "", first_stage_model_version: int = 0, - ) -> dict: + ) -> list[dict]: """ For each prediction in the first stage object detection, perform OCR as second stage. @@ -228,6 +230,7 @@ def two_stage_ocr( first_stage_model_version (int): version number for the first stage model Returns: + # TODO: fix docs dict: a json obj containing the results of the second stage detection """ # noqa: E501 // docs results = [] diff --git a/roboflow/models/classification.py b/roboflow/models/classification.py index 803eb5fe..f2df87ad 100644 --- a/roboflow/models/classification.py +++ b/roboflow/models/classification.py @@ -23,11 +23,11 @@ def __init__( self, api_key: str, id: str, - name: str = None, - version: int = None, + name: str | None = None, + version: int | None = None, local: bool = False, - colors: dict = None, - preprocessing: dict = None, + colors: dict | None = None, + preprocessing: dict | None = None, ): """ Create a ClassificationModel object through which you can run inference. @@ -59,7 +59,7 @@ def __init__( self.preprocessing = {} if preprocessing is None else preprocessing if local: - print("initalizing local classification model hosted at :" + local) + print(f"initalizing local classification model hosted at : {local}") self.base_url = local def predict(self, image_path, hosted=False): diff --git a/roboflow/models/inference.py b/roboflow/models/inference.py index bc706bf0..7c2fdc7a 100644 --- a/roboflow/models/inference.py +++ b/roboflow/models/inference.py @@ -140,7 +140,7 @@ def predict_video( fps: int = 5, additional_models: list = [], prediction_type: str = "batch-video", - ) -> List[str]: + ) -> tuple[str, str, str | None]: """ Infers detections based on image from specified model and image path. @@ -280,7 +280,7 @@ def predict_video( return job_id, signed_url, signed_url_expires - def poll_for_video_results(self, job_id: str = None) -> dict: + def poll_for_video_results(self, job_id: str | None = None) -> dict: """ Polls the Roboflow API to check if video inference is complete. diff --git a/roboflow/models/instance_segmentation.py b/roboflow/models/instance_segmentation.py index e232982d..1cd6c0fa 100644 --- a/roboflow/models/instance_segmentation.py +++ b/roboflow/models/instance_segmentation.py @@ -12,8 +12,8 @@ def __init__( self, api_key: str, version_id: str, - colors: dict = None, - preprocessing: dict = None, + colors: dict | None = None, + preprocessing: dict | None = None, local: bool = None, ): """ diff --git a/roboflow/models/keypoint_detection.py b/roboflow/models/keypoint_detection.py index aa64b880..790d4d35 100644 --- a/roboflow/models/keypoint_detection.py +++ b/roboflow/models/keypoint_detection.py @@ -23,8 +23,8 @@ def __init__( self, api_key: str, id: str, - name: str = None, - version: int = None, + name: str | None = None, + version: int | None = None, local: bool = False, ): """ @@ -54,7 +54,7 @@ def __init__( self.__generate_url() if local: - print("initalizing local keypoint detection model hosted at :" + local) + print(f"initalizing local keypoint detection model hosted at : {local}") self.base_url = local def predict(self, image_path, hosted=False): diff --git a/roboflow/models/video.py b/roboflow/models/video.py index 7307ebee..58b162c8 100644 --- a/roboflow/models/video.py +++ b/roboflow/models/video.py @@ -61,8 +61,8 @@ def predict( video_path: str, inference_type: str, fps: int = 5, - additional_models: list = None, - ) -> List[str, str]: + additional_models: list | None = None, + ) -> tuple[str, str]: """ Infers detections based on image from specified model and image path. @@ -91,6 +91,9 @@ def predict( if fps > 30: raise Exception("FPS must be less than or equal to 30.") + if additional_models is None: + additional_models = [] + for model in additional_models: if model not in SUPPORTED_ADDITIONAL_MODELS: raise Exception(f"Model {model} is not supported for video inference.") @@ -138,7 +141,7 @@ def predict( return job_id, signed_url - def poll_for_results(self, job_id: str = None) -> dict: + def poll_for_results(self, job_id: str | None = None) -> dict: """ Polls the Roboflow API to check if video inference is complete. diff --git a/roboflow/util/prediction.py b/roboflow/util/prediction.py index ce6fbbd7..a6bee5a3 100644 --- a/roboflow/util/prediction.py +++ b/roboflow/util/prediction.py @@ -500,15 +500,12 @@ def create_prediction_group(json_response, image_path, prediction_type, image_di colors=colors, ) prediction_list.append(prediction) - img_dims = image_dims elif prediction_type == CLASSIFICATION_MODEL: prediction = Prediction(json_response, image_path, prediction_type, colors=colors) prediction_list.append(prediction) - img_dims = image_dims elif prediction_type == SEMANTIC_SEGMENTATION_MODEL: prediction = Prediction(json_response, image_path, prediction_type, colors=colors) prediction_list.append(prediction) - img_dims = image_dims # Seperate list and return as a prediction group - return PredictionGroup(img_dims, image_path, *prediction_list) + return PredictionGroup(image_dims, image_path, *prediction_list) diff --git a/setup.py b/setup.py index 07818942..273a884b 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,9 @@ with open("./roboflow/__init__.py", "r") as f: content = f.read() - version = re.search(r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]', content).group(1) +_search_version = re.search(r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]', content) +assert _search_version +version = _search_version.group(1) with open("README.md", "r") as fh: From b19ee6d0c652b46566999640ca7575a83b0c0ed4 Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Fri, 21 Jun 2024 13:21:24 +0200 Subject: [PATCH 2/9] Enable mypy errors on CI --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ec228fec..b6e0532e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,5 +34,3 @@ jobs: run: "python -m unittest" - name: Check types with mypy run: mypy . - # TODO: Fix typing - continue-on-error: true From b1e9ae1ff9be1b40b7314cf6ebe5fd6dd87bb8fb Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Fri, 21 Jun 2024 13:29:43 +0200 Subject: [PATCH 3/9] Use `Optional[T]` instead of `T | None` for old Python compatibility --- roboflow/adapters/rfapi.py | 5 ++-- roboflow/core/project.py | 35 ++++++++++++------------ roboflow/models/classification.py | 9 +++--- roboflow/models/inference.py | 6 ++-- roboflow/models/instance_segmentation.py | 6 ++-- roboflow/models/video.py | 6 ++-- 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/roboflow/adapters/rfapi.py b/roboflow/adapters/rfapi.py index c3c6f86d..62b6ebb7 100644 --- a/roboflow/adapters/rfapi.py +++ b/roboflow/adapters/rfapi.py @@ -1,6 +1,7 @@ import json import os import urllib +from typing import Optional import requests from requests_toolbelt.multipart.encoder import MultipartEncoder @@ -43,8 +44,8 @@ def upload_image( split: str = "train", batch_name: str = DEFAULT_BATCH_NAME, tag_names: list = [], - sequence_number: int | None = None, - sequence_size: int | None = None, + sequence_number: Optional[int] = None, + sequence_size: Optional[int] = None, **kwargs, ): """ diff --git a/roboflow/core/project.py b/roboflow/core/project.py index d32f7a0b..d9119eff 100644 --- a/roboflow/core/project.py +++ b/roboflow/core/project.py @@ -4,6 +4,7 @@ import sys import time import warnings +from typing import Optional import requests from PIL import Image, UnidentifiedImageError @@ -30,7 +31,7 @@ class Project: A Roboflow Project. """ - def __init__(self, api_key: str, a_project: dict, model_format: str | None = None): + def __init__(self, api_key: str, a_project: dict, model_format: Optional[str] = None): """ Create a Project object that represents a Project associated with a Workspace. @@ -283,7 +284,7 @@ def train( return new_model - def version(self, version_number: int, local: str | None = None): + def version(self, version_number: int, local: Optional[str] = None): """ Retrieves information about a specific version and returns a Version() object. @@ -358,12 +359,12 @@ def check_valid_image(self, image_path: str): def upload( self, image_path: str, - annotation_path: str | None = None, + annotation_path: Optional[str] = None, hosted_image: bool = False, - image_id: str | None = None, + image_id: Optional[str] = None, split: str = "train", num_retry_uploads: int = 0, - batch_name: str | None = None, + batch_name: Optional[str] = None, tag_names: list = [], is_prediction: bool = False, **kwargs, @@ -549,15 +550,15 @@ def _annotation_params(self, annotation_path): def search( self, - like_image: str | None = None, - prompt: str | None = None, + like_image: Optional[str] = None, + prompt: Optional[str] = None, offset: int = 0, limit: int = 100, - tag: str | None = None, - class_name: str | None = None, - in_dataset: str | None = None, + tag: Optional[str] = None, + class_name: Optional[str] = None, + in_dataset: Optional[str] = None, batch: bool = False, - batch_id: str | None = None, + batch_id: Optional[str] = None, fields: list = ["id", "created", "name", "labels"], ): """ @@ -627,15 +628,15 @@ def search( def search_all( self, - like_image: str | None = None, - prompt: str | None = None, + like_image: Optional[str] = None, + prompt: Optional[str] = None, offset: int = 0, limit: int = 100, - tag: str | None = None, - class_name: str | None = None, - in_dataset: str | None = None, + tag: Optional[str] = None, + class_name: Optional[str] = None, + in_dataset: Optional[str] = None, batch: bool = False, - batch_id: str | None = None, + batch_id: Optional[str] = None, fields: list = ["id", "created"], ): """ diff --git a/roboflow/models/classification.py b/roboflow/models/classification.py index f2df87ad..25ccc981 100644 --- a/roboflow/models/classification.py +++ b/roboflow/models/classification.py @@ -3,6 +3,7 @@ import json import os import urllib +from typing import Optional import requests from PIL import Image @@ -23,11 +24,11 @@ def __init__( self, api_key: str, id: str, - name: str | None = None, - version: int | None = None, + name: Optional[str] = None, + version: Optional[int] = None, local: bool = False, - colors: dict | None = None, - preprocessing: dict | None = None, + colors: Optional[dict] = None, + preprocessing: Optional[dict] = None, ): """ Create a ClassificationModel object through which you can run inference. diff --git a/roboflow/models/inference.py b/roboflow/models/inference.py index 7c2fdc7a..b3dfb6ad 100644 --- a/roboflow/models/inference.py +++ b/roboflow/models/inference.py @@ -3,7 +3,7 @@ import os import time import urllib -from typing import List +from typing import Optional from urllib.parse import urljoin import requests @@ -140,7 +140,7 @@ def predict_video( fps: int = 5, additional_models: list = [], prediction_type: str = "batch-video", - ) -> tuple[str, str, str | None]: + ) -> tuple[str, str, Optional[str]]: """ Infers detections based on image from specified model and image path. @@ -280,7 +280,7 @@ def predict_video( return job_id, signed_url, signed_url_expires - def poll_for_video_results(self, job_id: str | None = None) -> dict: + def poll_for_video_results(self, job_id: Optional[str] = None) -> dict: """ Polls the Roboflow API to check if video inference is complete. diff --git a/roboflow/models/instance_segmentation.py b/roboflow/models/instance_segmentation.py index 1cd6c0fa..db1f66a8 100644 --- a/roboflow/models/instance_segmentation.py +++ b/roboflow/models/instance_segmentation.py @@ -1,3 +1,5 @@ +from typing import Optional + from roboflow.config import INSTANCE_SEGMENTATION_MODEL, INSTANCE_SEGMENTATION_URL from roboflow.models.inference import InferenceModel @@ -12,8 +14,8 @@ def __init__( self, api_key: str, version_id: str, - colors: dict | None = None, - preprocessing: dict | None = None, + colors: Optional[dict] = None, + preprocessing: Optional[dict] = None, local: bool = None, ): """ diff --git a/roboflow/models/video.py b/roboflow/models/video.py index 58b162c8..f4e13881 100644 --- a/roboflow/models/video.py +++ b/roboflow/models/video.py @@ -1,6 +1,6 @@ import json import time -from typing import List +from typing import Optional from urllib.parse import urljoin import magic @@ -61,7 +61,7 @@ def predict( video_path: str, inference_type: str, fps: int = 5, - additional_models: list | None = None, + additional_models: Optional[list] = None, ) -> tuple[str, str]: """ Infers detections based on image from specified model and image path. @@ -141,7 +141,7 @@ def predict( return job_id, signed_url - def poll_for_results(self, job_id: str | None = None) -> dict: + def poll_for_results(self, job_id: Optional[str] = None) -> dict: """ Polls the Roboflow API to check if video inference is complete. From 3d77bfb81dd835e6ed9e40c51605cb314d5e50c1 Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Tue, 25 Jun 2024 14:32:51 +0200 Subject: [PATCH 4/9] fixup! Fix most mypy errors --- roboflow/core/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roboflow/core/version.py b/roboflow/core/version.py index 4eb1dfd1..b2421cfa 100644 --- a/roboflow/core/version.py +++ b/roboflow/core/version.py @@ -456,7 +456,7 @@ def deploy(self, model_type: str, model_path: str, filename: str = "weights/best import ultralytics except ImportError: - raise RuntimeErrorException( + raise RuntimeError( "The ultralytics python package is required to deploy yolov8" " models. Please install it with `pip install ultralytics`" ) From db3c5e324476b3f4b9b68e50fab460da3e674ded Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Tue, 25 Jun 2024 14:39:01 +0200 Subject: [PATCH 5/9] fixup! Use `Optional[T]` instead of `T | None` for old Python compatibility --- roboflow/models/keypoint_detection.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/roboflow/models/keypoint_detection.py b/roboflow/models/keypoint_detection.py index 790d4d35..c4589e36 100644 --- a/roboflow/models/keypoint_detection.py +++ b/roboflow/models/keypoint_detection.py @@ -3,6 +3,7 @@ import json import os import urllib +from typing import Optional import requests from PIL import Image @@ -23,8 +24,8 @@ def __init__( self, api_key: str, id: str, - name: str | None = None, - version: int | None = None, + name: Optional[str] = None, + version: Optional[int] = None, local: bool = False, ): """ From 6282d66c48db02e291537e4bf7b644490d1a3d0e Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Tue, 25 Jun 2024 14:59:53 +0200 Subject: [PATCH 6/9] fixup! fixup! Fix most mypy errors --- roboflow/models/inference.py | 4 ++-- roboflow/models/video.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/roboflow/models/inference.py b/roboflow/models/inference.py index b3dfb6ad..307eb704 100644 --- a/roboflow/models/inference.py +++ b/roboflow/models/inference.py @@ -3,7 +3,7 @@ import os import time import urllib -from typing import Optional +from typing import Optional, Tuple from urllib.parse import urljoin import requests @@ -140,7 +140,7 @@ def predict_video( fps: int = 5, additional_models: list = [], prediction_type: str = "batch-video", - ) -> tuple[str, str, Optional[str]]: + ) -> Tuple[str, str, Optional[str]]: """ Infers detections based on image from specified model and image path. diff --git a/roboflow/models/video.py b/roboflow/models/video.py index f4e13881..35366a97 100644 --- a/roboflow/models/video.py +++ b/roboflow/models/video.py @@ -1,6 +1,6 @@ import json import time -from typing import Optional +from typing import Optional, Tuple from urllib.parse import urljoin import magic @@ -62,7 +62,7 @@ def predict( inference_type: str, fps: int = 5, additional_models: Optional[list] = None, - ) -> tuple[str, str]: + ) -> Tuple[str, str]: """ Infers detections based on image from specified model and image path. From 6d09b8a00993eec7b399bf51479ebfde4c8ed9e9 Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Tue, 25 Jun 2024 15:02:48 +0200 Subject: [PATCH 7/9] fixup! fixup! fixup! Fix most mypy errors --- roboflow/core/project.py | 4 ++-- roboflow/core/workspace.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/roboflow/core/project.py b/roboflow/core/project.py index d9119eff..83bd7c01 100644 --- a/roboflow/core/project.py +++ b/roboflow/core/project.py @@ -4,7 +4,7 @@ import sys import time import warnings -from typing import Optional +from typing import List, Optional import requests from PIL import Image, UnidentifiedImageError @@ -588,7 +588,7 @@ def search( >>> results = project.search(query="cat", limit=10) """ # noqa: E501 // docs - payload: dict[str, str | int | list[str]] = {} + payload: dict[str, str | int | List[str]] = {} if like_image is not None: payload["like_image"] = like_image diff --git a/roboflow/core/workspace.py b/roboflow/core/workspace.py index 922b8aad..df3efbfc 100644 --- a/roboflow/core/workspace.py +++ b/roboflow/core/workspace.py @@ -3,6 +3,7 @@ import json import os import sys +from typing import List import numpy as np import requests @@ -117,7 +118,7 @@ def create_project(self, project_name, project_type, project_license, annotation return self.project(r.json()["id"].split("/")[-1]) - def clip_compare(self, dir: str = "", image_ext: str = ".png", target_image: str = "") -> list[dict]: + def clip_compare(self, dir: str = "", image_ext: str = ".png", target_image: str = "") -> List[dict]: """ Compare all images in a directory to a target image using CLIP @@ -149,7 +150,7 @@ def two_stage( first_stage_model_version: int = 0, second_stage_model_name: str = "", second_stage_model_version: int = 0, - ) -> list[dict]: + ) -> List[dict]: """ For each prediction in a first stage detection, perform detection with the second stage model @@ -220,7 +221,7 @@ def two_stage_ocr( image: str = "", first_stage_model_name: str = "", first_stage_model_version: int = 0, - ) -> list[dict]: + ) -> List[dict]: """ For each prediction in the first stage object detection, perform OCR as second stage. From 16c3eaa477918af5287f61512260828673bcfdfe Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Tue, 25 Jun 2024 15:08:53 +0200 Subject: [PATCH 8/9] fixup! fixup! fixup! fixup! Fix most mypy errors --- pyproject.toml | 1 + roboflow/core/project.py | 4 ++-- roboflow/core/version.py | 9 +++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6f047913..bb3161d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -137,6 +137,7 @@ convention = "google" max-args = 20 [tool.mypy] +python_version = "3.8" exclude = [ "^build/" ] diff --git a/roboflow/core/project.py b/roboflow/core/project.py index 83bd7c01..0720cc42 100644 --- a/roboflow/core/project.py +++ b/roboflow/core/project.py @@ -4,7 +4,7 @@ import sys import time import warnings -from typing import List, Optional +from typing import Dict, List, Optional, Union import requests from PIL import Image, UnidentifiedImageError @@ -588,7 +588,7 @@ def search( >>> results = project.search(query="cat", limit=10) """ # noqa: E501 // docs - payload: dict[str, str | int | List[str]] = {} + payload: Dict[str, Union[str, int, List[str]]] = {} if like_image is not None: payload["like_image"] = like_image diff --git a/roboflow/core/version.py b/roboflow/core/version.py index b2421cfa..2fa9e0fc 100644 --- a/roboflow/core/version.py +++ b/roboflow/core/version.py @@ -6,6 +6,7 @@ import time import zipfile from importlib import import_module +from typing import Union import numpy as np import requests @@ -359,7 +360,7 @@ def live_plot(epochs, mAP, loss, title=""): plt.show() first_graph_write = False - previous_epochs: np.ndarray | list = [] + previous_epochs: Union[np.ndarray, list] = [] num_machine_spin_dots = [] while status == "training" or status == "running": @@ -381,9 +382,9 @@ def live_plot(epochs, mAP, loss, title=""): write_line(line="Training failed") break - epochs: np.ndarray | list - mAP: np.ndarray | list - loss: np.ndarray | list + epochs: Union[np.ndarray, list] + mAP: Union[np.ndarray, list] + loss: Union[np.ndarray, list] if "roboflow-train" in models.keys(): # training has started From b253544fb8d396163b046e544516fcf22a6f96d2 Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Tue, 25 Jun 2024 15:10:11 +0200 Subject: [PATCH 9/9] fixup! fixup! fixup! fixup! fixup! Fix most mypy errors --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b6e0532e..ec228fec 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,3 +34,5 @@ jobs: run: "python -m unittest" - name: Check types with mypy run: mypy . + # TODO: Fix typing + continue-on-error: true