Skip to content

Instantly share code, notes, and snippets.

@andreaskoepf
Last active December 24, 2015 20:38

Revisions

  1. andreaskoepf revised this gist Dec 2, 2015. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions 2d_conv_test.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    require 'nn'

    x = torch.rand(1,5,5)
    a = nn.SpatialConvolution(1,1,3,3)
    a.bias:zero()
    ay1 =torch.xcorr2(x,a.weight,'V')
    ay2 = a:forward(x)

    b = nn.SpatialFullConvolution(1,1,3,3)
    b.bias:zero()
    by1 = torch.conv2(x, b.weight, 'F')
    by2 = b:forward(x)

    print(ay1)
    print(ay2)
    print(by1)
    print(by2)
  2. andreaskoepf revised this gist Dec 1, 2015. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions deconv_test.lua
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    require 'nn'
    a = nn.SpatialConvolution(7,5,3,3)
    a.bias:zero()

    b = nn.SpatialFullConvolution(5,7,3,3)
    require 'nn'

    b.bias:zero()

    b.weight = a.weight

    test = torch.rand(7, 12, 12)
    @@ -16,5 +16,6 @@ y2 = b:backward(torch.zeros(5,10,10), test)
    z1 = a:backward(torch.zeros(7,12,12), test2)
    z2 = b:forward(test2)

    -- prints 0 twice
    print((y1-y2):abs():sum())
    print((z1-z2):abs():sum())
  3. andreaskoepf created this gist Dec 1, 2015.
    20 changes: 20 additions & 0 deletions deconv_test.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    a = nn.SpatialConvolution(7,5,3,3)
    a.bias:zero()

    b = nn.SpatialFullConvolution(5,7,3,3)
    require 'nn'

    b.bias:zero()
    b.weight = a.weight

    test = torch.rand(7, 12, 12)
    test2 = torch.rand(5, 10, 10)

    y1 = a:forward(test)
    y2 = b:backward(torch.zeros(5,10,10), test)

    z1 = a:backward(torch.zeros(7,12,12), test2)
    z2 = b:forward(test2)

    print((y1-y2):abs():sum())
    print((z1-z2):abs():sum())