Esempio n. 1
0
  def test_pad_images_boxes_and_classes(self):
    input_tensor_dict = {
        fields.InputDataFields.image:
            tf.placeholder(tf.float32, [None, None, 3]),
        fields.InputDataFields.groundtruth_boxes:
            tf.placeholder(tf.float32, [None, 4]),
        fields.InputDataFields.groundtruth_classes:
            tf.placeholder(tf.int32, [None, 3]),
        fields.InputDataFields.true_image_shape: tf.placeholder(tf.int32, [3]),
    }
    padded_tensor_dict = inputs.pad_input_data_to_static_shapes(
        tensor_dict=input_tensor_dict,
        max_num_boxes=3,
        num_classes=3,
        spatial_image_shape=[5, 6])

    self.assertAllEqual(
        padded_tensor_dict[fields.InputDataFields.image].shape.as_list(),
        [5, 6, 3])
    self.assertAllEqual(
        padded_tensor_dict[fields.InputDataFields.true_image_shape]
        .shape.as_list(), [3])
    self.assertAllEqual(
        padded_tensor_dict[fields.InputDataFields.groundtruth_boxes]
        .shape.as_list(), [3, 4])
    self.assertAllEqual(
        padded_tensor_dict[fields.InputDataFields.groundtruth_classes]
        .shape.as_list(), [3, 3])
Esempio n. 2
0
  def test_clip_boxes_and_classes(self):
    input_tensor_dict = {
        fields.InputDataFields.groundtruth_boxes:
            tf.placeholder(tf.float32, [None, 4]),
        fields.InputDataFields.groundtruth_classes:
            tf.placeholder(tf.int32, [None, 3]),
    }
    padded_tensor_dict = inputs.pad_input_data_to_static_shapes(
        tensor_dict=input_tensor_dict,
        max_num_boxes=3,
        num_classes=3,
        spatial_image_shape=[5, 6])

    self.assertAllEqual(
        padded_tensor_dict[fields.InputDataFields.groundtruth_boxes]
        .shape.as_list(), [3, 4])
    self.assertAllEqual(
        padded_tensor_dict[fields.InputDataFields.groundtruth_classes]
        .shape.as_list(), [3, 3])

    with self.test_session() as sess:
      out_tensor_dict = sess.run(
          padded_tensor_dict,
          feed_dict={
              input_tensor_dict[fields.InputDataFields.groundtruth_boxes]:
                  np.random.rand(5, 4),
              input_tensor_dict[fields.InputDataFields.groundtruth_classes]:
                  np.random.rand(2, 3),
          })

    self.assertAllEqual(
        out_tensor_dict[fields.InputDataFields.groundtruth_boxes].shape, [3, 4])
    self.assertAllEqual(
        out_tensor_dict[fields.InputDataFields.groundtruth_classes].shape,
        [3, 3])
Esempio n. 3
0
    def test_pad_images_boxes_and_classes(self):
        input_tensor_dict = {
            fields.InputDataFields.image:
            tf.placeholder(tf.float32, [None, None, 3]),
            fields.InputDataFields.groundtruth_boxes:
            tf.placeholder(tf.float32, [None, 4]),
            fields.InputDataFields.groundtruth_classes:
            tf.placeholder(tf.int32, [None, 3]),
            fields.InputDataFields.true_image_shape:
            tf.placeholder(tf.int32, [3]),
        }
        padded_tensor_dict = inputs.pad_input_data_to_static_shapes(
            tensor_dict=input_tensor_dict,
            max_num_boxes=3,
            num_classes=3,
            spatial_image_shape=[5, 6])

        self.assertAllEqual(
            padded_tensor_dict[fields.InputDataFields.image].shape.as_list(),
            [5, 6, 3])
        self.assertAllEqual(
            padded_tensor_dict[
                fields.InputDataFields.true_image_shape].shape.as_list(), [3])
        self.assertAllEqual(
            padded_tensor_dict[
                fields.InputDataFields.groundtruth_boxes].shape.as_list(),
            [3, 4])
        self.assertAllEqual(
            padded_tensor_dict[
                fields.InputDataFields.groundtruth_classes].shape.as_list(),
            [3, 3])
