Skip to content

Commit 4196062

Browse files
committed
add Path type in pil_loader, accimage_loader and default_loader acceptable input type.
1 parent 2f71018 commit 4196062

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

torchvision/datasets/folder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,15 @@ def __len__(self) -> int:
257257
IMG_EXTENSIONS = (".jpg", ".jpeg", ".png", ".ppm", ".bmp", ".pgm", ".tif", ".tiff", ".webp")
258258

259259

260-
def pil_loader(path: str) -> Image.Image:
260+
def pil_loader(path: str | Path) -> Image.Image:
261261
# open path as file to avoid ResourceWarning (https://github.com/python-pillow/Pillow/issues/835)
262262
with open(path, "rb") as f:
263263
img = Image.open(f)
264264
return img.convert("RGB")
265265

266266

267267
# TODO: specify the return type
268-
def accimage_loader(path: str) -> Any:
268+
def accimage_loader(path: str | Path) -> Any:
269269
import accimage
270270

271271
try:
@@ -275,7 +275,7 @@ def accimage_loader(path: str) -> Any:
275275
return pil_loader(path)
276276

277277

278-
def default_loader(path: str) -> Any:
278+
def default_loader(path: str | Path) -> Any:
279279
from torchvision import get_image_backend
280280

281281
if get_image_backend() == "accimage":

0 commit comments

Comments
 (0)