Esempio n. 1
0
def test_slice_cudaNo0():
    gaussian3d = Gaussian([2, 4, 4])
    x = gaussian3d(3).cuda(2)
    netStructure = [[3, 2, 1, 1], [4, 2, 1, 1], [3, 2, 1, 0], [1, 2, 1, 0]]
    sList3d = [
        CNN(netStructure),
        CNN(netStructure),
        CNN(netStructure),
        CNN(netStructure)
    ]
    tList3d = [
        CNN(netStructure),
        CNN(netStructure),
        CNN(netStructure),
        CNN(netStructure)
    ]

    realNVP = RealNVP([2, 4, 4], sList3d, tList3d, gaussian3d)
    realNVP = realNVP.cuda(2)
    z = realNVP._generateWithSlice(x, 0, True)
    print(realNVP._logProbabilityWithSlice(z, 0))
    zz = realNVP._inferenceWithSlice(z, 0, True)
    assert_array_almost_equal(x.cpu().data.numpy(), zz.cpu().data.numpy())
    assert_array_almost_equal(realNVP._generateLogjac.data.cpu().numpy(),
                              -realNVP._inferenceLogjac.data.cpu().numpy())
Esempio n. 2
0
def test_multiplyMask_generateWithSlice_CNN():
    gaussian3d = Gaussian([2, 4, 4])
    x = gaussian3d(3)
    #z3dp = z3d[:,0,:,:].view(10,-1,4,4)
    #print(z3dp)

    #print(x)
    netStructure = [[3, 2, 1, 1], [4, 2, 1, 1], [3, 2, 1, 0],
                    [1, 2, 1, 0]]  # [channel, filter_size, stride, padding]

    sList3d = [
        CNN(netStructure),
        CNN(netStructure),
        CNN(netStructure),
        CNN(netStructure)
    ]
    tList3d = [
        CNN(netStructure),
        CNN(netStructure),
        CNN(netStructure),
        CNN(netStructure)
    ]

    realNVP = RealNVP([2, 4, 4], sList3d, tList3d, gaussian3d)
    mask = realNVP.createMask(
        ["channel", "checkerboard", "channel", "checkerboard"], ifByte=1)

    z = realNVP._generateWithSlice(x, 0, True)
    #print(z)
    zz = realNVP._inferenceWithSlice(z, 0, True)

    #print(zz)

    assert_array_almost_equal(x.data.numpy(), zz.data.numpy())
    #print(realNVP._generateLogjac.data.numpy())
    #print(realNVP._inferenceLogjac.data.numpy())
    assert_array_almost_equal(realNVP._generateLogjac.data.numpy(),
                              -realNVP._inferenceLogjac.data.numpy())
Esempio n. 3
0
def test_template_slice_function():
    gaussian3d = Gaussian([2, 4, 4])
    x = gaussian3d(3)
    #z3dp = z3d[:,0,:,:].view(10,-1,4,4)
    #print(z3dp)

    #print(x)
    netStructure = [[3, 2, 1, 1], [4, 2, 1, 1], [3, 2, 1, 0],
                    [1, 2, 1, 0]]  # [channel, filter_size, stride, padding]

    sList3d = [
        CNN(netStructure),
        CNN(netStructure),
        CNN(netStructure),
        CNN(netStructure)
    ]
    tList3d = [
        CNN(netStructure),
        CNN(netStructure),
        CNN(netStructure),
        CNN(netStructure)
    ]

    realNVP = RealNVP([2, 4, 4], sList3d, tList3d, gaussian3d)

    z = realNVP._generateWithSlice(x, 0, True)
    #print(z)
    zz = realNVP._inferenceWithSlice(z, 0, True)

    #print(zz)

    assert_array_almost_equal(x.data.numpy(), zz.data.numpy())
    #print(realNVP._generateLogjac.data.numpy())
    #print(realNVP._inferenceLogjac.data.numpy())
    assert_array_almost_equal(realNVP._generateLogjac.data.numpy(),
                              -realNVP._inferenceLogjac.data.numpy())