In the forward function of a model, I extracted the first layer conv1 output(x), after some operations and then put back. And then prompted RuntimeError: std :: bad_cast. What is the reason? What should I do?
class ResNet(nn.Module):
def __init__( ):
def forward(self, x): x = self.conv1(x) net=x.data w=self.conv1.weight.data sigma=conv_forward_naive(x1, w) net=myactive(net,sigma) x.data=net x = self.bn1(x)
This is an error message
> File "/home/zl/anaconda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile
> execfile(filename, namespace)
> File "/home/zl/anaconda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile
> builtins.execfile(filename, *where)
> File "/home/zl/mycode/imagefolder/imagefolder.py", line 182, in <module>
> num_epochs=10)
> File "/home/zl/mycode/imagefolder/imagefolder.py", line 103, in train_model
> outputs = model(inputs)
> File "/home/zl/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.py", line 206, in __call__
> result = self.forward(*input, **kwargs)
> File "/home/zl/anaconda2/lib/python2.7/site-packages/torchvision/models/resnet.py", line 256, in forward
> x = self.bn1(x)
> File "/home/zl/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.py", line 206, in __call__
> result = self.forward(*input, **kwargs)
> File "/home/zl/anaconda2/lib/python2.7/site-packages/torch/nn/modules/batchnorm.py", line 43, in forward
> self.training, self.momentum, self.eps)
> File "/home/zl/anaconda2/lib/python2.7/site-packages/torch/nn/functional.py", line 463, in batch_norm
> return f(input, weight, bias)
> RuntimeError: std::bad_cast