版本:PaddlePaddle 2.1.0
错误信息: "result": "too many values to unpack (expected 3)"
自定义转换器代码:
输入函数:
import re
import base64
import numpy as np
import paddle.fluid as fluid
from PIL import Image
from io import BytesIO
## 将 Base64 转成 PIL Image
def base64_to_pil(image_base64):
"""read image from memory"""
image_base64 = re.sub('^data:image/.+;base64,', '', image_base64) # 需要去除头部格式信息
image_mem = BytesIO(base64.b64decode(image_base64)) # python3
image_pil = Image.open(image_mem).convert('RGB')
return image_pil
## 预处理代码
def preprocess(img):
# 图像缩放
if img.mode != 'RGB':
img = img.convert('RGB')
img = img.resize((224, 224), Image.BILINEAR)
img = np.array(img).astype('float32')
img = img.transpose((2, 0, 1)) / 255 # HWC to CHW 及归一化
return img
def feed(data_args = None):
def reader_infer(data_args):
"""
用于输入待预测数据,返回值会直接复值给paddle.static.Executor的run方法的feed参数。
模型加载方式选择:
paddle2.x:paddle.static.load_inference_model
paddle1.x:paddle.fluid.io.load_inference_model
:param data_args: 客户端请求参数,以k-v形式
:return dict
"""
def reader():
# x <type 'base64'> default value:''
image = data_args['imagebase']
# todo
# 格式转换
image = base64_to_pil(image)
# 预处理
image = preprocess(image)
image = image[np.newaxis,:, : ,:] #reshape(-1,3,224,224)
# 根据输入 Tensor 的名称和 Shape 构建 DataFeeder
c, h, w = image.shape
print("image shape:", image.shape)
img = fluid.layers.data(name='x', shape=[c, h, w], dtype='float32')
feeder = fluid.DataFeeder([img], fluid.CPUPlace())
return [[image]], feeder
# return image, feeder
# arg_x = None
return reader
输出函数:
def output(results, data_args):
"""
模型评测结果输出转换
:param results
:param data_args 请求参数
:return dict
"""
1条答案
按热度按时间jpfvwuh41#
请问您在使用哪个模型时遇到了这个错误?从报错信息来看,这似乎是在写 xx,xx,xx,xx .. = result 时发生的,其中 result 是一个三元组。但是左边的变量数量大于了3个,所以报错了。目前我无法从您提供的信息中判断出具体问题所在。
请说明一下出现错误的模型、程序报错展示的报错栈以及对应的代码片段。