提交 8b0330bd 编写于 作者: M MRXLT 提交者: BohaoWu

Merge pull request #786 from MRXLT/cuda-10

fix check cuda
......@@ -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
# 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
"""
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]
# 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
......@@ -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
# 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
......@@ -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.
先完成此消息的编辑!
想要评论请 注册