【问题标题】:Errors in converting Tensorflow Model to Tensorflow Lite Model将 TensorFlow 模型转换为 TensorFlow Lite 模型时出错
【发布时间】:2020-12-22 10:35:27
【问题描述】:

我想在 Tensorflow lite 框架中使用 yolov4-tiny 来计算视频中跨越虚拟线的对象。

我使用以下命令转换了从 AlexeyAB's repo 训练的暗网权重:

python save_model.py --weights yolov4-tiny.weights --output ./checkpoints/yolov4-tiny-608-tf --input_size 608 --model yolov4 --tiny --framework tflite

python convert_tflite.py --weights ./checkpoints/yolov4-tiny-608-tf --output ./checkpoints/yolov4-tiny-608.tflite

你可以找到convert_tflite.py here

第一个命令使用 numpy==1.19.0 成功。但是,第二个显示这些错误:

loc("batch_normalization/moving_mean"): error: is not immutable, try running tf-saved-model-optimize-global-tensors to prove tensors are immutable
Traceback (most recent call last):
  File "C:\Python37\lib\site-packages\tensorflow\lite\python\convert.py", line 213, in toco_convert_protos
    enable_mlir_converter)
  File "C:\Python37\lib\site-packages\tensorflow\lite\python\wrap_toco.py", line 38, in wrapped_toco_convert
    enable_mlir_converter)
Exception: <unknown>:0: error: loc("batch_normalization/moving_mean"): is not immutable, try running tf-saved-model-optimize-global-tensors to prove tensors are immutable


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "convert_tflite.py", line 76, in <module>
    app.run(main)
  File "C:\Python37\lib\site-packages\absl\app.py", line 303, in run
    _run_main(main, args)
  File "C:\Python37\lib\site-packages\absl\app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "convert_tflite.py", line 71, in main
    save_tflite()
  File "convert_tflite.py", line 45, in save_tflite
    tflite_model = converter.convert()
  File "C:\Python37\lib\site-packages\tensorflow\lite\python\lite.py", line 762, in convert
    result = _convert_saved_model(**converter_kwargs)
  File "C:\Python37\lib\site-packages\tensorflow\lite\python\convert.py", line 648, in convert_saved_model
    enable_mlir_converter=True)
  File "C:\Python37\lib\site-packages\tensorflow\lite\python\convert.py", line 216, in toco_convert_protos
    raise ConverterError(str(e))
tensorflow.lite.python.convert.ConverterError: <unknown>:0: error: loc("batch_normalization/moving_mean"): is not immutable, try running tf-saved-model-optimize-global-tensors to prove tensors are immutable

我尝试过其他版本的 Tensorflow(2.2、2.3、2.4),但没有运气。 我该怎么办?

这里提出了一个类似的问题:Tensorflow Issue 44790

这是我的系统详细信息: 视窗 10、x64 GeForce GTX 1060 英伟达驱动程序 460.89 CUDA 11.0.3 CuDNN 8.0.5.39 Python 3.7.2

【问题讨论】:

  • 我在这里找到了解决方案stackoverflow.com/questions/63652692/… 我将尝试使用 Ubuntu 运行转换以便能够使用 tf-nightly。
  • 您能否将其发布为答案,我仍然遇到错误
  • 这个我还没试过,但我找到了this one

标签: tensorflow object-detection tensorflow-lite yolo


【解决方案1】:
pip install tensorflow==2.3.0rc0

并在开始转换之前重新启动运行时

【讨论】:

    【解决方案2】:

    我通过关注 Github 问题上的一个帖子解决了这个问题。

    在 google colab 中,如果我使用默认的 TF 版本,即 2.4.0 或更高版本,我会遇到此问题。
    运行 !pip install tensorflow==2.3.0 并重新启动运行时,然后转换更正了问题。

    【讨论】:

      【解决方案3】:

      对我来说,这解决了我的问题:

      import tensorflow as tf
      
      if tf.__version__ != '2.3.0-rc0':
        !pip uninstall -y tensorflow
        !pip install tensorflow-gpu==2.3.0rc0
      

      并重新启动运行时,以便使用新安装的版本。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-05-14
        • 1970-01-01
        • 2019-04-14
        • 2020-12-03
        • 2021-04-16
        • 2019-12-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多