未验证 提交 cc7b4b9e 编写于 作者: D daminglu 提交者: GitHub

add return_numpy back (#10892)

上级 8653cf30
......@@ -56,7 +56,7 @@ class Inferencer(object):
else:
self.exe = executor.Executor(self.place)
def infer(self, inputs):
def infer(self, inputs, return_numpy=True):
"""
:param inputs: a map of {"input_name": input_var} that will be feed into the inference program
to get the predict value
......@@ -66,9 +66,11 @@ class Inferencer(object):
raise ValueError(
"inputs should be a map of {'input_name': input_var}")
with self._prog_and_scope_guard():
results = self.exe.run(feed=inputs,
fetch_list=[self.predict_var.name])
with executor.scope_guard(self.scope):
results = self.exe.run(self.inference_program,
feed=inputs,
fetch_list=[self.predict_var],
return_numpy=return_numpy)
return results
......
......@@ -92,7 +92,7 @@ def infer(use_cuda, inference_program, save_dirname=None):
tensor_x = numpy.random.uniform(0, 10, [batch_size, 13]).astype("float32")
results = inferencer.infer({'x': tensor_x})
print("infer results: ", numpy.array(results[0]))
print("infer results: ", results[0])
def main(use_cuda):
......
......@@ -112,7 +112,7 @@ def infer(use_cuda, inference_program, save_dirname=None):
results = inferencer.infer({'img': tensor_img})
print("infer results: ", numpy.array(results[0]))
print("infer results: ", results[0])
def main(use_cuda):
......
......@@ -93,7 +93,7 @@ def infer(use_cuda, inference_program, save_dirname=None):
results = inferencer.infer({'img': tensor_img})
print("infer results: ", numpy.array(results[0]))
print("infer results: ", results[0])
def main(use_cuda):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册