# import os
# import torch
# import torchvision
# from torch.utils.data import DataLoader
# from torchvision.datasets import ImageFolder
# from torch.nn import functional as F
# import torchvision.transforms as transforms
# from torchvision.datasets import MNIST, KMNIST

# import numpy as np
# from PIL import Image
# from utils import mkdir_if_missing

# def _transform(n_px):
#     return Compose([
#         Resize(n_px, interpolation=BICUBIC),
#         CenterCrop(n_px),
#         _convert_image_to_rgb,
#         ToTensor(),
#         Normalize((0.48145466, 0.4578275, 0.40821073), (0.26862954, 0.26130258, 0.27577711)),
#     ])

# class MNISTRGB(MNIST):
#     """MNIST Dataset.
#     """
#     def __getitem__(self, index):
#         img, target = self.data[index], int(self.targets[index])
#         img = Image.fromarray(img.numpy(), mode='L')
#         img = img.convert("RGB")

#         if self.transform is not None:
#             img = self.transform(img)

#         if self.target_transform is not None:
#             target = self.target_transform(target)

#         return img, target

# class KMNISTRGB(KMNIST):
#     """KMNIST Dataset.
#     """
#     def __getitem__(self, index):
#         img, target = self.data[index], int(self.targets[index])
#         img = Image.fromarray(img.numpy(), mode='L')
#         img = img.convert("RGB")

#         if self.transform is not None:
#             img = self.transform(img)

#         if self.target_transform is not None:
#             target = self.target_transform(target)

#         return img, target

# class MNIST(object):
#     def __init__(self, **options):
#         transform = _transform(224)

#         batch_size = options['batch_size']
#         data_root = os.path.join(options['dataroot'], 'mnist')

#         pin_memory = True if options['use_gpu'] else False

#         trainset = MNISTRGB(root=data_root, train=True, download=True, transform=transform)
        
#         trainloader = torch.utils.data.DataLoader(
#             trainset, batch_size=batch_size, shuffle=True,
#             num_workers=options['workers'], pin_memory=pin_memory,
#         )
        
#         testset = MNISTRGB(root=data_root, train=False, download=True, transform=transform)
        
#         testloader = torch.utils.data.DataLoader(
#             testset, batch_size=batch_size, shuffle=False,
#             num_workers=options['workers'], pin_memory=pin_memory,
#         )

#         self.trainloader = trainloader
#         self.testloader = testloader
#         self.num_classes = 10

# class KMNIST(object):
#     def __init__(self, **options):
#         # transform = transforms.Compose([
#         #     transforms.Resize(224),
#         #     transforms.ToTensor(),
#         # ])
#         transform = _transform(224)
#         batch_size = options['batch_size']
#         data_root = os.path.join(options['dataroot'], 'kmnist')

#         pin_memory = True if options['use_gpu'] else False

#         trainset = KMNISTRGB(root=data_root, train=True, download=True, transform=transform)
        
#         trainloader = torch.utils.data.DataLoader(
#             trainset, batch_size=batch_size, shuffle=True,
#             num_workers=options['workers'], pin_memory=pin_memory,
#         )
        
#         testset = KMNISTRGB(root=data_root, train=False, download=True, transform=transform)
        
#         testloader = torch.utils.data.DataLoader(
#             testset, batch_size=batch_size, shuffle=False,
#             num_workers=options['workers'], pin_memory=pin_memory,
#         )

#         self.trainloader = trainloader
#         self.testloader = testloader
#         self.num_classes = 10

# class CIFAR10(object):
#     def __init__(self, **options):

#         # transform_train = transforms.Compose([
#         #     transforms.RandomCrop(224, padding=4),
#         #     transforms.RandomHorizontalFlip(),
#         #     transforms.ToTensor(),
#         # ])
#         # transform = transforms.Compose([
#         #     transforms.ToTensor(),
#         # ])
#         transform = _transform(224)
#         transform_train = _transform(224)
#         batch_size = options['batch_size']
#         data_root = os.path.join(options['dataroot'], 'cifar10')

