you may refer to the implementation of ImageFolder.

  
      github.com
  
  
    pytorch/vision/blob/master/torchvision/datasets/folder.py#L65-L124 53

from torchvision import get_image_backend
if get_image_backend() == 'accimage':
    return accimage_loader(path)
else:
    return pil_loader(path)




class ImageFolder(data.Dataset):
"""A generic data loader where the images are arranged in this way: ::


    root/dog/xxx.png
    root/dog/xxy.png
    root/dog/xxz.png


    root/cat/123.png
    root/cat/nsdf3.png
    root/cat/asd932_.png


Args:
    root (string): Root directory path.


  This file has been truncated. show original

  
  
    
    
  
  


and it’s used with Dataloader

  
      github.com
  
  
    pytorch/examples/blob/master/imagenet/main.py#L103-L111 22

        best_prec1 = checkpoint['best_prec1']
        model.load_state_dict(checkpoint['state_dict'])
        optimizer.load_state_dict(checkpoint['optimizer'])
        print("=> loaded checkpoint '{}' (epoch {})"
              .format(args.resume, checkpoint['epoch']))
    else:
        print("=> no checkpoint found at '{}'".format(args.resume))


cudnn.benchmark = True