hi this is my first post, so if not suitable sorry.
basically I am developing a NN that uses images. However, I receive this error:
RuntimeError: Given groups=1, weight[5, 3, 436, 436], so expected input[5, 436, 436, 3] to have 3 channels, but got 436 channels instead
I got that legent of weight[batch,channel,h,w], but input has this data shift.
I copied the sample code from this.
only change I made is just changing self.conv1 = nn.Conv2d(3,6,5) to nn.Conv2d(3, 5, 436)
I can provide more info if necessary. Besides, can I use h!=w input images? thanks!
It looks like you provided an image with shapes [batch_size, w, h, channels]
instead of [batch_size, channels, h, w]
.
How did you load your images?
You can use non square images without a problem. If you need a non square kernel, you can provide the kernel_size
as a tuple
: kernel_size=(kh, kw)
.
yeah after some research, I saw that it is cwh problem. currently I am trying to find the solution to reverse the order.
My code is like this:
datasetTrain=FencerPicLoader('D:/x/x/x',transformations)
train_loader=DataLoader(dataset=datasetTrain,
batch_size=5,
shuffle=True,
num_workers=2)
for epoch in range(2): # loop over the dataset multiple times
running_loss = 0.0
for i, data in enumerate(train_loader, 0):
# get the inputs
inputs, labels = data
# zero the parameter gradients
optimizer.zero_grad()
# forward + backward + optimize
outputs = net(inputs)#####error jumps to Net()
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = nn.Conv2d(3, 5, 436)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16 * 5 * 5, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 10)
Thanks for help and kernel advice! 
You can just permute the dimensions:
inputs = inputs.permute(0, 3, 2, 1)
or change your Dataset
to return the input in the right shape.
1 Like
it gave this error:
RuntimeError: thnn_conv2d_forward is not implemented for type torch.ByteTensor
but probably the problem will be solved if I just change the array. 
edit: actually that solved the error. apparently forwarding is a problem… I believe I can solve probably.
nn.Conv2d
is complaining about your input. Cast your input to input.float()
and try it again.
Yeah, as I promised I solved that issue before the answer! 
ok last question (so so sorry I didnt want to), but before that: is there a good website that I can learn these kind of stuff easily? I think I will encounter more of them in the future and want to be less dependent on the pytorch forums etc. I checked stanford ML courses and fast.ai courses, but they hardly ever mentions these inner structures.
RuntimeError: Given input size: (5x1x1). Calculated output size: (5x0x0). Output size is too small at c:\programdata\miniconda3\conda-bld\pytorch_1524546371102\work\aten\src\thnn\generic/SpatialDilatedMaxPooling.c:67
so I got this error.
In conv2d(3,5,436), I get this error. If I say (3,5,218 or 109) I get RAM error like 71GB needed etc. If I write random number like 50, it works but it heavily slows the down computer.
THANKS