base_model_service.py 4.6 KB
Newer Older
走神的阿圆's avatar
走神的阿圆 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# coding: utf-8
# Copyright (c) 2019  PaddlePaddle Authors. All Rights Reserved.
#
# 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.
import six
import abc


走神的阿圆's avatar
走神的阿圆 已提交
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
class BaseModuleInfo(object):
    def __init__(self):
        self._modules_info = {}
        self._modules = []

    def set_modules_info(self, modules_info):
        # dict of modules info.
        self._modules_info = modules_info
        # list of modules name.
        self._modules = list(self._modules_info.keys())

    def get_module_info(self, module_name):
        return self._modules_info[module_name]

    def add_module(self, module_name, module_info):
        self._modules_info.update(module_info)
        self._modules.append(module_name)

    def get_module(self, module_name):
        return self.get_module_info(module_name).get("module", None)

    @property
    def modules_info(self):
        return self._modules_info


class CVModuleInfo(BaseModuleInfo):
    def __init__(self):
        self.cv_module_method = {
            "vgg19_imagenet": "predict_classification",
            "vgg16_imagenet": "predict_classification",
            "vgg13_imagenet": "predict_classification",
            "vgg11_imagenet": "predict_classification",
            "shufflenet_v2_imagenet": "predict_classification",
            "se_resnext50_32x4d_imagenet": "predict_classification",
            "se_resnext101_32x4d_imagenet": "predict_classification",
            "resnet_v2_50_imagenet": "predict_classification",
            "resnet_v2_34_imagenet": "predict_classification",
            "resnet_v2_18_imagenet": "predict_classification",
            "resnet_v2_152_imagenet": "predict_classification",
            "resnet_v2_101_imagenet": "predict_classification",
            "pnasnet_imagenet": "predict_classification",
            "nasnet_imagenet": "predict_classification",
            "mobilenet_v2_imagenet": "predict_classification",
            "googlenet_imagenet": "predict_classification",
            "alexnet_imagenet": "predict_classification",
            "yolov3_coco2017": "predict_object_detection",
            "ultra_light_fast_generic_face_detector_1mb_640":
            "predict_object_detection",
            "ultra_light_fast_generic_face_detector_1mb_320":
            "predict_object_detection",
            "ssd_mobilenet_v1_pascal": "predict_object_detection",
            "pyramidbox_face_detection": "predict_object_detection",
            "faster_rcnn_coco2017": "predict_object_detection",
            "cyclegan_cityscapes": "predict_gan",
            "deeplabv3p_xception65_humanseg": "predict_semantic_segmentation",
            "ace2p": "predict_semantic_segmentation",
            "pyramidbox_lite_server_mask": "predict_mask",
            "pyramidbox_lite_mobile_mask": "predict_mask"
        }
        super(CVModuleInfo, self).__init__()

    @property
    def cv_modules(self):
        return self._modules

    def add_module(self, module_name, module_info):
        if "CV" == module_info[module_name].get("category", ""):
            self._modules_info.update(module_info)
            self._modules.append(module_name)


class NLPModuleInfo(BaseModuleInfo):
    def __init__(self):
        super(NLPModuleInfo, self).__init__()

    @property
    def nlp_modules(self):
        return self._modules

    def add_module(self, module_name, module_info):
        if "NLP" == module_info[module_name].get("category", ""):
            self._modules_info.update(module_info)
            self._modules.append(module_name)


105 106 107 108 109 110 111 112 113 114 115 116 117
class V2ModuleInfo(BaseModuleInfo):
    def __init__(self):
        super(V2ModuleInfo, self).__init__()

    @property
    def modules(self):
        return self._modules

    def add_module(self, module_name, module_info):
        self._modules_info.update(module_info)
        self._modules.append(module_name)


走神的阿圆's avatar
走神的阿圆 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
class BaseModelService(object):
    def _initialize(self):
        pass

    @abc.abstractmethod
    def _pre_processing(self, data):
        pass

    @abc.abstractmethod
    def _inference(self, data):
        pass

    @abc.abstractmethod
    def _post_processing(self, data):
        pass
走神的阿圆's avatar
走神的阿圆 已提交
133 134 135 136


cv_module_info = CVModuleInfo()
nlp_module_info = NLPModuleInfo()
137
v2_module_info = V2ModuleInfo()