Exemplo n.º 1
0
    def testMultipleConvMaskAdded(self):
        number_of_layers = 5

        kernel_size = 3
        base_depth = 4
        depth_step = 7

        input_tensor = array_ops.ones((8, self.height, self.width, base_depth))

        top_layer = input_tensor

        for ix in range(number_of_layers):
            top_layer = layers.masked_conv2d(
                top_layer, base_depth + (ix + 1) * depth_step, kernel_size)

        masks = ops.get_collection(core_layers.MASK_COLLECTION)
        self.assertEqual(len(masks), number_of_layers)
        for ix in range(number_of_layers):
            self.assertListEqual(masks[ix].get_shape().as_list(), [
                kernel_size, kernel_size, base_depth + ix * depth_step,
                base_depth + (ix + 1) * depth_step
            ])

        masked_weight = ops.get_collection(
            core_layers.MASKED_WEIGHT_COLLECTION)
        self.assertEqual(len(masked_weight), number_of_layers)
        for ix in range(number_of_layers):
            self.assertListEqual(masked_weight[ix].get_shape().as_list(), [
                kernel_size, kernel_size, base_depth + ix * depth_step,
                base_depth + (ix + 1) * depth_step
            ])
Exemplo n.º 2
0
    def testSingleConvMaskAdded(self):
        kernel_size = 3
        input_depth, output_depth = 8, 32
        input_tensor = array_ops.ones(
            (8, self.height, self.width, input_depth))
        layers.masked_conv2d(input_tensor, output_depth, kernel_size)

        masks = ops.get_collection(core_layers.MASK_COLLECTION)
        self.assertEqual(len(masks), 1)
        self.assertListEqual(
            masks[0].get_shape().as_list(),
            [kernel_size, kernel_size, input_depth, output_depth])

        masked_weight = ops.get_collection(
            core_layers.MASKED_WEIGHT_COLLECTION)
        self.assertEqual(len(masked_weight), 1)
        self.assertListEqual(
            masked_weight[0].get_shape().as_list(),
            [kernel_size, kernel_size, input_depth, output_depth])
Exemplo n.º 3
0
  def _build_convolutional_model(self, number_of_layers):
    # Create a graph with several conv2d layers
    kernel_size = 3
    base_depth = 4
    depth_step = 7
    height, width = 7, 9
    with variable_scope.variable_scope("conv_model"):
      input_tensor = array_ops.ones((8, height, width, base_depth))
      top_layer = input_tensor
      for ix in range(number_of_layers):
        top_layer = layers.masked_conv2d(
            top_layer,
            base_depth + (ix + 1) * depth_step,
            kernel_size,
            scope="Conv_" + str(ix))

    return top_layer
Exemplo n.º 4
0
 def testInvalidRank5(self):
     input_tensor = array_ops.ones((8, 8, self.height, self.width, 3))
     with self.assertRaisesRegexp(ValueError, 'rank'):
         layers.masked_conv2d(input_tensor, 32, 3)