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"""This file contains a post-processor builder used in the DeepLab model."""17 18import tensorflow as tf19 20from deeplab2 import common21from deeplab2 import config_pb222from deeplab2.data import dataset23from deeplab2.model import utils24from deeplab2.model.post_processor import max_deeplab25from deeplab2.model.post_processor import panoptic_deeplab26 27 28def get_post_processor(29 config: config_pb2.ExperimentOptions,30 dataset_descriptor: dataset.DatasetDescriptor) -> tf.keras.layers.Layer:31 """Initializes a DeepLab post-processor.32 33 Args:34 config: A config_pb2.ExperimentOptions configuration.35 dataset_descriptor: A dataset.DatasetDescriptor.36 37 Returns:38 PostProcessor: A post-processor depending on the configuration.39 """40 supported_tasks = utils.get_supported_tasks(config)41 if config.model_options.WhichOneof('meta_architecture') == 'max_deeplab':42 return max_deeplab.PostProcessor(config, dataset_descriptor)43 if common.TASK_PANOPTIC_SEGMENTATION in supported_tasks:44 return panoptic_deeplab.PostProcessor(config, dataset_descriptor)45 return panoptic_deeplab.SemanticOnlyPostProcessor()46 