I am using a dataset of grayscale images of size 64X64 to train a network for two class image classification. The images are stored in train folder with class labels as subfolder name inside train folder but when ever I am loading the images it is converting into 3 channel images. The piece of code is:
data_dir_train = ‘C:/Users/rukhm/nodule_classification/data/train/’
data_dir_test = ‘C:/Users/rukhm/nodule_classification/data/test/’
train_dataset = torchvision.datasets.ImageFolder(data_dir_train,transform = transforms.ToTensor())
test_dataset = torchvision.datasets.ImageFolder(data_dir_test,transform = transforms.ToTensor())
trainloader = torch.utils.data.DataLoader(dataset=train_dataset,
batch_size=batch_size,
shuffle=True);
testloader = torch.utils.data.DataLoader(dataset=test_dataset,
batch_size=batch_size,
shuffle=True);
dataiter = iter(trainloader)
images, labels = dataiter.next()
print(images.shape) #shape of all images
print(images[1].shape) #shape of one image
print(labels[1].item()) #label number
Output:
torch.Size([100, 3, 64, 64])
torch.Size([3, 64, 64])
0