# The dataset code has been adapted from:
# https://github.com/yaoyao-liu/mini-imagenet-tools
# which has been distributed under the following license:
################################################################################
# MIT License
#
# Copyright (c) 2019 Yaoyao Liu
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

import csv
import glob
from pathlib import Path
from typing import Union, List, Tuple, Dict

from torchvision.datasets.folder import default_loader
from typing_extensions import Literal

import PIL
import numpy as np
from PIL import Image
from torch.utils.data.dataset import Dataset
from torchvision.transforms import Resize

# from mini_imagenet_data import (
#     MINI_IMAGENET_WNIDS,
#     MINI_IMAGENET_WNID_TO_IDX,
#     MINI_IMAGENET_CLASSES,
#     MINI_IMAGENET_CLASS_TO_IDX,
# )


class MiniImageNetDataset(Dataset):
    """
    The MiniImageNet dataset.

    This implementation is based on the one from
    https://github.com/yaoyao-liu/mini-imagenet-tools. Differently from that,
    this class doesn't rely on a pre-generated mini imagenet folder. Instead,
    this will use the original ImageNet folder by resizing images on-the-fly.

    The list of included files are the ones defined in the CSVs taken from the
    aforementioned repository. Those CSVs are generated by Ravi and Larochelle.
    See the linked repository for more details.

    Exactly as happens with the torchvision :class:`ImageNet` class, textual
    class labels (wnids) such as "n02119789", "n02102040", etc. are mapped to
    numerical labels based on their ascending order.

    All the fields found in the torchvision implementation of the ImageNet
    dataset (`wnids`, `wnid_to_idx`, `classes`, `class_to_idx`) are available.
    """

    def __init__(
        self,
        imagenet_path: Union[str, Path],
        split: Literal["all", "train", "val", "test"] = "all",
        resize_to: Union[int, Tuple[int, int]] = 84,
        loader=default_loader,
    ):
        """
        Creates an instance of the Mini ImageNet dataset.

        This dataset allows to obtain the whole dataset or even only specific
        splits. Beware that, when using a split different that "all", the
        returned dataset will contain patterns of a subset of the 100 classes.
        This happens because MiniImagenet was created with the idea of training,
        validating and testing on a disjoint set of classes.

        This implementation uses the filelists provided by
        https://github.com/yaoyao-liu/mini-imagenet-tools, which are the ones
        generated by Ravi and Larochelle (see the linked repo for more details).

        :param imagenet_path: The path to the imagenet folder. This has to be
            the path to the full imagenet 2012 folder (plain, not resized).
            Only the "train" folder will be used. Because of this, passing the
            path to the imagenet 2012 "train" folder is also allowed.
        :param split: The split to obtain. Defaults to "all". Valid values are
            "all", "train", "val" and "test".
        :param resize_to: The size of the output images. Can be an `int` value
            or a tuple of two ints. When passing a single `int` value, images
            will be resized by forcing as 1:1 aspect ratio. Defaults to 84,
            which means that images will have size 84x84.
        """
        self.imagenet_path = MiniImageNetDataset.get_train_path(imagenet_path)

        self.split: Literal["all", "train", "val", "test"] = split
        """
        The required split.
        """

        if isinstance(resize_to, int):
            resize_to = (resize_to, resize_to)

        self.resize_to: Tuple[int, int] = resize_to
        """
        The size of the output images, as a two ints tuple.
        """
        self._transform = Resize(
            self.resize_to, interpolation=PIL.Image.BILINEAR
        )

        # The following fields are filled by self.prepare_dataset()
        self.image_paths: List[str] = []
        """
        The paths to images.
        """

        self.targets: List[int] = []
        """
        The class labels for the patterns. Aligned with the image_paths field.
        """

        self.wnids: List[str] = []
        """
        The list of wnids (the textual class labels, such as "n02119789").
        """

        self.wnid_to_idx: Dict[str, int] = dict()
        """
        A dictionary mapping wnids to numerical labels in range [0, 100).
        """

        self.classes: List[Tuple[str, ...]] = []
        """
        A list mapping numerical labels (the element index) to a tuple of human
        readable categories. For instance:
        ('great grey owl', 'great gray owl', 'Strix nebulosa').
        """

        self.class_to_idx: Dict[str, int] = dict()
        """
        A dictionary mapping each string of the tuples found in the classes 
        field to their numerical label. That is, this dictionary contains the 
        inverse mapping of classes field.
        """

        self.loader = loader

        if not self.imagenet_path.exists():
            raise ValueError("The provided directory does not exist.")

        if self.split not in ["all", "train", "val", "test"]:
            raise ValueError(
                'Invalid split. Valid values are: "train", "val", ' '"test"'
            )

        self.prepare_dataset()

        super().__init__()

    @staticmethod
    def get_train_path(root_path: Union[str, Path]):
        root_path = Path(root_path)
        if (root_path / "train").exists():
            return root_path / "train"
        return root_path

    def prepare_dataset(self):
        # Read the CSV containing the file list for this split
        images = dict()

        csv_dir = Path(__file__).resolve().parent / "csv_files"
        if self.split == "all":
            considered_csvs = ["train.csv", "val.csv", "test.csv"]
        else:
            considered_csvs = [self.split + ".csv"]

        for csv_name in considered_csvs:
            csv_path = str(csv_dir / csv_name)

            with open(csv_path) as csvfile:
                csv_reader = csv.reader(csvfile, delimiter=",")
                next(csv_reader, None)  # Skip header

                for row in csv_reader:
                    if row[1] in images.keys():
                        images[row[1]].append(row[0])
                    else:
                        images[row[1]] = [row[0]]

        # Fill fields like wnids, wnid_to_idx, etc.
        # Those fields have the same meaning of the ones found in the
        # torchvision implementation of the ImageNet dataset. Of course some
        # work had to be done to keep this fields aligned for mini imagenet,
        # which only contains 100 classes of the original 1000.
        #
        # wnids are 'n01440764', 'n01443537', 'n01484850', etc.
        #
        # self.wnid_to_idx is a dict mapping wnids to numerical labels
        #
        # self.classes is a list mapping numerical labels (the element
        # index) to a tuple of human readable categories. For instance:
        # ('great grey owl', 'great gray owl', 'Strix nebulosa').
        #
        # self.class_to_idx is a dict mapping each string of the
        # aforementioned tuples to its numerical label. That is, it contains
        # the inverse mapping of self.classes.
        self.wnids = MINI_IMAGENET_WNIDS
        self.wnid_to_idx = MINI_IMAGENET_WNID_TO_IDX
        self.classes = MINI_IMAGENET_CLASSES
        self.class_to_idx = MINI_IMAGENET_CLASS_TO_IDX

        for cls in images.keys():
            cls_numerical_label = self.wnid_to_idx[cls]
            lst_files = []
            for file in glob.glob(
                str(self.imagenet_path / cls / ("*" + cls + "*"))
            ):
                lst_files.append(file)

            lst_index = [
                int(i[i.rfind("_") + 1 : i.rfind(".")]) for i in lst_files
            ]
            index_sorted = sorted(
                range(len(lst_index)), key=lst_index.__getitem__
            )

            index_selected = [
                int(i[i.index(".") - 4 : i.index(".")]) for i in images[cls]
            ]
            selected_images = np.array(index_sorted)[
                np.array(index_selected) - 1
            ]
            for i in np.arange(len(selected_images)):
                self.image_paths.append(lst_files[selected_images[i]])
                self.targets.append(cls_numerical_label)

    def __len__(self):
        return len(self.targets)

    def __getitem__(self, item):
        img = self.loader(self.image_paths[item])
        img = self._transform(img)
        return img, self.targets[item]


__all__ = ["MiniImageNetDataset"]

if __name__ == "__main__":
    import matplotlib.pyplot as plt

    print("Creating training dataset")
    train_dataset = MiniImageNetDataset(
        "/data/LargeData/Large/ImageNet/train/", split="train"
    )
    print("Creating validation dataset")
    val_dataset = MiniImageNetDataset("/data/LargeData/Large/ImageNet/train/", split="val")
    print("Creating test dataset")
    test_dataset = MiniImageNetDataset("/data/LargeData/Large/ImageNet/train/", split="test")

    print("Training patterns:", len(train_dataset))
    print("Validation patterns:", len(val_dataset))
    print("Test patterns:", len(test_dataset))

    for img_idx, (img, label) in enumerate(train_dataset):
        plt.title(
            "Class {}, {}\n{}".format(
                label,
                train_dataset.classes[label],
                train_dataset.image_paths[0],
            )
        )
        plt.imshow(img)
        plt.show()
        print(img)
        print(label)
        class_to_idx = train_dataset.class_to_idx[
            train_dataset.classes[label][0]
        ]
        assert class_to_idx == label
        if img_idx == 2:
            break

    for img_idx, (img, label) in enumerate(val_dataset):
        plt.title(
            "Class {}, {}\n{}".format(
                label, val_dataset.classes[label], val_dataset.image_paths[0]
            )
        )
        plt.imshow(img)
        plt.show()
        print(img)
        print(label)
        class_to_idx = val_dataset.class_to_idx[train_dataset.classes[label][0]]
        assert class_to_idx == label
        if img_idx == 2:
            break

    for img_idx, (img, label) in enumerate(test_dataset):
        plt.title(
            "Class {}, {}\n{}".format(
                label, test_dataset.classes[label], test_dataset.image_paths[0]
            )
        )
        plt.imshow(img)
        plt.show()
        print(img)
        print(label)
        class_to_idx = test_dataset.class_to_idx[
            train_dataset.classes[label][0]
        ]
        assert class_to_idx == label
        if img_idx == 2:
            break

