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"""Tests for post_processor_builder.py."""17 18import tensorflow as tf19 20from google.protobuf import text_format21from deeplab2 import common22from deeplab2 import config_pb223from deeplab2.data import dataset24from deeplab2.model.post_processor import post_processor_builder25 26 27class EvaluatorTest(tf.test.TestCase):28 29 def test_evaluates_panoptic_deeplab_model(self):30 experiment_options_textproto = """31 experiment_name: "evaluation_test"32 eval_dataset_options {33 dataset: "cityscapes_panoptic"34 file_pattern: "EMPTY"35 batch_size: 136 crop_size: 102537 crop_size: 204938 # Skip resizing.39 min_resize_value: 040 max_resize_value: 041 }42 evaluator_options {43 continuous_eval_timeout: 4320044 stuff_area_limit: 204845 center_score_threshold: 0.146 nms_kernel: 1347 save_predictions: true48 save_raw_predictions: false49 }50 """51 config = text_format.Parse(experiment_options_textproto,52 config_pb2.ExperimentOptions())53 config.model_options.panoptic_deeplab.instance.enable = True54 post_processor = post_processor_builder.get_post_processor(55 config, dataset.CITYSCAPES_PANOPTIC_INFORMATION)56 57 result_dict = {58 common.PRED_SEMANTIC_PROBS_KEY:59 tf.zeros([1, 1025, 2049, 19], dtype=tf.float32),60 common.PRED_CENTER_HEATMAP_KEY:61 tf.zeros([1, 1025, 2049, 1], dtype=tf.float32),62 common.PRED_OFFSET_MAP_KEY:63 tf.zeros([1, 1025, 2049, 2], dtype=tf.float32)64 }65 processed_dict = post_processor(result_dict)66 expected_keys = {67 common.PRED_PANOPTIC_KEY,68 common.PRED_SEMANTIC_KEY,69 common.PRED_INSTANCE_KEY,70 common.PRED_INSTANCE_CENTER_KEY,71 common.PRED_INSTANCE_SCORES_KEY72 }73 self.assertCountEqual(processed_dict.keys(), expected_keys)74 75 76if __name__ == '__main__':77 tf.test.main()78 