GithubHelp home page GithubHelp logo

Comments (4)

KyleWang-Hunter avatar KyleWang-Hunter commented on July 1, 2024 1

哈哈,我之前也提过,让自己改。看你用的是什么模型,以图片分类为例,只需要修改preprocess模型中model.py的execute函数,将读取输入图片的格式修改为base64就可以了,如下所示:

获取输入的base64字符串

input_tensor = pb_utils.get_input_tensor_by_name(request, self.input_names[0])
base64_string = input_tensor.as_numpy()[0][0]

解码 base64 字符串为图像

image_bytes = base64.b64decode(base64_string)
image = Image.open(io.BytesIO(image_bytes)).convert('RGB')
data = np.array(image)
outputs = self.preprocess_.run([data, ])

from fastdeploy.

ignore1999 avatar ignore1999 commented on July 1, 2024

哈哈,我之前也提过,让自己改。看你用的是什么模型,以图片分类为例,只需要修改preprocess模型中model.py的execute函数,将读取输入图片的格式修改为base64就可以了,如下所示:

获取输入的base64字符串

input_tensor = pb_utils.get_input_tensor_by_name(request, self.input_names[0]) base64_string = input_tensor.as_numpy()[0][0]

解码 base64 字符串为图像

image_bytes = base64.b64decode(base64_string) image = Image.open(io.BytesIO(image_bytes)).convert('RGB') data = np.array(image) outputs = self.preprocess_.run([data, ])

OK非常感谢,我试下

from fastdeploy.

ignore1999 avatar ignore1999 commented on July 1, 2024

@KyleWang-Hunter 我修改代码后出现'{"error":"Unable to parse \'data\': attempt to access JSON non-unsigned-integer as unsigned-integer"}'的问题,请问是否要修改"datatype" : "UINT8"或配置文件config.pbtxt的内容?我的json请求体如下:

payload = {
  "inputs" : [
    {
      "name" : "INPUT",
      "shape" : image.shape,
      "datatype" : "UINT8",
      "data" : [base64_string] # image.tolist() # 
    }
  ],
  "outputs" : [
    {
      "name" : "rec_texts"
    }
  ]
}

from fastdeploy.

KyleWang-Hunter avatar KyleWang-Hunter commented on July 1, 2024

UINT8

是的哦,请求的时候需要修改"datatype" : "BYTES",

另外,preprocess模型的config.pbtxt文件的数据类型也需要修改
name: "preprocess"
backend: "python"
max_batch_size: 16

input [
{
name: "preprocess_input"
data_type: TYPE_STRING
dims: [ -1 ]
}
]

output [
{
name: "preprocess_output"
data_type: TYPE_FP32
dims: [ 3, 224, 224 ]
}
]

version_policy: { all { }}

version_policy: { specific: { versions: [1,3]}}

version_policy: { latest: { num_versions: 2}}

instance_group [
{
# The number of instances is 1
count: 1
# Use CPU, GPU inference option is:KIND_GPU
kind: KIND_CPU
# The instance is deployed on the 0th GPU card
# gpus: [0]
}
]
runtime模型的config.pbtxt也需要修改
input [
{
# input name
name: "x"# 这里需要根据实际的模型参数来修改
# input type such as TYPE_FP32、TYPE_UINT8、TYPE_INT8、TYPE_INT16、TYPE_INT32、TYPE_INT64、TYPE_FP16、TYPE_STRING
data_type: TYPE_FP32
# input shape, The batch dimension is omitted and the actual shape is [batch, c, h, w]
dims: [ 3, 224, 224 ]
}
]

The output of the model is configured in the same format as the input

output [
{
name: "softmax_1.tmp_0"#这里也是,需要根据实际的模型参数来修改
data_type: TYPE_FP32
dims: [ 14 ]
}
]
postprocess也是一样

from fastdeploy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.