the error only happens in very specific conditions. (change the view of input tensor and use weight converted from numpy array.)
import torch
import torch.nn as nn
import numpy as np
from torch.autograd import Variable
filter_size = 5
a = torch.randn(3,3,64,64)
weights = np.random.rand(25).reshape(5,5)
weights = torch.from_numpy(weights.reshape(1,1,5,5))
out1 = nn.functional.conv2d(Variable(a.view(9,1,64,64)), Variable(weights))
psi = nn.Conv2d(1,1, filter_size, bias=True)
psi.weight.data.copy_(weights)
psi.bias.data.fill_(0)
out2 = psi(Variable(a.view(9,1,64,64)))
print(out1.mean())
print(out2.mean())
the error only happens in very specific conditions. (change the view of input tensor and use weight converted from numpy array.)
The output of functional conv2d is far off in scale (e12 or so.)