Skip to content

Commit 496ed83

Browse files
pmeierfacebook-github-bot
authored andcommitted
Type annotations for torchvision/utils.py (#2034) (#2428)
Summary: * type annotations for torchvision/utils.py * add missing annotation for make_grid * fix annotation for save_image * mirror PIL annotation for fp Pull Request resolved: #2428 Reviewed By: zhangguanheng66 Differential Revision: D22437423 Pulled By: fmassa fbshipit-source-id: 77a46deb22e4fbf4de02f9f7d0e418c656d40a65
1 parent bb779bb commit 496ed83

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

torchvision/utils.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
from typing import Union, Optional, Sequence, Tuple, Text, BinaryIO
2+
import io
3+
import pathlib
14
import torch
25
import math
36
irange = range
47

58

6-
def make_grid(tensor, nrow=8, padding=2,
7-
normalize=False, range=None, scale_each=False, pad_value=0):
9+
def make_grid(tensor: Union[torch.Tensor, Sequence[torch.Tensor]], nrow: int = 8,
10+
padding: int = 2, normalize: bool = False,
11+
range: Optional[Tuple[int, int]] = None, scale_each: bool = False,
12+
pad_value: int = 0) -> torch.Tensor:
813
"""Make a grid of images.
914
1015
Args:
@@ -88,8 +93,9 @@ def norm_range(t, range):
8893
return grid
8994

9095

91-
def save_image(tensor, fp, nrow=8, padding=2,
92-
normalize=False, range=None, scale_each=False, pad_value=0, format=None):
96+
def save_image(tensor: Union[torch.Tensor, Sequence[torch.Tensor]], fp: Union[Text, pathlib.Path, BinaryIO],
97+
nrow: int = 8, padding: int = 2, normalize: bool = False, range: Optional[Tuple[int, int]] = None,
98+
scale_each: bool = False, pad_value: int = 0, format: Optional[str] = None) -> None:
9399
"""Save a given Tensor into an image file.
94100
95101
Args:

0 commit comments

Comments
 (0)