Doing what ptrblck  suggested is definitely the “proper” way of doing this.
But if you want a quick fix that does not involve a custom loader you can just use torchvision.transforms.Grayscale(num_output_channels=1) (doc 4) as an extra transformation.
In your above code:



 rukhmini:

train_dataset = torchvision.datasets.ImageFolder(data_dir_train,transform = transforms.ToTensor())


It would look like this:
train_dataset = datasets.ImageFolder(data_dir_train,transform = 
                                     transforms.Compose([transforms.Grayscale(num_output_channels=1), 
                                                         transforms.ToTensor()]))

Since all PILs Image.convert('RGB') does is r==g==b
and transforms.Grayscale(num_output_channels=1) does (0.2989 * r + 0.587 * g + 0.114 * b)
this should not do too much to your data except for maybe a small change in the 0.00x margin.