#         pin_memory = True if options['use_gpu'] else False

#         trainset = torchvision.datasets.CIFAR10(root=data_root, train=True, download=True, transform=transform_train)
        
#         trainloader = torch.utils.data.DataLoader(
#             trainset, batch_size=batch_size, shuffle=True,
#             num_workers=options['workers'], pin_memory=pin_memory,
#         )
        
#         testset = torchvision.datasets.CIFAR10(root=data_root, train=False, download=True, transform=transform)
        
#         testloader = torch.utils.data.DataLoader(
#             testset, batch_size=batch_size, shuffle=False,
#             num_workers=options['workers'], pin_memory=pin_memory,
#         )

#         self.num_classes = 10
#         self.trainloader = trainloader
#         self.testloader = testloader

# class CIFAR100(object):
#     def __init__(self, **options):
#         # transform_train = transforms.Compose([
#         #     transforms.RandomCrop(224, padding=4),
#         #     transforms.RandomHorizontalFlip(),
#         #     transforms.ToTensor(),
#         # ])
#         # transform = transforms.Compose([
#         #     transforms.ToTensor(),
#         # ])

#         transform_train = _transform(224)
#         transform = _transform(224)
        
#         batch_size = options['batch_size']
#         data_root = os.path.join(options['dataroot'], 'cifar100')

#         pin_memory = True if options['use_gpu'] else False

#         trainset = torchvision.datasets.CIFAR100(root=data_root, train=True, download=True, transform=transform_train)
        
#         trainloader = torch.utils.data.DataLoader(
#             trainset, batch_size=batch_size, shuffle=True,
#             num_workers=options['workers'], pin_memory=pin_memory,
#         )
        
#         testset = torchvision.datasets.CIFAR100(root=data_root, train=False, download=True, transform=transform)
        
#         testloader = torch.utils.data.DataLoader(
#             testset, batch_size=batch_size, shuffle=False,
#             num_workers=options['workers'], pin_memory=pin_memory,
#         )

#         self.num_classes = 100
#         self.trainloader = trainloader
#         self.testloader = testloader


# class SVHN(object):
#     def __init__(self, **options):
#         # transform_train = transforms.Compose([
#         #     transforms.RandomCrop(224, padding=4),
#         #     transforms.RandomHorizontalFlip(),
#         #     transforms.ToTensor(),
#         # ])
#         # transform = transforms.Compose([
#         #     transforms.ToTensor(),
#         # ])

#         transform_train = _transform(224)
#         transform = _transform(224)

#         batch_size = options['batch_size']
#         data_root = os.path.join(options['dataroot'], 'svhn')

#         pin_memory = True if options['use_gpu'] else False

#         trainset = torchvision.datasets.SVHN(root=data_root, split='train', download=True, transform=transform_train)
        
#         trainloader = torch.utils.data.DataLoader(
#             trainset, batch_size=batch_size, shuffle=True,
#             num_workers=options['workers'], pin_memory=pin_memory,
#         )
        
#         testset = torchvision.datasets.SVHN(root=data_root, split='test', download=True, transform=transform)
        
#         testloader = torch.utils.data.DataLoader(
#             testset, batch_size=batch_size, shuffle=False,
#             num_workers=options['workers'], pin_memory=pin_memory,
#         )

#         self.num_classes = 10
#         self.trainloader = trainloader
#         self.testloader = testloader


# __factory = {
#     'mnist': MNIST,
#     'kmnist': KMNIST,
#     'cifar10': CIFAR10,
#     'cifar100': CIFAR100,
#     'svhn':SVHN,
# }

# def create(name, **options):
#     if name not in __factory.keys():
#         raise KeyError("Unknown dataset: {}".format(name))
#     return __factory[name](**options)