def testHorzConvWithVaryingImage(self):
image = np.asmatrix(('1.0 2.0 3.0;'
'1.1 2.0 4.0;'
'-4.3 0.0 8.9'))
expected = np.asmatrix(('-1.0 -1.0;'
'-0.9 -2.0;'
'-4.3 -8.9'))
expected = np.reshape(np.asarray(expected), (1, 3, 2, 1))
tf_image = tf.constant(image, shape=(1, 3, 3, 1), dtype=tf.float32)
horz_gradients = tf.contrib.layers.conv2d_in_plane(
tf_image,
weights_initializer=tf.constant_initializer([1, -1]),
kernel_size=[1, 2],
padding='VALID',
activation_fn=None)
init_op = tf.initialize_all_variables()
with self.test_session() as sess:
sess.run(init_op)
result = sess.run(horz_gradients)
self.assertAllClose(result, expected, rtol=1e-5, atol=1e-5)
评论列表
文章目录