Skip to content
Merged
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
10 changes: 8 additions & 2 deletions torchvision/prototype/transforms/_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import functools
import numbers
from collections import defaultdict

from typing import Any, Callable, Dict, Sequence, Tuple, Type, Union

import PIL.Image
Expand Down Expand Up @@ -43,13 +43,19 @@ def _check_fill_arg(fill: Union[FillType, Dict[Type, FillType]]) -> None:
raise TypeError("Got inappropriate fill arg")


def _default_fill(fill: FillType) -> FillType:
return fill


def _setup_fill_arg(fill: Union[FillType, Dict[Type, FillType]]) -> Dict[Type, FillType]:
_check_fill_arg(fill)

if isinstance(fill, dict):
return fill

return defaultdict(lambda: fill) # type: ignore[return-value, arg-type]
# This weird looking construct only exists, since `lambda`'s cannot be serialized by pickle.
# If it were possible, we could replace this with `defaultdict(lambda: fill)`
return defaultdict(functools.partial(_default_fill, fill))


def _check_padding_arg(padding: Union[int, Sequence[int]]) -> None:
Expand Down