未验证 提交 98db91b2 编写于 作者: u010070587's avatar u010070587 提交者: GitHub

Merge pull request #903 from FredHuang16/patch-15

add feature normalization to fix rec_score range problem  
......@@ -36,7 +36,7 @@ class RecPredictor(Predictor):
"transform_ops"])
self.postprocess = build_postprocess(config["RecPostProcess"])
def predict(self, images):
def predict(self, images, feature_normalize=True):
input_names = self.paddle_predictor.get_input_names()
input_tensor = self.paddle_predictor.get_input_handle(input_names[0])
......@@ -54,6 +54,12 @@ class RecPredictor(Predictor):
input_tensor.copy_from_cpu(image)
self.paddle_predictor.run()
batch_output = output_tensor.copy_to_cpu()
if feature_normalize:
feas_norm = np.sqrt(
np.sum(np.square(batch_output), axis=1, keepdims=True))
batch_output = np.divide(batch_output, feas_norm)
return batch_output
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册