From bdc9fad63838e5e1b354b5c357521ceb9652fa75 Mon Sep 17 00:00:00 2001 From: hongxin xiang Date: Thu, 24 Nov 2022 14:37:44 +0800 Subject: [PATCH 1/2] Fix compatible BUG: QMNIST and ImageNet datasets do not exist in torchvision 0.10.1. --- timm/data/dataset_factory.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/timm/data/dataset_factory.py b/timm/data/dataset_factory.py index 3777a5aa..92529357 100644 --- a/timm/data/dataset_factory.py +++ b/timm/data/dataset_factory.py @@ -4,7 +4,7 @@ Hacked together by / Copyright 2021, Ross Wightman """ import os -from torchvision.datasets import CIFAR100, CIFAR10, MNIST, QMNIST, KMNIST, FashionMNIST, ImageNet, ImageFolder +from torchvision.datasets import CIFAR100, CIFAR10, MNIST, KMNIST, FashionMNIST, ImageFolder try: from torchvision.datasets import Places365 has_places365 = True @@ -15,6 +15,16 @@ try: has_inaturalist = True except ImportError: has_inaturalist = False +try: + from torchvision.datasets import QMNIST + has_qmnist = True +except ImportError: + has_qmnist = False +try: + from torchvision.datasets import ImageNet + has_imagenet = True +except ImportError: + has_imagenet = False from .dataset import IterableImageDataset, ImageDataset @@ -22,7 +32,6 @@ _TORCH_BASIC_DS = dict( cifar10=CIFAR10, cifar100=CIFAR100, mnist=MNIST, - qmist=QMNIST, kmnist=KMNIST, fashion_mnist=FashionMNIST, ) From 653bdc7105098763cb672e344f6d716021f9c627 Mon Sep 17 00:00:00 2001 From: hongxin xiang Date: Fri, 25 Nov 2022 09:52:52 +0800 Subject: [PATCH 2/2] Fix comment: https://github.com/rwightman/pytorch-image-models/pull/1564#issuecomment-1326743424 --- timm/data/dataset_factory.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/timm/data/dataset_factory.py b/timm/data/dataset_factory.py index 92529357..757c2e5d 100644 --- a/timm/data/dataset_factory.py +++ b/timm/data/dataset_factory.py @@ -131,7 +131,12 @@ def create_dataset( elif split in _EVAL_SYNONYM: split = 'val' ds = Places365(split=split, **torch_kwargs) + elif name == 'qmnist': + assert has_qmnist, 'Please update to a newer PyTorch and torchvision for QMNIST dataset.' + use_train = split in _TRAIN_SYNONYM + ds = QMNIST(train=use_train, **torch_kwargs) elif name == 'imagenet': + assert has_imagenet, 'Please update to a newer PyTorch and torchvision for ImageNet dataset.' if split in _EVAL_SYNONYM: split = 'val' ds = ImageNet(split=split, **torch_kwargs)