Unverified Commit fd5109a0 authored by Philip Meier's avatar Philip Meier Committed by GitHub
Browse files

Cleanup prototype kernel dispatchers (#5417)

* add all legacy kernels

* clarify dispatcher docstrings
parent 9ae0169d
...@@ -17,7 +17,7 @@ T = TypeVar("T", bound=features._Feature) ...@@ -17,7 +17,7 @@ T = TypeVar("T", bound=features._Feature)
} }
) )
def erase(input: T, *args: Any, **kwargs: Any) -> T: def erase(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
... ...
...@@ -28,7 +28,7 @@ def erase(input: T, *args: Any, **kwargs: Any) -> T: ...@@ -28,7 +28,7 @@ def erase(input: T, *args: Any, **kwargs: Any) -> T:
} }
) )
def mixup(input: T, *args: Any, **kwargs: Any) -> T: def mixup(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
... ...
......
...@@ -19,7 +19,7 @@ T = TypeVar("T", bound=features._Feature) ...@@ -19,7 +19,7 @@ T = TypeVar("T", bound=features._Feature)
} }
) )
def adjust_brightness(input: T, *args: Any, **kwargs: Any) -> T: def adjust_brightness(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
... ...
...@@ -31,7 +31,7 @@ def adjust_brightness(input: T, *args: Any, **kwargs: Any) -> T: ...@@ -31,7 +31,7 @@ def adjust_brightness(input: T, *args: Any, **kwargs: Any) -> T:
} }
) )
def adjust_saturation(input: T, *args: Any, **kwargs: Any) -> T: def adjust_saturation(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
... ...
...@@ -43,7 +43,7 @@ def adjust_saturation(input: T, *args: Any, **kwargs: Any) -> T: ...@@ -43,7 +43,7 @@ def adjust_saturation(input: T, *args: Any, **kwargs: Any) -> T:
} }
) )
def adjust_contrast(input: T, *args: Any, **kwargs: Any) -> T: def adjust_contrast(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
... ...
...@@ -55,7 +55,7 @@ def adjust_contrast(input: T, *args: Any, **kwargs: Any) -> T: ...@@ -55,7 +55,7 @@ def adjust_contrast(input: T, *args: Any, **kwargs: Any) -> T:
} }
) )
def adjust_sharpness(input: T, *args: Any, **kwargs: Any) -> T: def adjust_sharpness(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
... ...
...@@ -67,7 +67,7 @@ def adjust_sharpness(input: T, *args: Any, **kwargs: Any) -> T: ...@@ -67,7 +67,7 @@ def adjust_sharpness(input: T, *args: Any, **kwargs: Any) -> T:
} }
) )
def posterize(input: T, *args: Any, **kwargs: Any) -> T: def posterize(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
... ...
...@@ -79,7 +79,7 @@ def posterize(input: T, *args: Any, **kwargs: Any) -> T: ...@@ -79,7 +79,7 @@ def posterize(input: T, *args: Any, **kwargs: Any) -> T:
} }
) )
def solarize(input: T, *args: Any, **kwargs: Any) -> T: def solarize(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
... ...
...@@ -91,7 +91,7 @@ def solarize(input: T, *args: Any, **kwargs: Any) -> T: ...@@ -91,7 +91,7 @@ def solarize(input: T, *args: Any, **kwargs: Any) -> T:
} }
) )
def autocontrast(input: T, *args: Any, **kwargs: Any) -> T: def autocontrast(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
... ...
...@@ -103,7 +103,7 @@ def autocontrast(input: T, *args: Any, **kwargs: Any) -> T: ...@@ -103,7 +103,7 @@ def autocontrast(input: T, *args: Any, **kwargs: Any) -> T:
} }
) )
def equalize(input: T, *args: Any, **kwargs: Any) -> T: def equalize(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
... ...
...@@ -115,5 +115,29 @@ def equalize(input: T, *args: Any, **kwargs: Any) -> T: ...@@ -115,5 +115,29 @@ def equalize(input: T, *args: Any, **kwargs: Any) -> T:
} }
) )
def invert(input: T, *args: Any, **kwargs: Any) -> T: def invert(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
...
@dispatch(
{
torch.Tensor: _F.adjust_hue,
PIL.Image.Image: _F.adjust_hue,
features.Image: K.adjust_hue_image,
}
)
def adjust_hue(input: T, *args: Any, **kwargs: Any) -> T:
"""TODO: add docstring"""
...
@dispatch(
{
torch.Tensor: _F.adjust_gamma,
PIL.Image.Image: _F.adjust_gamma,
features.Image: K.adjust_gamma_image,
}
)
def adjust_gamma(input: T, *args: Any, **kwargs: Any) -> T:
"""TODO: add docstring"""
... ...
...@@ -20,7 +20,7 @@ T = TypeVar("T", bound=features._Feature) ...@@ -20,7 +20,7 @@ T = TypeVar("T", bound=features._Feature)
}, },
) )
def horizontal_flip(input: T, *args: Any, **kwargs: Any) -> T: def horizontal_flip(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
if isinstance(input, features.BoundingBox): if isinstance(input, features.BoundingBox):
output = K.horizontal_flip_bounding_box(input, format=input.format, image_size=input.image_size) output = K.horizontal_flip_bounding_box(input, format=input.format, image_size=input.image_size)
return cast(T, features.BoundingBox.new_like(input, output)) return cast(T, features.BoundingBox.new_like(input, output))
...@@ -38,7 +38,7 @@ def horizontal_flip(input: T, *args: Any, **kwargs: Any) -> T: ...@@ -38,7 +38,7 @@ def horizontal_flip(input: T, *args: Any, **kwargs: Any) -> T:
} }
) )
def resize(input: T, *args: Any, **kwargs: Any) -> T: def resize(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
if isinstance(input, features.BoundingBox): if isinstance(input, features.BoundingBox):
size = kwargs.pop("size") size = kwargs.pop("size")
output = K.resize_bounding_box(input, size=size, image_size=input.image_size) output = K.resize_bounding_box(input, size=size, image_size=input.image_size)
...@@ -55,7 +55,7 @@ def resize(input: T, *args: Any, **kwargs: Any) -> T: ...@@ -55,7 +55,7 @@ def resize(input: T, *args: Any, **kwargs: Any) -> T:
} }
) )
def center_crop(input: T, *args: Any, **kwargs: Any) -> T: def center_crop(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
... ...
...@@ -67,7 +67,7 @@ def center_crop(input: T, *args: Any, **kwargs: Any) -> T: ...@@ -67,7 +67,7 @@ def center_crop(input: T, *args: Any, **kwargs: Any) -> T:
} }
) )
def resized_crop(input: T, *args: Any, **kwargs: Any) -> T: def resized_crop(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
... ...
...@@ -79,7 +79,7 @@ def resized_crop(input: T, *args: Any, **kwargs: Any) -> T: ...@@ -79,7 +79,7 @@ def resized_crop(input: T, *args: Any, **kwargs: Any) -> T:
} }
) )
def affine(input: T, *args: Any, **kwargs: Any) -> T: def affine(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
... ...
...@@ -91,5 +91,77 @@ def affine(input: T, *args: Any, **kwargs: Any) -> T: ...@@ -91,5 +91,77 @@ def affine(input: T, *args: Any, **kwargs: Any) -> T:
} }
) )
def rotate(input: T, *args: Any, **kwargs: Any) -> T: def rotate(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
...
@dispatch(
{
torch.Tensor: _F.pad,
PIL.Image.Image: _F.pad,
features.Image: K.pad_image,
}
)
def pad(input: T, *args: Any, **kwargs: Any) -> T:
"""TODO: add docstring"""
...
@dispatch(
{
torch.Tensor: _F.crop,
PIL.Image.Image: _F.crop,
features.Image: K.crop_image,
}
)
def crop(input: T, *args: Any, **kwargs: Any) -> T:
"""TODO: add docstring"""
...
@dispatch(
{
torch.Tensor: _F.perspective,
PIL.Image.Image: _F.perspective,
features.Image: K.perspective_image,
}
)
def perspective(input: T, *args: Any, **kwargs: Any) -> T:
"""TODO: add docstring"""
...
@dispatch(
{
torch.Tensor: _F.vflip,
PIL.Image.Image: _F.vflip,
features.Image: K.vertical_flip_image,
}
)
def vertical_flip(input: T, *args: Any, **kwargs: Any) -> T:
"""TODO: add docstring"""
...
@dispatch(
{
torch.Tensor: _F.five_crop,
PIL.Image.Image: _F.five_crop,
features.Image: K.five_crop_image,
}
)
def five_crop(input: T, *args: Any, **kwargs: Any) -> T:
"""TODO: add docstring"""
...
@dispatch(
{
torch.Tensor: _F.ten_crop,
PIL.Image.Image: _F.ten_crop,
features.Image: K.ten_crop_image,
}
)
def ten_crop(input: T, *args: Any, **kwargs: Any) -> T:
"""TODO: add docstring"""
... ...
from typing import TypeVar, Any from typing import TypeVar, Any
import PIL.Image
import torch import torch
from torchvision.prototype import features from torchvision.prototype import features
from torchvision.prototype.transforms import kernels as K from torchvision.prototype.transforms import kernels as K
...@@ -17,5 +18,17 @@ T = TypeVar("T", bound=features._Feature) ...@@ -17,5 +18,17 @@ T = TypeVar("T", bound=features._Feature)
} }
) )
def normalize(input: T, *args: Any, **kwargs: Any) -> T: def normalize(input: T, *args: Any, **kwargs: Any) -> T:
"""ADDME""" """TODO: add docstring"""
...
@dispatch(
{
torch.Tensor: _F.gaussian_blur,
PIL.Image.Image: _F.gaussian_blur,
features.Image: K.gaussian_blur_image,
}
)
def ten_gaussian_blur(input: T, *args: Any, **kwargs: Any) -> T:
"""TODO: add docstring"""
... ...
...@@ -18,6 +18,8 @@ from ._color import ( ...@@ -18,6 +18,8 @@ from ._color import (
autocontrast_image, autocontrast_image,
equalize_image, equalize_image,
invert_image, invert_image,
adjust_hue_image,
adjust_gamma_image,
) )
from ._geometry import ( from ._geometry import (
horizontal_flip_bounding_box, horizontal_flip_bounding_box,
...@@ -29,6 +31,12 @@ from ._geometry import ( ...@@ -29,6 +31,12 @@ from ._geometry import (
resized_crop_image, resized_crop_image,
affine_image, affine_image,
rotate_image, rotate_image,
pad_image,
crop_image,
perspective_image,
vertical_flip_image,
five_crop_image,
ten_crop_image,
) )
from ._misc import normalize_image from ._misc import normalize_image, gaussian_blur_image
from ._type_conversion import decode_image_with_pil, decode_video_with_av, label_to_one_hot from ._type_conversion import decode_image_with_pil, decode_video_with_av, label_to_one_hot
...@@ -10,3 +10,5 @@ solarize_image = _F.solarize ...@@ -10,3 +10,5 @@ solarize_image = _F.solarize
autocontrast_image = _F.autocontrast autocontrast_image = _F.autocontrast
equalize_image = _F.equalize equalize_image = _F.equalize
invert_image = _F.invert invert_image = _F.invert
adjust_hue_image = _F.adjust_hue
adjust_gamma_image = _F.adjust_gamma
...@@ -68,3 +68,9 @@ center_crop_image = _F.center_crop ...@@ -68,3 +68,9 @@ center_crop_image = _F.center_crop
resized_crop_image = _F.resized_crop resized_crop_image = _F.resized_crop
affine_image = _F.affine affine_image = _F.affine
rotate_image = _F.rotate rotate_image = _F.rotate
pad_image = _F.pad
crop_image = _F.crop
perspective_image = _F.perspective
vertical_flip_image = _F.vflip
five_crop_image = _F.five_crop
ten_crop_image = _F.ten_crop
...@@ -2,3 +2,4 @@ from torchvision.transforms import functional as _F ...@@ -2,3 +2,4 @@ from torchvision.transforms import functional as _F
normalize_image = _F.normalize normalize_image = _F.normalize
gaussian_blur_image = _F.gaussian_blur
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment