CoolFace
Apppublic

karolmajek/maxdeeplab

sourceHugging Faceupdated 5y agoView on Hugging Face
0likes
test_utils_test.py68 linesDownload Raw Back to evaluation
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"""Tests for test_utils."""17import numpy as np18import tensorflow as tf19 20from deeplab2.evaluation import test_utils21 22 23class TestUtilsTest(tf.test.TestCase):24 25  def test_read_test_image(self):26    image_array = test_utils.read_test_image('team_pred_class.png')27    self.assertSequenceEqual(image_array.shape, (231, 345, 4))28 29  def test_reads_segmentation_with_color_map(self):30    rgb_to_semantic_label = {(0, 0, 0): 0, (0, 0, 255): 1, (255, 0, 0): 23}31    labels = test_utils.read_segmentation_with_rgb_color_map(32        'team_pred_class.png', rgb_to_semantic_label)33 34    input_image = test_utils.read_test_image('team_pred_class.png')35    np.testing.assert_array_equal(36        labels == 0,37        np.logical_and(input_image[:, :, 0] == 0, input_image[:, :, 2] == 0))38    np.testing.assert_array_equal(labels == 1, input_image[:, :, 2] == 255)39    np.testing.assert_array_equal(labels == 23, input_image[:, :, 0] == 255)40 41  def test_reads_gt_segmentation(self):42    instance_label_to_semantic_label = {43        0: 0,44        47: 1,45        97: 1,46        133: 1,47        150: 1,48        174: 1,49        198: 23,50        215: 1,51        244: 1,52        255: 1,53    }54    instances, classes = test_utils.panoptic_segmentation_with_class_map(55        'team_gt_instance.png', instance_label_to_semantic_label)56 57    expected_label_shape = (231, 345)58    self.assertSequenceEqual(instances.shape, expected_label_shape)59    self.assertSequenceEqual(classes.shape, expected_label_shape)60    np.testing.assert_array_equal(instances == 0, classes == 0)61    np.testing.assert_array_equal(instances == 198, classes == 23)62    np.testing.assert_array_equal(63        np.logical_and(instances != 0, instances != 198), classes == 1)64 65 66if __name__ == '__main__':67  tf.test.main()68