conv_test.py 文件源码

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

项目:sonnet 作者: deepmind 项目源码 文件源码
def testComputationSame(self, use_bias):
    """Run through for something with a known answer using SAME padding."""
    conv1 = snt.Conv2D(
        output_channels=1,
        kernel_shape=3,
        stride=1,
        padding=snt.SAME,
        name="conv1",
        use_bias=use_bias,
        initializers=create_constant_initializers(1.0, 1.0, use_bias))

    out = conv1(tf.constant(np.ones([1, 5, 5, 1], dtype=np.float32)))
    expected_out = np.array([[5, 7, 7, 7, 5],
                             [7, 10, 10, 10, 7],
                             [7, 10, 10, 10, 7],
                             [7, 10, 10, 10, 7],
                             [5, 7, 7, 7, 5]])
    if not use_bias:
      expected_out -= 1

    with self.test_session():
      tf.variables_initializer(
          [conv1.w, conv1.b] if use_bias else [conv1.w]).run()

      self.assertAllClose(np.reshape(out.eval(), [5, 5]), expected_out)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号