I tried to my data set and test set, the original pictures are grayscales with format ‘.bmp’.
I used the following mothod :
addrBase1 = '../Train/'
addrBase2 = '../Test/'
transform = transforms.Compose(
[transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
# TrainSet
trainSet = torchvision.datasets.ImageFolder(addrBase1,
transform = transform)
trainLoader = torch.utils.data.DataLoader(trainSet, batch_size=batchSize, shuffle=True)
# TestSet
testSet1 = torchvision.datasets.ImageFolder(addrBase1,
transform = transform)
testSet2 = torchvision.datasets.ImageFolder(addrBase2,
transform = transform)
test1Loader = torch.utils.data.DataLoader(testSet1, batch_size=batchSize, shuffle=True)
test2Loader = torch.utils.data.DataLoader(testSet2, batch_size=batchSize, shuffle=True)
and then, I got the Initial datas with 3 channels, which means, parameter of Convolution layer is 3Nk*k.
I want to get 1 channels data, so, I added
transforms.Grayscale(1)
to transform.
transform = transforms.Compose(
[transforms.ToTensor(),
transforms.Grayscale(1),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
But when i run the codes, ‘Spyder’ told me the following messages:
What i want to solve are:
-
How to build a grayscale graph data set?
-
How to figure out the problem ’ img should be PIL Image. Got <class ‘torch.Tensor’> ’
Forgive me for my poor expression and thanks a lot in advances.