text: import logging
  import torch
  from torchvision import transforms, datasets
  from torch.utils.data import DataLoader, RandomSampler, DistributedSampler, SequentialSampler, Subset
  from sklearn.model_selection import train_test_split
  
  
  logger = logging.getLogger(__name__)
  
  def train_val_dataset(dataset, val_split=0.25):
      train_idx, val_idx = train_test_split(list(range(len(dataset))), test_size=val_split)
      datasets = {}
      datasets['train'] = Subset(dataset, train_idx)
      datasets['val'] = Subset(dataset, val_idx)
      return datasets
  
  def get_loader(args):
      if args.local_rank not in [-1, 0]:
          torch.distributed.barrier()
  
      transform_train = transforms.Compose([
          transforms.RandomResizedCrop((args.img_size, args.img_size), scale=(0.05, 1.0)),
          transforms.ToTensor(),
          transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
      ])
  
      dataset = datasets.ImageFolder('dataset/train/', transform=transform_train)
      trainset,testset = train_val_dataset(dataset)
  
      if args.local_rank == 0:
          torch.distributed.barrier()
  
      train_sampler = RandomSampler(trainset) if args.local_rank == -1 else DistributedSampler(trainset)
      test_sampler = SequentialSampler(testset)
  
      train_loader = DataLoader(trainset,
                                sampler=train_sampler,
                                batch_size=args.train_batch_size,
                                num_workers=4,
                                pin_memory=True)
      test_loader = DataLoader(testset,
                               sampler=test_sampler,
                               batch_size=args.eval_batch_size,
                               num_workers=4,
                               pin_memory=True) if testset is not None else None
  
      return train_loader, test_loader
  