|
开源项目:https://github.com/sirius-ai/MobileFaceNet_TF
模型:MobileFaceNet_9925_9680.pb 我的转换代码
报错日志:
--> Init runtime environment
E Catch exception when init runtime!
E Traceback (most recent call last):
E File "rknn/api/rknn_base.py", line 788, in rknn.api.rknn_base.RKNNBase.init_runtime
E RKNNAPI: rknn_init, msg_load_ack fail, ack = 1(ACK_FAIL), expect 0(ACK_SUCC)!
E RKNNAPI: ==============================================
E RKNNAPI: RKNN VERSION:
E RKNNAPI: API: 1.2.0 (1190a71 build: 2019-09-25 12:39:14)
E RKNNAPI: DRV: 0.9.8 (943f8e8 build: 2019-07-03 17:51:17)
E RKNNAPI: ==============================================
E File "rknn/api/rknn_runtime.py", line 303, in rknn.api.rknn_runtime.RKNNRuntime.build_graph
E Exception: RKNN init failed. error code: RKNN_ERR_MODEL_INVALID
E Current device id is: None
E Devices connected:
Init runtime environment failed
E ['TS018082190800251']
Process finished with exit code 255
'''
@author: Sun_Z_Z
@license: (C) Copyright 2018-2023, SCUT Lab.214 Limited.
@contact: 201810103145@mail.scut.edu.cn
@software: RKNN_Demo
@file: infer_with_tf_model.py
@time: 2019/12/3 下午2:31
'''
import numpy as np
import cv2
from rknn.api import RKNN
if __name__ == '__main__':
# Create RKNN object
rknn = RKNN()
# pre-process config
print('--> config model')
# rknn.config(channel_mean_value='103.94 116.78 123.68 58.82', reorder_channel='0 1 2')
print('done')
# Load tensorflow model
print('--> Loading model')
ret = rknn.load_tensorflow(tf_pb='./weights/MobileFaceNet_9925_9680.pb', inputs=['input'],
outputs=['embeddings'],
input_size_list=[[112, 112, 3]])
############################################################################
# 此处使用 inputs=['input'] 单输入是没问题的,也不会存在前面帖子里面说的要关闭 train_node 问题
# 因为 phase_train_placeholder = tf.placeholder_with_default(tf.constant(False, dtype=tf.bool), shape=None, name='phase_train')
# 这里是有一个默认值的 False
# 我尝试过 在对pb模型进行测试时,feed_dict 加不加 phase_train_placeholder 选项其推理结果是一样的
# 如: feed_dict = {images_placeholder: normed, phase_train_placeholder: False}
# feed_dict2 = {images_placeholder: normed}
# embs = sess.run(embeddings, feed_dict=feed_dict)
# embs2 = sess.run(embeddings, feed_dict=feed_dict2)
# print(embs-embs2)
# 结果为 全 0.
# 但是运行报错:
# E File "rknn/api/rknn_runtime.py", line 303, in rknn.api.rknn_runtime.RKNNRuntime.build_graph
# E Exception: RKNN init failed. error code: RKNN_ERR_MODEL_INVALID
# E Current device id is: None
# E Devices connected:
# Init runtime environment failed
# E ['TS018082190800251']
############################################################################
if ret != 0:
print('Load mobilenet_v1 failed!')
exit(ret)
print('done')
# Build model
print('--> Building model')
ret = rknn.build(do_quantization=True, dataset='./dataset.txt')
if ret != 0:
print('Build mobilenet_v1 failed!')
exit(ret)
print('done')
# Export rknn model
print('--> Export RKNN model')
ret = rknn.export_rknn('./mobilefacenet.rknn')
if ret != 0:
print('Export mobilefacenet.rknn failed!')
exit(ret)
print('done')
# Set inputs
img = cv2.imread('./sunzz112.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# init runtime environment
print('--> Init runtime environment')
ret = rknn.init_runtime(target='rk1808')
if ret != 0:
print('Init runtime environment failed')
exit(ret)
print('done')
# Inference
print('--> Running model')
outputs = rknn.inference(inputs=[img])
print(outputs)
print('done')
# perf
print('--> Begin evaluate model performance')
perf_results = rknn.eval_perf(inputs=[img])
print('done')
rknn.release()
|
|