Esempio n. 4
0
  def test_do_not_pad_dynamic_images(self):
    input_tensor_dict = {
        fields.InputDataFields.image:
            tf.placeholder(tf.float32, [None, None, 3]),
    }
    padded_tensor_dict = inputs.pad_input_data_to_static_shapes(
        tensor_dict=input_tensor_dict,
        max_num_boxes=3,
        num_classes=3,
        spatial_image_shape=[None, None])

    self.assertAllEqual(
        padded_tensor_dict[fields.InputDataFields.image].shape.as_list(),
        [None, None, 3])
Esempio n. 5
0
    def test_do_not_pad_dynamic_images(self):
        input_tensor_dict = {
            fields.InputDataFields.image:
            tf.placeholder(tf.float32, [None, None, 3]),
        }
        padded_tensor_dict = inputs.pad_input_data_to_static_shapes(
            tensor_dict=input_tensor_dict,
            max_num_boxes=3,
            num_classes=3,
            spatial_image_shape=[None, None])

        self.assertAllEqual(
            padded_tensor_dict[fields.InputDataFields.image].shape.as_list(),
            [None, None, 3])
Esempio n. 6
0
 def test_images_and_additional_channels_errors(self):
   input_tensor_dict = {
       fields.InputDataFields.image:
           tf.placeholder(tf.float32, [None, None, 3]),
       fields.InputDataFields.image_additional_channels:
           tf.placeholder(tf.float32, [None, None, 2]),
       fields.InputDataFields.original_image:
           tf.placeholder(tf.float32, [None, None, 3]),
   }
   with self.assertRaises(ValueError):
     _ = inputs.pad_input_data_to_static_shapes(
         tensor_dict=input_tensor_dict,
         max_num_boxes=3,
         num_classes=3,
         spatial_image_shape=[5, 6])
Esempio n. 7
0
 def test_images_and_additional_channels_errors(self):
     input_tensor_dict = {
         fields.InputDataFields.image:
         tf.placeholder(tf.float32, [None, None, 3]),
         fields.InputDataFields.image_additional_channels:
         tf.placeholder(tf.float32, [None, None, 2]),
         fields.InputDataFields.original_image:
         tf.placeholder(tf.float32, [None, None, 3]),
     }
     with self.assertRaises(ValueError):
         _ = inputs.pad_input_data_to_static_shapes(
             tensor_dict=input_tensor_dict,
             max_num_boxes=3,
             num_classes=3,
             spatial_image_shape=[5, 6])
Esempio n. 8
0
    def test_clip_boxes_and_classes(self):
        input_tensor_dict = {
            fields.InputDataFields.groundtruth_boxes:
            tf.placeholder(tf.float32, [None, 4]),
            fields.InputDataFields.groundtruth_classes:
            tf.placeholder(tf.int32, [None, 3]),
            fields.InputDataFields.num_groundtruth_boxes:
            tf.placeholder(tf.int32, [])
        }
        padded_tensor_dict = inputs.pad_input_data_to_static_shapes(
            tensor_dict=input_tensor_dict,
            max_num_boxes=3,
            num_classes=3,
            spatial_image_shape=[5, 6])

        self.assertAllEqual(
            padded_tensor_dict[
                fields.InputDataFields.groundtruth_boxes].shape.as_list(),
            [3, 4])
        self.assertAllEqual(
            padded_tensor_dict[
                fields.InputDataFields.groundtruth_classes].shape.as_list(),
            [3, 3])

        with self.test_session() as sess:
            out_tensor_dict = sess.run(
                padded_tensor_dict,
                feed_dict={
                    input_tensor_dict[fields.InputDataFields.groundtruth_boxes]:
                    np.random.rand(5, 4),
                    input_tensor_dict[fields.InputDataFields.groundtruth_classes]:
                    np.random.rand(2, 3),
                    input_tensor_dict[fields.InputDataFields.num_groundtruth_boxes]:
                    5,
                })

        self.assertAllEqual(
            out_tensor_dict[fields.InputDataFields.groundtruth_boxes].shape,
            [3, 4])
        self.assertAllEqual(
            out_tensor_dict[fields.InputDataFields.groundtruth_classes].shape,
            [3, 3])
        self.assertEqual(
            out_tensor_dict[fields.InputDataFields.num_groundtruth_boxes], 3)
