PaddlePaddle / Paddle-Lite

PaddlePaddle High Performance Deep Learning Inference Engine for Mobile and Edge (飞桨高性能深度学习端侧推理引擎)
https://www.paddlepaddle.org.cn/lite
Apache License 2.0
6.96k stars 1.61k forks source link

使用Paddle Lite运行python api demo时报错 #9917

Closed m1sift111 closed 3 weeks ago

m1sift111 commented 1 year ago

   1)Paddle Lite 版本:v2.8.0    2)运行设备环境:树莓派4B

paddle-bot[bot] commented 1 year ago

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网文档常见问题历史Issue来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQ and Github Issue to get the answer.Have a nice day!

sanersbug commented 1 year ago

1)Paddle Lite 版本:v2.8.0    2)运行设备环境:树莓派4B

  • 问题描述: 使用AI Studio PaddleDetection训练ssd_mobilenet_v1模型,成功导出v2.8.0版本的.nb模型。在尝试使用Paddle-Lite/lite/demo/python/mobilenetv1_light_api.py测试时,发生以下错误
F0109 21:58:43.796674 26988 reshape_op.cc:171] Check failed: output_dims[unk_dim_idx] * capacity == -input_size (0 vs. -1) Invalid shape is given.
*** Check failure stack trace: ***

在历史issue中,我看见类似运行python demo报错的内容,问题在于给出的ssd_mobilenet模型的input为1,而训练出的模型如下: image,其中有3个输入,故我修改python demo代码如下(其余部分未改动,仅改动了set input data部分)

# 3. Set input data
    c, h, w = args.input_shape[1], args.input_shape[2], args.input_shape[3] # 3, 480, 640
    # 输入[[h, w]]的图片大小
    input_tensor0 = predictor.get_input(0)
    input_tensor0.from_numpy(np.array([[h, w]]).astype("float32"))
    # 输入模型处理图像大小与实际图像大小的比例
    input_tensor2 = predictor.get_input(2)
    input_tensor2.from_numpy(np.ones((1, 2)).astype("float32"))
    # 输入[1, 3, h, w]的归一化后的图片数据
    input_tensor1 = predictor.get_input(1)
    read_image = len(args.image_path) != 0 and len(args.label_path) != 0
    if read_image == True:
        import cv2
        with open(args.label_path, "r") as f:
            label_list = f.readlines()
        image_mean = [0.485, 0.456, 0.406]
        image_std = [0.229, 0.224, 0.225]
        image_data = cv2.imread(args.image_path)
        image_data = cv2.resize(image_data, (h, w))
        image_data = cv2.cvtColor(image_data, cv2.COLOR_BGR2RGB)
        image_data = image_data.transpose((2, 0, 1)) / 255.0
        image_data = (image_data - np.array(image_mean).reshape(
            (3, 1, 1))) / np.array(image_std).reshape((3, 1, 1))
        image_data = image_data.reshape([1, c, h, w]).astype('float32')
        input_tensor1.from_numpy(image_data)
        print(input_tensor1.shape())
    else:
        input_tensor1.from_numpy(np.ones((1, c, h, w)).astype("float32"))

输入图片的为3 x 480 x 640大小,但报错如上所示,无法正常推测。 我推测为模型输入参数有误,但苦于没有基础,无法排除错误。还请能帮忙排查问题,给出建议,万分感谢!

嗨,请问你解决这个问题了吗,我也遇到了相同的问题,不过我的报错是output_dims[unk_dim_idx] * capacity == -input_size:-81600!=825584,我认为我这个也是模型输入的问题,另外,请问你这个查看模型输入输出的图是怎么查看的呢