class_docstr: `ImageNetv2 Dataset <https://arxiv.org/abs/1902.10811>`_ for studying the robustness of models trained on ImageNet dataset
  
  Args:
      opts: command-line arguments
class_docstr_tok: ["`","ImageNetv2","Dataset","<","https",":","\/\/arxiv.org\/abs\/1902.10811",">","`","_","for","studying","the","robustness","of","models","trained","on","ImageNet","dataset","Args",":","opts",":","command-line","arguments"]
code: def __init__(
      self,
      opts,
      *args,
      **kwargs,
  ) -> None:
      super().__init__(opts=opts, *args, **kwargs)
      if self.is_training:
          logger.error(
              "{} can only be used for evaluation".format(
                  self.__class__.__name__
              )
          )
  
      split = getattr(opts, "dataset.imagenet_v2.split", None)
      if split is None or split not in IMAGENETv2_SPLIT_LINK_MAP.keys():
          logger.error(
              "Please specify split for ImageNetv2. Supported ImageNetv2 splits are: {}".format(
                  IMAGENETv2_SPLIT_LINK_MAP.keys()
              )
          )
  
      split_path = get_local_path(
          opts, path=IMAGENETv2_SPLIT_LINK_MAP[split]["url"]
      )
      with tarfile.open(split_path) as tf:
          tf.extractall(self.root)
  
      root = Path(
          "{}/{}".format(
              self.root,
              IMAGENETv2_SPLIT_LINK_MAP[split]["extracted_folder_name"],
          )
      )
      file_names = list(root.glob("**/*.jpeg"))
      self.file_names = file_names
  
      setattr(
          opts, "dataset.collate_fn_name_train", "imagenet_collate_fn"
      )
      setattr(
          opts, "dataset.collate_fn_name_val", "imagenet_collate_fn"
      )
      setattr(
          opts, "dataset.collate_fn_name_test", "imagenet_collate_fn"
      )
  
file_path: ml-cvnets/data/datasets/classification/imagenet_v2.py
imports: import argparse
  import tarfile
  from pathlib import Path
  from typing import Dict, Tuple
  import torch
  from data.datasets import DATASET_REGISTRY
  from data.datasets.dataset_base import BaseImageDataset
  from data.transforms import image_pil
  from data.transforms.common import Compose
  from utils import logger
  from utils.download_utils import get_local_path
label_desc: Use image node_id 1 to create a new Imagenetv2Dataset object from inherited base classes: BaseImageDataset with example: obj = Imagenetv2Dataset(opts)