I used Pytorch transform to transform the data and Pytorch model to train them. But, I am geting the error message as “RuntimeError: Given groups=1, weight of size [244, 244, 3, 3], expected input[8, 1, 244, 244] to have 244 channels, but got 1 channels instead”.
Any suggestion on how to fix weight shape to accept the input?
Note:
I had converted the image to grayScale while tranforms.
train_transforms = transforms.Compose([
             transforms.ToPILImage(),
             transforms.Grayscale(num_output_channels=1),
             transforms.Resize((244,244)),
             transforms.RandomHorizontalFlip(),
             transforms.ToTensor(),
             transforms.Normalize((0.5,), (0.5,))
             ])

train_df = CustomImageDataset(train_data,train_transforms)
train_dataloader = torch.utils.data.DataLoader(
            train_df,
            batch_size=8,
            num_workers=1,
            shuffle=True,
        )

train_features, train_labels = next(iter(train_dataloader))
print(f"Feature batch shape: {train_features.size()}")
# this code output: Feature batch shape: torch.Size([8, 1, 244, 244])


import torch
from torch import nn
from d2l import torch as d2l

net = nn.Sequential(
    nn.Conv2d(244, 244, kernel_size=3, stride=1, padding=1), nn.ReLU(),
    nn.Dropout(p=0.5),
    nn.MaxPool2d(kernel_size=3, stride=1),
    nn.Dropout(p=0.5),
    nn.Conv2d(244, 256, kernel_size=3, padding=1), nn.ReLU(),
    nn.Dropout(p=0.5),
    nn.MaxPool2d(kernel_size=3, stride=1),
    nn.Dropout(p=0.5),
    nn.Conv2d(256, 256, kernel_size=3, padding=1), nn.ReLU(),
    nn.Linear(256, 3))

lr, num_epochs = 0.01, 10
d2l.train_ch6(net, train_dataloader, test_dataloader, num_epochs, lr, d2l.try_gpu())