What you did works.
I tried it. You just need to give the callable function custom_pil_loader when calling ImageFolder and not the name as a string.
The following worked for me:
import torch
import torchvision.transforms as transforms
import torchvision.datasets as dset
from PIL import Image

DATA_ROOT = '../data/dataset/'

def custom_pil_loader(path):
# open path as file to avoid ResourceWarning (https://github.com/python-pillow/Pillow/issues/835)
    with open(path, 'rb') as f:
        img = Image.open(f)
        img.load()
        return img

transform=transforms.Compose([transforms.Resize(256),
                              transforms.CenterCrop(256),
                              transforms.ToTensor(),
                              ])
    
default_ds = dset.ImageFolder(DATA_ROOT, transform,)
custom_ds = dset.ImageFolder(DATA_ROOT, transform, loader=custom_pil_loader)

default_dl = torch.utils.data.DataLoader(dataset=default_ds, batch_size=32)
custom_dl = torch.utils.data.DataLoader(dataset=custom_ds, batch_size=32)
     
print(iter(default_dl).next()[0].shape)
print(iter(custom_dl).next()[0].shape)

torch.Size([32, 3, 256, 256])
torch.Size([32, 1, 256, 256])

I had to also add img.load() at the end of the custom loader or I would get ValueError: seek of closed file.
Not sure what this is about tho. I found this fix on stackoverflow 3