from typing import Dict, List, Tuple

IMAGENET_TORCHVISION_WNIDS: List[str] = [
    "n01440764",
    "n01443537",
    "n01484850",
    "n01491361",
    "n01494475",
    "n01496331",
    "n01498041",
    "n01514668",
    "n01514859",
    "n01518878",
    "n01530575",
    "n01531178",
    "n01532829",
    "n01534433",
    "n01537544",
    "n01558993",
    "n01560419",
    "n01580077",
    "n01582220",
    "n01592084",
    "n01601694",
    "n01608432",
    "n01614925",
    "n01616318",
    "n01622779",
    "n01629819",
    "n01630670",
    "n01631663",
    "n01632458",
    "n01632777",
    "n01641577",
    "n01644373",
    "n01644900",
    "n01664065",
    "n01665541",
    "n01667114",
    "n01667778",
    "n01669191",
    "n01675722",
    "n01677366",
    "n01682714",
    "n01685808",
    "n01687978",
    "n01688243",
    "n01689811",
    "n01692333",
    "n01693334",
    "n01694178",
    "n01695060",
    "n01697457",
    "n01698640",
    "n01704323",
    "n01728572",
    "n01728920",
    "n01729322",
    "n01729977",
    "n01734418",
    "n01735189",
    "n01737021",
    "n01739381",
    "n01740131",
    "n01742172",
    "n01744401",
    "n01748264",
    "n01749939",
    "n01751748",
    "n01753488",
    "n01755581",
    "n01756291",
    "n01768244",
    "n01770081",
    "n01770393",
    "n01773157",
    "n01773549",
    "n01773797",
    "n01774384",
    "n01774750",
    "n01775062",
    "n01776313",
    "n01784675",
    "n01795545",
    "n01796340",
    "n01797886",
    "n01798484",
    "n01806143",
    "n01806567",
    "n01807496",
    "n01817953",
    "n01818515",
    "n01819313",
    "n01820546",
    "n01824575",
    "n01828970",
    "n01829413",
    "n01833805",
    "n01843065",
    "n01843383",
    "n01847000",
    "n01855032",
    "n01855672",
    "n01860187",
    "n01871265",
    "n01872401",
    "n01873310",
    "n01877812",
    "n01882714",
    "n01883070",
    "n01910747",
    "n01914609",
    "n01917289",
    "n01924916",
    "n01930112",
    "n01943899",
    "n01944390",
    "n01945685",
    "n01950731",
    "n01955084",
    "n01968897",
    "n01978287",
    "n01978455",
    "n01980166",
    "n01981276",
    "n01983481",
    "n01984695",
    "n01985128",
    "n01986214",
    "n01990800",
    "n02002556",
    "n02002724",
    "n02006656",
    "n02007558",
    "n02009229",
    "n02009912",
    "n02011460",
    "n02012849",
    "n02013706",
    "n02017213",
    "n02018207",
    "n02018795",
    "n02025239",
    "n02027492",
    "n02028035",
    "n02033041",
    "n02037110",
    "n02051845",
    "n02056570",
    "n02058221",
    "n02066245",
    "n02071294",
    "n02074367",
    "n02077923",
    "n02085620",
    "n02085782",
    "n02085936",
    "n02086079",
    "n02086240",
    "n02086646",
    "n02086910",
    "n02087046",
    "n02087394",
    "n02088094",
    "n02088238",
    "n02088364",
    "n02088466",
    "n02088632",
    "n02089078",
    "n02089867",
    "n02089973",
    "n02090379",
    "n02090622",
    "n02090721",
    "n02091032",
    "n02091134",
    "n02091244",
    "n02091467",
    "n02091635",
    "n02091831",
    "n02092002",
    "n02092339",
    "n02093256",
    "n02093428",
    "n02093647",
    "n02093754",
    "n02093859",
    "n02093991",
    "n02094114",
    "n02094258",
    "n02094433",
    "n02095314",
    "n02095570",
    "n02095889",
    "n02096051",
    "n02096177",
    "n02096294",
    "n02096437",
    "n02096585",
    "n02097047",
    "n02097130",
    "n02097209",
    "n02097298",
    "n02097474",
    "n02097658",
    "n02098105",
    "n02098286",
    "n02098413",
    "n02099267",
    "n02099429",
    "n02099601",
    "n02099712",
    "n02099849",
    "n02100236",
    "n02100583",
    "n02100735",
    "n02100877",
    "n02101006",
    "n02101388",
    "n02101556",
    "n02102040",
    "n02102177",
    "n02102318",
    "n02102480",
    "n02102973",
    "n02104029",
    "n02104365",
    "n02105056",
    "n02105162",
    "n02105251",
    "n02105412",
    "n02105505",
    "n02105641",
    "n02105855",
    "n02106030",
    "n02106166",
    "n02106382",
    "n02106550",
    "n02106662",
    "n02107142",
    "n02107312",
    "n02107574",
    "n02107683",
    "n02107908",
    "n02108000",
    "n02108089",
    "n02108422",
    "n02108551",
    "n02108915",
    "n02109047",
    "n02109525",
    "n02109961",
    "n02110063",
    "n02110185",
    "n02110341",
    "n02110627",
    "n02110806",
    "n02110958",
    "n02111129",
    "n02111277",
    "n02111500",
    "n02111889",
    "n02112018",
    "n02112137",
    "n02112350",
    "n02112706",
    "n02113023",
    "n02113186",
    "n02113624",
    "n02113712",
    "n02113799",
    "n02113978",
    "n02114367",
    "n02114548",
    "n02114712",
    "n02114855",
    "n02115641",
    "n02115913",
    "n02116738",
    "n02117135",
    "n02119022",
    "n02119789",
    "n02120079",
    "n02120505",
    "n02123045",
    "n02123159",
    "n02123394",
    "n02123597",
    "n02124075",
    "n02125311",
    "n02127052",
    "n02128385",
    "n02128757",
    "n02128925",
    "n02129165",
    "n02129604",
    "n02130308",
    "n02132136",
    "n02133161",
    "n02134084",
    "n02134418",
    "n02137549",
    "n02138441",
    "n02165105",
    "n02165456",
    "n02167151",
    "n02168699",
    "n02169497",
    "n02172182",
    "n02174001",
    "n02177972",
    "n02190166",
    "n02206856",
    "n02219486",
    "n02226429",
    "n02229544",
    "n02231487",
    "n02233338",
    "n02236044",
    "n02256656",
    "n02259212",
    "n02264363",
    "n02268443",
    "n02268853",
    "n02276258",
    "n02277742",
    "n02279972",
    "n02280649",
    "n02281406",
    "n02281787",
    "n02317335",
    "n02319095",
    "n02321529",
    "n02325366",
    "n02326432",
    "n02328150",
    "n02342885",
    "n02346627",
    "n02356798",
    "n02361337",
    "n02363005",
    "n02364673",
    "n02389026",
    "n02391049",
    "n02395406",
    "n02396427",
    "n02397096",
    "n02398521",
    "n02403003",
    "n02408429",
    "n02410509",
    "n02412080",
    "n02415577",
    "n02417914",
    "n02422106",
    "n02422699",
    "n02423022",
    "n02437312",
    "n02437616",
    "n02441942",
    "n02442845",
    "n02443114",
    "n02443484",
    "n02444819",
    "n02445715",
    "n02447366",
    "n02454379",
    "n02457408",
    "n02480495",
    "n02480855",
    "n02481823",
    "n02483362",
    "n02483708",
    "n02484975",
    "n02486261",
    "n02486410",
    "n02487347",
    "n02488291",
    "n02488702",
    "n02489166",
    "n02490219",
    "n02492035",
    "n02492660",
    "n02493509",
    "n02493793",
    "n02494079",
    "n02497673",
    "n02500267",
    "n02504013",
    "n02504458",
    "n02509815",
    "n02510455",
    "n02514041",
    "n02526121",
    "n02536864",
    "n02606052",
    "n02607072",
    "n02640242",
    "n02641379",
    "n02643566",
    "n02655020",
    "n02666196",
    "n02667093",
    "n02669723",
    "n02672831",
    "n02676566",
    "n02687172",
    "n02690373",
    "n02692877",
    "n02699494",
    "n02701002",
    "n02704792",
    "n02708093",
    "n02727426",
    "n02730930",
    "n02747177",
    "n02749479",
    "n02769748",
    "n02776631",
    "n02777292",
    "n02782093",
    "n02783161",
    "n02786058",
    "n02787622",
    "n02788148",
    "n02790996",
    "n02791124",
    "n02791270",
    "n02793495",
    "n02794156",
    "n02795169",
    "n02797295",
    "n02799071",
    "n02802426",
    "n02804414",
    "n02804610",
    "n02807133",
    "n02808304",
    "n02808440",
    "n02814533",
    "n02814860",
    "n02815834",
    "n02817516",
    "n02823428",
    "n02823750",
    "n02825657",
    "n02834397",
    "n02835271",
    "n02837789",
    "n02840245",
    "n02841315",
    "n02843684",
    "n02859443",
    "n02860847",
    "n02865351",
    "n02869837",
    "n02870880",
    "n02871525",
    "n02877765",
    "n02879718",
    "n02883205",
    "n02892201",
    "n02892767",
    "n02894605",
    "n02895154",
    "n02906734",
    "n02909870",
    "n02910353",
    "n02916936",
    "n02917067",
    "n02927161",
    "n02930766",
    "n02939185",
    "n02948072",
    "n02950826",
    "n02951358",
    "n02951585",
    "n02963159",
    "n02965783",
    "n02966193",
    "n02966687",
    "n02971356",
    "n02974003",
    "n02977058",
    "n02978881",
    "n02979186",
    "n02980441",
    "n02981792",
    "n02988304",
    "n02992211",
    "n02992529",
    "n02999410",
    "n03000134",
    "n03000247",
    "n03000684",
    "n03014705",
    "n03016953",
    "n03017168",
    "n03018349",
    "n03026506",
    "n03028079",
    "n03032252",
    "n03041632",
    "n03042490",
    "n03045698",
    "n03047690",
    "n03062245",
    "n03063599",
    "n03063689",
    "n03065424",
    "n03075370",
    "n03085013",
    "n03089624",
    "n03095699",
    "n03100240",
    "n03109150",
    "n03110669",
    "n03124043",
    "n03124170",
    "n03125729",
    "n03126707",
    "n03127747",
    "n03127925",
    "n03131574",
    "n03133878",
    "n03134739",
    "n03141823",
    "n03146219",
    "n03160309",
    "n03179701",
    "n03180011",
    "n03187595",
    "n03188531",
    "n03196217",
    "n03197337",
    "n03201208",
    "n03207743",
    "n03207941",
    "n03208938",
    "n03216828",
    "n03218198",
    "n03220513",
    "n03223299",
    "n03240683",
    "n03249569",
    "n03250847",
    "n03255030",
    "n03259280",
    "n03271574",
    "n03272010",
    "n03272562",
    "n03290653",
    "n03291819",
    "n03297495",
    "n03314780",
    "n03325584",
    "n03337140",
    "n03344393",
    "n03345487",
    "n03347037",
    "n03355925",
    "n03372029",
    "n03376595",
    "n03379051",
    "n03384352",
    "n03388043",
    "n03388183",
    "n03388549",
    "n03393912",
    "n03394916",
    "n03400231",
    "n03404251",
    "n03417042",
    "n03424325",
    "n03425413",
    "n03443371",
    "n03444034",
    "n03445777",
    "n03445924",
    "n03447447",
    "n03447721",
    "n03450230",
    "n03452741",
    "n03457902",
    "n03459775",
    "n03461385",
    "n03467068",
    "n03476684",
    "n03476991",
    "n03478589",
    "n03481172",
    "n03482405",
    "n03483316",
    "n03485407",
    "n03485794",
    "n03492542",
    "n03494278",
    "n03495258",
    "n03496892",
    "n03498962",
    "n03527444",
    "n03529860",
    "n03530642",
    "n03532672",
    "n03534580",
    "n03535780",
    "n03538406",
    "n03544143",
    "n03584254",
    "n03584829",
    "n03590841",
    "n03594734",
    "n03594945",
    "n03595614",
    "n03598930",
    "n03599486",
    "n03602883",
    "n03617480",
    "n03623198",
    "n03627232",
    "n03630383",
    "n03633091",
    "n03637318",
    "n03642806",
    "n03649909",
    "n03657121",
    "n03658185",
    "n03661043",
    "n03662601",
    "n03666591",
    "n03670208",
    "n03673027",
    "n03676483",
    "n03680355",
    "n03690938",
    "n03691459",
    "n03692522",
    "n03697007",
    "n03706229",
    "n03709823",
    "n03710193",
    "n03710637",
    "n03710721",
    "n03717622",
    "n03720891",
    "n03721384",
    "n03724870",
    "n03729826",
    "n03733131",
    "n03733281",
    "n03733805",
    "n03742115",
    "n03743016",
    "n03759954",
    "n03761084",
    "n03763968",
    "n03764736",
    "n03769881",
    "n03770439",
    "n03770679",
    "n03773504",
    "n03775071",
    "n03775546",
    "n03776460",
    "n03777568",
    "n03777754",
    "n03781244",
    "n03782006",
    "n03785016",
    "n03786901",
    "n03787032",
    "n03788195",
    "n03788365",
    "n03791053",
    "n03792782",
    "n03792972",
    "n03793489",
    "n03794056",
    "n03796401",
    "n03803284",
    "n03804744",
    "n03814639",
    "n03814906",
    "n03825788",
    "n03832673",
    "n03837869",
    "n03838899",
    "n03840681",
    "n03841143",
    "n03843555",
    "n03854065",
    "n03857828",
    "n03866082",
    "n03868242",
    "n03868863",
    "n03871628",
    "n03873416",
    "n03874293",
    "n03874599",
    "n03876231",
    "n03877472",
    "n03877845",
    "n03884397",
    "n03887697",
    "n03888257",
    "n03888605",
    "n03891251",
    "n03891332",
    "n03895866",
    "n03899768",
    "n03902125",
    "n03903868",
    "n03908618",
    "n03908714",
    "n03916031",
    "n03920288",
    "n03924679",
    "n03929660",
    "n03929855",
    "n03930313",
    "n03930630",
    "n03933933",
    "n03935335",
    "n03937543",
    "n03938244",
    "n03942813",
    "n03944341",
    "n03947888",
    "n03950228",
    "n03954731",
    "n03956157",
    "n03958227",
    "n03961711",
    "n03967562",
    "n03970156",
    "n03976467",
    "n03976657",
    "n03977966",
    "n03980874",
    "n03982430",
    "n03983396",
    "n03991062",
    "n03992509",
    "n03995372",
    "n03998194",
    "n04004767",
    "n04005630",
    "n04008634",
    "n04009552",
    "n04019541",
    "n04023962",
    "n04026417",
    "n04033901",
    "n04033995",
    "n04037443",
    "n04039381",
    "n04040759",
    "n04041544",
    "n04044716",
    "n04049303",
    "n04065272",
    "n04067472",
    "n04069434",
    "n04070727",
    "n04074963",
    "n04081281",
    "n04086273",
    "n04090263",
    "n04099969",
    "n04111531",
    "n04116512",
    "n04118538",
    "n04118776",
    "n04120489",
    "n04125021",
    "n04127249",
    "n04131690",
    "n04133789",
    "n04136333",
    "n04141076",
    "n04141327",
    "n04141975",
    "n04146614",
    "n04147183",
    "n04149813",
    "n04152593",
    "n04153751",
    "n04154565",
    "n04162706",
    "n04179913",
    "n04192698",
    "n04200800",
    "n04201297",
    "n04204238",
    "n04204347",
    "n04208210",
    "n04209133",
    "n04209239",
    "n04228054",
    "n04229816",
    "n04235860",
    "n04238763",
    "n04239074",
    "n04243546",
    "n04251144",
    "n04252077",
    "n04252225",
    "n04254120",
    "n04254680",
    "n04254777",
    "n04258138",
    "n04259630",
    "n04263257",
    "n04264628",
    "n04265275",
    "n04266014",
    "n04270147",
    "n04273569",
    "n04275548",
    "n04277352",
    "n04285008",
    "n04286575",
    "n04296562",
    "n04310018",
    "n04311004",
    "n04311174",
    "n04317175",
    "n04325704",
    "n04326547",
    "n04328186",
    "n04330267",
    "n04332243",
    "n04335435",
    "n04336792",
    "n04344873",
    "n04346328",
    "n04347754",
    "n04350905",
    "n04355338",
    "n04355933",
    "n04356056",
    "n04357314",
    "n04366367",
    "n04367480",
    "n04370456",
    "n04371430",
    "n04371774",
    "n04372370",
    "n04376876",
    "n04380533",
    "n04389033",
    "n04392985",
    "n04398044",
    "n04399382",
    "n04404412",
    "n04409515",
    "n04417672",
    "n04418357",
    "n04423845",
    "n04428191",
    "n04429376",
    "n04435653",
    "n04442312",
    "n04443257",
    "n04447861",
    "n04456115",
    "n04458633",
    "n04461696",
    "n04462240",
    "n04465501",
    "n04467665",
    "n04476259",
    "n04479046",
    "n04482393",
    "n04483307",
    "n04485082",
    "n04486054",
    "n04487081",
    "n04487394",
    "n04493381",
    "n04501370",
    "n04505470",
    "n04507155",
    "n04509417",
    "n04515003",
    "n04517823",
    "n04522168",
    "n04523525",
    "n04525038",
    "n04525305",
    "n04532106",
    "n04532670",
    "n04536866",
    "n04540053",
    "n04542943",
    "n04548280",
    "n04548362",
    "n04550184",
    "n04552348",
    "n04553703",
    "n04554684",
    "n04557648",
    "n04560804",
    "n04562935",
    "n04579145",
    "n04579432",
    "n04584207",
    "n04589890",
    "n04590129",
    "n04591157",
    "n04591713",
    "n04592741",
    "n04596742",
    "n04597913",
    "n04599235",
    "n04604644",
    "n04606251",
    "n04612504",
    "n04613696",
    "n06359193",
    "n06596364",
    "n06785654",
    "n06794110",
    "n06874185",
    "n07248320",
    "n07565083",
    "n07579787",
    "n07583066",
    "n07584110",
    "n07590611",
    "n07613480",
    "n07614500",
    "n07615774",
    "n07684084",
    "n07693725",
    "n07695742",
    "n07697313",
    "n07697537",
    "n07711569",
    "n07714571",
    "n07714990",
    "n07715103",
    "n07716358",
    "n07716906",
    "n07717410",
    "n07717556",
    "n07718472",
    "n07718747",
    "n07720875",
    "n07730033",
    "n07734744",
    "n07742313",
    "n07745940",
    "n07747607",
    "n07749582",
    "n07753113",
    "n07753275",
    "n07753592",
    "n07754684",
    "n07760859",
    "n07768694",
    "n07802026",
    "n07831146",
    "n07836838",
    "n07860988",
    "n07871810",
    "n07873807",
    "n07875152",
    "n07880968",
    "n07892512",
    "n07920052",
    "n07930864",
    "n07932039",
    "n09193705",
    "n09229709",
    "n09246464",
    "n09256479",
    "n09288635",
    "n09332890",
    "n09399592",
    "n09421951",
    "n09428293",
    "n09468604",
    "n09472597",
    "n09835506",
    "n10148035",
    "n10565667",
    "n11879895",
    "n11939491",
    "n12057211",
    "n12144580",
    "n12267677",
    "n12620546",
    "n12768682",
    "n12985857",
    "n12998815",
    "n13037406",
    "n13040303",
    "n13044778",
    "n13052670",
    "n13054560",
    "n13133613",
    "n15075141",
]

