未验证 提交 b623f4b8 编写于 作者: G Guoxia Wang 提交者: GitHub

fix json output (#5708)

上级 1be468bf
...@@ -15,8 +15,12 @@ def model_inference(image): ...@@ -15,8 +15,12 @@ def model_inference(image):
model_path=model_path, model_path=model_path,
params_path=params_path, params_path=params_path,
label_path=label_path) label_path=label_path)
scores, labels = predictor.predict(image) class_ids, scores, labels = predictor.predict(image)
json_out = {"scores": scores.tolist(), "labels": labels.tolist()} json_out = {
"class_ids": class_ids.tolist(),
"scores": scores.tolist(),
"labels": labels.tolist()
}
return image, json_out return image, json_out
......
...@@ -4,6 +4,7 @@ import numpy as np ...@@ -4,6 +4,7 @@ import numpy as np
import paddle import paddle
from download import get_model_path, get_data_path from download import get_model_path, get_data_path
class Predictor(object): class Predictor(object):
def __init__(self, def __init__(self,
model_type="paddle", model_type="paddle",
...@@ -42,8 +43,8 @@ class Predictor(object): ...@@ -42,8 +43,8 @@ class Predictor(object):
self.predictor.run() self.predictor.run()
outputs = [] outputs = []
for output_idx in range(len(self.output_names)): for output_idx in range(len(self.output_names)):
output_tensor = self.predictor.get_output_handle( output_tensor = self.predictor.get_output_handle(self.output_names[
self.output_names[output_idx]) output_idx])
outputs.append(output_tensor.copy_to_cpu()) outputs.append(output_tensor.copy_to_cpu())
if self.postprocess is not None: if self.postprocess is not None:
output_data = self.postprocess(outputs) output_data = self.postprocess(outputs)
...@@ -69,7 +70,7 @@ class Predictor(object): ...@@ -69,7 +70,7 @@ class Predictor(object):
for line in f: for line in f:
if len(line) < 2: if len(line) < 2:
continue continue
label = line.strip().split(',')[0].split(' ')[2] label = line.strip().split(',')[1].strip()
labels.append(label) labels.append(label)
return labels return labels
...@@ -83,6 +84,5 @@ class Predictor(object): ...@@ -83,6 +84,5 @@ class Predictor(object):
pred = np.array(logits).squeeze() pred = np.array(logits).squeeze()
pred = self.softmax(pred) pred = self.softmax(pred)
class_idx = pred.argsort()[::-1] class_idx = pred.argsort()[::-1]
return pred[class_idx[:5]], np.array(self.labels)[class_idx[:5]] return class_idx[:5], pred[class_idx[:5]], np.array(self.labels)[
class_idx[:5]]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册