TFLiteConverter:converter.convert()不起作用

时间:2019-04-05 12:25:08

标签: python tensorflow tensorflow-lite

我正在尝试量化一个新的tflite。 下面的代码正常运行,直到该行为止:

input_arrays = converter.get_input_arrays()

你能帮我吗?

TensorFlow版本:1.13.1

Python版本:3.6.5

用于重现问题的代码

import numpy as np
import tensorflow as tf
from tensorflow.python.platform import gfile
tf.enable_eager_execution()

import sys
import os
if sys.version_info.major >= 3:
    import pathlib
else:
    import pathlib2 as pathlib

pbfiles_path = "D:\\Ricardo\\Ambientes Virtuals do Python\\virtualTFr1.13\\Scripts\\pbfiles"
saved_model_dir = str(sorted(pathlib.Path(pbfiles_path).glob("*.pbtxt" or "*.pb"))[-1])

os.environ['CUDA_VISIBLE_DEVICES'] = "-1"
with tf.Graph().as_default() as graph: 


    with tf.Session() as sess:
        print("Loading Graph")

        modelFile = '/pbfiles/saved_model.pb'
        with gfile.FastGFile(modelFile, 'rb') as f:
            converter = tf.lite.TFLiteConverter.from_session(sess,
                                                             input_tensors={"input_1"},
                                                             output_tensors={"conv2d_19/Sigmoid"})
            converter.inference_type = tf.lite.constants.QUANTIZED_UINT8
            input_arrays = converter.get_input_arrays()
            tflite_model = converter.convert()
            open("quant_converted_model.tflite", "wb").write(tflite_model)

预期结果:

生成量化的tflie文件。

实际结果:以下错误。

D:\quantization\venv\Scripts\python.exe D:/quantization/venv/quantization.py
TF VERSION: 1.13.1
2019-04-03 15:21:12.605076: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
WARNING:tensorflow:From D:/quantization/venv/quantization.py:25: FastGFile.init (from tensorflow.python.platform.gfile) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.gfile.GFile.
Traceback (most recent call last):
    File "D:/quantization/venv/quantization.py", line 30, in 
        input_arrays = converter.get_input_arrays()
    File "D:\quantization\venv\lib\site-packages\tensorflow\lite\python\lite.py", line 471, in get_input_arrays
        return [_tensor_name(tensor) for tensor in self._input_tensors]
    File "D:\quantization\venv\lib\site-packages\tensorflow\lite\python\lite.py", line 471, in 
Loading Graph
        return [_tensor_name(tensor) for tensor in self._input_tensors]
    File "D:\quantization\venv\lib\site-packages\tensorflow\lite\python\convert.py", line 217, in tensor_name
return x.name.split(":")[0]
AttributeError: 'str' object has no attribute 'name'

0 个答案:

没有答案