|
本帖最后由 BCAIZLF 于 2023-11-21 17:00 编辑
1.利用pytorch做模型量化感知训练。
2.成功转换为rknn模型。
3.调用rknn.init_runtime(perf_debug=True)失败
pt转rknn代码
from PIL import Image
import numpy as np
#from matplotlib import pyplot as plt
import re
import math
import random
from PIL import Image
from rknn.api import RKNN
import os
os.environ["CUDA_VISIBLE_DEVICES"] ="2"
if __name__ == '__main__':
# Create RKNN object
rknn = RKNN(verbose=True)
rknn.config(mean_values=[[0,0,0]], reorder_channel='', batch_size=1,target_platform=['rv1126'])#rk3399pro#'rv1109','rv1126'#,target_platform=['rk3399pro','rk1808']
# Load tensorflow model
print('--> Loading model')
# rknn.load_darknet(model='./yolov3.cfg', weight="./yolov3.weights")
ret = rknn.load_pytorch(model='/work/models/pt/VGGTCNQnewjit.pt', input_size_list=[[3,96,288]])
# ret = rknn.load_onnx(model = '/work/models/onnx/epoch_20220721_192x320_320s_yuanban.onnx')
print('done.........................................')
# Build model
print('--> Building model')
# ret = rknn.build(do_quantization=False)#True
ret = rknn.build(do_quantization=False, dataset='/work/files/dataset_192x320.txt', pre_compile=False)#True
# ret = rknn.build(do_quantization=False,pre_compile=True)#True
if ret != 0:
print('Build pytorch failed!')
exit(ret)
print('done')
rknn.export_rknn('/work/models/rknn/VGGTCNQnewjit.rknn')
print('export VGGTCNQnewjit.rknn done')
exit(0)
运行脚本代码报错
from rknn.api import RKNN
import numpy as np
RKNN_LOG_LEVEL=5
def init_model(rknn_path):
rknn = RKNN()
print('build rknn')
rknn.load_rknn(rknn_path)
print('load rknn')
ret = rknn.init_runtime(perf_debug=True)
print(ret)
if ret != 0:
print('Init runtime environment failed')
exit(ret)
rknn.eval_perf()
return rknn
if __name__ == '__main__':
p = np.ones([1,3,96,288],dtype=np.uint8)
model = init_model('/work/models/rknn/VGGTCNQ.rknn')
output = model.inference([p])
print('done!')
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|