示例#1
0
def test_equal_numpy_biort1():
    h = biort('near_sym_b')[0]
    ref = np_colfilter(mandrill, h)
    y_op = colfilter(mandrill_t, h)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
示例#2
0
def test_equal_numpy_qshift1():
    h = qshift('qshift_c')[0]
    ref = np_colfilter(mandrill, h)
    y_op = colfilter(mandrill_t, h)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
示例#3
0
def test_equal_numpy_biort1():
    h = biort('near_sym_b')[0]
    ref = np_colfilter(mandrill.T, h).T
    y_op = rowfilter(mandrill_t, h)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
示例#4
0
def test_equal_numpy_biort2():
    h = biort('near_sym_b')[0]
    im = mandrill[52:407, 30:401]
    im_t = tf.expand_dims(tf.constant(im, tf.float32), axis=0)
    ref = np_colfilter(im, h)
    y_op = colfilter(im_t, h)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
示例#5
0
def test_equal_small_in():
    h = qshift('qshift_b')[0]
    im = mandrill[0:4,0:4]
    im_t = tf.expand_dims(tf.constant(im, tf.float32), axis=0)
    ref = np_colfilter(im, h)
    y_op = colfilter(im_t, h)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
示例#6
0
def test_equal_numpy_qshift2():
    h = qshift('qshift_c')[0]
    im = mandrill[15:307, 40:267]
    im_t = tf.expand_dims(tf.constant(im, tf.float32), axis=0)
    ref = np_colfilter(im.T, h).T
    y_op = rowfilter(im_t, h)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
示例#7
0
def test_equal_numpy_biort2():
    h = biort('near_sym_b')[0]
    im = mandrill[15:307, 40:267]
    im_t = tf.expand_dims(tf.constant(im, tf.float32), axis=0)
    ref = np_colfilter(im.T, h).T
    y_op = rowfilter(im_t, h)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
示例#8
0
def test_equal_small_in():
    h = qshift('qshift_b')[0]
    im = mandrill[0:4,0:4]
    im_t = tf.expand_dims(tf.constant(im, tf.float32), axis=0)
    ref = np_colfilter(im.T, h).T
    y_op = rowfilter(im_t, h)
    with tf.Session() as sess:
        y = sess.run(y_op)
    np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
示例#9
0
def setup():
    global barbara, barbara_t, tf
    global bshape, bshape_extracol
    global ref_rowfilter, ch
    py3nvml.grab_gpus(1, gpu_fraction=0.5)
    barbara = datasets.barbara()
    barbara = (barbara / barbara.max()).astype('float32')
    barbara = barbara.transpose([2, 0, 1])
    bshape = list(barbara.shape)
    bshape_extracol = bshape[:]
    bshape_extracol[2] += 1
    barbara_t = torch.unsqueeze(torch.tensor(barbara, dtype=torch.float32),
                                dim=0).to(dev)
    ch = barbara_t.shape[1]

    # Some useful functions
    ref_rowfilter = lambda x, h: np.stack([np_colfilter(s.T, h).T for s in x],
                                          axis=0)
示例#10
0
if __name__ == '__main__':
    # It is important to use float32 as most GPUs still work on single precision
    # floating points. These arrays need 64 MiB of memory each.
    #  a = np.random.randn(16, 3, 64, 64).astype('float32')
    w = np.random.randn(1, 11).astype('float32')
    a = np.repeat(np.expand_dims(np.arange(10), axis=0), repeats=5,
                  axis=0).astype('float32')
    a = np.repeat(np.expand_dims(a, axis=0), repeats=3, axis=0)
    a = np.repeat(np.expand_dims(a, axis=0), repeats=2, axis=0)
    w = np.array([1, 1, 1, 1, 1]).astype('float32')
    w = np.expand_dims(w, -1)

    # Some useful functions
    ref_colfilter = lambda x, h: np.stack(
        [np.stack([np_colfilter(s, h) for s in c], axis=0) for c in x], axis=0)
    ref_rowfilter = lambda x, h: np.stack(
        [np.stack([np_colfilter(s.T, h).T for s in c], axis=0) for c in x],
        axis=0)

    y1 = ref_colfilter(a, w)
    y2 = ref_rowfilter(a, w)

    w_col = torch.tensor(w, dtype=torch.float32).cuda()
    w_row = torch.tensor(w, dtype=torch.float32).cuda()
    a_t = torch.tensor(a, requires_grad=True)
    a_t_gpu = a_t.cuda()

    mod = ColFilter(w_col)
    y1_t = mod(a_t_gpu)
    gradcheck(mod, (a_t_gpu, ), eps=1e-2, atol=1e-3)