Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
b93ffa5a
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看板
未验证
提交
b93ffa5a
编写于
5月 11, 2020
作者:
M
MRXLT
提交者:
GitHub
5月 11, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #546 from guru4elephant/preprocess_doc_cont
Preprocess doc cont
上级
c0a227ad
6daa1e5e
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
196 addition
and
5 deletion
+196
-5
CMakeLists.txt
CMakeLists.txt
+11
-0
core/CMakeLists.txt
core/CMakeLists.txt
+5
-0
core/configure/CMakeLists.txt
core/configure/CMakeLists.txt
+10
-0
python/examples/faster_rcnn_model/new_test_client.py
python/examples/faster_rcnn_model/new_test_client.py
+10
-4
python/examples/resnet_v2_50/resnet50_debug.py
python/examples/resnet_v2_50/resnet50_debug.py
+31
-0
python/paddle_serving_app/__init__.py
python/paddle_serving_app/__init__.py
+1
-0
python/paddle_serving_app/local_predict.py
python/paddle_serving_app/local_predict.py
+124
-0
python/setup.py.app.in
python/setup.py.app.in
+4
-1
未找到文件。
CMakeLists.txt
浏览文件 @
b93ffa5a
...
...
@@ -85,6 +85,17 @@ include(generic)
include
(
flags
)
endif
()
if
(
APP
)
include
(
external/zlib
)
include
(
external/boost
)
include
(
external/protobuf
)
include
(
external/gflags
)
include
(
external/glog
)
include
(
external/pybind11
)
include
(
external/python
)
include
(
generic
)
endif
()
if
(
SERVER
)
include
(
external/cudnn
)
include
(
paddlepaddle
)
...
...
core/CMakeLists.txt
浏览文件 @
b93ffa5a
...
...
@@ -23,6 +23,11 @@ add_subdirectory(pdcodegen)
add_subdirectory
(
sdk-cpp
)
endif
()
if
(
APP
)
add_subdirectory
(
configure
)
endif
()
if
(
CLIENT
)
add_subdirectory
(
general-client
)
endif
()
...
...
core/configure/CMakeLists.txt
浏览文件 @
b93ffa5a
if
(
SERVER OR CLIENT
)
LIST
(
APPEND protofiles
${
CMAKE_CURRENT_LIST_DIR
}
/proto/server_configure.proto
${
CMAKE_CURRENT_LIST_DIR
}
/proto/sdk_configure.proto
...
...
@@ -28,6 +29,7 @@ FILE(GLOB inc ${CMAKE_CURRENT_BINARY_DIR}/*.pb.h)
install
(
FILES
${
inc
}
DESTINATION
${
PADDLE_SERVING_INSTALL_DIR
}
/include/configure
)
endif
()
py_proto_compile
(
general_model_config_py_proto SRCS proto/general_model_config.proto
)
add_custom_target
(
general_model_config_py_proto_init ALL COMMAND
${
CMAKE_COMMAND
}
-E touch __init__.py
)
...
...
@@ -51,6 +53,14 @@ add_custom_command(TARGET general_model_config_py_proto POST_BUILD
endif
()
if
(
APP
)
add_custom_command
(
TARGET general_model_config_py_proto POST_BUILD
COMMAND
${
CMAKE_COMMAND
}
-E make_directory
${
PADDLE_SERVING_BINARY_DIR
}
/python/paddle_serving_app/proto
COMMAND cp *.py
${
PADDLE_SERVING_BINARY_DIR
}
/python/paddle_serving_app/proto
COMMENT
"Copy generated general_model_config proto file into directory paddle_serving_app/proto."
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
)
endif
()
if
(
SERVER
)
py_proto_compile
(
server_config_py_proto SRCS proto/server_configure.proto
)
add_custom_target
(
server_config_py_proto_init ALL COMMAND
${
CMAKE_COMMAND
}
-E touch __init__.py
)
...
...
python/examples/faster_rcnn_model/new_test_client.py
浏览文件 @
b93ffa5a
...
...
@@ -22,13 +22,19 @@ preprocess = Sequential([
])
postprocess
=
RCNNPostprocess
(
"label_list.txt"
,
"output"
)
client
=
Client
()
client
.
load_client_config
(
"faster_rcnn_client_conf/serving_client_conf.prototxt"
)
client
.
load_client_config
(
"faster_rcnn_client_conf/serving_client_conf.prototxt"
)
client
.
connect
([
'127.0.0.1:9393'
])
im
=
preprocess
(
sys
.
argv
[
2
])
fetch_map
=
client
.
predict
(
feed
=
{
"image"
:
im
,
"im_info"
:
np
.
array
(
list
(
im
.
shape
[
1
:])
+
[
1.0
]),
"im_shape"
:
np
.
array
(
list
(
im
.
shape
[
1
:])
+
[
1.0
])},
fetch
=
[
"multiclass_nms"
])
fetch_map
=
client
.
predict
(
feed
=
{
"image"
:
im
,
"im_info"
:
np
.
array
(
list
(
im
.
shape
[
1
:])
+
[
1.0
]),
"im_shape"
:
np
.
array
(
list
(
im
.
shape
[
1
:])
+
[
1.0
])
},
fetch
=
[
"multiclass_nms"
])
fetch_map
[
"image"
]
=
sys
.
argv
[
1
]
postprocess
(
fetch_map
)
python/examples/resnet_v2_50/resnet50_debug.py
0 → 100644
浏览文件 @
b93ffa5a
# 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.
from
paddle_serving_app.reader
import
Sequential
,
File2Image
,
Resize
,
CenterCrop
from
paddle_serving_app.reader
import
RGB2BGR
,
Transpose
,
Div
,
Normalize
from
paddle_serving_app
import
Debugger
import
sys
debugger
=
Debugger
()
debugger
.
load_model_config
(
sys
.
argv
[
1
],
gpu
=
True
)
seq
=
Sequential
([
File2Image
(),
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
)
])
image_file
=
"daisy.jpg"
img
=
seq
(
image_file
)
fetch_map
=
debugger
.
predict
(
feed
=
{
"image"
:
img
},
fetch
=
[
"feature_map"
])
print
(
fetch_map
[
"feature_map"
].
reshape
(
-
1
))
python/paddle_serving_app/__init__.py
浏览文件 @
b93ffa5a
...
...
@@ -16,3 +16,4 @@ from .reader.image_reader import ImageReader, File2Image, URL2Image, Sequential,
from
.reader.lac_reader
import
LACReader
from
.reader.senta_reader
import
SentaReader
from
.models
import
ServingModels
from
.local_predict
import
Debugger
python/paddle_serving_app/local_predict.py
0 → 100644
浏览文件 @
b93ffa5a
# -*- coding: utf-8 -*-
"""
# 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
os
import
google.protobuf.text_format
import
numpy
as
np
import
argparse
import
paddle.fluid
as
fluid
from
.proto
import
general_model_config_pb2
as
m_config
from
paddle.fluid.core
import
PaddleTensor
from
paddle.fluid.core
import
AnalysisConfig
from
paddle.fluid.core
import
create_paddle_predictor
import
logging
logging
.
basicConfig
(
format
=
"%(asctime)s - %(levelname)s - %(message)s"
)
logger
=
logging
.
getLogger
(
"fluid"
)
logger
.
setLevel
(
logging
.
INFO
)
class
Debugger
(
object
):
def
__init__
(
self
):
self
.
feed_names_
=
[]
self
.
fetch_names_
=
[]
self
.
feed_types_
=
{}
self
.
fetch_types_
=
{}
self
.
feed_shapes_
=
{}
self
.
feed_names_to_idx_
=
{}
self
.
fetch_names_to_idx_
=
{}
self
.
fetch_names_to_type_
=
{}
def
load_model_config
(
self
,
model_path
,
gpu
=
False
,
profile
=
True
,
cpu_num
=
1
):
client_config
=
"{}/serving_server_conf.prototxt"
.
format
(
model_path
)
model_conf
=
m_config
.
GeneralModelConfig
()
f
=
open
(
client_config
,
'r'
)
model_conf
=
google
.
protobuf
.
text_format
.
Merge
(
str
(
f
.
read
()),
model_conf
)
config
=
AnalysisConfig
(
model_path
)
self
.
feed_names_
=
[
var
.
alias_name
for
var
in
model_conf
.
feed_var
]
self
.
fetch_names_
=
[
var
.
alias_name
for
var
in
model_conf
.
fetch_var
]
self
.
feed_names_to_idx_
=
{}
self
.
fetch_names_to_idx_
=
{}
for
i
,
var
in
enumerate
(
model_conf
.
feed_var
):
self
.
feed_names_to_idx_
[
var
.
alias_name
]
=
i
self
.
feed_types_
[
var
.
alias_name
]
=
var
.
feed_type
self
.
feed_shapes_
[
var
.
alias_name
]
=
var
.
shape
for
i
,
var
in
enumerate
(
model_conf
.
fetch_var
):
self
.
fetch_names_to_idx_
[
var
.
alias_name
]
=
i
self
.
fetch_names_to_type_
[
var
.
alias_name
]
=
var
.
fetch_type
if
not
gpu
:
config
.
disable_gpu
()
else
:
config
.
enable_use_gpu
(
100
,
0
)
if
profile
:
config
.
enable_profile
()
config
.
set_cpu_math_library_num_threads
(
cpu_num
)
self
.
predictor
=
create_paddle_predictor
(
config
)
def
predict
(
self
,
feed
=
None
,
fetch
=
None
):
if
feed
is
None
or
fetch
is
None
:
raise
ValueError
(
"You should specify feed and fetch for prediction"
)
fetch_list
=
[]
if
isinstance
(
fetch
,
str
):
fetch_list
=
[
fetch
]
elif
isinstance
(
fetch
,
list
):
fetch_list
=
fetch
else
:
raise
ValueError
(
"Fetch only accepts string and list of string"
)
feed_batch
=
[]
if
isinstance
(
feed
,
dict
):
feed_batch
.
append
(
feed
)
elif
isinstance
(
feed
,
list
):
feed_batch
=
feed
else
:
raise
ValueError
(
"Feed only accepts dict and list of dict"
)
int_slot_batch
=
[]
float_slot_batch
=
[]
int_feed_names
=
[]
float_feed_names
=
[]
int_shape
=
[]
float_shape
=
[]
fetch_names
=
[]
counter
=
0
batch_size
=
len
(
feed_batch
)
for
key
in
fetch_list
:
if
key
in
self
.
fetch_names_
:
fetch_names
.
append
(
key
)
if
len
(
fetch_names
)
==
0
:
raise
ValueError
(
"Fetch names should not be empty or out of saved fetch list."
)
return
{}
inputs
=
[]
for
name
in
self
.
feed_names_
:
inputs
.
append
(
PaddleTensor
(
feed
[
name
][
np
.
newaxis
,
:]))
outputs
=
self
.
predictor
.
run
(
inputs
)
fetch_map
=
{}
for
name
in
fetch
:
fetch_map
[
name
]
=
outputs
[
self
.
fetch_names_to_idx_
[
name
]].
as_ndarray
()
return
fetch_map
python/setup.py.app.in
浏览文件 @
b93ffa5a
...
...
@@ -42,10 +42,11 @@ if '${PACK}' == 'ON':
REQUIRED_PACKAGES = [
'six >= 1.10.0', 'sentencepiece'
'six >= 1.10.0', 'sentencepiece'
, 'opencv-python', 'pillow'
]
packages=['paddle_serving_app',
'paddle_serving_app.proto',
'paddle_serving_app.reader',
'paddle_serving_app.utils',
'paddle_serving_app.models',
...
...
@@ -54,6 +55,8 @@ packages=['paddle_serving_app',
package_data={}
package_dir={'paddle_serving_app':
'${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_app',
'paddle_serving_app.proto':
'${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_app/proto',
'paddle_serving_app.reader':
'${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_app/reader',
'paddle_serving_app.utils':
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录