Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何获取op的多个输出? #1857

Closed
XinyuDu opened this issue Sep 27, 2022 · 2 comments
Closed

如何获取op的多个输出? #1857

XinyuDu opened this issue Sep 27, 2022 · 2 comments

Comments

@XinyuDu
Copy link

XinyuDu commented Sep 27, 2022

改造了Serving/core/general-server/op/general_detection_op.cpp增加了输出boxes的代码。但是client端获取不到增加的输出。请问应该怎么改prototxt或者client端实现获取多个输出?
增加部分如下:

    int box_size_out = box_num*4*2*sizeof(int);
    void *box_data_out = MempoolWrapper::instance().malloc(box_size_out);
    if (!box_data_out) {
      LOG(ERROR) << "Malloc failed, size: " << box_size_out;
      return -1;
    }
    
    int* databuf_int = reinterpret_cast<int*>(box_data_out);
    for (int i = 0; i < box_num; ++i) {
      for (int row = 0; row < 4; row++){
        *databuf_int = boxes[i][row][0];
        databuf_int++;
        *databuf_int = boxes[i][row][1];
        databuf_int++;
      }
    }

    // memcpy(databuf_data_out, &boxes, databuf_size_out);
    char *box_char_out = reinterpret_cast<char*>(box_data_out);
    paddle::PaddleBuf paddleBuf_out_2(box_char_out, box_size_out);
    paddle::PaddleTensor tensor_out_2;

    tensor_out_2.name = "boxes";
    tensor_out_2.dtype = paddle::PaddleDType::INT32;
    tensor_out_2.shape = {box_num, 4, 2};
    tensor_out_2.data = paddleBuf_out_2;
    out->push_back(tensor_out_2);

获取serving输出的det_cpp_client.py如下:

import sys
import numpy as np
import base64
import os
import cv2
from paddle_serving_app.reader import Sequential, URL2Image, ResizeByFactor
from paddle_serving_app.reader import Div, Normalize, Transpose
from paddle_serving_app.reader import OCRReader
from paddle_serving_app.reader import DBPostProcess, FilterBoxes, GetRotateCropImage, SortedBoxes


client = Client()
client.load_client_config(sys.argv[1:])
client.connect(["127.0.0.1:9293"])
fetch_list = client.get_fetch_names()
print(fetch_list)

test_img_dir = "imgs/"
img_file = '1.jpg'

def cv2_to_base64(image):
    return base64.b64encode(image)  #data.tostring()).decode('utf8')

with open(os.path.join(test_img_dir, img_file), 'rb') as file:
    image_data = file.read()
    image = cv2_to_base64(image_data)

det_out = client.predict(
        feed={"x": image},
        fetch=["x","boxes"],
        batch=True)

print(det_out)

serving启动代码如下:

python3 -m paddle_serving_server.serve --model ocr_det_model --op GeneralDetectionOp --port 9293

client启动代码如下:

python3 det_cpp_client.py ocr_det_client

@github-actions
Copy link

Message that will be displayed on users' first issue

@ooxoxx
Copy link

ooxoxx commented Jul 5, 2023

请问您的问题解决了吗?我也有同样的需求

@paddle-bot paddle-bot bot closed this as completed Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants