PaddlePaddle / PaddleClas

A treasure chest for visual classification and recognition powered by PaddlePaddle
Apache License 2.0
5.5k stars 1.17k forks source link

图片方向分类模型serving部署报错:{'err_no': 5, 'err_msg': '(log_id=2) imagenet failed to predict.', 'key': [], 'value': [], 'tensors': []} #2837

Open MarkHe735 opened 1 year ago

MarkHe735 commented 1 year ago

将图片文字方向模型部署为serving服务。 模型参考文档:https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/zh_CN/models/PULC/PULC_text_image_orientation.md 对方向分类模型进行了微调,inference模型预测正常。 部署参考文档:https://github.com/PaddlePaddle/PaddleClas/tree/release/2.5/deploy/paddleserving#readme 采用docker部署方式,没有GPU;文档中的imagenet部署成功;方向分类器始终报错。

  1. PaddleClas版本以及PaddlePaddle版本: paddle-serving-app 0.7.0 paddle-serving-client 0.7.0 paddle-serving-server 0.7.0 paddleclas 2.5.1 paddlepaddle 2.2.0 a. 具体操作系统:Linux docker b. Python版本号,如Python3.7 c. CUDA/cuDNN版本, CPU预测
  2. 完整的代码(相比于repo中代码,有改动的地方)、详细的错误信息及相关log log.txt内容 2023/06/19 07:53:02 start proxy service grep: warning: GREP_OPTIONS is deprecated; please use an alias or script E0619 07:53:03.268620 3511 analysis_config.cc:91] Please compile with gpu to EnableGpu() I0619 07:53:03.288556 3511 analysis_predictor.cc:668] ir_optim is turned off, no IR pass will be executed ^[[1m^[[35m--- Running analysis [ir_graph_build_pass]^[[0m ^[[1m^[[35m--- Running analysis [ir_graph_clean_pass]^[[0m ^[[1m^[[35m--- Running analysis [ir_analysis_pass]^[[0m ^[[1m^[[35m--- Running analysis [ir_params_sync_among_devices_pass]^[[0m ^[[1m^[[35m--- Running analysis [adjust_cudnn_workspace_size_pass]^[[0m ^[[1m^[[35m--- Running analysis [inference_op_replace_pass]^[[0m ^[[1m^[[35m--- Running analysis [memory_optimize_pass]^[[0m I0619 07:53:03.306725 3511 memory_optimize_pass.cc:214] Cluster name : conv2d_48.tmp_1 size: 2048 I0619 07:53:03.306746 3511 memory_optimize_pass.cc:214] Cluster name : batch_norm_2.tmp_2 size: 1605632 I0619 07:53:03.306756 3511 memory_optimize_pass.cc:214] Cluster name : hardswish_33.tmp_0 size: 802816 I0619 07:53:03.306766 3511 memory_optimize_pass.cc:214] Cluster name : hardswish_30.tmp_0 size: 1605632 I0619 07:53:03.306774 3511 memory_optimize_pass.cc:214] Cluster name : x size: 602112 ^[[1m^[[35m--- Running analysis [ir_graph_to_program_pass]^[[0m I0619 07:53:03.325022 3511 analysis_predictor.cc:717] ======= optimize end ======= I0619 07:53:03.325529 3511 naive_executor.cc:98] --- skip [feed], feed -> x I0619 07:53:03.326546 3511 naive_executor.cc:98] --- skip [hardswish_30.tmp_0], fetch -> fetch

python web服务启动代码,仅修改了读取标签部分: `import sys from paddle_serving_app.reader import Sequential, URL2Image, Resize, CenterCrop, RGB2BGR, Transpose, Div, Normalize, Base64ToImage try: from paddle_serving_server_gpu.web_service import WebService, Op except ImportError: from paddle_serving_server.web_service import WebService, Op import logging import numpy as np import base64, cv2

class ImagenetOp(Op): def init_op(self): self.seq = Sequential([ 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("pplcnet.label") as fin: for line in fin: idx, label = line.split() self.label_dict[idx] = label label_idx += 1

def preprocess(self, input_dicts, data_id, log_id):
    (_, input_dict), = input_dicts.items()
    batch_size = len(input_dict.keys())
    imgs = []
    for key in input_dict.keys():
        data = base64.b64decode(input_dict[key].encode('utf8'))
        data = np.fromstring(data, np.uint8)
        im = cv2.imdecode(data, cv2.IMREAD_COLOR)
        img = self.seq(im)
        imgs.append(img[np.newaxis, :].copy())
    input_imgs = np.concatenate(imgs, axis=0)
    return {"inputs": input_imgs}, False, None, ""

def postprocess(self, input_dicts, fetch_dict, data_id, log_id):
    score_list = fetch_dict["prediction"]
    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)
    result["label"] = str(result["label"])
    result["prob"] = str(result["prob"])
    return result, None, ""

class ImageService(WebService): def get_pipeline_response(self, read_op): image_op = ImagenetOp(name="imagenet", input_ops=[read_op]) return image_op

uci_service = ImageService(name="imagenet") uci_service.prepare_pipeline_config("config.yml") uci_service.run_service() `

标签文件pplcnet.label内容: 0 0 1 90 2 180 3 270

配置文件config.yum内容,仅修改了serving模型目录: `worker_num: 1

http端口, rpc_port和http_port不允许同时为空。当rpc_port可用且http_port为空时,不自动生成http_port

http_port: 18080 rpc_port: 9993

dag:

op资源类型, True, 为线程模型;False,为进程模型

is_thread_op: False

op: imagenet:

并发数,is_thread_op=True时,为线程并发;否则为进程并发

    concurrency: 1

    #当op配置没有server_endpoints时,从local_service_conf读取本地服务配置
    local_service_conf:

        #uci模型路径
        model_config: Direction_cls_serving

        #计算硬件类型: 空缺时由devices决定(CPU/GPU),0=cpu, 1=gpu, 2=tensorRT, 3=arm cpu, 4=kunlun xpu
        device_type: 1

        #计算硬件ID,当devices为""或不写时为CPU预测;当devices为"0", "0,1,2"时为GPU预测,表示使用的GPU卡
        devices: "0" # "0,1"

        #client类型,包括brpc, grpc和local_predictor.local_predictor不启动Serving服务,进程内预测
        client_type: local_predictor

        #Fetch结果列表,以client_config中fetch_var的alias_name为准
        fetch_list: ["prediction"]

`

预测命令:python3.7 pipeline_http_client.py 报错信息为:{'err_no': 5, 'err_msg': '(log_id=0) imagenet failed to predict.', 'key': [], 'value': [], 'tensors': []}

请大牛们指教

Summmerlpc commented 3 months ago

同样的问题,请问解决了吗