首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >K.random_normal(shape=(batch,dim))的Tflite TOCO转换失败

K.random_normal(shape=(batch,dim))的Tflite TOCO转换失败
EN

Stack Overflow用户
提问于 2019-05-27 15:22:31
回答 2查看 145关注 0票数 0

我正在使用tensorflow lite的toco_convert来做一些以前的工作。这些是我在执行以下命令时遇到的错误。

代码语言:javascript
复制
toco\
--graph_def_file=6-graphmh-55epoc.pb \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--output_file=/leaves.tflite \
--inference_type=FLOAT \
--input_type=FLOAT \
--input_arrays=ImageTensor \
--output_arrays=SemanticPredictions \
--input_shapes=1,113,3 \

我得到的错误是:

代码语言:javascript
复制
Traceback (most recent call last):
  File "C:\Users\ash\AppData\Local\Continuum\anaconda3\envs\diec\Scripts\toco_from_protos-script.py", line 10, in <module>
    sys.exit(main())
  File "C:\Users\ash\AppData\Local\Continuum\anaconda3\envs\diec\lib\site-packages\tensorflow\lite\toco\python\toco_from_protos.py", line 59, in main
    app.run(main=execute, argv=[sys.argv[0]] + unparsed)
  File "C:\Users\ash\AppData\Local\Continuum\anaconda3\envs\diec\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run
    _sys.exit(main(argv))
  File "C:\Users\ash\AppData\Local\Continuum\anaconda3\envs\diec\lib\site-packages\tensorflow\lite\toco\python\toco_from_protos.py", line 33, in execute
    output_str = tensorflow_wrap_toco.TocoConvert(model_str, toco_str, input_str)
Exception: We are continually in the process of adding support to TensorFlow Lite for more ops. It would be helpful if you could inform us of how this conversion went by opening a github issue at https://github.com/tensorflow/tensorflow/issues/new?template=40-tflite-op-request.md
 and pasting the following:

Some of the operators in the model are not supported by the standard TensorFlow Lite runtime. If those are native TensorFlow operators, you might be able to use the extended runtime by passing --enable_select_tf_ops, or by setting target_ops=TFLITE_BUILTINS,SELECT_TF_OPS when calling tf.lite.TFLiteConverter(). Otherwise, if you have a custom implementation for them you can disable this error with --allow_custom_ops, or by setting allow_custom_ops=True when calling tf.lite.TFLiteConverter(). Here is a list of builtin operators you are using: ADD, EXP, FULLY_CONNECTED, LOGISTIC, MUL. Here is a list of operators for which you will need custom implementations: RandomStandardNormal.

我知道tf.lite.toco_convert已经过时了,但我需要用它来完成以前的工作。我认为这是由于下面这行epsilon = K.random_normal(shape=(batch, dim)) return z_mean + K.exp(0.5 * z_log_var) * epsilon造成的。我不确定为什么会发生这种情况,因为旧的tensorflow keras.backend有random_normal属性。如果您可以调试或指向一些资源来规避此错误,将会很有帮助。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-06-10 12:00:15

推荐的方法:

代码语言:javascript
复制
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
converter.target_ops = [tf.lite.OpsSet.TFLITE_BUILTINS,
                        tf.lite.OpsSet.SELECT_TF_OPS]
tflite_model = converter.convert()

转换:

代码语言:javascript
复制
toco\
--graph_def_file=6-graphmh-55epoc.pb \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--output_file=/leaves.tflite \
--inference_type=FLOAT \
--input_type=FLOAT \
--input_arrays=ImageTensor \
--output_arrays=SemanticPredictions \
--input_shapes=1,256,3 \
票数 0
EN

Stack Overflow用户

发布于 2019-05-27 16:08:28

从这里找到解决方案:https://www.tensorflow.org/lite/guide/ops_select

代码语言:javascript
复制
import tensorflow as tf

converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
converter.target_ops = [tf.lite.OpsSet.TFLITE_BUILTINS,
                        tf.lite.OpsSet.SELECT_TF_OPS]
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)

这是因为RandomStandardNormal不是TensorFlow lite的一部分,所以我们需要使用tf.lite.OpsSet来包含它

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56321465

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档