def test_equal_numpy_qshift1(): ha = qshift('qshift_c')[0] hb = qshift('qshift_c')[1] ref = np_coldfilt(mandrill.T, ha, hb).T y_op = rowdfilt(mandrill_t, ha, hb) with tf.Session() as sess: y = sess.run(y_op) np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
def test_equal_numpy_qshift2(): ha = qshift('qshift_c')[0] hb = qshift('qshift_c')[1] im = mandrill[:508, :504] im_t = tf.expand_dims(tf.constant(im, tf.float32), axis=0) ref = np_coldfilt(im.T, ha, hb).T y_op = rowdfilt(im_t, ha, hb) with tf.Session() as sess: y = sess.run(y_op) np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
def test_equal_small_in(): ha = qshift('qshift_b')[0] hb = qshift('qshift_b')[1] im = mandrill[0:4,0:4] im_t = tf.expand_dims(tf.constant(im, tf.float32), axis=0) ref = np_coldfilt(im, ha, hb) y_op = coldfilt(im_t, ha, hb) with tf.Session() as sess: y = sess.run(y_op) np.testing.assert_array_almost_equal(y[0], ref, decimal=4)
def setup(): global barbara, barbara_t global bshape, bshape_half global ref_rowdfilt, ch py3nvml.grab_gpus(1, gpu_fraction=0.5, env_set_ok=True) barbara = datasets.barbara() barbara = (barbara / barbara.max()).astype('float32') barbara = barbara.transpose([2, 0, 1]) bshape = list(barbara.shape) bshape_half = bshape[:] bshape_half[2] //= 2 barbara_t = torch.unsqueeze(torch.tensor(barbara, dtype=torch.float32), dim=0).to(dev) ch = barbara_t.shape[1] # Some useful functions ref_rowdfilt = lambda x, ha, hb: np.stack( [np_coldfilt(s.T, ha, hb).T for s in x], axis=0)