layers_test.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:lsdc 作者: febert 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号