Skip to content

ConvNd C implementation doesn't check tensor types #1357

@angelleng

Description

@angelleng

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 output of functional conv2d is far off in scale (e12 or so.)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions