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

fix json output (#5709)

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