Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
8b0330bd
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看板
提交
8b0330bd
编写于
8月 10, 2020
作者:
M
MRXLT
提交者:
BohaoWu
8月 14, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #786 from MRXLT/cuda-10
fix check cuda
上级
0889bc19
dcc38973
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
266 addition
and
11 deletion
+266
-11
python/paddle_serving_app/reader/__init__.py
python/paddle_serving_app/reader/__init__.py
+3
-3
python/paddle_serving_app/reader/audio_reader.py
python/paddle_serving_app/reader/audio_reader.py
+50
-0
python/paddle_serving_app/reader/frame_extractor.py
python/paddle_serving_app/reader/frame_extractor.py
+105
-0
python/paddle_serving_app/reader/frame_reader.py
python/paddle_serving_app/reader/frame_reader.py
+71
-0
python/paddle_serving_app/utils/__init__.py
python/paddle_serving_app/utils/__init__.py
+2
-0
python/paddle_serving_app/utils/arr2image.py
python/paddle_serving_app/utils/arr2image.py
+31
-0
python/paddle_serving_server_gpu/__init__.py
python/paddle_serving_server_gpu/__init__.py
+4
-8
未找到文件。
python/paddle_serving_app/reader/__init__.py
浏览文件 @
8b0330bd
...
...
@@ -11,12 +11,12 @@
# 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
.audio_reader
import
AudioFeatureOp
from
.chinese_bert_reader
import
ChineseBertReader
from
.frame_reader
import
FrameExtractOp
from
.image_reader
import
ImageReader
,
File2Image
,
URL2Image
,
Sequential
,
Normalize
from
.image_reader
import
CenterCrop
,
Resize
,
Transpose
,
Div
,
RGB2BGR
,
BGR2RGB
,
ResizeByFactor
from
.image_reader
import
RCNNPostprocess
,
SegPostprocess
,
PadStride
from
.image_reader
import
DBPostProcess
,
FilterBoxes
,
GetRotateCropImage
,
SortedBoxes
from
.image_reader
import
DBPostProcess
,
FilterBoxes
from
.lac_reader
import
LACReader
from
.senta_reader
import
SentaReader
from
.imdb_reader
import
IMDBDataset
from
.ocr_reader
import
OCRReader
python/paddle_serving_app/reader/audio_reader.py
0 → 100644
浏览文件 @
8b0330bd
# 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.
# pylint: disable=doc-string-missing
"""
audio feature op
"""
import
ffmpeg
import
numpy
import
logging
import
cv2
import
adpredictor
as
adpredictor
try
:
from
paddle_serving_server.pipeline
import
Op
except
Exception
as
e
:
from
paddle_serving_server_gpu.pipeline
import
Op
_LOGGER
=
logging
.
getLogger
()
class
AudioFeatureOp
(
Op
):
"""
audio feature op class
"""
def
extract_audio_from_video
(
self
,
local_video_path
):
"""
extract audios from video
Params:
local_video_path, string
Returns:
audio pcm s16 le raw data for success, None for failed
"""
out
,
_
=
(
ffmpeg
.
input
(
local_video_path
,
).
output
(
'-'
,
format
=
's16le'
,
acodec
=
'pcm_s16le'
,
ac
=
1
,
ar
=
'16k'
)
.
overwrite_output
().
run
(
capture_stdout
=
True
))
result
=
numpy
.
frombuffer
(
out
,
dtype
=
numpy
.
short
)
return
result
\ No newline at end of file
python/paddle_serving_app/reader/frame_extractor.py
0 → 100644
浏览文件 @
8b0330bd
"""
frame extractor
"""
import
sys
import
numpy
as
np
from
paddle_serving_client
import
Client
import
logging
import
hwextract
as
hwextract
from
multiprocessing.pool
import
ThreadPool
_LOGGER
=
logging
.
getLogger
(
__name__
)
class
FrameData
(
object
):
"""
store frame data in python
"""
def
__init__
(
self
):
"""
constructor
"""
self
.
_width
=
0
self
.
_height
=
0
self
.
_img
=
None
def
width
(
self
):
"""
return width
"""
return
self
.
_width
def
height
(
self
):
"""
return height
"""
return
self
.
_height
def
img
(
self
):
"""
return img array
"""
return
self
.
_img
def
set_width
(
self
,
width
):
"""
set width
"""
self
.
_width
=
width
def
set_height
(
self
,
height
):
"""
set height
"""
self
.
_height
=
height
def
set_img
(
self
,
img
):
"""
set_img
"""
self
.
_img
=
img
def
set_data
(
self
,
frame
):
"""
set all data using frame
"""
self
.
_width
=
frame
.
width
()
self
.
_height
=
frame
.
height
()
self
.
_img
=
np
.
array
(
frame
,
copy
=
True
)
class
FrameExt
(
object
):
"""
extract and call tns
"""
def
__init__
(
self
):
"""
constructor
"""
self
.
_handler
=
None
def
init_handler
(
self
,
card_idx
):
"""
init handler
"""
self
.
_handler
=
hwextract
.
HwExtractFrameJpeg
(
card_idx
)
result
=
self
.
_handler
.
init_handler
()
return
result
def
extract_frame
(
self
,
file_name
):
"""
hardware extract video
"""
frame_list
=
self
.
_handler
.
extract_frame
(
file_name
,
1
)
result_list
=
[]
for
item
in
frame_list
:
tmp_frame
=
FrameData
()
tmp_frame
.
set_data
(
item
)
result_list
.
append
(
tmp_frame
)
item
.
free_memory
()
return
result_list
def
chunks
(
self
,
lst
,
n
):
"""Yield successive n-sized chunks from lst."""
for
i
in
range
(
0
,
len
(
lst
),
n
):
yield
lst
[
i
:
i
+
n
]
python/paddle_serving_app/reader/frame_reader.py
0 → 100644
浏览文件 @
8b0330bd
# 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.
# pylint: disable=doc-string-missing
"""
frame extract op
"""
import
logging
import
sys
import
frame_extractor
as
frame_ext
try
:
from
paddle_serving_server.pipeline
import
Op
except
Exception
as
e
:
from
paddle_serving_server_gpu.pipeline
import
Op
_LOGGER
=
logging
.
getLogger
(
__name__
)
class
FrameExtractOp
(
Op
):
""" frame extract op """
def
init_op
(
self
):
"""
overwrite init_op function to load custom resources.
note:
since only one frame_extractor instance can run on
each gpu card, this op can only start one single thread.
"""
pipeline_config
=
util
.
load_config
(
sys
.
argv
[
1
])
self
.
is_thread
=
pipeline_config
[
"dag"
][
"is_thread_op"
]
op_config
=
util
.
load_config
(
pipeline_config
[
"op_config"
])
self
.
frame_ext
=
frame_ext
.
FrameExt
()
self
.
frame_ext
.
init_handler
(
op_config
[
"frame_extract_card"
])
def
preprocess
(
self
,
input_dict
):
""" extract frame """
(
_
,
input_data
),
=
input_dict
.
items
()
video_data
=
input_data
.
get
(
"video_data"
)
is_pcm_raw_data
=
input_data
.
get
(
"is_pcm_raw_data"
)
seq
=
input_data
.
get
(
"seq"
,
None
)
if
is_pcm_raw_data
:
raise
Exception
(
"not support pcm_raw_data"
)
frame_list
=
self
.
frame_ext
.
extract_frame
(
video_data
)
frame_batches
=
self
.
frame_ext
.
chunks
(
frame_list
,
8
)
if
not
self
.
is_thread
:
# TODO: object hwextract.HwFrameResult could
# not be serialized correctly.
frame_batches
=
list
(
frame_batches
)
#for frame_list in frame_batches:
# width = frame_list[0].width()
# height = frame_list[0].height()
# _LOGGER.error("[FrameExt]({}) width: {}, height: {}"
# .format(type(frame_list[0]), width, height))
# break
output_dict
=
{
"frame_batches"
:
frame_batches
,
"seq"
:
None
}
return
output_dict
python/paddle_serving_app/utils/__init__.py
浏览文件 @
8b0330bd
...
...
@@ -11,3 +11,5 @@
# 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
.arr2image
import
Arr2Image
\ No newline at end of file
python/paddle_serving_app/utils/arr2image.py
0 → 100644
浏览文件 @
8b0330bd
# 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
cv2
import
yaml
class
Arr2Image
(
object
):
"""
from numpy array image(jpeg) to cv::Mat image
"""
def
__init__
(
self
):
pass
def
__call__
(
self
,
img_arr
):
img
=
cv2
.
imdecode
(
img_arr
,
cv2
.
IMREAD_COLOR
)
return
img
def
__repr__
(
self
):
return
self
.
__class__
.
__name__
+
"()"
\ No newline at end of file
python/paddle_serving_server_gpu/__init__.py
浏览文件 @
8b0330bd
...
...
@@ -235,15 +235,11 @@ class Server(object):
self
.
bin_path
=
os
.
environ
[
"SERVING_BIN"
]
def
check_cuda
(
self
):
cuda_flag
=
False
r
=
os
.
popen
(
"ldd {} | grep cudart"
.
format
(
self
.
bin_path
))
r
=
r
.
read
().
split
(
"="
)
if
len
(
r
)
>=
2
and
"cudart"
in
r
[
1
]
and
os
.
system
(
"ls /dev/ | grep nvidia > /dev/null"
)
==
0
:
cuda_flag
=
True
if
not
cuda_flag
:
if
os
.
system
(
"ls /dev/ | grep nvidia > /dev/null"
)
==
0
:
pass
else
:
raise
SystemExit
(
"
CUDA
not found, please check your environment or use cpu version by
\"
pip install paddle_serving_server
\"
"
"
GPU
not found, please check your environment or use cpu version by
\"
pip install paddle_serving_server
\"
"
)
def
set_gpuid
(
self
,
gpuid
=
0
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录