PaddlePaddle / Serving

A flexible, high-performance carrier for machine learning models(『飞桨』服务化部署框架)
Apache License 2.0
893 stars 250 forks source link

win10 部署serving后,运行examples下的ocr案例没有问题,想运行图像分类案例imagenet报错如下 #1118

Closed meishitouzhele closed 5 months ago

meishitouzhele commented 3 years ago

File ".\resnet50_web_service.py", line 78 image_service.run_web_service() ^ SyntaxError: invalid syntax 能提供一个运行examples下图像分类的过程吗?,想运行通过后 发布下自己的图像分类model(在centos的docker下能正常的model,想在win10下测试)感谢

meishitouzhele commented 3 years ago

image

HexToString commented 3 years ago

1、请问你运行的是原始的resnet50_web_service.py文件么? 2、检查代码在image_service.run_web_service()前必须有image_service.run_rpc_service() 3、也有可能是缺少flask?

meishitouzhele commented 3 years ago

我是把前必须有image_service.run_rpc_service() 这个注释了,现在放开了,cpu或者gpu报如下we问题 image image

meishitouzhele commented 3 years ago

image

meishitouzhele commented 3 years ago

运行同目录下的test_image_reader.py有点异常

M)_}X1LC7J7KP8D2GN18BC0

meishitouzhele commented 3 years ago

额 标记的都不是这个问题吧

HexToString commented 3 years ago

1、test_image_reader.py问题 这个看起来是一个编解码的问题,可能win平台默认的编解码是gbk,指定utf-8即可。 2、倒数第二张图的no attribute 'set gpus'问题 这个看起来像是你使用了gpu,但是ImageService继承自了cpu版本的web_service,如果是使用v0.5.0版本,请使用 if device == "cpu": from paddle_serving_server.web_service import WebService else: from paddle_serving_server_gpu.web_service import WebService 如果还不能解决您的问题,请查一下你引入的继承的WebService,有没有set_gpus方法即可。

另外,请您把您的环境信息最好一并发过来,这样会比较容易定位问题。

至于上面的问题,有点看不太明白,麻烦您详细描述一下是什么情况下报的这个错。

meishitouzhele commented 3 years ago

好的 感谢 我重新整理下。

HexToString commented 3 years ago

您太客气了,用户就是上帝,是我们一贯的服务宗旨。

HexToString commented 3 years ago

仔细看了一下,您的第一个问题貌似是protobuf导致的问题。 您是否修改了相关的内容呢?例如是否修改了proto文件或其相关文件?

meishitouzhele commented 3 years ago

额 没有修改 目前就是win10原生环境 pip安装了 paddlehub,然后能正常使用官网demo和自己训练的model。然后pip安装了paddleserving 运行官方的ocr model能正常发布、调用,然后运行官方的imagenet 发布报错。cpu和gpu都报错

HexToString commented 3 years ago

您使用的是哪个版本的呢? 麻烦能把pip list打出来看一下么?

meishitouzhele commented 3 years ago

C:\Users\Administrator>pip list Package Version


-pencv-python 4.5.1.48 alabaster 0.7.12 appdirs 1.4.4 astor 0.8.1 Babel 2.9.0 bce-python-sdk 0.8.59 cached-property 1.5.2 certifi 2020.12.5 cfgv 3.2.0 chardet 4.0.0 click 7.1.2 colorama 0.4.4 colorlog 4.8.0 cycler 0.10.0 decorator 4.4.2 distlib 0.3.1 docutils 0.16 easydict 1.9 filelock 3.0.12 flake8 3.9.0 Flask 1.1.2 Flask-Babel 2.0.0 Flask-Cors 3.0.10 func-timeout 4.3.5 future 0.18.2 gast 0.3.3 gitdb 4.0.7 GitPython 3.1.14 grpcio 1.33.2 grpcio-tools 1.33.2 h5py 3.2.1 identify 2.2.2 idna 2.10 imagesize 1.2.0 importlib-metadata 3.10.0 itsdangerous 1.1.0 jieba 0.42.1 Jinja2 2.11.3 joblib 1.0.1 kiwisolver 1.3.1 MarkupSafe 1.1.1 matplotlib 3.4.1 mccabe 0.6.1 mistune 0.8.4 nodeenv 1.5.0 numpy 1.19.3 opencv-python 4.2.0.32 packaging 20.9 paddle-serving-app 0.3.0 paddle-serving-client 0.5.0 paddle-serving-server 0.5.0 paddle-serving-server-gpu 0.5.0.post102 paddlehub 2.0.0rc0 paddlenlp 2.0.0rc15 paddlepaddle 2.0.1 paddlepaddle-gpu 2.0.1.post110 paddleslim 1.1.1 paddlex 1.3.7 Pillow 8.2.0 pip 21.0.1 pre-commit 2.11.1 protobuf 3.15.6 psutil 5.8.0 pyclipper 1.2.1 pycodestyle 2.7.0 pycryptodome 3.10.1 pyflakes 2.3.1 Pygments 2.8.1 pyparsing 2.4.7 python-dateutil 2.8.1 pytz 2021.1 PyYAML 5.4.1 pyzmq 22.0.3 rarfile 4.0 requests 2.25.1 scikit-learn 0.24.1 scipy 1.6.2 sentencepiece 0.1.83 seqeval 1.2.2 setuptools 47.1.0 Shapely 1.7.1 shellcheck-py 0.7.1.1 six 1.15.0 sklearn 0.0 smmap 4.0.0 snowballstemmer 2.1.0 Sphinx 2.1.0 sphinx-rtd-theme 0.5.2 sphinxcontrib-applehelp 1.0.2 sphinxcontrib-devhelp 1.0.2 sphinxcontrib-htmlhelp 1.0.3 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-qthelp 1.0.3 sphinxcontrib-serializinghtml 1.1.4 threadpoolctl 2.1.0 toml 0.10.2 tqdm 4.59.0 typing-extensions 3.7.4.3 urllib3 1.26.4 virtualenv 20.4.3 visualdl 2.1.1 Werkzeug 1.0.1 xlwt 1.3.0 zipp 3.4.1

