def testUnknownInputChannelsConv3D(self):
   volumes = array_ops.placeholder(dtypes.float32, (5, 6, 7, 9, None))
   layer = conv_layers.Conv3D(32, [3, 3, 3], activation=nn_ops.relu)
   with self.assertRaisesRegexp(ValueError,
                                'The channel dimension of the inputs '
                                'should be defined. Found `None`.'):
     _ = layer.apply(volumes)
  def testConstraints(self):
    # Conv1D
    k_constraint = lambda x: x / math_ops.reduce_sum(x)
    b_constraint = lambda x: x / math_ops.reduce_max(x)
    conv1d = conv_layers.Conv1D(2, 3,
                                kernel_constraint=k_constraint,
                                bias_constraint=b_constraint)
    inputs = random_ops.random_uniform((5, 3, 5), seed=1)
    conv1d(inputs)
    self.assertEqual(conv1d.kernel_constraint, k_constraint)
    self.assertEqual(conv1d.bias_constraint, b_constraint)

    # Conv2D
    k_constraint = lambda x: x / math_ops.reduce_sum(x)
    b_constraint = lambda x: x / math_ops.reduce_max(x)
    conv2d = conv_layers.Conv2D(2, 3,
                                kernel_constraint=k_constraint,
                                bias_constraint=b_constraint)
    inputs = random_ops.random_uniform((5, 3, 3, 5), seed=1)
    conv2d(inputs)
    self.assertEqual(conv2d.kernel_constraint, k_constraint)
    self.assertEqual(conv2d.bias_constraint, b_constraint)

    # Conv3D
    k_constraint = lambda x: x / math_ops.reduce_sum(x)
    b_constraint = lambda x: x / math_ops.reduce_max(x)
    conv3d = conv_layers.Conv3D(2, 3,
                                kernel_constraint=k_constraint,
                                bias_constraint=b_constraint)
    inputs = random_ops.random_uniform((5, 3, 3, 3, 5), seed=1)
    conv3d(inputs)
    self.assertEqual(conv3d.kernel_constraint, k_constraint)
    self.assertEqual(conv3d.bias_constraint, b_constraint)
 def testUnknownInputChannelsConv3D(self):
     volumes = random_ops.random_uniform((5, 6, 7, 9, 9))
     volumes._shape = tensor_shape.as_shape((5, 6, 7, 9, None))
     layer = conv_layers.Conv3D(32, [3, 3, 3], activation=nn_ops.relu)
     with self.assertRaisesRegexp(
             ValueError, 'The channel dimension of the inputs '
             'should be defined. Found `None`.'):
         _ = layer.apply(volumes)
 def testCreateConv3D(self):
   depth, height, width = 6, 7, 9
   volumes = random_ops.random_uniform((5, depth, height, width, 4))
   layer = conv_layers.Conv3D(32, [3, 3, 3], activation=nn_ops.relu)
   output = layer.apply(volumes)
   self.assertEqual(output.op.name, 'conv3d/Relu')
   self.assertListEqual(output.get_shape().as_list(),
                        [5, depth - 2, height - 2, width - 2, 32])
   self.assertListEqual(layer.kernel.get_shape().as_list(), [3, 3, 3, 4, 32])
   self.assertListEqual(layer.bias.get_shape().as_list(), [32])