task.py 1.5 KB
Newer Older
1
#  Copyright (c) 2019  PaddlePaddle Authors. All Rights Reserved.
Z
Zeyu Chen 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15
#
# 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 os
16
import collections
Z
Zeyu Chen 已提交
17
import paddle.fluid as fluid
18 19 20 21
import time
import numpy as np
import multiprocessing

Z
Zeyu Chen 已提交
22 23

class Task(object):
Z
Zeyu Chen 已提交
24 25
    def __init__(self, task_type, graph_var_dict, main_program,
                 startup_program):
26 27
        self.task_type = task_type
        self.graph_var_dict = graph_var_dict
Z
Zeyu Chen 已提交
28 29
        self._main_program = main_program
        self._startup_program = startup_program
W
wuzewu 已提交
30
        self._inference_program = main_program.clone(for_test=True)
31 32 33 34 35 36

    def variable(self, var_name):
        if var_name in self.graph_var_dict:
            return self.graph_var_dict[var_name]

        raise KeyError("var_name {} not in task graph".format(var_name))
Z
Zeyu Chen 已提交
37 38 39 40 41 42

    def main_program(self):
        return self._main_program

    def startup_program(self):
        return self._startup_program
W
wuzewu 已提交
43 44 45

    def inference_program(self):
        return self._inference_program