meishitouzhele commented 3 years ago

上面是环境,然后我运行案例里的 我修改了下使用gpu,错误提示改变成了下面这样, D:\serving\Serving\python\examples\imagenet>resnet50_web_service.py ResNet50_vd_model gpu 9292 This API will be deprecated later. Please do not use it This API will be deprecated later. Please do not use it This API will be deprecated later. Please do not use it 子目录或文件 workdir_0 已经存在。 'touch' 不是内部或外部命令,也不是可运行的程序 或批处理文件。 'touch' 不是内部或外部命令,也不是可运行的程序 或批处理文件。 This API will be deprecated later. Please do not use it web service address: http://192.168.1.101:9292/image/prediction Traceback (most recent call last): File "D:\serving\Serving\python\examples\imagenet\resnet50_web_service.py", line 75, in image_service.run_rpc_service() File "C:\Program Files\Python37\lib\site-packages\paddle_serving_server_gpu\web_service.py", line 239, in run_rpc_service p.start() File "C:\Program Files\Python37\lib\multiprocessing\process.py", line 112, in start self._popen = self._Popen(self) File "C:\Program Files\Python37\lib\multiprocessing\context.py", line 223, in _Popen return _default_context.get_context().Process._Popen(process_obj) File "C:\Program Files\Python37\lib\multiprocessing\context.py", line 322, in _Popen return Popen(process_obj) File "C:\Program Files\Python37\lib\multiprocessing\popen_spawn_win32.py", line 89, in init reduction.dump(process_obj, to_child) File "C:\Program Files\Python37\lib\multiprocessing\reduction.py", line 60, in dump ForkingPickler(file, protocol).dump(obj) _pickle.PicklingError: Can't pickle <class 'server_configure_pb2.InferServiceConf'>: it's not the same object as server_configure_pb2.InferServiceConf

D:\serving\Serving\python\examples\imagenet>Traceback (most recent call last): File "", line 1, in File "C:\Program Files\Python37\lib\multiprocessing\spawn.py", line 99, in spawn_main new_handle = reduction.steal_handle(parent_pid, pipe_handle) File "C:\Program Files\Python37\lib\multiprocessing\reduction.py", line 82, in steal_handle _winapi.PROCESS_DUP_HANDLE, False, source_pid) OSError: [WinError 87] 参数错误。

服务端代码如下:

meishitouzhele commented 3 years ago

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_client import Client import numpy as np from paddle_serving_app.reader import Sequential, URL2Image, Resize, CenterCrop, RGB2BGR, Transpose, Div, Normalize, Base64ToImage

if len(sys.argv) != 4: print("python resnet50_web_service.py model device port") sys.exit(-1)

device = sys.argv[2]

if device == "cpu": from paddle_serving_server.web_service import WebService else: from paddle_serving_server_gpu.web_service import WebService

class ImageService(WebService): def init_imagenet_setting(self): self.seq = Sequential([ URL2Image(), 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, feed=[], fetch=[]):
    feed_batch = []
    is_batch = True
    for ins in feed:
        if "image" not in ins:
            raise ("feed data error!")
        img = self.seq(ins["image"])
        feed_batch.append({"image": img[np.newaxis, :]})
    return feed_batch, fetch, is_batch

def postprocess(self, feed=[], fetch=[], fetch_map={}):
    score_list = fetch_map["score"]
    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)
    return result

image_service = ImageService(name="image") image_service.load_model_config(sys.argv[1])

image_service.init_imagenet_setting() if device == "gpu": image_service.set_gpus("0") image_service.prepare_server( workdir="workdir", port=int(sys.argv[3]), device=device) image_service.run_rpc_service() image_service.run_web_service()

HexToString commented 3 years ago

问题的原因是序列化的问题,但是为什么你这会出这个问题,还不能确定。 有一个办法您可以试一下, web_service.py文件中

server_pros = [](将这一句删除) for i, service in enumerate(self.rpc_service_list): p = Process(target=self._launch_rpc_service, args=(i, )) server_pros.append(p)(将这一句删除) for p in server_pros:(将这一句删除) p.start()

meishitouzhele commented 3 years ago

额 我没找到这个文件 web_service.py 请问再哪里?

HexToString commented 3 years ago

这个文章也许可以帮到您,说是win和Linux多进程差异导致的。 https://blog.csdn.net/lijinzemmm/article/details/75735805?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-5.control&dist_request_id=1330144.34750.16182099985152017&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-5.control

meishitouzhele commented 3 years ago

嗯嗯 感谢