File size: 2,263 Bytes
506da10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# coding=utf-8
# Copyright 2021 The Deeplab2 Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Test for vip_deeplab.py."""
import numpy as np
import tensorflow as tf

from deeplab2.model.post_processor import vip_deeplab


class PostProcessingTest(tf.test.TestCase):

  def test_stitch_video_panoptic_prediction(self):
    concat_semantic = np.array(
        [[[0, 0, 0, 0],
          [0, 1, 1, 0],
          [0, 2, 2, 0],
          [2, 2, 3, 3]]], dtype=np.int32)
    concat_instance = np.array(
        [[[1, 1, 2, 2],
          [1, 0, 0, 2],
          [1, 1, 1, 2],
          [2, 2, 1, 1]]], dtype=np.int32)
    next_semantic = np.array(
        [[[0, 1, 1, 0],
          [0, 1, 1, 0],
          [0, 2, 2, 0],
          [2, 2, 3, 3]]], dtype=np.int32)
    next_instance = np.array(
        [[[2, 0, 0, 1],
          [2, 0, 0, 1],
          [2, 4, 4, 1],
          [5, 5, 3, 3]]], dtype=np.int32)
    label_divisor = 1000
    concat_panoptic = concat_semantic * label_divisor + concat_instance
    next_panoptic = next_semantic * label_divisor + next_instance
    new_panoptic = vip_deeplab.stitch_video_panoptic_prediction(
        concat_panoptic,
        next_panoptic,
        label_divisor)
    # The expected instance is manually computed. It should receive the IDs
    # propagated from concat_instance by IoU matching between concat_panoptic
    # and next_panoptic.
    expected_semantic = next_semantic
    expected_instance = np.array(
        [[[1, 0, 0, 2],
          [1, 0, 0, 2],
          [1, 1, 1, 2],
          [2, 2, 1, 1]]], dtype=np.int32)
    expected_panoptic = expected_semantic * label_divisor + expected_instance
    np.testing.assert_array_equal(expected_panoptic, new_panoptic)


if __name__ == '__main__':
  tf.test.main()