Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
29ccd204
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
29ccd204
编写于
6月 13, 2022
作者:
H
HydrogenSulfate
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add cpp serving infer
上级
1d0da582
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
69 addition
and
45 deletion
+69
-45
deploy/paddleserving/recognition/test_cpp_serving_client.py
deploy/paddleserving/recognition/test_cpp_serving_client.py
+1
-2
deploy/paddleserving/test_cpp_serving_client.py
deploy/paddleserving/test_cpp_serving_client.py
+23
-24
test_tipc/config/PP-ShiTu/PPShiTu_linux_gpu_normal_normal_serving_cpp_linux_gpu_cpu.txt
...iTu_linux_gpu_normal_normal_serving_cpp_linux_gpu_cpu.txt
+18
-0
test_tipc/test_serving_infer.sh
test_tipc/test_serving_infer.sh
+27
-19
未找到文件。
deploy/paddleserving/recognition/test_cpp_serving_client.py
浏览文件 @
29ccd204
...
...
@@ -113,10 +113,9 @@ if __name__ == "__main__":
"im_shape"
:
im_shape
},
fetch
=
[
"features"
,
"boxes"
],
batch
=
False
)
print
(
fetch_map
.
keys
())
#add retrieval procedure
det_boxes
=
fetch_map
[
"boxes"
]
print
(
det_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
)
...
...
deploy/paddleserving/test_cpp_serving_client.py
浏览文件 @
29ccd204
...
...
@@ -12,16 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
sys
import
base64
import
time
from
paddle_serving_client
import
Client
#app
from
paddle_serving_app.reader
import
Sequential
,
URL2Image
,
Resize
from
paddle_serving_app.reader
import
CenterCrop
,
RGB2BGR
,
Transpose
,
Div
,
Normalize
import
time
def
bytes_to_base64
(
image
:
bytes
)
->
str
:
"""encode bytes into base64 string
"""
return
base64
.
b64encode
(
image
).
decode
(
'utf8'
)
client
=
Client
()
client
.
load_client_config
(
"./ResNet50_
vd_serving/serving_server
_conf.prototxt"
)
client
.
load_client_config
(
"./ResNet50_
client/serving_client
_conf.prototxt"
)
client
.
connect
([
"127.0.0.1:9292"
])
label_dict
=
{}
...
...
@@ -31,22 +35,17 @@ with open("imagenet.label") as fin:
label_dict
[
label_idx
]
=
line
.
strip
()
label_idx
+=
1
#preprocess
seq
=
Sequential
([
URL2Image
(),
Resize
(
256
),
CenterCrop
(
224
),
RGB2BGR
(),
Transpose
((
2
,
0
,
1
)),
Div
(
255
),
Normalize
([
0.485
,
0.456
,
0.406
],
[
0.229
,
0.224
,
0.225
],
True
)
])
start
=
time
.
time
()
image_file
=
"https://paddle-serving.bj.bcebos.com/imagenet-example/daisy.jpg"
image_file
=
"./daisy.jpg"
for
i
in
range
(
1
):
img
=
seq
(
image_file
)
fetch_map
=
client
.
predict
(
feed
=
{
"inputs"
:
img
},
fetch
=
[
"prediction"
],
batch
=
False
)
prob
=
max
(
fetch_map
[
"prediction"
][
0
])
label
=
label_dict
[
fetch_map
[
"prediction"
][
0
].
tolist
().
index
(
prob
)].
strip
(
).
replace
(
","
,
""
)
print
(
"prediction: {}, probability: {}"
.
format
(
label
,
prob
))
end
=
time
.
time
()
print
(
end
-
start
)
start
=
time
.
time
()
with
open
(
image_file
,
'rb'
)
as
img_file
:
image_data
=
img_file
.
read
()
image
=
bytes_to_base64
(
image_data
)
fetch_dict
=
client
.
predict
(
feed
=
{
"inputs"
:
image
},
fetch
=
[
"prediction"
],
batch
=
False
)
prob
=
max
(
fetch_dict
[
"prediction"
][
0
])
label
=
label_dict
[
fetch_dict
[
"prediction"
][
0
].
tolist
().
index
(
prob
)].
strip
().
replace
(
","
,
""
)
print
(
"prediction: {}, probability: {}"
.
format
(
label
,
prob
))
end
=
time
.
time
()
print
(
end
-
start
)
test_tipc/config/PP-ShiTu/PPShiTu_linux_gpu_normal_normal_serving_cpp_linux_gpu_cpu.txt
0 → 100644
浏览文件 @
29ccd204
===========================serving_params===========================
model_name:PPShiTu
python:python3.7
cls_inference_model_url:https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/general_PPLCNet_x2_5_lite_v1.0_infer.tar
det_inference_model_url:https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar
trans_model:-m paddle_serving_client.convert
--dirname:./models/general_PPLCNet_x2_5_lite_v1.0_infer/
--dirname:./models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer/
--model_filename:inference.pdmodel
--params_filename:inference.pdiparams
--serving_server:./models/general_PPLCNet_x2_5_lite_v1.0_serving/
--serving_client:./models/general_PPLCNet_x2_5_lite_v1.0_client/
--serving_server:./models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_serving/
--serving_client:./models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_client/
serving_dir:./paddleserving/recognition
web_service:null
--use_gpu:0|null
pipline:test_cpp_serving_client.py
test_tipc/test_serving_infer.sh
浏览文件 @
29ccd204
...
...
@@ -84,16 +84,16 @@ function func_serving_cls(){
break
fi
done
set_client_feed_type_cmd
=
"sed -i '/feed_type/,/: .*/s/feed_type: .*/feed_type: 20/'
${
serving_client_value
}
/serving_client_conf.prototxt"
serving_client_dir_name
=
$(
func_get_url_file_name
"
$serving_client_value
"
)
set_client_feed_type_cmd
=
"sed -i '/feed_type/,/: .*/s/feed_type: .*/feed_type: 20/'
${
serving_client_dir_name
}
/serving_client_conf.prototxt"
eval
${
set_client_feed_type_cmd
}
set_client_shape_cmd
=
"sed -i '/shape: 3/,/shape: 3/s/shape: 3/shape: 1/'
${
serving_client_
valu
e
}
/serving_client_conf.prototxt"
set_client_shape_cmd
=
"sed -i '/shape: 3/,/shape: 3/s/shape: 3/shape: 1/'
${
serving_client_
dir_nam
e
}
/serving_client_conf.prototxt"
eval
${
set_client_shape_cmd
}
set_client_shape224_cmd
=
"sed -i '/shape: 224/,/shape: 224/s/shape: 224//'
${
serving_client_
valu
e
}
/serving_client_conf.prototxt"
set_client_shape224_cmd
=
"sed -i '/shape: 224/,/shape: 224/s/shape: 224//'
${
serving_client_
dir_nam
e
}
/serving_client_conf.prototxt"
eval
${
set_client_shape224_cmd
}
set_client_shape224_cmd
=
"sed -i '/shape: 224/,/shape: 224/s/shape: 224//'
${
serving_client_
valu
e
}
/serving_client_conf.prototxt"
set_client_shape224_cmd
=
"sed -i '/shape: 224/,/shape: 224/s/shape: 224//'
${
serving_client_
dir_nam
e
}
/serving_client_conf.prototxt"
eval
${
set_client_shape224_cmd
}
serving_client_dir_name
=
$(
func_get_url_file_name
"
$serving_client_value
"
)
set_pipeline_load_config_cmd
=
"sed -i '/load_client_config/,/.prototxt/s/.
\/
.*
\/
serving_client_conf.prototxt/.
\/
${
serving_client_dir_name
}
\/
serving_client_conf.prototxt/'
${
pipeline_py
}
"
eval
${
set_pipeline_load_config_cmd
}
...
...
@@ -105,10 +105,12 @@ function func_serving_cls(){
for
use_gpu
in
${
web_use_gpu_list
[*]
}
;
do
if
[[
${
use_gpu
}
=
"null"
]]
;
then
web_service_cpp_cmd
=
"
${
python_
}
-m paddle_serving_server.serve --model
${
serving_server_dir_name
}
--op GeneralClasOp --port 9292 &"
# echo ${web_service_cpp_cmd}
eval
${
web_service_cpp_cmd
}
sleep
5s
_save_log_path
=
"
${
LOG_PATH
}
/server_infer_cpp_cpu_pipeline_batchsize_1.log"
pipeline_cmd
=
"
${
python_
}
test_cpp_serving_client.py >
${
_save_log_path
}
2>&1 "
echo
{
pipeline_cmd
}
eval
${
pipeline_cmd
}
last_status
=
${
PIPESTATUS
[0]
}
eval
"cat
${
_save_log_path
}
"
...
...
@@ -122,8 +124,7 @@ function func_serving_cls(){
_save_log_path
=
"
${
LOG_PATH
}
/server_infer_cpp_gpu_pipeline_batchsize_1.log"
pipeline_cmd
=
"
${
python_
}
test_cpp_serving_client.py >
${
_save_log_path
}
2>&1 "
eval
$pipeline_cmd
eval
${
pipeline_cmd
}
last_status
=
${
PIPESTATUS
[0]
}
eval
"cat
${
_save_log_path
}
"
status_check
${
last_status
}
"
${
pipeline_cmd
}
"
"
${
status_log
}
"
"
${
model_name
}
"
...
...
@@ -245,7 +246,6 @@ function func_serving_rec(){
done
# pdserving
export
SERVING_BIN
=
$PWD
/Serving/server-build-gpu-opencv/core/general-server/serving
cd
./deploy
set_dirname
=
$(
func_set_params
"
${
cls_infer_model_dir_key
}
"
"
${
cls_infer_model_dir_value
}
"
)
set_model_filename
=
$(
func_set_params
"
${
model_filename_key
}
"
"
${
model_filename_value
}
"
)
...
...
@@ -263,15 +263,22 @@ function func_serving_rec(){
det_trans_model_cmd
=
"
${
python_interp
}
${
trans_model_py
}
${
set_dirname
}
${
set_model_filename
}
${
set_params_filename
}
${
set_serving_server
}
${
set_serving_client
}
"
eval
$det_trans_model_cmd
cp_prototxt_cmd
=
"cp ./paddleserving/recognition/preprocess/general_PPLCNet_x2_5_lite_v1.0_serving/*.prototxt
${
cls_serving_server_value
}
"
eval
${
cp_prototxt_cmd
}
cp_prototxt_cmd
=
"cp ./paddleserving/recognition/preprocess/general_PPLCNet_x2_5_lite_v1.0_client/*.prototxt
${
cls_serving_client_value
}
"
eval
${
cp_prototxt_cmd
}
cp_prototxt_cmd
=
"cp ./paddleserving/recognition/preprocess/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_client/*.prototxt
${
det_serving_client_value
}
"
eval
${
cp_prototxt_cmd
}
cp_prototxt_cmd
=
"cp ./paddleserving/recognition/preprocess/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_serving/*.prototxt
${
det_serving_server_value
}
"
eval
${
cp_prototxt_cmd
}
if
[[
${
FILENAME
}
=
~
"cpp"
]]
;
then
cp_prototxt_cmd
=
"cp ./paddleserving/recognition/preprocess/general_PPLCNet_x2_5_lite_v1.0_serving/*.prototxt
${
cls_serving_server_value
}
"
eval
${
cp_prototxt_cmd
}
cp_prototxt_cmd
=
"cp ./paddleserving/recognition/preprocess/general_PPLCNet_x2_5_lite_v1.0_client/*.prototxt
${
cls_serving_client_value
}
"
eval
${
cp_prototxt_cmd
}
cp_prototxt_cmd
=
"cp ./paddleserving/recognition/preprocess/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_client/*.prototxt
${
det_serving_client_value
}
"
eval
${
cp_prototxt_cmd
}
cp_prototxt_cmd
=
"cp ./paddleserving/recognition/preprocess/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_serving/*.prototxt
${
det_serving_server_value
}
"
eval
${
cp_prototxt_cmd
}
else
# modify the alias_name of fetch_var to "outputs"
server_fetch_var_line_cmd
=
"sed -i '/fetch_var/,/is_lod_tensor/s/alias_name: .*/alias_name:
\"
features
\"
/'
$cls_serving_server_value
/serving_server_conf.prototxt"
eval
${
server_fetch_var_line_cmd
}
client_fetch_var_line_cmd
=
"sed -i '/fetch_var/,/is_lod_tensor/s/alias_name: .*/alias_name:
\"
features
\"
/'
$cls_serving_client_value
/serving_client_conf.prototxt"
eval
${
client_fetch_var_line_cmd
}
fi
prototxt_dataline
=
$(
awk
'NR==1, NR==3{print}'
${
cls_serving_server_value
}
/serving_server_conf.prototxt
)
IFS
=
$'
\n
'
prototxt_lines
=(
${
prototxt_dataline
}
)
...
...
@@ -283,6 +290,7 @@ function func_serving_rec(){
unset
http_proxy
if
[[
${
FILENAME
}
=
~
"cpp"
]]
;
then
export
SERVING_BIN
=
$PWD
/../Serving/server-build-gpu-opencv/core/general-server/serving
for
use_gpu
in
${
web_use_gpu_list
[*]
}
;
do
if
[
${
use_gpu
}
=
"null"
]
;
then
det_serving_server_dir_name
=
$(
func_get_url_file_name
"
$det_serving_server_value
"
)
...
...
@@ -290,7 +298,7 @@ function func_serving_rec(){
eval
$web_service_cpp_cmd
sleep
5s
_save_log_path
=
"
${
LOG_PATH
}
/server_infer_cpp_cpu_batchsize_1.log"
pipeline_cmd
=
"
${
python_interp
}
test_cpp_serving_client.py
>
${
_save_log_path
}
2>&1 "
pipeline_cmd
=
"
${
python_interp
}
${
pipeline_py
}
>
${
_save_log_path
}
2>&1 "
eval
${
pipeline_cmd
}
last_status
=
${
PIPESTATUS
[0]
}
eval
"cat
${
_save_log_path
}
"
...
...
@@ -303,7 +311,7 @@ function func_serving_rec(){
eval
$web_service_cpp_cmd
sleep
5s
_save_log_path
=
"
${
LOG_PATH
}
/server_infer_cpp_gpu_batchsize_1.log"
pipeline_cmd
=
"
${
python_interp
}
test_cpp_serving_client.py
>
${
_save_log_path
}
2>&1 "
pipeline_cmd
=
"
${
python_interp
}
${
pipeline_py
}
>
${
_save_log_path
}
2>&1 "
eval
${
pipeline_cmd
}
last_status
=
${
PIPESTATUS
[0]
}
eval
"cat
${
_save_log_path
}
"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录