static_runner.py 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Copyright (c) 2020 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.

from __future__ import print_function

C
Chen Weihang 已提交
17
from paddle.fluid.dygraph.jit import _SaveLoadConfig
18
from paddle.fluid.dygraph.io import TranslatedLayer
19 20


21 22 23
# NOTE: This class will be deprecated later.
# It is kept here because PaddleHub is already using this API.
class StaticModelRunner(object):
24 25 26 27 28
    """
    A Dynamic graph Layer for loading inference program and related parameters,
    and then performing fine-tune training or inference.

    .. note::
29 30
        This is a temporary API, which will be deprecated later, please use 
        `fluid.dygraph.jit.load` to achieve the same function.
31 32
    """

33
    def __new__(cls, model_dir, model_filename=None, params_filename=None):
C
Chen Weihang 已提交
34
        configs = _SaveLoadConfig()
35
        if model_filename is not None:
36
            configs.model_filename = model_filename
37
        if params_filename is not None:
38 39
            configs.params_filename = params_filename
        return TranslatedLayer._construct(model_dir, configs)