karolmajek/maxdeeplab
0
1# coding=utf-82# Copyright 2021 The Deeplab2 Authors.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15 16"""Test for vip_deeplab.py."""17import numpy as np18import tensorflow as tf19 20from deeplab2.model.post_processor import vip_deeplab21 22 23class PostProcessingTest(tf.test.TestCase):24 25 def test_stitch_video_panoptic_prediction(self):26 concat_semantic = np.array(27 [[[0, 0, 0, 0],28 [0, 1, 1, 0],29 [0, 2, 2, 0],30 [2, 2, 3, 3]]], dtype=np.int32)31 concat_instance = np.array(32 [[[1, 1, 2, 2],33 [1, 0, 0, 2],34 [1, 1, 1, 2],35 [2, 2, 1, 1]]], dtype=np.int32)36 next_semantic = np.array(37 [[[0, 1, 1, 0],38 [0, 1, 1, 0],39 [0, 2, 2, 0],40 [2, 2, 3, 3]]], dtype=np.int32)41 next_instance = np.array(42 [[[2, 0, 0, 1],43 [2, 0, 0, 1],44 [2, 4, 4, 1],45 [5, 5, 3, 3]]], dtype=np.int32)46 label_divisor = 100047 concat_panoptic = concat_semantic * label_divisor + concat_instance48 next_panoptic = next_semantic * label_divisor + next_instance49 new_panoptic = vip_deeplab.stitch_video_panoptic_prediction(50 concat_panoptic,51 next_panoptic,52 label_divisor)53 # The expected instance is manually computed. It should receive the IDs54 # propagated from concat_instance by IoU matching between concat_panoptic55 # and next_panoptic.56 expected_semantic = next_semantic57 expected_instance = np.array(58 [[[1, 0, 0, 2],59 [1, 0, 0, 2],60 [1, 1, 1, 2],61 [2, 2, 1, 1]]], dtype=np.int32)62 expected_panoptic = expected_semantic * label_divisor + expected_instance63 np.testing.assert_array_equal(expected_panoptic, new_panoptic)64 65 66if __name__ == '__main__':67 tf.test.main()68 