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

15
from paddle.fluid.dygraph.jit import _SaveLoadConfig
16
from paddle.fluid.dygraph.io import TranslatedLayer
17 18


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

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

31
    def __new__(cls, model_dir, model_filename=None, params_filename=None):
32
        configs = _SaveLoadConfig()
33
        if model_filename is not None:
34
            configs.model_filename = model_filename
35
        if params_filename is not None:
36 37
            configs.params_filename = params_filename
        return TranslatedLayer._construct(model_dir, configs)