Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from kornia:main #60

Merged
merged 3 commits into from
Dec 18, 2024
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
exclude: ^$|.devcontainer

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.2
rev: v0.8.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
1 change: 1 addition & 0 deletions kornia/augmentation/auto/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def get_transformation_matrix(
params: params for the sequence.
recompute: if to recompute the transformation matrix according to the params.
default: False.
extra_args: Optional dictionary of extra arguments with specific options for different input types.

"""
if params is None:
Expand Down
1 change: 1 addition & 0 deletions kornia/augmentation/auto/operations/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def get_transformation_matrix(
params: params for the sequence.
recompute: if to recompute the transformation matrix according to the params.
default: False.
extra_args: Optional dictionary of extra arguments with specific options for different input types.

"""
if params is None:
Expand Down
2 changes: 2 additions & 0 deletions kornia/augmentation/container/augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,10 @@ def __call__(
"""Overwrite the __call__ function to handle various inputs.

Args:
inputs: Inputs to operate on.
input_names_to_handle: List of input names to convert, if None, handle all inputs.
output_type: Desired output type ('tensor', 'numpy', or 'pil').
kwargs: Additional arguments.

Returns:
Callable: Decorated function with converted input and output types.
Expand Down
2 changes: 1 addition & 1 deletion kornia/augmentation/container/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def get_transformation_matrix(
params: params for the sequence.
recompute: if to recompute the transformation matrix according to the params.
default: False.

extra_args: Optional dictionary of extra arguments with specific options for different input types.
"""
raise NotImplementedError

Expand Down
4 changes: 3 additions & 1 deletion kornia/augmentation/container/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def get_transformation_matrix(
params: params for the sequence.
recompute: if to recompute the transformation matrix according to the params.
default: False.

extra_args: Optional dictionary of extra arguments with specific options for different input types.
"""
if params is None:
raise NotImplementedError("requires params to be provided.")
Expand Down Expand Up @@ -326,8 +326,10 @@ def __call__(
"""Overwrite the __call__ function to handle various inputs.

Args:
inputs: Inputs to operate on.
input_names_to_handle: List of input names to convert, if None, handle all inputs.
output_type: Desired output type ('tensor', 'numpy', or 'pil').
kwargs: Additional arguments.

Returns:
Callable: Decorated function with converted input and output types.
Expand Down
18 changes: 9 additions & 9 deletions kornia/augmentation/container/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def transform(cls, input: T, module: Module, param: ParamItem, extra_args: Optio
module: any torch Module but only kornia augmentation modules will count
to apply transformations.
param: the corresponding parameters to the module.

extra_args: Optional dictionary of extra arguments with specific options for different input types.
"""
raise NotImplementedError

Expand All @@ -64,7 +64,7 @@ def inverse(cls, input: T, module: Module, param: ParamItem, extra_args: Optiona
module: any torch Module but only kornia augmentation modules will count
to apply transformations.
param: the corresponding parameters to the module.

extra_args: Optional dictionary of extra arguments with specific options for different input types.
"""
raise NotImplementedError

Expand Down Expand Up @@ -255,7 +255,7 @@ def transform(
module: any torch Module but only kornia augmentation modules will count
to apply transformations.
param: the corresponding parameters to the module.

extra_args: Optional dictionary of extra arguments with specific options for different input types.
"""
if extra_args is None:
extra_args = {}
Expand Down Expand Up @@ -304,7 +304,7 @@ def transform_list(
module: any torch Module but only kornia augmentation modules will count
to apply transformations.
param: the corresponding parameters to the module.

extra_args: Optional dictionary of extra arguments with specific options for different input types.
"""
if extra_args is None:
extra_args = {}
Expand Down Expand Up @@ -369,7 +369,7 @@ def inverse(
module: any torch Module but only kornia augmentation modules will count
to apply transformations.
param: the corresponding parameters to the module.

extra_args: Optional dictionary of extra arguments with specific options for different input types.
"""
if extra_args is None:
extra_args = {}
Expand Down Expand Up @@ -417,7 +417,7 @@ def transform(
module: any torch Module but only kornia augmentation modules will count
to apply transformations.
param: the corresponding parameters to the module.

extra_args: Optional dictionary of extra arguments with specific options for different input types.
"""
if extra_args is None:
extra_args = {}
Expand Down Expand Up @@ -463,7 +463,7 @@ def inverse(
module: any torch Module but only kornia augmentation modules will count
to apply transformations.
param: the corresponding parameters to the module.

extra_args: Optional dictionary of extra arguments with specific options for different input types.
"""
if extra_args is None:
extra_args = {}
Expand Down Expand Up @@ -514,7 +514,7 @@ def transform(
module: any torch Module but only kornia augmentation modules will count
to apply transformations.
param: the corresponding parameters to the module.

extra_args: Optional dictionary of extra arguments with specific options for different input types.
"""
if extra_args is None:
extra_args = {}
Expand Down Expand Up @@ -561,7 +561,7 @@ def inverse(
module: any torch Module but only kornia augmentation modules will count
to apply transformations.
param: the corresponding parameters to the module.

extra_args: Optional dictionary of extra arguments with specific options for different input types.
"""
if extra_args is None:
extra_args = {}
Expand Down
12 changes: 8 additions & 4 deletions kornia/augmentation/container/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ def transform_boxes( # type: ignore[override]
Args:
input: tensor with shape :math:`(B, T, N, 4, 2)`.
If input is a `Keypoints` type, the internal shape is :math:`(B * T, N, 4, 2)`.

params: params for the sequence.
extra_args: Optional dictionary of extra arguments with specific options for different input types.
"""
if isinstance(input, Tensor):
batchsize, frame_num = input.size(0), input.size(1)
Expand All @@ -272,7 +273,8 @@ def inverse_boxes( # type: ignore[override]
Args:
input: tensor with shape :math:`(B, T, N, 4, 2)`.
If input is a `Keypoints` type, the internal shape is :math:`(B * T, N, 4, 2)`.

params: params for the sequence.
extra_args: Optional dictionary of extra arguments with specific options for different input types.
"""
if isinstance(input, Tensor):
batchsize, frame_num = input.size(0), input.size(1)
Expand All @@ -291,7 +293,8 @@ def transform_keypoints( # type: ignore[override]
Args:
input: tensor with shape :math:`(B, T, N, 2)`.
If input is a `Keypoints` type, the internal shape is :math:`(B * T, N, 2)`.

params: params for the sequence.
extra_args: Optional dictionary of extra arguments with specific options for different input types.
"""
if isinstance(input, Tensor):
batchsize, frame_num = input.size(0), input.size(1)
Expand All @@ -310,7 +313,8 @@ def inverse_keypoints( # type: ignore[override]
Args:
input: tensor with shape :math:`(B, T, N, 2)`.
If input is a `Keypoints` type, the internal shape is :math:`(B * T, N, 2)`.

params: params for the sequence.
extra_args: Optional dictionary of extra arguments with specific options for different input types.
"""
if isinstance(input, Tensor):
frame_num, batchsize = input.size(0), input.size(1)
Expand Down
3 changes: 2 additions & 1 deletion kornia/augmentation/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ def _transform_output_shape(
r"""Collapse the broadcasted batch dimensions an input tensor to be the specified shape.

Args:
input: Tensor
output: Tensor
shape: List/tuple of int
reference_shape: Tensor representation of shape to control which dimensions are collapsed.

Returns:
Tensor
Expand Down
2 changes: 1 addition & 1 deletion kornia/contrib/extract_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def extract_tensor_patches(
window_size: the size of the sliding window and the output patch size.
stride: stride of the sliding window.
padding: Zero-padding added to both side of the input.
allow_auto_adding: whether to allow automatic padding if the window and stride do not fit into the image.
allow_auto_padding: whether to allow automatic padding if the window and stride do not fit into the image.

Returns:
the tensor with the extracted patches with shape :math:`(B, N, C, H_{out}, W_{out})`.
Expand Down
2 changes: 1 addition & 1 deletion kornia/contrib/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def window_unpartition(windows: Tensor, window_size: int, pad_hw: tuple[int, int
"""Window unpartition into original sequences and removing padding.

Args:
x: input tokens with [B * num_windows, window_size, window_size, C].
windows: input tokens with [B * num_windows, window_size, window_size, C].
window_size: window size.
pad_hw: padded height and width (Hp, Wp).
hw: original height and width (H, W) before padding.
Expand Down
6 changes: 4 additions & 2 deletions kornia/contrib/models/rt_detr/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def from_name(model_name: str, num_classes: int = 80) -> RTDETRConfig:

Args:
model_name: 'rtdetr_r18vd', 'rtdetr_r34vd', 'rtdetr_r50vd_m', 'rtdetr_r50vd', 'rtdetr_r101vd'.
num_classes: Number of classes to detect.

"""
if model_name == "rtdetr_r18vd":
Expand All @@ -107,8 +108,8 @@ def __init__(self, backbone: ResNetD | PPHGNetV2, encoder: HybridEncoder, decode

Args:
backbone: backbone network for feature extraction.
neck: neck network for feature fusion.
head: head network to decode features into detection results.
encoder: neck network for feature fusion.
decoder: head network to decode features into detection results.

"""
super().__init__()
Expand Down Expand Up @@ -255,6 +256,7 @@ def from_name(model_name: str, num_classes: int = 80) -> RTDETR:

Args:
model_name: 'rtdetr_r18vd', 'rtdetr_r34vd', 'rtdetr_r50vd_m', 'rtdetr_r50vd', 'rtdetr_r101vd'.
num_classes: number of classes to detect.

"""
model = RTDETR.from_config(RTDETRConfig.from_name(model_name, num_classes))
Expand Down
3 changes: 2 additions & 1 deletion kornia/contrib/models/sam/architecture/image_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(
depth: Depth of ViT.
num_heads: Number of attention heads in each ViT block.
mlp_ratio: Ratio of mlp hidden dim to embedding dim.
out_chans: Number of output channels.
qkv_bias: If True, add a learnable bias to query, key, value.
norm_layer: Normalization layer.
act_layer: Activation layer.
Expand Down Expand Up @@ -194,7 +195,7 @@ def __init__(
dim: Number of input channels.
num_heads: Number of attention heads.
qkv_bias: If True, add a learnable bias to query, key, value.
rel_pos: If True, add relative positional embeddings to the attention map.
use_rel_pos: If True, add relative positional embeddings to the attention map.
rel_pos_zero_init: If True, zero initialize relative positional parameters.
input_size: Input resolution for calculating the relative positional parameter size.

Expand Down
2 changes: 2 additions & 0 deletions kornia/contrib/models/sam/architecture/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(
num_heads: the number of heads for multihead attention. Must divide embedding_dim
mlp_dim: the channel dimension internal to the MLP block
activation: the activation to use in the MLP block
attention_downsample_rate: downsampling rate from embedding dimension

""" # noqa: D205
super().__init__()
Expand Down Expand Up @@ -117,6 +118,7 @@ def __init__(
mlp_dim: the hidden dimension of the mlp block
activation: the activation of the mlp block
skip_first_layer_pe: skip the PE on the first layer
attention_downsample_rate: downsampling rate from embedding dimension

"""
super().__init__()
Expand Down
4 changes: 3 additions & 1 deletion kornia/contrib/visual_prompter.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def set_image(self, image: Tensor, mean: Optional[Tensor] = None, std: Optional[
image: RGB image. Normally images with range of [0-1], the model preprocess normalize the
pixel values with the mean and std defined in its initialization. Expected to be into a float32
dtype. Shape :math:`(3, H, W)`.
mean: mean value of dataset for normalization.
std: standard deviation of dataset for normalization.

"""
KORNIA_CHECK_SHAPE(image, ["3", "H", "W"])
Expand Down Expand Up @@ -236,7 +238,7 @@ def predict(
Args:
keypoints: Point prompts to the model. Each point is in (X,Y) in pixels. Shape :math:`(K, N, 2)`. Where
`N` is the number of points and `K` the number of prompts.
keypoint_labels: Labels for the point prompts. 1 indicates a foreground point and 0 indicates a background
keypoints_labels: Labels for the point prompts. 1 indicates a foreground point and 0 indicates a background
point. Shape :math:`(K, N)`. Where `N` is the number of points, and `K` the number of
prompts.
boxes: A box prompt to the model. If a tensor, should be in a xyxy mode. Shape :math:`(K, 4)`
Expand Down
2 changes: 1 addition & 1 deletion kornia/core/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def KORNIA_CHECK_SAME_DEVICES(tensors: list[Tensor], msg: Optional[str] = None,
"""Check whether a list provided tensors live in the same device.

Args:
x: a list of tensors.
tensors: a list of tensors.
msg: message to show in the exception.
raises: bool indicating whether an exception should be raised upon failure.

Expand Down
1 change: 1 addition & 0 deletions kornia/core/mixin/image_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def show(self, n_row: Optional[int] = None, backend: str = "pil", display: bool
Args:
n_row: Number of images displayed in each row of the grid.
backend: visualization backend. Only PIL is supported now.
display: Whether or not to show the image.

"""
if self._output_image is None:
Expand Down
Loading