Esempio n. 9
0
  def test_images_and_additional_channels(self):
    input_tensor_dict = {
        fields.InputDataFields.image:
            tf.placeholder(tf.float32, [None, None, 3]),
        fields.InputDataFields.image_additional_channels:
            tf.placeholder(tf.float32, [None, None, 2]),
    }
    padded_tensor_dict = inputs.pad_input_data_to_static_shapes(
        tensor_dict=input_tensor_dict,
        max_num_boxes=3,
        num_classes=3,
        spatial_image_shape=[5, 6])

    self.assertAllEqual(
        padded_tensor_dict[fields.InputDataFields.image].shape.as_list(),
        [5, 6, 5])
    self.assertAllEqual(
        padded_tensor_dict[fields.InputDataFields.image_additional_channels]
        .shape.as_list(), [5, 6, 2])
Esempio n. 10
0
  def test_images_and_additional_channels(self):
    input_tensor_dict = {
        fields.InputDataFields.image:
            tf.placeholder(tf.float32, [None, None, 3]),
        fields.InputDataFields.image_additional_channels:
            tf.placeholder(tf.float32, [None, None, 2]),
    }
    padded_tensor_dict = inputs.pad_input_data_to_static_shapes(
        tensor_dict=input_tensor_dict,
        max_num_boxes=3,
        num_classes=3,
        spatial_image_shape=[5, 6])

    self.assertAllEqual(
        padded_tensor_dict[fields.InputDataFields.image].shape.as_list(),
        [5, 6, 5])
    self.assertAllEqual(
        padded_tensor_dict[fields.InputDataFields.image_additional_channels]
        .shape.as_list(), [5, 6, 2])
Esempio n. 11
0
  def test_keypoints(self):
    input_tensor_dict = {
        fields.InputDataFields.groundtruth_keypoints:
            tf.placeholder(tf.float32, [None, 16, 4]),
        fields.InputDataFields.groundtruth_keypoint_visibilities:
            tf.placeholder(tf.bool, [None, 16]),
    }
    padded_tensor_dict = inputs.pad_input_data_to_static_shapes(
        tensor_dict=input_tensor_dict,
        max_num_boxes=3,
        num_classes=3,
        spatial_image_shape=[5, 6])

    self.assertAllEqual(
        padded_tensor_dict[fields.InputDataFields.groundtruth_keypoints]
        .shape.as_list(), [3, 16, 4])
    self.assertAllEqual(
        padded_tensor_dict[
            fields.InputDataFields.groundtruth_keypoint_visibilities]
        .shape.as_list(), [3, 16])
Esempio n. 12
0
  def test_keypoints(self):
    input_tensor_dict = {
        fields.InputDataFields.groundtruth_keypoints:
            tf.placeholder(tf.float32, [None, 16, 4]),
        fields.InputDataFields.groundtruth_keypoint_visibilities:
            tf.placeholder(tf.bool, [None, 16]),
    }
    padded_tensor_dict = inputs.pad_input_data_to_static_shapes(
        tensor_dict=input_tensor_dict,
        max_num_boxes=3,
        num_classes=3,
        spatial_image_shape=[5, 6])

    self.assertAllEqual(
        padded_tensor_dict[fields.InputDataFields.groundtruth_keypoints]
        .shape.as_list(), [3, 16, 4])
    self.assertAllEqual(
        padded_tensor_dict[
            fields.InputDataFields.groundtruth_keypoint_visibilities]
        .shape.as_list(), [3, 16])