1 Star 0 Fork 0

Mr.Harsh/tspi_-RKNN_MobileNetV3

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test.py 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
Mr.Harsh 提交于 2024-03-04 13:49 +08:00 . add readme
import cv2
import numpy as np
from rknnlite.api import RKNNLite
INPUT_SIZE = 224
RK3566_MODEL = 'tspi_moblienetv3_demo.rknn'
labels=["cat","cattle","dog","house","pig"]
def show_top5(result):
output = result[0].reshape(-1)
labels=["cat","cattle","dog","house","pig"]
# Softmax
output = np.exp(output) / np.sum(np.exp(output))
# Get the indices of the top 5 largest values
output_sorted_indices = np.argsort(output)[::-1][:5]
top5_str = '-----TOP 5-----\n'
for i, index in enumerate(output_sorted_indices):
value = output[index]
if value > 0:
topi = '[{:>3d}] score:{:.6f} class:"{}"\n'.format(index, value, labels[index])
else:
topi = '-1: 0.0\n'
top5_str += topi
print(top5_str)
if __name__ == '__main__':
rknn_lite = RKNNLite()
# Load RKNN model
print('--> Load RKNN model')
ret = rknn_lite.load_rknn(RK3566_MODEL)
if ret != 0:
print('Load RKNN model failed')
exit(ret)
print('done')
ori_img = cv2.imread('./demo_cat.jpg')
img = cv2.cvtColor(ori_img, cv2.COLOR_BGR2RGB)
img = np.expand_dims(img, 0)
# Init runtime environment
print('--> Init runtime environment')
ret = rknn_lite.init_runtime()
if ret != 0:
print('Init runtime environment failed')
exit(ret)
print('done')
# Inference
print('--> Running model')
outputs = rknn_lite.inference(inputs=[img])
# Show the classification results
show_top5(outputs)
print('done')
rknn_lite.release()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/mrharsh/tspi_-RKNN_MobileNetV3.git
git@gitee.com:mrharsh/tspi_-RKNN_MobileNetV3.git
mrharsh
tspi_-RKNN_MobileNetV3
tspi_-RKNN_MobileNetV3
master

搜索帮助