1 Star 0 Fork 0

wandongdong/tflite2opencl

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
run_tflite_model.py 1.88 KB
一键复制 编辑 原始数据 按行查看 历史
wandongdong 提交于 2021-01-18 01:10 . add gather tflite op
import numpy as np
from tensorflow.quantization import fake_quant_with_min_max_vars
from tensorflow.python.framework import graph_util
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
model_path = "../run_lite/models/resnet_v2_50.tflite"
input_file = "../run_lite/models/resnet_v2_50.tflite.ms.bin"
output_file = "../run_lite/models/resnet_v2_50.tflite.ms.out"
# Load TFLite model and allocate tensors.
interpreter = tf.lite.Interpreter(model_path=model_path)
tensors = interpreter.allocate_tensors()
# Get input and output tensors.
input_details = interpreter.get_input_details()
print(input_details)
output_details = interpreter.get_output_details()
print(str(output_details))
input_shape = (1, 224, 224, 3)
with tf.Session( ) as sess:
# input = ((np.random.randint(1, 1, input_shape))).astype(dtype=np.float32)
input = (((np.array(list(range(224*224*3)))/(224*224*3)/2).reshape(input_shape))).astype(dtype=np.float32)
print("input_data: ", input)
interpreter.set_tensor(input_details[0]['index'], input)
interpreter.invoke()
with open(input_file, 'wb') as fo:
fo.write(input.astype(np.float32, copy=False))
with open(output_file, 'w') as text_file:
for output_detail in output_details:
output_data = interpreter.get_tensor(output_detail['index'])
flatten_data = np.squeeze(output_data).flatten()
size = flatten_data.shape[0]
# text = output_detail['name'] + ' ' + str(len(output_detail['shape'])) + ' '
text = 'Softmax-114' + ' ' + str(len(output_detail['shape'])) + ' '
for i in range(len(output_detail['shape'])):
text += str(output_detail['shape'][i]) + ' '
text_file.write(text + '\n')
for i in range(size):
text_file.write(str((flatten_data[i])) + ' ')
text_file.write('\n')
print("output_data: ", output_data)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ddwsky/tflite2opencl.git
git@gitee.com:ddwsky/tflite2opencl.git
ddwsky
tflite2opencl
tflite2opencl
master

搜索帮助