Skip to content

Commit ef29a77

Browse files
authored
Merge branch 'main' into prototype/video_corrections
2 parents 3333d31 + 019139f commit ef29a77

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

torchvision/prototype/transforms/_utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import functools
12
import numbers
23
from collections import defaultdict
3-
44
from typing import Any, Callable, Dict, Sequence, Tuple, Type, Union
55

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

4545

46+
def _default_fill(fill: FillType) -> FillType:
47+
return fill
48+
49+
4650
def _setup_fill_arg(fill: Union[FillType, Dict[Type, FillType]]) -> Dict[Type, FillType]:
4751
_check_fill_arg(fill)
4852

4953
if isinstance(fill, dict):
5054
return fill
5155

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

5460

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

0 commit comments

Comments
 (0)