Toybrick

rknn模型推理报错

ImmanuelLee

注册会员

积分
52
发表于 2024-1-24 15:44:18    查看: 1443|回复: 2 | [复制链接]    打印 | 显示全部楼层
问题背景:
我的目的是将线性判别分析算法的程序rknn化,将程序运行在香橙派5B的NPU上。


线性判别分析算法的rknn化,实现步骤是:
①用pytorch库一步步参照sklearn库中的线性判别算法的实现过程写出线性判别分析的pytorch程序;
②将pytorch程序写出的线性判别分析算法导出为pt模型;
③将pt模型转换为onnx模型;
④将onnx模型转换为rknn模型;

但是将rknn模型运行起来报错;

运行rknn模型的程序如下:
from rknnlite.api import RKNNLite as RKNN
import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler
import pickle



# model='linear_model.rknn'
# model='CNN_Lee20231201.rknn'
model='LDA_Lee20240122.rknn'

# input_test_data = [23, 32, 197, 1022, 1, 1, 18, 24, 169, 458, 1, 1, 25, 31, 173, 697, 1, 1, 27, 36, 195, 1221, 1, 1]
# 定义特征名称和数据
feature_names = ['AverageAbsoluteValue_Channel1', 'RootMeanSquare_Channel1', 'MeanFrequency_Channel1' \
    , 'Hjorth Activity_Channel1', 'Hjorth Mobility_Channel1', 'Hjorth Complexity_Channel1' \
    , 'AverageAbsoluteValue_Channel2', 'RootMeanSquare_Channel2', 'MeanFrequency_Channel2' \
    , 'Hjorth Activity_Channel2', 'Hjorth Mobility_Channel2', 'Hjorth Complexity_Channel2' \
    , 'AverageAbsoluteValue_Channel3', 'RootMeanSquare_Channel3', 'MeanFrequency_Channel3' \
    , 'Hjorth Activity_Channel3', 'Hjorth Mobility_Channel3', 'Hjorth Complexity_Channel3' \
    , 'AverageAbsoluteValue_Channel4', 'RootMeanSquare_Channel4', 'MeanFrequency_Channel4' \
    , 'Hjorth Activity_Channel4', 'Hjorth Mobility_Channel4', 'Hjorth Complexity_Channel4']
features_Sample = [23, 32, 197, 1022, 1, 1, 18, 24, 169, 458, 1, 1, 25, 31, 173, 697, 1, 1, 27, 36, 195, 1221, 1, 1]
features_MergedArray = np.array(features_Sample)
features_MergedArrayD2 = features_MergedArray.reshape(1, -1)
# 转换为DataFrame并设置特征名称
features_MergedDataFrame = pd.DataFrame(features_MergedArrayD2, columns=feature_names)

with open('scaler_PytorchCNNVersion.pkl', 'rb') as f:
    scaler = pickle.load(f)

features_scaled = scaler.transform(features_MergedDataFrame)
# 将 float64 转换为 float32
#features_scaled_float32 = features_scaled.astype(np.float32)
features_scaled_float32 = features_scaled.astype(np.float16)



# rknn=RKNN()
rknn=RKNN(verbose=True)

ret=rknn.load_rknn(path=model)
print('--> Init runtime environment')
ret = rknn.init_runtime(
    #target=None,
    #target="rk3588",
    # target_sub_class=None,
    device_id=None,
    # perf_debug=False,
    # eval_mem=False,
    async_mode=False,
    core_mask=RKNN.NPU_CORE_AUTO
    #core_mask=0
)

if ret != 0:
    print('Init runtime environment failed')
    exit(ret)
print('done')


print(22222222111111222222222)
# output=rknn.inference(inputs=[features_scaled_float32])
output=rknn.inference(inputs=[features_scaled_float32])
print(111111)
print(output)
print(111111)



报错如下:
D RKNN: [15:10:01.805] normalize target: CPU
D RKNN: [15:10:01.805] Get NPU frequency: 1000MHz
W RKNN: [15:10:01.805] failed to get DDR freq, take 1560MHz as default freq
D RKNN: [15:10:01.805] Get DDR frequency: 1560MHz
D RKNN: [15:10:01.805] dump npy tensor to: dumps/000_InputOperator_0_shape_1_24_float.npy
D RKNN: [15:10:01.806] dump npy tensor to: dumps/001_Reshape_Gemm_3_2conv_transpose1_output_shape_1_24_1_1_float.npy
D RKNN: [15:10:01.806] dump npy tensor to: dumps/002_Conv_4_conv_shape_1_1_1_1_float.npy
D RKNN: [15:10:01.806] dump npy tensor to: dumps/003_Reshape_6_shape_1_float.npy
E RKNN: [15:10:01.805] failed open dump path: dumps/000_InputOperator_0_shape_1_24_float.npy
E RKNN: [15:10:01.806] failed open dump path: dumps/001_Reshape_Gemm_3_2conv_transpose1_output_shape_1_24_1_1_float.npy
E RKNN: [15:10:01.806] failed open dump path: dumps/002_Conv_4_conv_shape_1_1_1_1_float.npy
E RKNN: [15:10:01.806] failed open dump path: dumps/003_Reshape_6_shape_1_float.npy
E RKNN: [15:10:01.807] DoElementwiseLogical unknown inputA layout:0
/tmp/tmp7b2e49h0:行 3:  4631 已放弃               (核心已转储) python /home/orangepi/Pycharm/pycharm-community-2023.1/plugins/python-ce/helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 127.0.0.1 --port 38573 --file /home/orangepi/EMG_RKNN_Lee/myRKNN_Project/02_inference/inference_LDA_rknn_Lee20240124.py
ERROR conda.cli.main_run:execute(49): `conda run python /home/orangepi/Pycharm/pycharm-community-2023.1/plugins/python-ce/helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 127.0.0.1 --port 38573 --file /home/orangepi/EMG_RKNN_Lee/myRKNN_Project/02_inference/inference_LDA_rknn_Lee20240124.py` failed. (See above for error)


经过断点调试,发现报错的语句为:
output=rknn.inference(inputs=[features_scaled_float32])



回复

使用道具 举报

jefferyzhang

版主

积分
12928
发表于 2024-1-25 16:02:34 | 显示全部楼层
1. 更新最新版本rknn
2. 测试仿真能否正常推理
回复

使用道具 举报

ImmanuelLee

注册会员

积分
52
 楼主| 发表于 2024-2-27 15:50:23 | 显示全部楼层
jefferyzhang 发表于 2024-1-25 16:02
1. 更新最新版本rknn
2. 测试仿真能否正常推理

谢谢~!~!~!
回复

使用道具 举报

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

本版积分规则

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


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