Comments (4)
哈哈,我之前也提过,让自己改。看你用的是什么模型,以图片分类为例,只需要修改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.
哈哈,我之前也提过,让自己改。看你用的是什么模型,以图片分类为例,只需要修改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.
@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.
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)
- 编译成功,CPU运行成功 GPU运行失败
- 在华为昇腾Atlas 300推理卡上编译安装FastDeploy,后尝试部署uie模型出现问题。[ERROR] fastdeploy/runtime/runtime_option.cc(181)::UsePaddleBackend The FastDeploy didn't compile with Paddle Inference. HOT 1
- rk3588部署飞浆ocr使用命令行代码可以运行,但是使用python脚本调用出现问题 HOT 1
- Failed to build on Ubuntu 20 HOT 2
- pp-ocr服务化部署问题 HOT 1
- FastDeploy-release-1.0.7 单个模型在70ms作用,piplin需要300-500毫秒 HOT 3
- RuntimeError: FastDeploy initalized failed! Error: DLL load failed while importing fastdeploy_main: 找不到指定的程序。 HOT 1
- C#编译完成后部署异常返回值为0xc00000374 HOT 1
- FastDeploy推理PPOCR过程加载字库文件ppocr_keys_v1.txt出现的编码报错的异常 HOT 1
- 服务化部署。http调用返回识别结果正常,grpc调用特殊符号部分会乱码
- 模型服务化部署是否支持yolov8 HOT 1
- C++使用预编译库预测pp_liteseg模型时结果内score_map为什么是空值,图像可视化已经正确标准,到处模型是也设置--output_op none,测试好几个模型score_map都是空值,不明白是为什么
- Serving encrypted models
- 在rk3588上部署paddleseg模型,发现在性能十分不如意,有没有办法提高npu的占用率或者是多核调用? HOT 3
- 从内存中加载模型时报错:进程已结束,退出代码为 -1073741819 (0xC0000005) HOT 1
- 在运行contrib的分类模型(非ppcls)的模型结果不对
- How to read camera for super Resolution
- 编译android的aar包失败,希望能集成RKNPU2,能否给出更详细的操作步骤
- CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastdeploy.