message: Improve grouped convolution tests
diff: @@ -25,6 +25,8 @@ from tensorflow.python import keras
  from tensorflow.python.eager import context
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  +from tensorflow.python.ops import nn
  +from tensorflow.python.ops import random_ops
  from tensorflow.python.keras import keras_parameterized
  from tensorflow.python.keras import testing_utils
  from tensorflow.python.platform import test
  @@ -303,19 +305,35 @@ class GroupedConvTest(keras_parameterized.TestCase):
  ('Conv2D', keras.layers.Conv2D, (32, 12, 12, 32)),
  ('Conv3D', keras.layers.Conv3D, (32, 12, 12, 12, 32)),
  )
  - def test_group_conv(self, layer, input_shape):
  + def test_group_conv(self, layer_cls, input_shape):
  if test.is_gpu_available(cuda_only=True):
  with test_util.use_gpu():
  - inputs = np.random.uniform(size=input_shape)
  + inputs = random_ops.random_uniform(shape=input_shape)
  - outputs = layer(16, 3, groups=4, kernel_initializer="ones")(inputs)
  + layer = layer_cls(16, 3, groups=4)
  + layer.build(input_shape)
  - input_slices = np.split(inputs, 4, axis=-1)
  + input_slices = array_ops.split(inputs, 4, axis=-1)
  + weight_slices = array_ops.split(layer.kernel, 4, axis=-1)
  expected_outputs = array_ops.concat([
  - layer(16 // 4, 3, kernel_initializer="ones")(slice)
  - for slice in input_slices], axis=-1)
  + nn.convolution_v2(inputs, weights)
  + for inputs, weights in zip(input_slices, weight_slices)], axis=-1)
  - self.assertAllClose(outputs, expected_outputs)
  + self.assertAllClose(layer(inputs), expected_outputs, rtol=1e-5)
  +
  + def test_group_conv_depthwise(self):
  + if test.is_gpu_available(cuda_only=True):
  + with test_util.use_gpu():
  + inputs = random_ops.random_uniform(shape=(3, 27, 27, 32))
  +
  + layer = keras.layers.Conv2D(32, 3, groups=32)
  + layer.build((3, 27, 27, 32))
  +
  + weights_dw = array_ops.reshape(layer.kernel, [3, 3, 32, 1])
  + expected_outputs = nn.depthwise_conv2d(
  + inputs, weights_dw, strides=[1, 1, 1, 1], padding="VALID")
  +
  + self.assertAllClose(layer(inputs), expected_outputs, rtol=1e-5)
  @keras_parameterized.run_all_keras_modes
  