def testVertConvWithVaryingImage(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(('-0.1 0.0 -1.0;'
' 5.4 2.0 -4.9'))
expected = np.reshape(np.asarray(expected), (1, 2, 3, 1))
tf_image = tf.constant(image, shape=(1, 3, 3, 1), dtype=tf.float32)
vert_gradients = tf.contrib.layers.conv2d_in_plane(
tf_image,
weights_initializer=tf.constant_initializer([1, -1]),
kernel_size=[2, 1],
padding='VALID',
activation_fn=None)
init_op = tf.global_variables_initializer()
with self.test_session() as sess:
sess.run(init_op)
result = sess.run(vert_gradients)
self.assertAllClose(result, expected, rtol=1e-5, atol=1e-5)
评论列表
文章目录