Closed meishitouzhele closed 5 months ago
1、请问你运行的是原始的resnet50_web_service.py文件么? 2、检查代码在image_service.run_web_service()前必须有image_service.run_rpc_service() 3、也有可能是缺少flask?
我是把前必须有image_service.run_rpc_service() 这个注释了,现在放开了,cpu或者gpu报如下we问题
运行同目录下的test_image_reader.py有点异常
额 标记的都不是这个问题吧
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方法即可。
另外,请您把您的环境信息最好一并发过来,这样会比较容易定位问题。
至于上面的问题,有点看不太明白,麻烦您详细描述一下是什么情况下报的这个错。
好的 感谢 我重新整理下。
您太客气了,用户就是上帝,是我们一贯的服务宗旨。
仔细看了一下,您的第一个问题貌似是protobuf导致的问题。 您是否修改了相关的内容呢?例如是否修改了proto文件或其相关文件?
额 没有修改 目前就是win10原生环境 pip安装了 paddlehub,然后能正常使用官网demo和自己训练的model。然后pip安装了paddleserving 运行官方的ocr model能正常发布、调用,然后运行官方的imagenet 发布报错。cpu和gpu都报错
您使用的是哪个版本的呢? 麻烦能把pip list打出来看一下么?
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
上面是环境,然后我运行案例里的 我修改了下使用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
D:\serving\Serving\python\examples\imagenet>Traceback (most recent call last):
File "
服务端代码如下:
#
#
#
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()
问题的原因是序列化的问题,但是为什么你这会出这个问题,还不能确定。 有一个办法您可以试一下, 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()
额 我没找到这个文件 web_service.py 请问再哪里?
嗯嗯 感谢
File ".\resnet50_web_service.py", line 78 image_service.run_web_service() ^ SyntaxError: invalid syntax 能提供一个运行examples下图像分类的过程吗?,想运行通过后 发布下自己的图像分类model(在centos的docker下能正常的model,想在win10下测试)感谢