IMAGENET_TORCHVISION_WNID_TO_IDX: Dict[str, int] = {
    cls_name: i for i, cls_name in enumerate(IMAGENET_TORCHVISION_WNIDS)
}

IMAGENET_TORCHVISION_CLASSES: List[Tuple[str, ...]] = [
    ("tench", "Tinca tinca"),
    ("goldfish", "Carassius auratus"),
    (
        "great white shark",
        "white shark",
        "man-eater",
        "man-eating shark",
        "Carcharodon carcharias",
    ),
    ("tiger shark", "Galeocerdo cuvieri"),
    ("hammerhead", "hammerhead shark"),
    ("electric ray", "crampfish", "numbfish", "torpedo"),
    ("stingray",),
    ("cock",),
    ("hen",),
    ("ostrich", "Struthio camelus"),
    ("brambling", "Fringilla montifringilla"),
    ("goldfinch", "Carduelis carduelis"),
    ("house finch", "linnet", "Carpodacus mexicanus"),
    ("junco", "snowbird"),
    ("indigo bunting", "indigo finch", "indigo bird", "Passerina cyanea"),
    ("robin", "American robin", "Turdus migratorius"),
    ("bulbul",),
    ("jay",),
    ("magpie",),
    ("chickadee",),
    ("water ouzel", "dipper"),
    ("kite",),
    ("bald eagle", "American eagle", "Haliaeetus leucocephalus"),
    ("vulture",),
    ("great grey owl", "great gray owl", "Strix nebulosa"),
    ("European fire salamander", "Salamandra salamandra"),
    ("common newt", "Triturus vulgaris"),
    ("eft",),
    ("spotted salamander", "Ambystoma maculatum"),
    ("axolotl", "mud puppy", "Ambystoma mexicanum"),
    ("bullfrog", "Rana catesbeiana"),
    ("tree frog", "tree-frog"),
    ("tailed frog", "bell toad", "ribbed toad", "tailed toad", "Ascaphus trui"),
    ("loggerhead", "loggerhead turtle", "Caretta caretta"),
    (
        "leatherback turtle",
        "leatherback",
        "leathery turtle",
        "Dermochelys coriacea",
    ),
    ("mud turtle",),
    ("terrapin",),
    ("box turtle", "box tortoise"),
    ("banded gecko",),
    ("common iguana", "iguana", "Iguana iguana"),
    ("American chameleon", "anole", "Anolis carolinensis"),
    ("whiptail", "whiptail lizard"),
    ("agama",),
    ("frilled lizard", "Chlamydosaurus kingi"),
    ("alligator lizard",),
    ("Gila monster", "Heloderma suspectum"),
    ("green lizard", "Lacerta viridis"),
    ("African chameleon", "Chamaeleo chamaeleon"),
    (
        "Komodo dragon",
        "Komodo lizard",
        "dragon lizard",
        "giant lizard",
        "Varanus komodoensis",
    ),
    ("African crocodile", "Nile crocodile", "Crocodylus niloticus"),
    ("American alligator", "Alligator mississipiensis"),
    ("triceratops",),
    ("thunder snake", "worm snake", "Carphophis amoenus"),
    ("ringneck snake", "ring-necked snake", "ring snake"),
    ("hognose snake", "puff adder", "sand viper"),
    ("green snake", "grass snake"),
    ("king snake", "kingsnake"),
    ("garter snake", "grass snake"),
    ("water snake",),
    ("vine snake",),
    ("night snake", "Hypsiglena torquata"),
    ("boa constrictor", "Constrictor constrictor"),
    ("rock python", "rock snake", "Python sebae"),
    ("Indian cobra", "Naja naja"),
    ("green mamba",),
    ("sea snake",),
    (
        "horned viper",
        "cerastes",
        "sand viper",
        "horned asp",
        "Cerastes cornutus",
    ),
    ("diamondback", "diamondback rattlesnake", "Crotalus adamanteus"),
    ("sidewinder", "horned rattlesnake", "Crotalus cerastes"),
    ("trilobite",),
    ("harvestman", "daddy longlegs", "Phalangium opilio"),
    ("scorpion",),
    ("black and gold garden spider", "Argiope aurantia"),
    ("barn spider", "Araneus cavaticus"),
    ("garden spider", "Aranea diademata"),
    ("black widow", "Latrodectus mactans"),
    ("tarantula",),
    ("wolf spider", "hunting spider"),
    ("tick",),
    ("centipede",),
    ("black grouse",),
    ("ptarmigan",),
    ("ruffed grouse", "partridge", "Bonasa umbellus"),
    ("prairie chicken", "prairie grouse", "prairie fowl"),
    ("peacock",),
    ("quail",),
    ("partridge",),
    ("African grey", "African gray", "Psittacus erithacus"),
    ("macaw",),
    ("sulphur-crested cockatoo", "Kakatoe galerita", "Cacatua galerita"),
    ("lorikeet",),
    ("coucal",),
    ("bee eater",),
    ("hornbill",),
    ("hummingbird",),
    ("jacamar",),
    ("toucan",),
    ("drake",),
    ("red-breasted merganser", "Mergus serrator"),
    ("goose",),
    ("black swan", "Cygnus atratus"),
    ("tusker",),
    ("echidna", "spiny anteater", "anteater"),
    (
        "platypus",
        "duckbill",
        "duckbilled platypus",
        "duck-billed platypus",
        "Ornithorhynchus anatinus",
    ),
    ("wallaby", "brush kangaroo"),
    (
        "koala",
        "koala bear",
        "kangaroo bear",
        "native bear",
        "Phascolarctos cinereus",
    ),
    ("wombat",),
    ("jellyfish",),
    ("sea anemone", "anemone"),
    ("brain coral",),
    ("flatworm", "platyhelminth"),
    ("nematode", "nematode worm", "roundworm"),
    ("conch",),
    ("snail",),
    ("slug",),
    ("sea slug", "nudibranch"),
    ("chiton", "coat-of-mail shell", "sea cradle", "polyplacophore"),
    ("chambered nautilus", "pearly nautilus", "nautilus"),
    ("Dungeness crab", "Cancer magister"),
    ("rock crab", "Cancer irroratus"),
    ("fiddler crab",),
    (
        "king crab",
        "Alaska crab",
        "Alaskan king crab",
        "Alaska king crab",
        "Paralithodes camtschatica",
    ),
    (
        "American lobster",
        "Northern lobster",
        "Maine lobster",
        "Homarus americanus",
    ),
    (
        "spiny lobster",
        "langouste",
        "rock lobster",
        "crawfish",
        "crayfish",
        "sea crawfish",
    ),
    ("crayfish", "crawfish", "crawdad", "crawdaddy"),
    ("hermit crab",),
    ("isopod",),
    ("white stork", "Ciconia ciconia"),
    ("black stork", "Ciconia nigra"),
    ("spoonbill",),
    ("flamingo",),
    ("little blue heron", "Egretta caerulea"),
    ("American egret", "great white heron", "Egretta albus"),
    ("bittern",),
    ("crane",),
    ("limpkin", "Aramus pictus"),
    ("European gallinule", "Porphyrio porphyrio"),
    ("American coot", "marsh hen", "mud hen", "water hen", "Fulica americana"),
    ("bustard",),
    ("ruddy turnstone", "Arenaria interpres"),
    ("red-backed sandpiper", "dunlin", "Erolia alpina"),
    ("redshank", "Tringa totanus"),
    ("dowitcher",),
    ("oystercatcher", "oyster catcher"),
    ("pelican",),
    ("king penguin", "Aptenodytes patagonica"),
    ("albatross", "mollymawk"),
    (
        "grey whale",
        "gray whale",
        "devilfish",
        "Eschrichtius gibbosus",
        "Eschrichtius robustus",
    ),
    ("killer whale", "killer", "orca", "grampus", "sea wolf", "Orcinus orca"),
    ("dugong", "Dugong dugon"),
    ("sea lion",),
    ("Chihuahua",),
    ("Japanese spaniel",),
    ("Maltese dog", "Maltese terrier", "Maltese"),
    ("Pekinese", "Pekingese", "Peke"),
    ("Shih-Tzu",),
    ("Blenheim spaniel",),
    ("papillon",),
    ("toy terrier",),
    ("Rhodesian ridgeback",),
    ("Afghan hound", "Afghan"),
    ("basset", "basset hound"),
    ("beagle",),
    ("bloodhound", "sleuthhound"),
    ("bluetick",),
    ("black-and-tan coonhound",),
    ("Walker hound", "Walker foxhound"),
    ("English foxhound",),
    ("redbone",),
    ("borzoi", "Russian wolfhound"),
    ("Irish wolfhound",),
    ("Italian greyhound",),
    ("whippet",),
    ("Ibizan hound", "Ibizan Podenco"),
    ("Norwegian elkhound", "elkhound"),
    ("otterhound", "otter hound"),
    ("Saluki", "gazelle hound"),
    ("Scottish deerhound", "deerhound"),
    ("Weimaraner",),
    ("Staffordshire bullterrier", "Staffordshire bull terrier"),
    (
        "American Staffordshire terrier",
        "Staffordshire terrier",
        "American pit bull terrier",
        "pit bull terrier",
    ),
    ("Bedlington terrier",),
    ("Border terrier",),
    ("Kerry blue terrier",),
    ("Irish terrier",),
    ("Norfolk terrier",),
    ("Norwich terrier",),
    ("Yorkshire terrier",),
    ("wire-haired fox terrier",),
    ("Lakeland terrier",),
    ("Sealyham terrier", "Sealyham"),
    ("Airedale", "Airedale terrier"),
    ("cairn", "cairn terrier"),
    ("Australian terrier",),
    ("Dandie Dinmont", "Dandie Dinmont terrier"),
    ("Boston bull", "Boston terrier"),
    ("miniature schnauzer",),
    ("giant schnauzer",),
    ("standard schnauzer",),
    ("Scotch terrier", "Scottish terrier", "Scottie"),
    ("Tibetan terrier", "chrysanthemum dog"),
    ("silky terrier", "Sydney silky"),
    ("soft-coated wheaten terrier",),
    ("West Highland white terrier",),
    ("Lhasa", "Lhasa apso"),
    ("flat-coated retriever",),
    ("curly-coated retriever",),
    ("golden retriever",),
    ("Labrador retriever",),
    ("Chesapeake Bay retriever",),
    ("German short-haired pointer",),
    ("vizsla", "Hungarian pointer"),
    ("English setter",),
    ("Irish setter", "red setter"),
    ("Gordon setter",),
    ("Brittany spaniel",),
    ("clumber", "clumber spaniel"),
    ("English springer", "English springer spaniel"),
    ("Welsh springer spaniel",),
    ("cocker spaniel", "English cocker spaniel", "cocker"),
    ("Sussex spaniel",),
    ("Irish water spaniel",),
    ("kuvasz",),
    ("schipperke",),
    ("groenendael",),
    ("malinois",),
    ("briard",),
    ("kelpie",),
    ("komondor",),
    ("Old English sheepdog", "bobtail"),
    ("Shetland sheepdog", "Shetland sheep dog", "Shetland"),
    ("collie",),
    ("Border collie",),
    ("Bouvier des Flandres", "Bouviers des Flandres"),
    ("Rottweiler",),
    ("German shepherd", "German shepherd dog", "German police dog", "alsatian"),
    ("Doberman", "Doberman pinscher"),
    ("miniature pinscher",),
    ("Greater Swiss Mountain dog",),
    ("Bernese mountain dog",),
    ("Appenzeller",),
    ("EntleBucher",),
    ("boxer",),
    ("bull mastiff",),
    ("Tibetan mastiff",),
    ("French bulldog",),
    ("Great Dane",),
    ("Saint Bernard", "St Bernard"),
    ("Eskimo dog", "husky"),
    ("malamute", "malemute", "Alaskan malamute"),
    ("Siberian husky",),
    ("dalmatian", "coach dog", "carriage dog"),
    ("affenpinscher", "monkey pinscher", "monkey dog"),
    ("basenji",),
    ("pug", "pug-dog"),
    ("Leonberg",),
    ("Newfoundland", "Newfoundland dog"),
    ("Great Pyrenees",),
    ("Samoyed", "Samoyede"),
    ("Pomeranian",),
    ("chow", "chow chow"),
    ("keeshond",),
    ("Brabancon griffon",),
    ("Pembroke", "Pembroke Welsh corgi"),
    ("Cardigan", "Cardigan Welsh corgi"),
    ("toy poodle",),
    ("miniature poodle",),
    ("standard poodle",),
    ("Mexican hairless",),
    ("timber wolf", "grey wolf", "gray wolf", "Canis lupus"),
    ("white wolf", "Arctic wolf", "Canis lupus tundrarum"),
    ("red wolf", "maned wolf", "Canis rufus", "Canis niger"),
    ("coyote", "prairie wolf", "brush wolf", "Canis latrans"),
    ("dingo", "warrigal", "warragal", "Canis dingo"),
    ("dhole", "Cuon alpinus"),
    ("African hunting dog", "hyena dog", "Cape hunting dog", "Lycaon pictus"),
    ("hyena", "hyaena"),
    ("red fox", "Vulpes vulpes"),
    ("kit fox", "Vulpes macrotis"),
    ("Arctic fox", "white fox", "Alopex lagopus"),
    ("grey fox", "gray fox", "Urocyon cinereoargenteus"),
    ("tabby", "tabby cat"),
    ("tiger cat",),
    ("Persian cat",),
    ("Siamese cat", "Siamese"),
    ("Egyptian cat",),
    (
        "cougar",
        "puma",
        "catamount",
        "mountain lion",
        "painter",
        "panther",
        "Felis concolor",
    ),
    ("lynx", "catamount"),
    ("leopard", "Panthera pardus"),
    ("snow leopard", "ounce", "Panthera uncia"),
    ("jaguar", "panther", "Panthera onca", "Felis onca"),
    ("lion", "king of beasts", "Panthera leo"),
    ("tiger", "Panthera tigris"),
    ("cheetah", "chetah", "Acinonyx jubatus"),
    ("brown bear", "bruin", "Ursus arctos"),
    (
        "American black bear",
        "black bear",
        "Ursus americanus",
        "Euarctos americanus",
    ),
    ("ice bear", "polar bear", "Ursus Maritimus", "Thalarctos maritimus"),
    ("sloth bear", "Melursus ursinus", "Ursus ursinus"),
    ("mongoose",),
    ("meerkat", "mierkat"),
    ("tiger beetle",),
    ("ladybug", "ladybeetle", "lady beetle", "ladybird", "ladybird beetle"),
    ("ground beetle", "carabid beetle"),
    ("long-horned beetle", "longicorn", "longicorn beetle"),
    ("leaf beetle", "chrysomelid"),
    ("dung beetle",),
    ("rhinoceros beetle",),
    ("weevil",),
    ("fly",),
    ("bee",),
    ("ant", "emmet", "pismire"),
    ("grasshopper", "hopper"),
    ("cricket",),
    ("walking stick", "walkingstick", "stick insect"),
    ("cockroach", "roach"),
    ("mantis", "mantid"),
    ("cicada", "cicala"),
    ("leafhopper",),
    ("lacewing", "lacewing fly"),
    (
        "dragonfly",
        "darning needle",
        "devil's darning needle",
        "sewing needle",
        "snake feeder",
        "snake doctor",
        "mosquito hawk",
        "skeeter hawk",
    ),
    ("damselfly",),
    ("admiral",),
    ("ringlet", "ringlet butterfly"),
    ("monarch", "monarch butterfly", "milkweed butterfly", "Danaus plexippus"),
    ("cabbage butterfly",),
    ("sulphur butterfly", "sulfur butterfly"),
    ("lycaenid", "lycaenid butterfly"),
    ("starfish", "sea star"),
    ("sea urchin",),
    ("sea cucumber", "holothurian"),
    ("wood rabbit", "cottontail", "cottontail rabbit"),
    ("hare",),
    ("Angora", "Angora rabbit"),
    ("hamster",),
    ("porcupine", "hedgehog"),
    ("fox squirrel", "eastern fox squirrel", "Sciurus niger"),
    ("marmot",),
    ("beaver",),
    ("guinea pig", "Cavia cobaya"),
    ("sorrel",),
    ("zebra",),
    ("hog", "pig", "grunter", "squealer", "Sus scrofa"),
    ("wild boar", "boar", "Sus scrofa"),
    ("warthog",),
    ("hippopotamus", "hippo", "river horse", "Hippopotamus amphibius"),
    ("ox",),
    ("water buffalo", "water ox", "Asiatic buffalo", "Bubalus bubalis"),
    ("bison",),
    ("ram", "tup"),
    (
        "bighorn",
        "bighorn sheep",
        "cimarron",
        "Rocky Mountain bighorn",
        "Rocky Mountain sheep",
        "Ovis canadensis",
    ),
    ("ibex", "Capra ibex"),
    ("hartebeest",),
    ("impala", "Aepyceros melampus"),
    ("gazelle",),
    ("Arabian camel", "dromedary", "Camelus dromedarius"),
    ("llama",),
    ("weasel",),
    ("mink",),
    ("polecat", "fitch", "foulmart", "foumart", "Mustela putorius"),
    ("black-footed ferret", "ferret", "Mustela nigripes"),
    ("otter",),
    ("skunk", "polecat", "wood pussy"),
    ("badger",),
    ("armadillo",),
    ("three-toed sloth", "ai", "Bradypus tridactylus"),
    ("orangutan", "orang", "orangutang", "Pongo pygmaeus"),
    ("gorilla", "Gorilla gorilla"),
    ("chimpanzee", "chimp", "Pan troglodytes"),
    ("gibbon", "Hylobates lar"),
    ("siamang", "Hylobates syndactylus", "Symphalangus syndactylus"),
    ("guenon", "guenon monkey"),
    ("patas", "hussar monkey", "Erythrocebus patas"),
    ("baboon",),
    ("macaque",),
    ("langur",),
    ("colobus", "colobus monkey"),
    ("proboscis monkey", "Nasalis larvatus"),
    ("marmoset",),
    ("capuchin", "ringtail", "Cebus capucinus"),
    ("howler monkey", "howler"),
    ("titi", "titi monkey"),
    ("spider monkey", "Ateles geoffroyi"),
    ("squirrel monkey", "Saimiri sciureus"),
    ("Madagascar cat", "ring-tailed lemur", "Lemur catta"),
    ("indri", "indris", "Indri indri", "Indri brevicaudatus"),
    ("Indian elephant", "Elephas maximus"),
    ("African elephant", "Loxodonta africana"),
    (
        "lesser panda",
        "red panda",
        "panda",
        "bear cat",
        "cat bear",
        "Ailurus fulgens",
    ),
    (
        "giant panda",
        "panda",
        "panda bear",
        "coon bear",
        "Ailuropoda melanoleuca",
    ),
    ("barracouta", "snoek"),
    ("eel",),
    (
        "coho",
        "cohoe",
        "coho salmon",
        "blue jack",
        "silver salmon",
        "Oncorhynchus kisutch",
    ),
    ("rock beauty", "Holocanthus tricolor"),
    ("anemone fish",),
    ("sturgeon",),
    ("gar", "garfish", "garpike", "billfish", "Lepisosteus osseus"),
    ("lionfish",),
    ("puffer", "pufferfish", "blowfish", "globefish"),
    ("abacus",),
    ("abaya",),
    ("academic gown", "academic robe", "judge's robe"),
    ("accordion", "piano accordion", "squeeze box"),
    ("acoustic guitar",),
    ("aircraft carrier", "carrier", "flattop", "attack aircraft carrier"),
    ("airliner",),
    ("airship", "dirigible"),
    ("altar",),
    ("ambulance",),
    ("amphibian", "amphibious vehicle"),
    ("analog clock",),
    ("apiary", "bee house"),
    ("apron",),
    (
        "ashcan",
        "trash can",
        "garbage can",
        "wastebin",
        "ash bin",
        "ash-bin",
        "ashbin",
        "dustbin",
        "trash barrel",
        "trash bin",
    ),
    ("assault rifle", "assault gun"),
    ("backpack", "back pack", "knapsack", "packsack", "rucksack", "haversack"),
    ("bakery", "bakeshop", "bakehouse"),
    ("balance beam", "beam"),
    ("balloon",),
    ("ballpoint", "ballpoint pen", "ballpen", "Biro"),
    ("Band Aid",),
    ("banjo",),
    ("bannister", "banister", "balustrade", "balusters", "handrail"),
    ("barbell",),
    ("barber chair",),
    ("barbershop",),
    ("barn",),
    ("barometer",),
    ("barrel", "cask"),
    ("barrow", "garden cart", "lawn cart", "wheelbarrow"),
    ("baseball",),
    ("basketball",),
    ("bassinet",),
    ("bassoon",),
    ("bathing cap", "swimming cap"),
    ("bath towel",),
    ("bathtub", "bathing tub", "bath", "tub"),
    (
        "beach wagon",
        "station wagon",
        "wagon",
        "estate car",
        "beach waggon",
        "station waggon",
        "waggon",
    ),
    ("beacon", "lighthouse", "beacon light", "pharos"),
    ("beaker",),
    ("bearskin", "busby", "shako"),
    ("beer bottle",),
    ("beer glass",),
    ("bell cote", "bell cot"),
    ("bib",),
    ("bicycle-built-for-two", "tandem bicycle", "tandem"),
    ("bikini", "two-piece"),
    ("binder", "ring-binder"),
    ("binoculars", "field glasses", "opera glasses"),
    ("birdhouse",),
    ("boathouse",),
    ("bobsled", "bobsleigh", "bob"),
    ("bolo tie", "bolo", "bola tie", "bola"),
    ("bonnet", "poke bonnet"),
    ("bookcase",),
    ("bookshop", "bookstore", "bookstall"),
    ("bottlecap",),
    ("bow",),
    ("bow tie", "bow-tie", "bowtie"),
    ("brass", "memorial tablet", "plaque"),
    ("brassiere", "bra", "bandeau"),
    ("breakwater", "groin", "groyne", "mole", "bulwark", "seawall", "jetty"),
    ("breastplate", "aegis", "egis"),
    ("broom",),
    ("bucket", "pail"),
    ("buckle",),
    ("bulletproof vest",),
    ("bullet train", "bullet"),
    ("butcher shop", "meat market"),
    ("cab", "hack", "taxi", "taxicab"),
    ("caldron", "cauldron"),
    ("candle", "taper", "wax light"),
    ("cannon",),
    ("canoe",),
    ("can opener", "tin opener"),
    ("cardigan",),
    ("car mirror",),
    ("carousel", "carrousel", "merry-go-round", "roundabout", "whirligig"),
    ("carpenter's kit", "tool kit"),
    ("carton",),
    ("car wheel",),
    (
        "cash machine",
        "cash dispenser",
        "automated teller machine",
        "automatic teller machine",
        "automated teller",
        "automatic teller",
        "ATM",
    ),
    ("cassette",),
    ("cassette player",),
    ("castle",),
    ("catamaran",),
    ("CD player",),
    ("cello", "violoncello"),
    (
        "cellular telephone",
        "cellular phone",
        "cellphone",
        "cell",
        "mobile phone",
    ),
    ("chain",),
    ("chainlink fence",),
    (
        "chain mail",
        "ring mail",
        "mail",
        "chain armor",
        "chain armour",
        "ring armor",
        "ring armour",
    ),
    ("chain saw", "chainsaw"),
    ("chest",),
    ("chiffonier", "commode"),
    ("chime", "bell", "gong"),
    ("china cabinet", "china closet"),
    ("Christmas stocking",),
    ("church", "church building"),
    (
        "cinema",
        "movie theater",
        "movie theatre",
        "movie house",
        "picture palace",
    ),
    ("cleaver", "meat cleaver", "chopper"),
    ("cliff dwelling",),
    ("cloak",),
    ("clog", "geta", "patten", "sabot"),
    ("cocktail shaker",),
    ("coffee mug",),
    ("coffeepot",),
    ("coil", "spiral", "volute", "whorl", "helix"),
    ("combination lock",),
    ("computer keyboard", "keypad"),
    ("confectionery", "confectionary", "candy store"),
    ("container ship", "containership", "container vessel"),
    ("convertible",),
    ("corkscrew", "bottle screw"),
    ("cornet", "horn", "trumpet", "trump"),
    ("cowboy boot",),
    ("cowboy hat", "ten-gallon hat"),
    ("cradle",),
    ("crane",),
    ("crash helmet",),
    ("crate",),
    ("crib", "cot"),
    ("Crock Pot",),
    ("croquet ball",),
    ("crutch",),
    ("cuirass",),
    ("dam", "dike", "dyke"),
    ("desk",),
    ("desktop computer",),
    ("dial telephone", "dial phone"),
    ("diaper", "nappy", "napkin"),
    ("digital clock",),
    ("digital watch",),
    ("dining table", "board"),
    ("dishrag", "dishcloth"),
    ("dishwasher", "dish washer", "dishwashing machine"),
    ("disk brake", "disc brake"),
    ("dock", "dockage", "docking facility"),
    ("dogsled", "dog sled", "dog sleigh"),
    ("dome",),
    ("doormat", "welcome mat"),
    ("drilling platform", "offshore rig"),
    ("drum", "membranophone", "tympan"),
    ("drumstick",),
    ("dumbbell",),
    ("Dutch oven",),
    ("electric fan", "blower"),
    ("electric guitar",),
    ("electric locomotive",),
    ("entertainment center",),
    ("envelope",),
    ("espresso maker",),
    ("face powder",),
    ("feather boa", "boa"),
    ("file", "file cabinet", "filing cabinet"),
    ("fireboat",),
    ("fire engine", "fire truck"),
    ("fire screen", "fireguard"),
    ("flagpole", "flagstaff"),
    ("flute", "transverse flute"),
    ("folding chair",),
    ("football helmet",),
    ("forklift",),
    ("fountain",),
    ("fountain pen",),
    ("four-poster",),
    ("freight car",),
    ("French horn", "horn"),
    ("frying pan", "frypan", "skillet"),
    ("fur coat",),
    ("garbage truck", "dustcart"),
    ("gasmask", "respirator", "gas helmet"),
    ("gas pump", "gasoline pump", "petrol pump", "island dispenser"),
    ("goblet",),
    ("go-kart",),
    ("golf ball",),
    ("golfcart", "golf cart"),
    ("gondola",),
    ("gong", "tam-tam"),
    ("gown",),
    ("grand piano", "grand"),
    ("greenhouse", "nursery", "glasshouse"),
    ("grille", "radiator grille"),
    ("grocery store", "grocery", "food market", "market"),
    ("guillotine",),
    ("hair slide",),
    ("hair spray",),
    ("half track",),
    ("hammer",),
    ("hamper",),
    ("hand blower", "blow dryer", "blow drier", "hair dryer", "hair drier"),
    ("hand-held computer", "hand-held microcomputer"),
    ("handkerchief", "hankie", "hanky", "hankey"),
    ("hard disc", "hard disk", "fixed disk"),
    ("harmonica", "mouth organ", "harp", "mouth harp"),
    ("harp",),
    ("harvester", "reaper"),
    ("hatchet",),
    ("holster",),
    ("home theater", "home theatre"),
    ("honeycomb",),
    ("hook", "claw"),
    ("hoopskirt", "crinoline"),
    ("horizontal bar", "high bar"),
    ("horse cart", "horse-cart"),
    ("hourglass",),
    ("iPod",),
    ("iron", "smoothing iron"),
    ("jack-o'-lantern",),
    ("jean", "blue jean", "denim"),
    ("jeep", "landrover"),
    ("jersey", "T-shirt", "tee shirt"),
    ("jigsaw puzzle",),
    ("jinrikisha", "ricksha", "rickshaw"),
    ("joystick",),
    ("kimono",),
    ("knee pad",),
    ("knot",),
    ("lab coat", "laboratory coat"),
    ("ladle",),
    ("lampshade", "lamp shade"),
    ("laptop", "laptop computer"),
    ("lawn mower", "mower"),
    ("lens cap", "lens cover"),
    ("letter opener", "paper knife", "paperknife"),
    ("library",),
    ("lifeboat",),
    ("lighter", "light", "igniter", "ignitor"),
    ("limousine", "limo"),
    ("liner", "ocean liner"),
    ("lipstick", "lip rouge"),
    ("Loafer",),
    ("lotion",),
    (
        "loudspeaker",
        "speaker",
        "speaker unit",
        "loudspeaker system",
        "speaker system",
    ),
    ("loupe", "jeweler's loupe"),
    ("lumbermill", "sawmill"),
    ("magnetic compass",),
    ("mailbag", "postbag"),
    ("mailbox", "letter box"),
    ("maillot",),
    ("maillot", "tank suit"),
    ("manhole cover",),
    ("maraca",),
    ("marimba", "xylophone"),
    ("mask",),
    ("matchstick",),
    ("maypole",),
    ("maze", "labyrinth"),
    ("measuring cup",),
    ("medicine chest", "medicine cabinet"),
    ("megalith", "megalithic structure"),
    ("microphone", "mike"),
    ("microwave", "microwave oven"),
    ("military uniform",),
    ("milk can",),
    ("minibus",),
    ("miniskirt", "mini"),
    ("minivan",),
    ("missile",),
    ("mitten",),
    ("mixing bowl",),
    ("mobile home", "manufactured home"),
    ("Model T",),
    ("modem",),
    ("monastery",),
    ("monitor",),
    ("moped",),
    ("mortar",),
    ("mortarboard",),
    ("mosque",),
    ("mosquito net",),
    ("motor scooter", "scooter"),
    ("mountain bike", "all-terrain bike", "off-roader"),
    ("mountain tent",),
    ("mouse", "computer mouse"),
    ("mousetrap",),
    ("moving van",),
    ("muzzle",),
    ("nail",),
    ("neck brace",),
    ("necklace",),
    ("nipple",),
    ("notebook", "notebook computer"),
    ("obelisk",),
    ("oboe", "hautboy", "hautbois"),
    ("ocarina", "sweet potato"),
    ("odometer", "hodometer", "mileometer", "milometer"),
    ("oil filter",),
    ("organ", "pipe organ"),
    ("oscilloscope", "scope", "cathode-ray oscilloscope", "CRO"),
    ("overskirt",),
    ("oxcart",),
    ("oxygen mask",),
    ("packet",),
    ("paddle", "boat paddle"),
    ("paddlewheel", "paddle wheel"),
    ("padlock",),
    ("paintbrush",),
    ("pajama", "pyjama", "pj's", "jammies"),
    ("palace",),
    ("panpipe", "pandean pipe", "syrinx"),
    ("paper towel",),
    ("parachute", "chute"),
    ("parallel bars", "bars"),
    ("park bench",),
    ("parking meter",),
    ("passenger car", "coach", "carriage"),
    ("patio", "terrace"),
    ("pay-phone", "pay-station"),
    ("pedestal", "plinth", "footstall"),
    ("pencil box", "pencil case"),
    ("pencil sharpener",),
    ("perfume", "essence"),
    ("Petri dish",),
    ("photocopier",),
    ("pick", "plectrum", "plectron"),
    ("pickelhaube",),
    ("picket fence", "paling"),
    ("pickup", "pickup truck"),
    ("pier",),
    ("piggy bank", "penny bank"),
    ("pill bottle",),
    ("pillow",),
    ("ping-pong ball",),
    ("pinwheel",),
    ("pirate", "pirate ship"),
    ("pitcher", "ewer"),
    ("plane", "carpenter's plane", "woodworking plane"),
    ("planetarium",),
    ("plastic bag",),
    ("plate rack",),
    ("plow", "plough"),
    ("plunger", "plumber's helper"),
    ("Polaroid camera", "Polaroid Land camera"),
    ("pole",),
    (
        "police van",
        "police wagon",
        "paddy wagon",
        "patrol wagon",
        "wagon",
        "black Maria",
    ),
    ("poncho",),
    ("pool table", "billiard table", "snooker table"),
    ("pop bottle", "soda bottle"),
    ("pot", "flowerpot"),
    ("potter's wheel",),
    ("power drill",),
    ("prayer rug", "prayer mat"),
    ("printer",),
    ("prison", "prison house"),
    ("projectile", "missile"),
    ("projector",),
    ("puck", "hockey puck"),
    ("punching bag", "punch bag", "punching ball", "punchball"),
    ("purse",),
    ("quill", "quill pen"),
    ("quilt", "comforter", "comfort", "puff"),
    ("racer", "race car", "racing car"),
    ("racket", "racquet"),
    ("radiator",),
    ("radio", "wireless"),
    ("radio telescope", "radio reflector"),
    ("rain barrel",),
    ("recreational vehicle", "RV", "R.V."),
    ("reel",),
    ("reflex camera",),
    ("refrigerator", "icebox"),
    ("remote control", "remote"),
    ("restaurant", "eating house", "eating place", "eatery"),
    ("revolver", "six-gun", "six-shooter"),
    ("rifle",),
    ("rocking chair", "rocker"),
    ("rotisserie",),
    ("rubber eraser", "rubber", "pencil eraser"),
    ("rugby ball",),
    ("rule", "ruler"),
    ("running shoe",),
    ("safe",),
    ("safety pin",),
    ("saltshaker", "salt shaker"),
    ("sandal",),
    ("sarong",),
    ("sax", "saxophone"),
    ("scabbard",),
    ("scale", "weighing machine"),
    ("school bus",),
    ("schooner",),
    ("scoreboard",),
    ("screen", "CRT screen"),
    ("screw",),
    ("screwdriver",),
    ("seat belt", "seatbelt"),
    ("sewing machine",),
    ("shield", "buckler"),
    ("shoe shop", "shoe-shop", "shoe store"),
    ("shoji",),
    ("shopping basket",),
    ("shopping cart",),
    ("shovel",),
    ("shower cap",),
    ("shower curtain",),
    ("ski",),
    ("ski mask",),
    ("sleeping bag",),
    ("slide rule", "slipstick"),
    ("sliding door",),
    ("slot", "one-armed bandit"),
    ("snorkel",),
    ("snowmobile",),
    ("snowplow", "snowplough"),
    ("soap dispenser",),
    ("soccer ball",),
    ("sock",),
    ("solar dish", "solar collector", "solar furnace"),
    ("sombrero",),
    ("soup bowl",),
    ("space bar",),
    ("space heater",),
    ("space shuttle",),
    ("spatula",),
    ("speedboat",),
    ("spider web", "spider's web"),
    ("spindle",),
    ("sports car", "sport car"),
    ("spotlight", "spot"),
    ("stage",),
    ("steam locomotive",),
    ("steel arch bridge",),
    ("steel drum",),
    ("stethoscope",),
    ("stole",),
    ("stone wall",),
    ("stopwatch", "stop watch"),
    ("stove",),
    ("strainer",),
    ("streetcar", "tram", "tramcar", "trolley", "trolley car"),
    ("stretcher",),
    ("studio couch", "day bed"),
    ("stupa", "tope"),
    ("submarine", "pigboat", "sub", "U-boat"),
    ("suit", "suit of clothes"),
    ("sundial",),
    ("sunglass",),
    ("sunglasses", "dark glasses", "shades"),
    ("sunscreen", "sunblock", "sun blocker"),
    ("suspension bridge",),
    ("swab", "swob", "mop"),
    ("sweatshirt",),
    ("swimming trunks", "bathing trunks"),
    ("swing",),
    ("switch", "electric switch", "electrical switch"),
    ("syringe",),
    ("table lamp",),
    ("tank", "army tank", "armored combat vehicle", "armoured combat vehicle"),
    ("tape player",),
    ("teapot",),
    ("teddy", "teddy bear"),
    ("television", "television system"),
    ("tennis ball",),
    ("thatch", "thatched roof"),
    ("theater curtain", "theatre curtain"),
    ("thimble",),
    ("thresher", "thrasher", "threshing machine"),
    ("throne",),
    ("tile roof",),
    ("toaster",),
    ("tobacco shop", "tobacconist shop", "tobacconist"),
    ("toilet seat",),
    ("torch",),
    ("totem pole",),
    ("tow truck", "tow car", "wrecker"),
    ("toyshop",),
    ("tractor",),
    (
        "trailer truck",
        "tractor trailer",
        "trucking rig",
        "rig",
        "articulated lorry",
        "semi",
    ),
    ("tray",),
    ("trench coat",),
    ("tricycle", "trike", "velocipede"),
    ("trimaran",),
    ("tripod",),
    ("triumphal arch",),
    ("trolleybus", "trolley coach", "trackless trolley"),
    ("trombone",),
    ("tub", "vat"),
    ("turnstile",),
    ("typewriter keyboard",),
    ("umbrella",),
    ("unicycle", "monocycle"),
    ("upright", "upright piano"),
    ("vacuum", "vacuum cleaner"),
    ("vase",),
    ("vault",),
    ("velvet",),
    ("vending machine",),
    ("vestment",),
    ("viaduct",),
    ("violin", "fiddle"),
    ("volleyball",),
    ("waffle iron",),
    ("wall clock",),
    ("wallet", "billfold", "notecase", "pocketbook"),
    ("wardrobe", "closet", "press"),
    ("warplane", "military plane"),
    ("washbasin", "handbasin", "washbowl", "lavabo", "wash-hand basin"),
    ("washer", "automatic washer", "washing machine"),
    ("water bottle",),
    ("water jug",),
    ("water tower",),
    ("whiskey jug",),
    ("whistle",),
    ("wig",),
    ("window screen",),
    ("window shade",),
    ("Windsor tie",),
    ("wine bottle",),
    ("wing",),
    ("wok",),
    ("wooden spoon",),
    ("wool", "woolen", "woollen"),
    ("worm fence", "snake fence", "snake-rail fence", "Virginia fence"),
    ("wreck",),
    ("yawl",),
    ("yurt",),
    ("web site", "website", "internet site", "site"),
    ("comic book",),
    ("crossword puzzle", "crossword"),
    ("street sign",),
    ("traffic light", "traffic signal", "stoplight"),
    ("book jacket", "dust cover", "dust jacket", "dust wrapper"),
    ("menu",),
    ("plate",),
    ("guacamole",),
    ("consomme",),
    ("hot pot", "hotpot"),
    ("trifle",),
    ("ice cream", "icecream"),
    ("ice lolly", "lolly", "lollipop", "popsicle"),
    ("French loaf",),
    ("bagel", "beigel"),
    ("pretzel",),
    ("cheeseburger",),
    ("hotdog", "hot dog", "red hot"),
    ("mashed potato",),
    ("head cabbage",),
    ("broccoli",),
    ("cauliflower",),
    ("zucchini", "courgette"),
    ("spaghetti squash",),
    ("acorn squash",),
    ("butternut squash",),
    ("cucumber", "cuke"),
    ("artichoke", "globe artichoke"),
    ("bell pepper",),
    ("cardoon",),
    ("mushroom",),
    ("Granny Smith",),
    ("strawberry",),
    ("orange",),
    ("lemon",),
    ("fig",),
    ("pineapple", "ananas"),
    ("banana",),
    ("jackfruit", "jak", "jack"),
    ("custard apple",),
    ("pomegranate",),
    ("hay",),
    ("carbonara",),
    ("chocolate sauce", "chocolate syrup"),
    ("dough",),
    ("meat loaf", "meatloaf"),
    ("pizza", "pizza pie"),
    ("potpie",),
    ("burrito",),
    ("red wine",),
    ("espresso",),
    ("cup",),
    ("eggnog",),
    ("alp",),
    ("bubble",),
    ("cliff", "drop", "drop-off"),
    ("coral reef",),
    ("geyser",),
    ("lakeside", "lakeshore"),
    ("promontory", "headland", "head", "foreland"),
    ("sandbar", "sand bar"),
    ("seashore", "coast", "seacoast", "sea-coast"),
    ("valley", "vale"),
    ("volcano",),
    ("ballplayer", "baseball player"),
    ("groom", "bridegroom"),
    ("scuba diver",),
    ("rapeseed",),
    ("daisy",),
    (
        "yellow lady's slipper",
        "yellow lady-slipper",
        "Cypripedium calceolus",
        "Cypripedium parviflorum",
    ),
    ("corn",),
    ("acorn",),
    ("hip", "rose hip", "rosehip"),
    ("buckeye", "horse chestnut", "conker"),
    ("coral fungus",),
    ("agaric",),
    ("gyromitra",),
    ("stinkhorn", "carrion fungus"),
    ("earthstar",),
    (
        "hen-of-the-woods",
        "hen of the woods",
        "Polyporus frondosus",
        "Grifola frondosa",
    ),
    ("bolete",),
    ("ear", "spike", "capitulum"),
    ("toilet tissue", "toilet paper", "bathroom tissue"),
]


