Toybrick

2.0.0无法运行模型

yinjun

新手上路

积分
25
楼主
发表于 2024-5-16 10:18:18    查看: 331|回复: 1 | [复制链接]    打印 | 只看该作者
本帖最后由 yinjun 于 2024-5-16 10:20 编辑

rt,运行后会报错
rknn_outputs_get,  p_ctx->queue_output.size() = 0!
求大佬帮我看看怎么解决

错误日志

E RKNNAPI: Catch runtime Crash! Stack backtrace:
Segmentation Fault
  # 0: 0x5e5298c38c  
  # 1: 0x5e5298f408  
  # 2: 0x72ccade5ec  __kernel_rt_sigreturn

E RKNNAPI: rknn_outputs_get,  p_ctx->queue_output.size() = 0!
E inference: Traceback (most recent call last):
  File "rknn/api/rknn_log.py", line 309, in rknn.api.rknn_log.error_catch_decorator.error_catch_wrapper
  File "rknn/api/rknn_base.py", line 2589, in rknn.api.rknn_base.RKNNBase.inference
  File "rknn/api/rknn_runtime.py", line 554, in rknn.api.rknn_runtime.RKNNRuntime.get_outputs
Exception: E Get outputs failed, error code: RKNN_ERR_FAIL


模型
看附件

代码
  1. import os
  2. import urllib
  3. import traceback
  4. import time
  5. import sys
  6. import numpy as np
  7. import cv2
  8. import torch
  9. from rknn.api import RKNN
  10. from blazefacenumpy import BlazeFace
  11. ONNX_MODEL = 'best.onnx' # onnx 模型的路径
  12. ONNX_MODEL = 'rppg_new.onnx' # onnx 模型的路径
  13. ONNX_MODEL = 'blazeface128.onnx' # onnx 模型的路径
  14. # ONNX_MODEL = 'v3.onnx' # onnx 模型的路径
  15. # ONNX_MODEL = 'alexnet.onnx' # onnx 模型的路径
  16. TFLITE_MODEL = 'face_detection_front.tflite'
  17. # TFLITE_MODEL = 'alexnet_float32.tflite'

  18. # /anaconda/envs/horizon_bpu/lib/python3.8/site-packages/rknn/3rdparty/platform-tools/adb/linux-x86_64
  19. # tcpip

  20. RKNN_MODEL = './yolov8-ghost-pose.rknn'  # 转换后的 RKNN 模型保存路径
  21. RKNN_MODEL = './bz128_3568.rknn'  # 转换后的 RKNN 模型保存路径
  22. # RKNN_MODEL = './facenet——3568.rknn'  # 转换后的 RKNN 模型保存路径
  23. RKNN_MODEL = './pfldv3.rknn'  # 转换后的 RKNN 模型保存路径
  24. DATASET = './test.txt'   # 数据集文件路径

  25. QUANTIZE_ON = False   # 是否进行量化


  26. def plot_detections(img, detections):


  27.     if isinstance(detections, torch.Tensor):
  28.         detections = detections.cpu().numpy()



  29.     # if detections.ndim == 1:
  30.     #     detections = np.expand_dims(detections, axis=0)

  31.     # print("Found %d faces" % detections.shape[0])
  32.         
  33.     for i in range(detections.shape[0]):
  34.         ymin = int(detections[i, 0] * img.shape[0])
  35.         xmin = int(detections[i, 1] * img.shape[1])
  36.         ymax = int(detections[i, 2] * img.shape[0])
  37.         xmax = int(detections[i, 3] * img.shape[1])

  38.         cv2.rectangle(img,(xmin,ymin),(xmax,ymax),(170,234,242),5,lineType=cv2.LINE_AA)
  39.    
  40.         # if with_keypoints:
  41.         #     for k in range(6):
  42.         #         kp_x = detections[i, 4 + k*2    ] * img.shape[1]
  43.         #         kp_y = detections[i, 4 + k*2 + 1] * img.shape[0]
  44.         #         circle = patches.Circle((kp_x, kp_y), radius=0.5, linewidth=1,
  45.         #                                 edgecolor="lightskyblue", facecolor="none",
  46.         #                                 alpha=detections[i, 16])
  47.         #         ax.add_patch(circle)


  48. if __name__ == '__main__':

  49.         # 创建 RKNN 对象
  50.         rknn = RKNN(verbose=False)

  51.     # 检查 ONNX 模型文件是否存在
  52.         if not os.path.exists(ONNX_MODEL):
  53.                 print('model not exist')
  54.                 exit(-1)

  55.         # 配置模型预处理参数
  56.         print('--> Config model')
  57.         rknn.config(#reorder_channel='0 1 2', # 表示 RGB 通道
  58.                                 
  59.                             mean_values=[[0, 0, 0]], # 每个通道的像素均值,预处理时对应通道减去该值
  60.                             std_values=[[255, 255, 255]], # 每个通道的像素标准差,每个通道除以该值
  61.                             optimization_level=3, # 优化级别
  62.                                 quantized_method='layer',
  63.                                 float_dtype="float16",
  64.                             target_platform = 'RK3568', #指定目标平台为rv1126
  65.                                 # quantize_input_node=QUANTIZE_ON
  66.                                 )  # 对时输入节点进行量化


  67.         # 加载 ONNX 模型
  68.         # print('--> Loading model')
  69.         model = rknn.load_rknn(RKNN_MODEL)
  70.         ret = rknn.init_runtime(target="rk3568")
  71.         print("start")
  72.         frame = cv2.imread('./test.jpg')
  73.         frame =cv2.resize(frame,(112,112))
  74.    

  75.         back_net = BlazeFace(back_model=False).to("cpu")

  76.       
  77.         input = np.reshape(frame,-1)
  78.    
  79.         

  80.         pred = rknn.inference(inputs=[input], data_format='nhwc')

  81.         kk1 = np.reshape( pred[1],-1)[222:225]
  82.         print(pred[1].astype(np.float16))
  83.         kk =np.reshape( pred[0],-1)[2::10].astype(np.int16)
  84.         print('pred')

  85.         # print('bz load')
  86.         # back_net.load_anchors("anchors.npy")

  87.         # deback = back_net._tensors_to_detections(raw_box_tensor=pred[0],raw_score_tensor=pred[1],anchors=back_net.anchors)

  88.     # # 4. Non-maximum suppression to remove overlapping detections:
  89.         # filtered_detections = []
  90.         # for i in range(len(deback)):
  91.         #         faces = back_net._weighted_non_max_suppression(deback[i])
  92.                
  93.         #         faces = np.stack(faces) if len(faces) > 0 else np.zeros((0, 17))
  94.         #         filtered_detections.append(faces)
  95.         # plot_detections(frame,filtered_detections[0])

  96.         # cv2.imwrite('test_out.jpg',frame)

  97.    

复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

yinjun

新手上路

积分
25
沙发
 楼主| 发表于 2024-5-16 12:36:02 | 只看该作者
新发现:rknn不支持Linear层,会报错,有什么好的解决方法吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

产品中心 购买渠道 开源社区 Wiki教程 资料下载 关于Toybrick


快速回复 返回顶部 返回列表