class_docstr: .. figure:: https://3qeqpr26caki16dnhd19sv6by6v-wpengine.netdna-ssl.com/wp-content/uploads/2017/08/
      Sample-of-Images-from-the-ImageNet-Dataset-used-in-the-ILSVRC-Challenge.png
      :width: 400
      :alt: Imagenet
  Specs:
      - 1000 classes
      - Each image is (3 x varies x varies) (here we default to 3 x 224 x 224)
  Imagenet train, val and test dataloaders.
  The train set is the imagenet train.
  The val set is taken from the train set with `num_imgs_per_val_class` images per class.
  For example if `num_imgs_per_val_class=2` then there will be 2,000 images in the validation set.
  The test set is the official imagenet validation set.
   Example::
      from pl_bolts.datamodules import ImagenetDataModule
      dm = ImagenetDataModule(IMAGENET_PATH)
      model = LitModel()
      Trainer().fit(model, datamodule=dm)
class_docstr_tok: ["..","figure",":",":","https",":","\/\/3qeqpr26caki16dnhd19sv6by6v-wpengine.netdna-ssl.com\/wp-content\/uploads\/2017\/08\/","Sample-of-Images-from-the-ImageNet-Dataset-used-in-the-ILSVRC-Challenge.png",":","width",":","400",":","alt",":","Imagenet","Specs",":","-","1000","classes","-","Each","image","is","(","3","x","varies","x","varies",")","(","here","we","default","to","3","x","224","x","224",")","Imagenet","train",",","val","and","test","dataloaders",".","The","train","set","is","the","imagenet","train",".","The","val","set","is","taken","from","the","train","set","with","`","num_imgs_per_val_class","`","images","per","class",".","For","example","if","`","num_imgs_per_val_class=2","`","then","there","will","be","2,000","images","in","the","validation","set",".","The","test","set","is","the","official","imagenet","validation","set",".","Example",":",":","from","pl_bolts.datamodules","import","ImagenetDataModule","dm","=","ImagenetDataModule","(","IMAGENET_PATH",")","model","=","LitModel","(",")","Trainer","(",")",".fit","(","model",",","datamodule=dm",")"]
docstr: Creates train, val, and test dataset.
docstr_tok: ["Creates","train",",","val",",","and","test","dataset","."]
code: def setup(self, stage: Optional[str] = None) -> None:
      """Creates train, val, and test dataset."""
      if stage == "fit" or stage is None:
          train_transforms = (
              self.train_transform()
              if self.train_transforms is None
              else self.train_transforms
          )
          val_transforms = (
              self.val_transform()
              if self.val_transforms is None
              else self.val_transforms
          )
          self.dataset_train = ImageFolder(
              self.data_dir / "train", transform=train_transforms
          )
          self.dataset_val = ImageFolder(
              self.data_dir / "val", transform=val_transforms
          )
  
      if stage == "test" or stage is None:
          test_transforms = (
              self.val_transform()
              if self.test_transforms is None
              else self.test_transforms
          )
          self.dataset_test = ImageFolder(
              self.data_dir / "val", transform=test_transforms
          )
  
imports: import os
  from pathlib import Path
  from typing import Any, List, Union, Callable, Optional
  from torch.utils.data import Dataset, DataLoader
  from torch.utils.data.dataloader import default_collate
  from torch.utils.data.distributed import DistributedSampler
  from pytorch_lightning import LightningDataModule
  from torchvision import transforms
  from torchvision.datasets import ImageFolder
label_desc: Use image node_id 5 for calling the ImagenetDataModule obj's underlying member method code with example usage: obj.setup(stage) without return types