0
I am getting the following error message:
RuntimeError: w groups=3, expected weight to be at least 3 at dimension 0, but got weight of size [1, 1, 2, 2] instead
when i try to convolve a image with a filter using the “functional version of conv2d”
i know why i am receiving this error message… it is because i need to have 3 dimensions in channel 0. But i have now i idea how to add two more dimensions.
I have flailed around for quite some time trying to add two more, but i cant figure it out. I want to the kernal applied one all color channels… so i just want to replicate it 2 more times.
import torch.nn as nn
import torch
import torch.nn.functional as nnf
from PIL import Image
from torchvision import transforms
img = Image.open("GOPR0305.jpg")
preprocess = transforms.Compose([transforms.ToTensor()])
img_t = preprocess(img)
img_t = torch.unsqueeze(img_t, 0)
hci = [1, -1]
hri = [-1, 1]
hc = [1.0, -1.0]
hr = [-1.0, 1.0]
lc = [0.5, 0.5]
lr = [0.5, 0.5]
hh_k = torch.tensor([hc ,hr])[None, None, ...]
hl_k = torch.tensor([hc ,lr])[None, None, ...]
lh_k = torch.tensor([lc ,hr])[None, None, ...]
ll_k = torch.tensor([lc ,lr])[None, None, ...]
in_t = torch.tensor([ [14, 7, 6, 2,] , [4 ,8 ,11 ,1], [3, 5, 9 ,10], [12, 15, 16, 13] ])[None, None, ...]
in_t = torch.tensor([ [14.0, 7.0, 6.0, 2.0,] , [4.0 ,8.0 ,11.0 ,1.0], [3.0, 5.0, 9.0 ,10.0], [12.0, 15.0, 16.0, 13.0] ])[None, None, ...]
def wave_haar(in_t):
hh = nnf.conv2d(in_t, hh_k,stride=2,groups=3)
ll = nnf.conv2d(in_t, ll_k,stride=2)
hl = nnf.conv2d(in_t, hl_k,stride=2)
lh = nnf.conv2d(in_t, lh_k,stride=2)
return [ll,hl,lh,hh]
[ll,hl,lh,hh] = wave_haar(img_t[:,2:])
print(img_t.shape)
print(img_t.size())
print(img_t)
print(img_t.shape)
print(ll.shape)