MINI_IMAGENET_WNIDS: List[str] = [
    "n02110341",
    "n01930112",
    "n04509417",
    "n04067472",
    "n04515003",
    "n02120079",
    "n03924679",
    "n02687172",
    "n03075370",
    "n07747607",
    "n09246464",
    "n02457408",
    "n04418357",
    "n03535780",
    "n04435653",
    "n03207743",
    "n04251144",
    "n03062245",
    "n02174001",
    "n07613480",
    "n03998194",
    "n02074367",
    "n04146614",
    "n04243546",
    "n03854065",
    "n03838899",
    "n02871525",
    "n03544143",
    "n02108089",
    "n13133613",
    "n03676483",
    "n03337140",
    "n03272010",
    "n01770081",
    "n09256479",
    "n02091244",
    "n02116738",
    "n04275548",
    "n03773504",
    "n02606052",
    "n03146219",
    "n04149813",
    "n07697537",
    "n02823428",
    "n02089867",
    "n03017168",
    "n01704323",
    "n01532829",
    "n03047690",
    "n03775546",
    "n01843383",
    "n02971356",
    "n13054560",
    "n02108551",
    "n02101006",
    "n03417042",
    "n04612504",
    "n01558993",
    "n04522168",
    "n02795169",
    "n06794110",
    "n01855672",
    "n04258138",
    "n02110063",
    "n07584110",
    "n02091831",
    "n03584254",
    "n03888605",
    "n02113712",
    "n03980874",
    "n02219486",
    "n02138441",
    "n02165456",
    "n02108915",
    "n03770439",
    "n01981276",
    "n03220513",
    "n02099601",
    "n02747177",
    "n01749939",
    "n03476684",
    "n02105505",
    "n02950826",
    "n04389033",
    "n03347037",
    "n02966193",
    "n03127925",
    "n03400231",
    "n04296562",
    "n03527444",
    "n04443257",
    "n02443484",
    "n02114548",
    "n04604644",
    "n01910747",
    "n04596742",
    "n02111277",
    "n03908618",
    "n02129165",
    "n02981792",
]

MINI_IMAGENET_WNID_TO_IDX: Dict[str, int] = {
    cls_name: i for i, cls_name in enumerate(MINI_IMAGENET_WNIDS)
}

MINI_IMAGENET_CLASSES: List[Tuple[str, ...]] = []
for wnid in MINI_IMAGENET_WNIDS:
    imagenet_idx = IMAGENET_TORCHVISION_WNID_TO_IDX[wnid]
    MINI_IMAGENET_CLASSES.append(IMAGENET_TORCHVISION_CLASSES[imagenet_idx])

MINI_IMAGENET_CLASS_TO_IDX: Dict[str, int] = {
    cls: idx for idx, clss in enumerate(MINI_IMAGENET_CLASSES) for cls in clss
}