提交 a503f3ca 编写于 作者: T Tao Luo 提交者: GitHub

support multi-field for inference

上级 caffcc83
...@@ -41,17 +41,20 @@ class Inference(object): ...@@ -41,17 +41,20 @@ class Inference(object):
yield [each_result[field] for each_result in result] yield [each_result[field] for each_result in result]
def infer(self, field='value', **kwargs): def infer(self, field='value', **kwargs):
if not isinstance(field, list) and not isinstance(field, tuple):
field = [field]
retv_list = []
for each_field in field:
retv = None retv = None
for result in self.iter_infer_field(field=field, **kwargs): for result in self.iter_infer_field(field=each_field, **kwargs):
if retv is None: if retv is None:
retv = [[]] * len(result) retv = [[]] * len(result)
for i, item in enumerate(result): for i, item in enumerate(result):
retv[i].append(item) retv[i].append(item)
retv = [numpy.concatenate(out) for out in retv] retv = [numpy.concatenate(out) for out in retv]
if len(retv) == 1: retv_list.append(retv[0] if len(retv) == 1 else retv)
return retv[0] return retv_list[0] if len(retv_list) == 1 else retv_list
else:
return retv
def infer(output_layer, parameters, input, feeding=None, field='value'): def infer(output_layer, parameters, input, feeding=None, field='value'):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册