Exemple #1
0
 def test_custom_conv2d_passes_custom_layer_options(self,
                                                    mock_custom_layer_impl):
   x = tf.constant(
       [[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]],
        [[[0, 0, 0], [-1, -2, -3]], [[1, -2, 2], [2, 5, 3]]]],
       dtype=tf.float32)
   layers.custom_conv2d(x, 1, 2)
   mock_custom_layer_impl.assert_called_once_with(
       mock.ANY,
       kernel_shape=[2, 2, 3, 1],
       bias_shape=(1,),
       activation=None,
       he_initializer_slope=1.0,
       use_weight_scaling=True)
Exemple #2
0
 def test_custom_conv2d_passes_conv2d_options(self, mock_conv2d):
   x = tf.constant(
       [[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]],
        [[[0, 0, 0], [-1, -2, -3]], [[1, -2, 2], [2, 5, 3]]]],
       dtype=tf.float32)
   layers.custom_conv2d(x, 1, 2)
   mock_conv2d.assert_called_once_with(
       x,
       filters=1,
       kernel_size=[2, 2],
       strides=(1, 1),
       padding='SAME',
       use_bias=False,
       kernel_initializer=mock.ANY)
Exemple #3
0
 def _to_rgb(x):
     return layers.custom_conv2d(x=x,
                                 filters=colors,
                                 kernel_size=1,
                                 padding='SAME',
                                 activation=to_rgb_activation,
                                 scope='to_rgb')
Exemple #4
0
 def _conv2d(scope, x, kernel_size, filters, padding='SAME'):
     return layers.custom_conv2d(x=x,
                                 filters=filters,
                                 kernel_size=kernel_size,
                                 padding=padding,
                                 activation=tf.nn.leaky_relu,
                                 he_initializer_slope=0.0,
                                 scope=scope)
Exemple #5
0
 def _to_rgb(x):
   return layers.custom_conv2d(
       x=x,
       filters=colors,
       kernel_size=1,
       padding='SAME',
       activation=to_rgb_activation,
       scope='to_rgb')
Exemple #6
0
 def _conv2d(scope, x, kernel_size, filters, padding='SAME'):
   return layers.custom_conv2d(
       x=x,
       filters=filters,
       kernel_size=kernel_size,
       padding=padding,
       activation=tf.nn.leaky_relu,
       he_initializer_slope=0.0,
       scope=scope)
Exemple #7
0
  def test_custom_conv2d_list_kernel_size(self, mock_zeros_initializer,
                                          mock_random_normal_initializer):
    mock_zeros_initializer.return_value = tf.constant_initializer(1.0)
    mock_random_normal_initializer.return_value = tf.constant_initializer(3.0)
    x = tf.constant(
        [[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]],
         [[[0, 0, 0], [-1, -2, -3]], [[1, -2, 2], [2, 5, 3]]]],
        dtype=tf.float32)
    output = layers.custom_conv2d(x, 1, [2, 3])
    with self.test_session(use_gpu=True) as sess:
      sess.run(tf.global_variables_initializer())
      output_np = sess.run(output)

    expected_np = [[
        [[56.15432739], [56.15432739]],
        [[41.30508804], [41.30508804]],
    ], [[[4.53553391], [4.53553391]], [[8.7781744], [8.7781744]]]]
    self.assertNDArrayNear(output_np, expected_np, 1.0e-5)
Exemple #8
0
  def test_custom_conv2d_scalar_kernel_size(self, mock_zeros_initializer,
                                            mock_random_normal_initializer):
    mock_zeros_initializer.return_value = tf.constant_initializer(1.0)
    mock_random_normal_initializer.return_value = tf.constant_initializer(3.0)
    x = tf.constant(
        [[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]],
         [[[0, 0, 0], [-1, -2, -3]], [[1, -2, 2], [2, 5, 3]]]],
        dtype=tf.float32)
    output = layers.custom_conv2d(x, 1, 2)
    with self.test_session(use_gpu=True) as sess:
      sess.run(tf.global_variables_initializer())
      output_np = sess.run(output)

    expected_np = [[[[68.54998016], [42.56921768]], [[50.36344528],
                                                     [29.57883835]]],
                   [[[5.33012676], [4.46410179]], [[10.52627945],
                                                   [9.66025352]]]]
    self.assertNDArrayNear(output_np, expected_np, 1.0e-5)