Repository: pytorch/pytorch

Issue:
SpatialFullConvolution loaded from Lua doesn't have finput attribute
I am new to python，when i solve the promblem with the help below：
https://github.com/pytorch/pytorch/issues/897

I find some confusion in the code：
https://github.com/pytorch/pytorch/blob/master/torch/legacy/nn/JoinTable.py#L7

I set ‘dimension=1；self.dimension = dimension’，it seem ok for me，but i don’t kown how the value of ’dimension‘ was initialled. 

Thank you !


Discussion:
I already Konw it comes from
 'module = JoinTable(dimension, nInputDims)'
But when I convert the model  to pytorch , error appears:

Traceback (most recent call last):
  File "test.py", line 173, in <module>
    G_net_f       =generator.forward(input)
  File "/usr/local/lib/python2.7/dist-packages/torch/legacy/nn/Module.py", line 33, in forward
    return self.updateOutput(input)
  File "/usr/local/lib/python2.7/dist-packages/torch/legacy/nn/Sequential.py", line 36, in updateOutput
    currentOutput = module.updateOutput(currentOutput)
  File "/usr/local/lib/python2.7/dist-packages/torch/legacy/nn/JoinTable.py", line 37, in updateOutput
    self.output.narrow(dim, offset, currentOutput.size(dim)).copy_(currentOutput)
RuntimeError: inconsistent tensor size at /home/lxl/pytorch-master/torch/lib/TH/generic/THTensorCopy.c:51

I Use "generator.modules[0] = nn.JoinTable(1)",it was fine ,but  error again:

Traceback (most recent call last):
  File "test.py", line 171, in <module>
    G_net_f       =generator.forward(input)
  File "/usr/local/lib/python2.7/dist-packages/torch/legacy/nn/Module.py", line 33, in forward
    return self.updateOutput(input)
  File "/usr/local/lib/python2.7/dist-packages/torch/legacy/nn/Sequential.py", line 36, in updateOutput
    currentOutput = module.updateOutput(currentOutput)
  File "/usr/local/lib/python2.7/dist-packages/torch/legacy/nn/SpatialFullConvolution.py", line 96, in updateOutput
    if self.finput is None:
AttributeError: 'SpatialFullConvolution' object has no attribute 'finput'

How old is the Lua model file you're trying to import? Can you please try to load it in Lua, save again, and load it in PyTorch? Also, please update PyTorch to the newest version.
The model is convert from the cudnn model  trained by myseft 
the code below is the convert code

```
require 'nn'
require 'cudnn'
require'torch'
a={'celeba_24_G','celeba_encZ_7','celeba_encY_5'}
for i,v in ipairs(a) 
    do print(v) 
    model_cudnn=torch.load(v..'.t7')
    model_nn=cudnn.convert(model_cudnn, nn):float()
    torch.save(v..'_nn.t7',model_nn)
end  
```

BTW，my torch was installed on 17th Dec,2016

the pytorch version i use：
Metadata-Version: 1.0
Name: torch
Version: 0.1.10+997312c
I Build it from source today

Resolving patch:
diff --git a/torch/legacy/nn/SpatialFullConvolution.py b/torch/legacy/nn/SpatialFullConvolution.py
--- a/torch/legacy/nn/SpatialFullConvolution.py
+++ b/torch/legacy/nn/SpatialFullConvolution.py
@@ -88,14 +88,14 @@ def updateOutput(self, input):
             tW = targetTensor.size(tDims - 1)
             adjW = self._calculateAdj(tW, self.kW, self.padW, self.dW)
             adjH = self._calculateAdj(tH, self.kH, self.padH, self.dH)
-            if self.finput is None:
+            if not hasattr(self, 'finput') or self.finput is None:
                 self.finput = input[0].new()
-            if self.fgradInput is None:
+            if not hasattr(self, 'fgradInput') or self.fgradInput is None:
                 self.fgradInput = input[0].new()
         else:
-            if self.finput is None:
+            if not hasattr(self, 'finput') or self.finput is None:
                 self.finput = input.new()
-            if self.fgradInput is None:
+            if not hasattr(self, 'fgradInput') or self.fgradInput is None:
                 self.fgradInput = input.new()
 
         inputTensor = self._makeContiguous(inputTensor)


Test patch: