tensorflow - 用于 sparkfun 边缘微控制器的 Tensorflow lite,未找到内置操作码“CONV_2D”版本 2 和 3 的操作
问题描述
我正在尝试将我的 TFlite 模型与 sparkfun edge (Apollo 3) 微控制器一起使用来识别来自 Piano App 的简单曲调,例如 (do re mi fa ....) 我将以下 python 代码与 tensorflow v2 一起使用
from tensorflow.keras import layers......
model = tf.keras.Sequential([
layers.InputLayer(input_shape=(2048,)),
layers.Reshape(target_shape=(1,2048,1)),
layers.Conv2D(8,(1,8),strides=(1,8)),
layers.MaxPool2D((1,2),strides=(1,2)),
layers.Conv2D(8,(1,8),strides=(1,8)),
layers.MaxPool2D((1,2),strides=(1,2)),
layers.Reshape(target_shape=(64,)) ,
layers.Dense(8,activation="softmax")
])
model.build(input_shape=(2048,))
model.compile(optimizer="adam",loss="binary_crossentropy")
我训练模型并使用以下代码对其进行转换
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS]
model_tflite = converter.convert()
open('model.tflite', "wb").write(model_tflite)
!apt-get install xxd
!xxd -i 'model.tflite' > 'model.cc'
!cat 'model.cc'
我从微控制器得到以下调试输出:
setup_NN invoked ///
Model TFLITE_SCHEMA_VERSION OK ///
interpreter OK ///
AllocateTensors OK ///
________________
in_dim= 2 ///
input_type = kTfLiteFloat32 ///
in_size[0]= 1 ///
in_size[1]= 2048 ///
________________
out_dim= 2 ///
output_type = kTfLiteFloat32 ///
out_size[0]= 1 ///
out_size[1]= 8 ///
________________
Setup OK
Loop funktion inoked
**Didn't find op for builtin opcode 'CONV_2D' version '2'**
Invoke failed
___________________
当我改变
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS]
to
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
with adding a
representative_dataset function
我得到错误:没有找到内置操作码'CONV_2D'版本' 3 '的操作
我认为sparkfun edge MC 接受 float32 作为输入,我是否必须尝试使用 tensorflow.compat.v1 insted of v2?你能指出哪里错了,或者只是给我看一个工作的例子?
可以说像 sine_model 这样只有完全连接层 + 激活的另一个模型对我来说很好(在 float32 中),但我真的需要 conv 层,我知道使用 Conv1D 更好,但我在某处读到它是不支持
解决方案
推荐阅读
- python - 包含多个语句的“async with”会同步执行它们吗?
- applescript - 如何使用 AppleScript 将文件写入为 UTF-8
- javascript - 使用 Twilio WebRTC Go 进行 JS 出站视频通话
- typescript - 尝试使用 fastify-jwt 签署 jwt 时未定义 Fastify
- c# - 无法异步加载视图 - ASP.NET Core MVC
- javascript - 在 Gmail 撰写编辑器中键入时跟踪 onchage 的最佳方法是什么?
- r - 如何在长时间序列中绘制各种多个变量(在同一列中)?
- java - Spring Vault 返回 null
- node.js - 反应原生 Windows 应用程序未连接到本地主机
- r - 如何检查聚合是否可能?