Skip to content

A temporary fix to windows unittests failing in INaturalistTestCase. #9007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
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
12 changes: 5 additions & 7 deletions test/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@

@contextlib.contextmanager
def get_tmp_dir(src=None, **kwargs):
tmp_dir = tempfile.mkdtemp(**kwargs)
if src is not None:
os.rmdir(tmp_dir)
shutil.copytree(src, tmp_dir)
try:
with tempfile.TemporaryDirectory(
**kwargs,
) as tmp_dir:
if src is not None:
shutil.copytree(src, tmp_dir)
yield tmp_dir
finally:
shutil.rmtree(tmp_dir)


def set_rng_seed(seed):
Expand Down
2 changes: 0 additions & 2 deletions test/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import re
import shutil
import string
import sys
import unittest
import xml.etree.ElementTree as ET
import zipfile
Expand Down Expand Up @@ -1904,7 +1903,6 @@ def test_class_to_idx(self):
assert dataset.class_to_idx == class_to_idx


@pytest.mark.skipif(sys.platform in ("win32", "cygwin"), reason="temporarily disabled on Windows")
class INaturalistTestCase(datasets_utils.ImageDatasetTestCase):
DATASET_CLASS = datasets.INaturalist
FEATURE_TYPES = (PIL.Image.Image, (int, tuple))
Expand Down
5 changes: 3 additions & 2 deletions torchvision/datasets/inaturalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(
for fname in files:
self.index.append((dir_index, fname))

self.loader = loader or Image.open
self.loader = loader

def _init_2021(self) -> None:
"""Initialize based on 2021 layout"""
Expand Down Expand Up @@ -184,7 +184,8 @@ def __getitem__(self, index: int) -> Tuple[Any, Any]:
"""

cat_id, fname = self.index[index]
img = self.loader(os.path.join(self.root, self.all_categories[cat_id], fname))
image_path = os.path.join(self.root, self.all_categories[cat_id], fname)
img = self.loader(image_path) if self.loader is not None else Image.open(image_path)

target: Any = []
for t in self.target_type:
Expand Down