当前位置:网站首页>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
边栏推荐
- 通俗易懂!图解Go协程原理及实战
- Google Earth Engine APP——利用S2影像进行最大值影像合成分析
- Brush the title "sword finger offer" day04
- GO基础知识—数组和切片
- 九种方式,教你读取 resources 目录下的文件路径
- Voice live broadcast system - Principles to be followed in developing push notifications
- Easy to understand! Graphic go synergy principle and Practice
- July training (day 23) - dictionary tree
- July training (day 12) - linked list
- Understand chisel language. 22. Chisel sequential circuit (II) -- detailed explanation of chisel counter: counter, timer and pulse width modulation
猜你喜欢

习题 --- 快排、归并、浮点数二分

Brush the title "sword finger offer" day04

Nacos配置中心动态刷新数据源

拟搬迁!211中国石油大学(华东)新校区,正式启用!

Talk about 10 scenarios of index failure. It's too stupid

Nacos configuration center dynamically refreshes the data source

九种方式,教你读取 resources 目录下的文件路径

A ride into Qinchuan -- a brief talk on how beego Autorouter works

为什么微服务一定要有API网关?

XML概述
随机推荐
C# 给Word每一页设置不同文字水印
Understand chisel language. 23. Chisel sequential circuit (III) -- detailed explanation of chisel shift register
Expose a technology boss from a poor family
July training (day 16) - queue
NPM common commands
圆环工件毛刺(凸起)缺口(凹陷)检测案例
【云原生 • DevOps】一文掌握容器管理工具 Rancher
Eureka delayed registration of a pit
刷题《剑指Offer》day03
Exercises --- quick arrangement, merging, floating point number dichotomy
[cloud native • Devops] master the container management tool rancher
Esp8266 Arduino programming example ADC
WordPress prohibits login or registration of plug-ins with a specified user name [v1.0]
习题 --- 快排、归并、浮点数二分
Nacos configuration center dynamically refreshes the data source
npm常用命令
Google Earth Engine APP——打印点的坐标到控制台上和map上,设置样式并更新
Review summary of engineering surveying examination
Interview Essentials: shrimp skin server 15 consecutive questions
吃透Chisel语言.24.Chisel时序电路(四)——Chisel内存(Memory)详解