Hi ,as the topic said, this is my code:
import imutils
import cv2
from imutils import paths
import torch
import torch.nn as nn
import torch.optim as optim
from torch.optim import lr_scheduler
import numpy as np
import torchvision
from torchvision import datasets, models, transforms
import matplotlib.pyplot as plt
import time
from PIL import Image
import os
import copy
if name == ‘main’:
# Data augmentation and normalization for training
# Just normalization for validation
data_transforms = {
transforms.Compose([
transforms.Resize((224,224)),
transforms.ToTensor()
]),
}

data_dir = './pill'

image_datasets = datasets.ImageFolder(data_dir,
                                          data_transforms)

dataloaders = torch.utils.data.DataLoader(image_datasets, batch_size=8,
                                             shuffle=True, num_workers=8)

train_size = int(0.8 * len(image_datasets))
test_size = len(image_datasets) - train_size
train_dataset, test_dataset = torch.utils.data.random_split(image_datasets, [train_size, test_size])

I can get the length by len(train_dataset.dataset), while I can not get train_dataset.dataset[0], this will cause an error:
TypeError                                 Traceback (most recent call last)
 in 
----> 1 train_dataset.dataset[0]
~\anaconda3\Lib\site-packages\torchvision\datasets\folder.py in getitem(self, index)
138         sample = self.loader(path)
139         if self.transform is not None:
–> 140             sample = self.transform(sample)
141         if self.target_transform is not None:
142             target = self.target_transform(target)
TypeError: ‘set’ object is not callable
Could you help me solve this problem? Thanks a lot!!