Skip to content

Commit

Permalink
Resolve ruff rules through 0.5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
justincdavis committed Aug 4, 2024
1 parent 3778e69 commit 479acc4
Show file tree
Hide file tree
Showing 19 changed files with 1,333 additions and 134 deletions.
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,8 @@ compiler = [
"botocore>=1.34.37", # Removes the need for search during install
]
ci = [
"pyupgrade>=3.10",
"black>=24.0",
"isort>=5.10",
"ruff>=0.2.1",
"mypy>=1.8.0,<1.11.0",
"ruff>=0.5.6",
"mypy>=1.11.1",
"types-setuptools>=57.0.0",
"types-requests>=2.25.0",
]
Expand Down
5 changes: 5 additions & 0 deletions src/oakutils/aruco/localizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def localize(
markers : Sequence[tuple[int, np.ndarray, np.ndarray, np.ndarray, np.ndarray]]
A sequence of markers detected sin the image
Returns
-------
np.ndarray
The transform from the world to camera
"""
transforms = []
for tag, transform, _, _, _ in markers:
Expand Down
6 changes: 3 additions & 3 deletions src/oakutils/blobs/_compiler/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from pathlib import Path
from typing import Callable

import requests.exceptions as rexcepts
import torch
from requests.exceptions import ConnectionError, HTTPError

from oakutils.blobs.definitions import AbstractModel, InputType

Expand Down Expand Up @@ -219,7 +219,7 @@ def _compile(
)
err_msg = base_str
raise RuntimeError(err_msg) from err
except HTTPError as err:
except rexcepts.HTTPError as err:
err_dict: dict[str, str] = {}
for line in f.getvalue().split("\n"):
if ": " not in line:
Expand All @@ -233,7 +233,7 @@ def _compile(
f"Error compiling blob for the OAK-D.\n Error from OpenVINO: {stderr}"
)
raise RuntimeError(err_msg) from err
except ConnectionError as err:
except rexcepts.ConnectionError as err:
msg_str = "Error compiling blob. "
msg_str += "Could not connect to the blobconverter server. "
msg_str += "Check your internet connection and try again."
Expand Down
31 changes: 28 additions & 3 deletions src/oakutils/blobs/definitions/abstract_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2024 Justin Davis (davisjustin302@gmail.com)
#
# MIT License
# ruff: noqa: DOC202
"""
Module for the AbstractModel class.
Expand Down Expand Up @@ -33,14 +34,38 @@ def __init__(self: Self) -> None:
@classmethod
@abstractmethod
def model_type(cls: type[AbstractModel]) -> ModelType:
"""Use to get the type of input this model takes."""
"""
Use to get the type of input this model takes.
Returns
-------
ModelType
The type of arguments this model takes.
"""

@classmethod
@abstractmethod
def input_names(cls: type[AbstractModel]) -> list[tuple[str, InputType]]:
"""Use to get the names of the input tensors."""
"""
Use to get the names of the input tensors.
Returns
-------
list[tuple[str, InputType]]
The names of the input tensors and their datatype.
"""

@classmethod
@abstractmethod
def output_names(cls: type[AbstractModel]) -> list[str]:
"""Use to get the names of the output tensors."""
"""
Use to get the names of the output tensors.
Returns
-------
list[str]
The names of the output tensors.
"""
140 changes: 128 additions & 12 deletions src/oakutils/blobs/definitions/closing.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,41 @@ def __init__(self: Self, kernel_size: int = 3) -> None:

@classmethod
def model_type(cls: type[Closing]) -> ModelType:
"""Use to get the type of input this model takes."""
"""
Use to get the type of input this model takes.
Returns
-------
ModelType
The type of arguments this model takes.
"""
return ModelType.KERNEL

@classmethod
def input_names(cls: type[Closing]) -> list[tuple[str, InputType]]:
"""Use to get the names of the input tensors."""
"""
Use to get the names of the input tensors.
Returns
-------
list[tuple[str, InputType]]
The names of the input tensors and their datatype.
"""
return [("input", InputType.FP16)]

@classmethod
def output_names(cls: type[Closing]) -> list[str]:
"""Use to get the names of the output tensors."""
"""
Use to get the names of the output tensors.
Returns
-------
list[str]
The names of the output tensors.
"""
return ["output"]

def forward(self: Self, image: torch.Tensor) -> torch.Tensor:
Expand All @@ -80,6 +104,11 @@ def forward(self: Self, image: torch.Tensor) -> torch.Tensor:
image : torch.Tensor
The input tensor to run the model on
Returns
-------
torch.Tensor
The output tensor
"""
return kornia.morphology.closing(image, self._kernel)

Expand Down Expand Up @@ -112,17 +141,41 @@ def __init__(self: Self, kernel_size: int = 3) -> None:

@classmethod
def model_type(cls: type[ClosingGray]) -> ModelType:
"""Use to get the type of input this model takes."""
"""
Use to get the type of input this model takes.
Returns
-------
ModelType
The type of arguments this model takes.
"""
return ModelType.KERNEL

@classmethod
def input_names(cls: type[ClosingGray]) -> list[tuple[str, InputType]]:
"""Use to get the names of the input tensors."""
"""
Use to get the names of the input tensors.
Returns
-------
list[tuple[str, InputType]]
The names of the input tensors and their datatype.
"""
return [("input", InputType.FP16)]

@classmethod
def output_names(cls: type[ClosingGray]) -> list[str]:
"""Use to get the names of the output tensors."""
"""
Use to get the names of the output tensors.
Returns
-------
list[str]
The names of the output tensors.
"""
return ["output"]

def forward(self: Self, image: torch.Tensor) -> torch.Tensor:
Expand All @@ -134,6 +187,11 @@ def forward(self: Self, image: torch.Tensor) -> torch.Tensor:
image : torch.Tensor
The input tensor to run the model on
Returns
-------
torch.Tensor
The output tensor
"""
closing = kornia.morphology.closing(image, self._kernel)
return kornia.color.bgr_to_grayscale(closing)
Expand Down Expand Up @@ -178,17 +236,41 @@ def __init__(

@classmethod
def model_type(cls: type[ClosingBlur]) -> ModelType:
"""Use to get the type of input this model takes."""
"""
Use to get the type of input this model takes.
Returns
-------
ModelType
The type of arguments this model takes.
"""
return ModelType.DUAL_KERNEL

@classmethod
def input_names(cls: type[ClosingBlur]) -> list[tuple[str, InputType]]:
"""Use to get the names of the input tensors."""
"""
Use to get the names of the input tensors.
Returns
-------
list[tuple[str, InputType]]
The names of the input tensors and their datatype.
"""
return [("input", InputType.FP16)]

@classmethod
def output_names(cls: type[ClosingBlur]) -> list[str]:
"""Use to get the names of the output tensors."""
"""
Use to get the names of the output tensors.
Returns
-------
list[str]
The names of the output tensors.
"""
return ["output"]

def forward(self: Self, image: torch.Tensor) -> torch.Tensor:
Expand All @@ -200,6 +282,11 @@ def forward(self: Self, image: torch.Tensor) -> torch.Tensor:
image : torch.Tensor
The input tensor to run the model on
Returns
-------
torch.Tensor
The output tensor
"""
gaussian = kornia.filters.gaussian_blur2d(
image,
Expand Down Expand Up @@ -248,17 +335,41 @@ def __init__(

@classmethod
def model_type(cls: type[ClosingBlurGray]) -> ModelType:
"""Use to get the type of input this model takes."""
"""
Use to get the type of input this model takes.
Returns
-------
ModelType
The type of arguments this model takes.
"""
return ModelType.DUAL_KERNEL

@classmethod
def input_names(cls: type[ClosingBlurGray]) -> list[tuple[str, InputType]]:
"""Use to get the names of the input tensors."""
"""
Use to get the names of the input tensors.
Returns
-------
list[tuple[str, InputType]]
The names of the input tensors and their datatype.
"""
return [("input", InputType.FP16)]

@classmethod
def output_names(cls: type[ClosingBlurGray]) -> list[str]:
"""Use to get the names of the output tensors."""
"""
Use to get the names of the output tensors.
Returns
-------
list[str]
The names of the output tensors.
"""
return ["output"]

def forward(self: Self, image: torch.Tensor) -> torch.Tensor:
Expand All @@ -270,6 +381,11 @@ def forward(self: Self, image: torch.Tensor) -> torch.Tensor:
image : torch.Tensor
The input tensor to run the model on
Returns
-------
torch.Tensor
The output tensor
"""
gaussian = kornia.filters.gaussian_blur2d(
image,
Expand Down
Loading

0 comments on commit 479acc4

Please sign in to comment.