ValueError: batch_size should be a positive integer value

Any idea what is causing this error message

“ValueError: batch_size should be a positive integer value, but got batch_size=Compose(
ToTensor()”

from torchvision import datasets
import torch.utils.data
from torch.utils.data import DataLoader
from torchvision import transforms
from dataset2 import CellsDataset
from torchvision import datasets
import torch
import torchvision
import torchvision.transforms as transforms


class ImageFolderWithPaths(datasets.ImageFolder):
    """Custom dataset that includes image file paths. Extends
    torchvision.datasets.ImageFolder
    """

# override the __getitem__ method. this is the method that dataloader calls
def __getitem__(self, index):
    # this is what ImageFolder normally returns 
    original_tuple = super(ImageFolderWithPaths, self).__getitem__(index)
    # the image file path
    path = self.imgs[index][0]
    # make a new tuple that includes original and the path
    tuple_with_path = (original_tuple + (path,))
    return tuple_with_path

# EXAMPLE USAGE:
# instantiate the dataset and dataloader
data_dir = "/Users/nubstech/Documents/GitHub/CellCountingDirectCount/Eddata/Healthy_curated"
dataset = ImageFolderWithPaths(data_dir) # our custom dataset
dataloader = DataLoader(dataset)
dataset = DataLoader(data_dir, transforms.Compose([transforms.ToTensor()]))

# iterate over data
for inputs, labels, paths in dataloader:
    # use the above variables freely
   print(inputs, labels, paths)

Hi,
You are setting transforms into batch_size. DataLoader does not accept transforms, you need to apply it on Dataset.

dataset = ImageFolderWithPaths(data_dir, transform=transforms.Compose([transforms.ToTensor()]))
dataloader = DataLoader(dataset, batch_size=16)

Or I think you mistyped Dataloader with ImageFolderWithPaths in the last line. As a Dataloader does not accept a data direction or transform which on the otherside, your custom dataset does.

Official tutorial

Bests