Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
d39a7fac
S
Serving
项目概览
PaddlePaddle
/
Serving
接近 2 年 前同步成功
通知
186
Star
833
Fork
253
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
105
列表
看板
标记
里程碑
合并请求
10
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Serving
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
105
Issue
105
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d39a7fac
编写于
12月 20, 2021
作者:
S
stephon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add README.md
上级
0fa1f54d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
178 addition
and
1 deletion
+178
-1
core/general-server/op/CMakeLists.txt
core/general-server/op/CMakeLists.txt
+1
-1
examples/C++/PaddleClas/pp_shitu/README.md
examples/C++/PaddleClas/pp_shitu/README.md
+22
-0
examples/C++/PaddleClas/pp_shitu/README_CN.md
examples/C++/PaddleClas/pp_shitu/README_CN.md
+22
-0
examples/C++/PaddleClas/pp_shitu/run_cpp_serving.sh
examples/C++/PaddleClas/pp_shitu/run_cpp_serving.sh
+0
-0
examples/C++/PaddleClas/pp_shitu/test_cpp_serving_pipeline.py
...ples/C++/PaddleClas/pp_shitu/test_cpp_serving_pipeline.py
+133
-0
未找到文件。
core/general-server/op/CMakeLists.txt
浏览文件 @
d39a7fac
...
@@ -5,7 +5,7 @@ if(WITH_OPENCV)
...
@@ -5,7 +5,7 @@ if(WITH_OPENCV)
LIST
(
APPEND op_srcs
${
ocrtools_srcs
}
)
LIST
(
APPEND op_srcs
${
ocrtools_srcs
}
)
else
()
else
()
set
(
EXCLUDE_DIR
"general_detection_op.cpp"
)
set
(
EXCLUDE_DIR
"general_detection_op.cpp"
)
set
(
EXCLUDE_DIR
"general_
infer
_op.cpp"
)
set
(
EXCLUDE_DIR
"general_
picodet
_op.cpp"
)
set
(
EXCLUDE_DIR
"general_feature_extract_op.cpp"
)
set
(
EXCLUDE_DIR
"general_feature_extract_op.cpp"
)
foreach
(
TMP_PATH
${
op_srcs
}
)
foreach
(
TMP_PATH
${
op_srcs
}
)
string
(
FIND
${
TMP_PATH
}
${
EXCLUDE_DIR
}
EXCLUDE_DIR_FOUND
)
string
(
FIND
${
TMP_PATH
}
${
EXCLUDE_DIR
}
EXCLUDE_DIR_FOUND
)
...
...
examples/C++/PaddleClas/pp_shitu/README.md
0 → 100644
浏览文件 @
d39a7fac
# PP-Shitu
## Get Model
```
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/serving/pp_shitu.tar.gz
tar -xzvf pp_shitu.tar.gz
```
## Get test images and index
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/data/drink_dataset_v1.0.tar
tar -xvf drink_dataset_v1.0.tar
## RPC Service
### Start Service
```
sh run_cpp_serving.sh
```
### Client Prediction
```
python3 test_cpp_serving_pipeline.py ./drint_dataset_v1.0/test_images/nongfu_spring.jpeg
```
\ No newline at end of file
examples/C++/PaddleClas/pp_shitu/README_CN.md
0 → 100644
浏览文件 @
d39a7fac
# PP-Shitu
## 获取模型
```
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/serving/pp_shitu.tar.gz
tar -xzvf pp_shitu.tar.gz
```
## 获取测试图像和index
wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/data/drink_dataset_v1.0.tar
tar -xvf drink_dataset_v1.0.tar
## RPC 服务
### 启动服务端
```
sh run_cpp_serving.sh
```
### 客户端预测
```
python3 test_cpp_serving_pipeline.py ./drint_dataset_v1.0/test_images/nongfu_spring.jpeg
```
examples/C++/PaddleClas/pp_shitu/run_cpp_serv
er
.sh
→
examples/C++/PaddleClas/pp_shitu/run_cpp_serv
ing
.sh
浏览文件 @
d39a7fac
文件已移动
examples/C++/PaddleClas/pp_shitu/test_cpp_serving_pipeline.py
0 → 100644
浏览文件 @
d39a7fac
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
sys
import
numpy
as
np
from
paddle_serving_client
import
Client
from
paddle_serving_app.reader
import
*
import
cv2
import
faiss
import
os
import
pickle
rec_nms_thresold
=
0.05
rec_score_thres
=
0.5
feature_normalize
=
True
return_k
=
1
index_dir
=
"./drink_dataset_v1.0/index"
def
init_index
(
index_dir
):
assert
os
.
path
.
exists
(
os
.
path
.
join
(
index_dir
,
"vector.index"
)),
"vector.index not found ..."
assert
os
.
path
.
exists
(
os
.
path
.
join
(
index_dir
,
"id_map.pkl"
)),
"id_map.pkl not found ... "
searcher
=
faiss
.
read_index
(
os
.
path
.
join
(
index_dir
,
"vector.index"
))
with
open
(
os
.
path
.
join
(
index_dir
,
"id_map.pkl"
),
"rb"
)
as
fd
:
id_map
=
pickle
.
load
(
fd
)
return
searcher
,
id_map
#get box
def
nms_to_rec_results
(
results
,
thresh
=
0.1
):
filtered_results
=
[]
x1
=
np
.
array
([
r
[
"bbox"
][
0
]
for
r
in
results
]).
astype
(
"float32"
)
y1
=
np
.
array
([
r
[
"bbox"
][
1
]
for
r
in
results
]).
astype
(
"float32"
)
x2
=
np
.
array
([
r
[
"bbox"
][
2
]
for
r
in
results
]).
astype
(
"float32"
)
y2
=
np
.
array
([
r
[
"bbox"
][
3
]
for
r
in
results
]).
astype
(
"float32"
)
scores
=
np
.
array
([
r
[
"rec_scores"
]
for
r
in
results
])
areas
=
(
x2
-
x1
+
1
)
*
(
y2
-
y1
+
1
)
order
=
scores
.
argsort
()[::
-
1
]
while
order
.
size
>
0
:
i
=
order
[
0
]
xx1
=
np
.
maximum
(
x1
[
i
],
x1
[
order
[
1
:]])
yy1
=
np
.
maximum
(
y1
[
i
],
y1
[
order
[
1
:]])
xx2
=
np
.
minimum
(
x2
[
i
],
x2
[
order
[
1
:]])
yy2
=
np
.
minimum
(
y2
[
i
],
y2
[
order
[
1
:]])
w
=
np
.
maximum
(
0.0
,
xx2
-
xx1
+
1
)
h
=
np
.
maximum
(
0.0
,
yy2
-
yy1
+
1
)
inter
=
w
*
h
ovr
=
inter
/
(
areas
[
i
]
+
areas
[
order
[
1
:]]
-
inter
)
inds
=
np
.
where
(
ovr
<=
thresh
)[
0
]
order
=
order
[
inds
+
1
]
filtered_results
.
append
(
results
[
i
])
return
filtered_results
def
postprocess
(
fetch_dict
,
feature_normalize
,
det_boxes
,
searcher
,
id_map
,
return_k
,
rec_score_thres
,
rec_nms_thresold
):
batch_features
=
fetch_dict
[
"features"
]
#do feature norm
if
feature_normalize
:
feas_norm
=
np
.
sqrt
(
np
.
sum
(
np
.
square
(
batch_features
),
axis
=
1
,
keepdims
=
True
))
batch_features
=
np
.
divide
(
batch_features
,
feas_norm
)
scores
,
docs
=
searcher
.
search
(
batch_features
,
return_k
)
results
=
[]
for
i
in
range
(
scores
.
shape
[
0
]):
pred
=
{}
if
scores
[
i
][
0
]
>=
rec_score_thres
:
pred
[
"bbox"
]
=
[
int
(
x
)
for
x
in
det_boxes
[
i
,
2
:]]
pred
[
"rec_docs"
]
=
id_map
[
docs
[
i
][
0
]].
split
()[
1
]
pred
[
"rec_scores"
]
=
scores
[
i
][
0
]
results
.
append
(
pred
)
#do nms
results
=
nms_to_rec_results
(
results
,
rec_nms_thresold
)
return
results
#do client
if
__name__
==
"__main__"
:
client
=
Client
()
client
.
load_client_config
([
"picodet_PPLCNet_x2_5_mainbody_lite_v2.0_client"
,
"general_PPLCNet_x2_5_lite_v2.0_client"
])
client
.
connect
([
'127.0.0.1:9400'
])
im
=
cv2
.
imread
(
sys
.
argv
[
1
])
im_shape
=
np
.
array
(
im
.
shape
[:
2
]).
reshape
(
-
1
)
fetch_map
=
client
.
predict
(
feed
=
{
"image"
:
im
,
"im_shape"
:
im_shape
},
fetch
=
[
"features"
,
"boxes"
],
batch
=
False
)
#add retrieval procedure
det_boxes
=
fetch_map
[
"boxes"
]
searcher
,
id_map
=
init_index
(
index_dir
)
results
=
postprocess
(
fetch_map
,
feature_normalize
,
det_boxes
,
searcher
,
id_map
,
return_k
,
rec_score_thres
,
rec_nms_thresold
)
print
(
results
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录