Are the images in subfolders 0 all belong to class 0?
if So, simply use ImageFolder
train_dataset = ImageFolder('train',Transofroms)
data,label = train_dataset[100]# the 100th picture
train_loader = Dataloader(train_dataset)
for data,label in train_loader:
    train()

have a look at the example of Imagenet

  
      github.com
  
  
    pytorch/examples/blob/master/imagenet/main.py#L97-L121 8

# optionally resume from a checkpoint
if args.resume:
    if os.path.isfile(args.resume):
        print("=> loading checkpoint '{}'".format(args.resume))
        checkpoint = torch.load(args.resume)
        args.start_epoch = checkpoint['epoch']
        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


# Data loading code
traindir = os.path.join(args.data, 'train')
valdir = os.path.join(args.data, 'val')
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],


  This file has been truncated. show original