AttributeError in Classification report
The thing is i want to output the precisio, recall, and f1-score using classification report. But when i run below code, that error occurs. How can i fix the AttributeError?
print(classification_report(test.targets.cpu().numpy(),
  File &quot;C:\Users\Admin\PycharmProjects\ImageRotation\venv\lib\site-packages\torch\utils\data\dataset.py&quot;, line 83, in __getattr__
    raise AttributeError
AttributeError

This is where i load the data from my directory.
data_loader = ImageFolder(data_dir,transform = transformer)


lab = data_loader.classes
num_classes = int(len(lab))
print(&quot;Number of Classes: &quot;, num_classes)

print(&quot;The classes are as follows : \n&quot;,data_loader.classes)

batch_size = 128
train_size = int(len(data_loader) * 0.8)
test_size = len(data_loader) - train_size

train,test = random_split(data_loader,[train_size,test_size])


train_size = int(len(train) * 0.8)
val_size = len(train) - train_size
train_data, val_data = random_split(train,[train_size,val_size])
#load the train and validation into batches.
print(f&quot;Length of Train Data : {len(train_data)}&quot;)
print(f&quot;Length of Validation Data : {len(val_data)}&quot;)
print(f&quot;Length of Test Data : {len(test)}&quot;)

train_dl = DataLoader(train_data, batch_size, shuffle = True)
val_dl = DataLoader(val_data, batch_size*2)
test_dl = DataLoader(test, batch_size, shuffle=True)

model.evaL() code
with torch.no_grad():
    # set the model in evaluation mode
    model.eval()

    # initialize a list to store our predictions
    preds = []
    # loop over the test set
    for (x, y) in test_dl:
        # send the input to the device
        x = x.to(device)
        # make the predictions and add them to the list
        pred = model(x)
        preds.extend(pred.argmax(axis=1).cpu().numpy())
# generate a classification report
print(classification_report(test.targets.cpu().numpy(),
                            np.array(preds), target_names=test.classes))


It seems, ImageFolder is the your dataset object, but that is not inherited ted from torch.utils.data.Datasets. 
torch Dataloader tries to call the __getitem__ method in the your Dataset object, but since it is not torch.utils.data.Dataset object it does not have has a function, then that causes to AttributeError now you are getting. 
Convert ImageFolder to torch torch dataset. For further library details : torch doc
Practical implemtation : ast_dataloader 
Also, you can use freeze model [without back propagation] to speedup the inference process.
   with torch.no_grad():
        # make the predictions and add them to the list
        pred = model(x)


Update&gt;
sample torch dataset:
from torch.utils.data import Dataset
class Dataset_train(Dataset):
    def __init__(self, list_IDs, labels, base_dir):
        &quot;&quot;&quot;self.list_IDs    : list of strings (each string: utt key),
           self.labels      : dictionary (key: utt key, value: label integer)&quot;&quot;&quot;
        self.list_IDs = list_IDs
        self.labels = labels
        self.base_dir = base_dir

    def __len__(self):
        return len(self.list_IDs)

    def __getitem__(self, index):
        key = self.list_IDs[index]
        X, _ = get_sample(f&quot;{self.base_dir}/{key}&quot;, self.noises)
        y = self.labels[index]
        return X, y

[Note] get_sample is custom build function for .wav file read. you could replace it with any funtion.
torch example-1 
torch example-2 
medium example
