Code snippet to reproduce the issue.
import torch
import torchvision
import torchvision.transforms as transforms

def load_data():
    
    transform = transforms.Compose([
        transforms.ToTensor(),
        transforms.Lambda(lambda z: print(z.min(), z.max()))
    ])

    dataset = torchvision.datasets.ImageFolder('/home/ssd0/images/', transform=transform)
    dataloader = torch.utils.data.DataLoader(dataset, batch_size=16, shuffle=False, num_workers=4)
    
    return dataloader

for data in load_data():
    pass

The above code ends in error because transforms.Lambda(lambda z: print(z.min(), z.max())) returns NoneType. But if you carefully see the prints, it displays 16 torch tensors of min and max value of each image of the first batch. And this keeps changing every time I run the code. Setting num_workers=1 resolves this problem. I suspect 4 parallel workers are racing against each other. Please tell me if I am doing something wrong.