hughperkins / pytorch

Python wrappers for torch and lua
BSD 2-Clause "Simplified" License
431 stars 70 forks source link

PyTorchAug.save() doesn't save correct weights. #45

Closed jatinsha closed 5 years ago

jatinsha commented 5 years ago
>>> l
nn.SpatialConvolution(1 -> 3, 3x3, 1,1, 1,1)

>>> l.weight.asNumpyTensor()
array([[[[2., 2., 2.],
         [2., 2., 2.],
         [2., 2., 2.]]],

       [[[2., 2., 2.],
         [2., 2., 2.],
         [2., 2., 2.]]],

       [[[2., 2., 2.],
         [2., 2., 2.],
         [2., 2., 2.]]]], dtype=float32)

>>> PyTorchAug.save('/home/jatin17/workspace/pySeer/sketch/test_WW.net',l)
>>> l2=PyTorchAug.load('/home/jatin17/workspace/pySeer/sketch/test_WW.net')

>>> l2.weight.asNumpyTensor()
array([[[[-0.20179332, -0.32749048,  0.22701705],
         [ 0.18695774, -0.11507146,  0.32600074],
         [-0.3111914 , -0.24465627,  0.26392609]]],

       [[[ 0.14200437, -0.17333959,  0.25616663],
         [ 0.04954733, -0.14041339,  0.00439858],
         [-0.18362816, -0.13976645, -0.26147268]]],

       [[[-0.16414926, -0.31703166,  0.13214643],
         [ 0.06721597, -0.26673907, -0.13336769],
         [-0.02258702,  0.22950082,  0.30467097]]]])

#Lua torch7
th> xx=torch.load('test_WW.net')
th> xx.weight
(1,1,.,.) = 
 -0.2018 -0.3275  0.2270
  0.1870 -0.1151  0.3260
 -0.3112 -0.2447  0.2639

(2,1,.,.) = 
  0.1420 -0.1733  0.2562
  0.0495 -0.1404  0.0044
 -0.1836 -0.1398 -0.2615

(3,1,.,.) = 
 -0.1641 -0.3170  0.1321
  0.0672 -0.2667 -0.1334
 -0.0226  0.2295  0.3047
[torch.DoubleTensor of size 3x1x3x3]

PyTorchAug.load works fine and loads correct weights. Verified using luaTorch load method which matches the weights.