- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已通过以下方式将模型导出到 ONNX:
# Export the model
torch_out = torch.onnx._export(learn.model, # model being run
x, # model input (or a tuple for multiple inputs)
EXPORT_PATH + "mnist.onnx", # where to save the model (can be a file or file-like object)
export_params=True) # store the trained parameter weights inside the model file
tf_rep.export_graph(EXPORT_PATH + 'mnist-test/mnist-tf-export.pb')
toco
:
toco \
--graph_def_file=mnist-tf-export.pb \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--inference_type=FLOAT \
--input_type=FLOAT \
--input_arrays=0 \
--output_arrays=add_10 \
--input_shapes=1,3,28,28 \
--output_file=mnist.tflite`
File "anaconda3/lib/python3.6/site-packages/tensorflow/lite/python/convert.py", line 172, in toco_convert_protos
"TOCO failed. See console for info.\n%s\n%s\n" % (stdout, stderr))
tensorflow.lite.python.convert.ConverterError: TOCO failed. See console for info.
2018-11-06 16:28:33.864889: I tensorflow/lite/toco/import_tensorflow.cc:1268] Converting unsupported operation: PyFunc
2018-11-06 16:28:33.874130: F tensorflow/lite/toco/import_tensorflow.cc:114] Check failed: attr.value_case() == AttrValue::kType (1 vs. 6)
最佳答案
我认为 ONNX 文件,即 model.onnx
您提供的已损坏我不知道是什么问题,但它没有对 ONNX 运行时进行任何推断。
Now you can run PyTorch Models directly on mobile phones. check out PyTorch Mobile's documentation here
This answer is for TensorFlow version 1,
For TensorFlow version 2 or higher click link
This class (tf.compat.v1.lite.TocoConverter) has been deprecated. Please use lite.TFLiteConverter instead.
# Export the model from PyTorch to ONNX
torch_out = torch.onnx._export(model, # model being run
x, # model input (or a tuple for multiple inputs)
EXPORT_PATH + "mnist.onnx", # where to save the model (can be a file or file-like object)
export_params=True, # store the trained parameter weights inside the model file
input_names=['main_input'], # specify the name of input layer in onnx model
output_names=['main_output']) # specify the name of input layer in onnx model
所以在你的情况下:
Please note that this method is only working when tensorflow_version < 2
pip install onnx-tf==1.5.0
现在要将 .onnx 模型转换为 TensorFlow 卡住图,请在 shell 中运行以下命令
onnx-tf convert -i "mnist.onnx" -o "mnist.pb"
从 TensorFlow FreezeGraph .pb 转换为 TF
import tensorflow as tf
# make a converter object from the saved tensorflow file
converter = tf.lite.TFLiteConverter.from_frozen_graph('mnist.pb', #TensorFlow freezegraph .pb model file
input_arrays=['main_input'], # name of input arrays as defined in torch.onnx.export function before.
output_arrays=['main_output'] # name of output arrays defined in torch.onnx.export function before.
)
# tell converter which type of optimization techniques to use
converter.optimizations = [tf.lite.Optimize.DEFAULT]
# to view the best option for optimization read documentation of tflite about optimization
# go to this link https://www.tensorflow.org/lite/guide/get_started#4_optimize_your_model_optional
# convert the model
tf_lite_model = converter.convert()
# save the converted model
open('mnist.tflite', 'wb').write(tf_lite_model)
要为您的模型用例选择最适合优化的选项,请参阅有关 TensorFlow lite 优化的官方指南
Note: You can try my Jupyter Notebook Convert ONNX model to Tensorflow Lite on Google Colaboratory link
关于tensorflow - 你如何将 .onnx 转换为 tflite?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53182177/
我正在尝试将我使用 Keras 定义的网络转换为 tflite。网络如下: model = tf.keras.Sequential([ # Embedding tf.k
您使用的模型的顶级目录是什么 :/home/USER/PROJECT/tf-models 我是否编写了自定义代码(而不是使用 TensorFlow 中提供的股票示例脚本) : 否 操作系统平台和发行版
我刚刚使用 Google AutoML 训练了一个单标签图像分类模型,但未能在 Android 手机中使用它。我修改了代码并将我的自定义模型替换为来自 https://github.com/tenso
我正在尝试将经过训练的模型从检查点文件转换为 tflite .我正在使用 tf.lite.LiteConverter .浮点转换顺利进行,推理速度合理。但是INT8的推理速度转换非常慢。我试图通过输入
我试图将 albert 的 .pb 模型转换为 tflite 我使用https://github.com/google-research/albert制作了.pb模型在 tf 1.15 中 我用过tc
我有一个用 Tensorflow.Keras 编写的自定义神经网络,并应用 Hard-swish 函数作为激活(如 MobileNetV3 论文中使用的那样): 实现: def swish(x):
我正在尝试使用来自 TensorFlow for Poets 2 的移动网络传输学习示例进行图像分类的 TFLite 实现 我能够使用代码实验室中的四个花卉样本成功完成迁移学习并获得以下屏幕 这是正在
我是 tensorflow 的新手,我正在尝试将我的 .pb(原型(prototype)缓冲区)文件转换为精简版。但我面临一些问题。import time,sys,warnings,glob,rand
我尝试通过 TFLite 将我的模型 (pb) 转换为精简版。这是我的代码: import tensorflow as tf graph_def_file = "./graph.pb" input_a
有了经过训练的“.h5”Keras 模型文件,我正在尝试优化推理时间: 探索了 2 个选项: 通过 TensorRT 加速推理 'int8' 量化。 此时我可以将模型文件转换为 TensorFlow
我有一个简单的网络,我已经使用 tensorflow 进行了剪枝和量化。我专门按照本教程在我的网络上应用: https://www.tensorflow.org/model_optimization/
我正在加载 this python中的对象检测模型。我可以使用以下代码行加载它: import tflite_runtime.interpreter as tflite model_path = 'p
好的,所以在我的应用程序中,我正在尝试使用人脸网络模型来实现人脸识别,该模型转换为 tflite,平均约为 93 MB, 但是这个模型最终会增加我的 apk 的大小。 所以我正在尝试寻找替代方法来解决
我得到了 MobileNet 的预训练 .pb 文件,发现它没有被量化,而完全量化的模型应该转换成 .tflite 格式。由于我不熟悉移动应用程序开发工具,我如何从 .tflite 文件中获取 M
我想知道是否有办法知道 tflite 中特定节点的输入和输出列表?我知道我可以获得输入/输出详细信息,但这不允许我重建解释器内部发生的计算过程。所以我要做的是: interpreter = tf.li
我对 TensorFlow 和 TensorFlow Lite 相当陌生。我已遵循有关如何使用 toco 量化模型并将模型转换为定点计算的教程。现在我有一个 tflite 文件,它应该只执行定点操作。
我从姿势估计 tflite 模型开始,用于获取人类的关键点。 https://www.tensorflow.org/lite/models/pose_estimation/overview 我开始拟合
我正在使用here中的posenet tflite模型。它接受输入 1*353*257*3 输入图像并返回 4 个尺寸为 1*23*17*17、1*23*17*34、1*23*17*64 和 1*23
我已经阅读了多个代码实验室,在这些代码实验室中,Google 对属于一类的图像进行了分类。如果我需要使用 2 个或更多类怎么办?比如我想对一张图片是水果还是蔬菜进行分类,然后分类是水果还是蔬菜。 最佳
目前,我正在尝试制作一个 Android 食品识别应用程序。我设法构建了一个应用程序来处理图像并在“mobilenet_quant_v1_224.tflite”预训练模型上运行。一切正常,现在我想将自
我是一名优秀的程序员,十分优秀!