-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1352 from bjjwwang/v0.6.3
Darknet encryption
- Loading branch information
Showing
10 changed files
with
1,203 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
python/examples/pipeline/PaddleClas/DarkNet53-encryption/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# 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` |
24 changes: 24 additions & 0 deletions
24
python/examples/pipeline/PaddleClas/DarkNet53-encryption/README_CN.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# 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` | ||
|
||
~ |
25 changes: 25 additions & 0 deletions
25
python/examples/pipeline/PaddleClas/DarkNet53-encryption/config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#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" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions
15
python/examples/pipeline/PaddleClas/DarkNet53-encryption/encrypt.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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() |
5 changes: 5 additions & 0 deletions
5
python/examples/pipeline/PaddleClas/DarkNet53-encryption/get_model.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
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 |
20 changes: 20 additions & 0 deletions
20
python/examples/pipeline/PaddleClas/DarkNet53-encryption/http_client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
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()) |
20 changes: 20 additions & 0 deletions
20
python/examples/pipeline/PaddleClas/DarkNet53-encryption/https_client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
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()) |
Oops, something went wrong.