当前位置:网站首页>Simple use of tflite
Simple use of tflite
2022-07-27 09:51:00 【A grain of sand in the vast sea of people】
Environmental Science
tensorflow=2.4.1
Practical examples
hold Tensorflow The model of is transformed into tflite
import tensorflow as tf
def convert_to_tflite(model):
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tfmodel = converter.convert()
file = open('yourmodel.tflite', 'wb')
file.write(tfmodel)
file.close()function Tflite Model
import tensorflow as tf
def run_reference_by_tflite(input):
interpreter = tf.lite.Interpreter(model_path="yourmodel.tflite")
interpreter.allocate_tensors()
# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
# input details
print(input_details, len(input_details))
# output details
print(output_details)
# input_details[0]['index'] = the index which accepts the input
interpreter.set_tensor(input_details[0]['index'], input)
# run the inference
interpreter.invoke()
# output_details[0]['index'] = the index which provides the input
output_data = interpreter.get_tensor(output_details[0]['index'])
print('interpreter: ', output_data)
Related errors and solutions
1. ValueError: Cannot set tensor: Got value of type NOTYPE but expected type FLOAT32 for input 0,
or
ValueError: Cannot set tensor: Got value of type INT32 but expected type FLOAT32 for input 0,
or
ValueError: Cannot set tensor: Got value of type UINT8 but expected type FLOAT32 for input 0, name: input_1
resolvent :
under_exp = np.array(under_exp, dtype=np.float32)Reference material
python - How to convert keras(h5) file to a tflite file? - Stack Overflow
边栏推荐
- Google Earth engine app - print the coordinates of points to the console and map, set the style and update it
- C# 给Word每一页设置不同文字水印
- Towards the peak of life
- LeetCode.814. 二叉树剪枝____DFS
- 九种方式,教你读取 resources 目录下的文件路径
- QT | about the problem that QT creator cannot open the project and compile it
- Nccl collective communication --collective operations
- 年底了,我教你怎么拿高绩效!
- Google Earth Engine APP——打印点的坐标到控制台上和map上,设置样式并更新
- [SCM]源码管理 - perforce 分支的锁定
猜你喜欢

Exercises --- quick arrangement, merging, floating point number dichotomy

Understand chisel language. 27. Chisel advanced finite state machine (I) -- basic finite state machine (Moore machine)
![[SCM]源码管理 - perforce 分支的锁定](/img/c6/daead474a64a9a3c86dd140c097be0.jpg)
[SCM]源码管理 - perforce 分支的锁定

Quickly apply JS to customize the effect of lunar phase change
![Flash memory usage and stm32subemx installation tutorial [day 3]](/img/ff/43ef2d0e1bdfd24fbc5c99e76455f1.png)
Flash memory usage and stm32subemx installation tutorial [day 3]

吃透Chisel语言.23.Chisel时序电路(三)——Chisel移位寄存器(Shift Register)详解

35 spark streaming backpressure mechanism, spark data skew solution and kylin's brief introduction

吃透Chisel语言.25.Chisel进阶之输入信号处理(一)——异步输入与去抖动

Voice live broadcast system - Principles to be followed in developing push notifications

flash闪存使用和STM32CUBEMX安装教程【第三天】
随机推荐
Brush the title "sword finger offer" day04
July training (day 21) - heap (priority queue)
七月集训(第19天) —— 二叉树
Understand chisel language. 23. Chisel sequential circuit (III) -- detailed explanation of chisel shift register
Eureka 延迟注册的一个坑
食品安全 | 垃圾食品越吃越想吃?这份常见食品热量表请收好
Exercises --- quick arrangement, merging, floating point number dichotomy
Esp8266 Arduino programming example ADC
华为交换机双上行组网Smart-link配置指南
Summary of engineering material knowledge points (full)
Understand chisel language. 25. Advanced input signal processing of chisel (I) -- asynchronous input and de jitter
九种方式,教你读取 resources 目录下的文件路径
[SCM]源码管理 - perforce 分支的锁定
What age are you still using date
语音直播系统——开发推送通知需要遵守的原则
A ride into Qinchuan -- a brief talk on how beego Autorouter works
How to restore the original version after installing Hal Library
[raspberry pie] box related manual-4 web agent
曝光一位出身寒门的技术大佬
Qt | 关于Qt Creator打开项目编译不过的问题