conv_test.py 文件源码

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

项目:sonnet 作者: deepmind 项目源码 文件源码
def testSharing(self, use_bias):
    """Sharing is working."""
    conv1 = snt.DepthwiseConv2D(
        channel_multiplier=3, kernel_shape=3, stride=1, padding=snt.SAME,
        use_bias=use_bias)

    x = np.random.randn(1, 5, 5, 1)
    x1 = tf.constant(x, dtype=np.float32)
    x2 = tf.constant(x, dtype=np.float32)

    out1 = conv1(x1)
    out2 = conv1(x2)

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

      # Kernel shape was set to 3, which is expandeded to [3, 3, 3].
      # Input channels are 1, output channels := in_channels * multiplier.
      # multiplier is kernel_shape[2] == 3. So weight layout must be:
      # (3, 3, 1, 3).
      w = np.random.randn(3, 3, 1, 3)  # Now change the weights.
      conv1.w.assign(w).eval()
      self.assertAllClose(out1.eval(), out2.eval())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号