Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
836ccfe5
S
Serving
项目概览
PaddlePaddle
/
Serving
1 年多 前同步成功
通知
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看板
提交
836ccfe5
编写于
8月 17, 2021
作者:
J
Jiawei Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add DarkNet53-encryption
上级
9171a266
变更
11
展开全部
隐藏空白更改
内联
并排
Showing
11 changed file
with
1204 addition
and
0 deletion
+1204
-0
python/examples/pipeline/PaddleClas/DarkNet53-encryption/README.md
...amples/pipeline/PaddleClas/DarkNet53-encryption/README.md
+23
-0
python/examples/pipeline/PaddleClas/DarkNet53-encryption/README_CN.md
...les/pipeline/PaddleClas/DarkNet53-encryption/README_CN.md
+24
-0
python/examples/pipeline/PaddleClas/DarkNet53-encryption/config.yml
...mples/pipeline/PaddleClas/DarkNet53-encryption/config.yml
+25
-0
python/examples/pipeline/PaddleClas/DarkNet53-encryption/daisy.jpg
...amples/pipeline/PaddleClas/DarkNet53-encryption/daisy.jpg
+0
-0
python/examples/pipeline/PaddleClas/DarkNet53-encryption/encrypt.py
...mples/pipeline/PaddleClas/DarkNet53-encryption/encrypt.py
+15
-0
python/examples/pipeline/PaddleClas/DarkNet53-encryption/get_model.sh
...les/pipeline/PaddleClas/DarkNet53-encryption/get_model.sh
+5
-0
python/examples/pipeline/PaddleClas/DarkNet53-encryption/http_client.py
...s/pipeline/PaddleClas/DarkNet53-encryption/http_client.py
+20
-0
python/examples/pipeline/PaddleClas/DarkNet53-encryption/https_client.py
.../pipeline/PaddleClas/DarkNet53-encryption/https_client.py
+20
-0
python/examples/pipeline/PaddleClas/DarkNet53-encryption/imagenet.label
...s/pipeline/PaddleClas/DarkNet53-encryption/imagenet.label
+1000
-0
python/examples/pipeline/PaddleClas/DarkNet53-encryption/key
python/examples/pipeline/PaddleClas/DarkNet53-encryption/key
+1
-0
python/examples/pipeline/PaddleClas/DarkNet53-encryption/web_service.py
...s/pipeline/PaddleClas/DarkNet53-encryption/web_service.py
+71
-0
未找到文件。
python/examples/pipeline/PaddleClas/DarkNet53-encryption/README.md
0 → 100644
浏览文件 @
836ccfe5
# Imagenet Pipeline WebService
This document will takes Imagenet service as an example to introduce how to use Pipeline WebService.
## Get model
```
sh get_model.sh
python encrypt.py
```
## Start server
```
python -m paddle_serving_server.serve --model encrypt_server/ --port 9400 --encryption_rpc_port 9401 --use_encryption_model &
python web_service.py &>log.txt &
```
## client test
```
python http_client.py
```
if you configure the api gateway, you can use
`https_client.py`
python/examples/pipeline/PaddleClas/DarkNet53-encryption/README_CN.md
0 → 100644
浏览文件 @
836ccfe5
# Imagenet Pipeline WebService
这里以 Imagenet 服务为例来介绍 Pipeline WebService 的使用。
## 获取模型
```
sh get_model.sh
python encrypt.py
```
## 启动服务
```
python -m paddle_serving_server.serve --model encrypt_server/ --port 9400 --encryption_rpc_port 9401 --use_encryption_model &
python web_service.py &>log.txt &
```
## 测试
```
python http_client.py
```
如果您已经配置好了api gateway, 您可以使用
`https_client.py`
~
python/examples/pipeline/PaddleClas/DarkNet53-encryption/config.yml
0 → 100644
浏览文件 @
836ccfe5
#worker_num, 最大并发数。当build_dag_each_worker=True时, 框架会创建worker_num个进程,每个进程内构建grpcSever和DAG
##当build_dag_each_worker=False时,框架会设置主线程grpc线程池的max_workers=worker_num
worker_num
:
1
#http端口, rpc_port和http_port不允许同时为空。当rpc_port可用且http_port为空时,不自动生成http_port
http_port
:
18080
rpc_port
:
9993
dag
:
#op资源类型, True, 为线程模型;False,为进程模型
is_thread_op
:
False
op
:
imagenet
:
#并发数,is_thread_op=True时,为线程并发;否则为进程并发
concurrency
:
1
client_type
:
brpc
retry
:
1
timeout
:
3000
server_endpoints
:
[
"
127.0.0.1:9400"
]
client_config
:
"
encrypt_client"
fetch_list
:
[
"
save_infer_model/scale_0.tmp_0"
]
batch_size
:
1
auto_batching_timeout
:
2000
use_encryption_model
:
True
encryption_key
:
"
./key"
python/examples/pipeline/PaddleClas/DarkNet53-encryption/daisy.jpg
0 → 100644
浏览文件 @
836ccfe5
38.8 KB
python/examples/pipeline/PaddleClas/DarkNet53-encryption/encrypt.py
0 → 100644
浏览文件 @
836ccfe5
from
paddle_serving_client.io
import
inference_model_to_serving
def
serving_encryption
():
inference_model_to_serving
(
dirname
=
"./DarkNet53/ppcls_model/"
,
model_filename
=
"__model__"
,
params_filename
=
"./__params__"
,
serving_server
=
"encrypt_server"
,
serving_client
=
"encrypt_client"
,
encryption
=
True
)
if
__name__
==
"__main__"
:
serving_encryption
()
python/examples/pipeline/PaddleClas/DarkNet53-encryption/get_model.sh
0 → 100644
浏览文件 @
836ccfe5
wget
--no-check-certificate
https://paddle-serving.bj.bcebos.com/model/DarkNet53.tar
tar
-xf
DarkNet53.tar
wget
--no-check-certificate
https://paddle-serving.bj.bcebos.com/imagenet-example/image_data.tar.gz
tar
-xzvf
image_data.tar.gz
python/examples/pipeline/PaddleClas/DarkNet53-encryption/http_client.py
0 → 100644
浏览文件 @
836ccfe5
import
numpy
as
np
import
requests
import
json
import
cv2
import
base64
import
os
def
cv2_to_base64
(
image
):
return
base64
.
b64encode
(
image
).
decode
(
'utf8'
)
if
__name__
==
"__main__"
:
url
=
"http://127.0.0.1:18080/imagenet/prediction"
with
open
(
os
.
path
.
join
(
"."
,
"daisy.jpg"
),
'rb'
)
as
file
:
image_data1
=
file
.
read
()
image
=
cv2_to_base64
(
image_data1
)
header
=
{
"Content-Type"
:
"application/json"
,
"apikey"
:
"WeJn7tVjuujtGxBgl6cWRGpmL2VMEBdb"
,
"X-INSTANCE-ID"
:
"kong_ins10"
}
data
=
{
"key"
:
[
"image"
],
"value"
:
[
image
]}
for
i
in
range
(
1
):
r
=
requests
.
post
(
url
=
url
,
data
=
json
.
dumps
(
data
))
print
(
r
.
json
())
python/examples/pipeline/PaddleClas/DarkNet53-encryption/https_client.py
0 → 100644
浏览文件 @
836ccfe5
import
numpy
as
np
import
requests
import
json
import
cv2
import
base64
import
os
def
cv2_to_base64
(
image
):
return
base64
.
b64encode
(
image
).
decode
(
'utf8'
)
if
__name__
==
"__main__"
:
url
=
"https://10.21.8.132:8443/image-clas/imagenet/prediction"
with
open
(
os
.
path
.
join
(
"."
,
"daisy.jpg"
),
'rb'
)
as
file
:
image_data1
=
file
.
read
()
image
=
cv2_to_base64
(
image_data1
)
headers
=
{
"Content-Type"
:
"application/json"
,
"apikey"
:
"BlfvO08Z9mQpFjcMagl2dxOIA8h2UVdp"
,
"X-INSTANCE-ID"
:
"kong_ins10"
}
data
=
{
"key"
:
[
"image"
],
"value"
:
[
image
]}
for
i
in
range
(
1
):
r
=
requests
.
post
(
url
=
url
,
headers
=
headers
,
data
=
json
.
dumps
(
data
),
verify
=
False
)
print
(
r
.
json
())
python/examples/pipeline/PaddleClas/DarkNet53-encryption/imagenet.label
0 → 100644
浏览文件 @
836ccfe5
此差异已折叠。
点击以展开。
python/examples/pipeline/PaddleClas/DarkNet53-encryption/key
0 → 100644
浏览文件 @
836ccfe5
-eu-?wX
\ No newline at end of file
python/examples/pipeline/PaddleClas/DarkNet53-encryption/web_service.py
0 → 100644
浏览文件 @
836ccfe5
# 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
from
paddle_serving_app.reader
import
Sequential
,
URL2Image
,
Resize
,
CenterCrop
,
RGB2BGR
,
Transpose
,
Div
,
Normalize
,
Base64ToImage
from
paddle_serving_server.web_service
import
WebService
,
Op
import
logging
import
numpy
as
np
import
base64
,
cv2
class
ImagenetOp
(
Op
):
def
init_op
(
self
):
self
.
seq
=
Sequential
([
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
)
])
self
.
label_dict
=
{}
label_idx
=
0
with
open
(
"imagenet.label"
)
as
fin
:
for
line
in
fin
:
self
.
label_dict
[
label_idx
]
=
line
.
strip
()
label_idx
+=
1
def
preprocess
(
self
,
input_dicts
,
data_id
,
log_id
):
(
_
,
input_dict
),
=
input_dicts
.
items
()
batch_size
=
len
(
input_dict
.
keys
())
imgs
=
[]
for
key
in
input_dict
.
keys
():
data
=
base64
.
b64decode
(
input_dict
[
key
].
encode
(
'utf8'
))
data
=
np
.
fromstring
(
data
,
np
.
uint8
)
im
=
cv2
.
imdecode
(
data
,
cv2
.
IMREAD_COLOR
)
img
=
self
.
seq
(
im
)
imgs
.
append
(
img
[
np
.
newaxis
,
:].
copy
())
input_imgs
=
np
.
concatenate
(
imgs
,
axis
=
0
)
return
{
"image"
:
input_imgs
},
False
,
None
,
""
def
postprocess
(
self
,
input_dicts
,
fetch_dict
,
log_id
):
score_list
=
fetch_dict
[
"save_infer_model/scale_0.tmp_0"
]
result
=
{
"label"
:
[],
"prob"
:
[]}
for
score
in
score_list
:
score
=
score
.
tolist
()
max_score
=
max
(
score
)
result
[
"label"
].
append
(
self
.
label_dict
[
score
.
index
(
max_score
)]
.
strip
().
replace
(
","
,
""
))
result
[
"prob"
].
append
(
max_score
)
result
[
"label"
]
=
str
(
result
[
"label"
])
result
[
"prob"
]
=
str
(
result
[
"prob"
])
return
result
,
None
,
""
class
ImageService
(
WebService
):
def
get_pipeline_response
(
self
,
read_op
):
image_op
=
ImagenetOp
(
name
=
"imagenet"
,
input_ops
=
[
read_op
])
return
image_op
uci_service
=
ImageService
(
name
=
"imagenet"
)
uci_service
.
prepare_pipeline_config
(
"config.yml"
)
uci_service
.
run_service
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录