1

我正在尝试使用 Google Colab 构建用于 Google Coral 设备的模型。为此,我需要冻结图表,然后将其转换为 TfLite。我可以使用教程成功创建模型并对其进行测试,但我无法弄清楚如何冻结图形。在教程结束时,模型以 Saved_Model 格式保存。我的 Google Colab 笔记本可在此处找到:https ://drive.google.com/file/d/1F6wvz4yUp6Iz2hY3n7bQYnYBJe7H5JUE/view?usp=sharing

我尝试了在网上找到的各种代码示例,但都以错误告终。目前我正在尝试使用此代码来冻结图形

from tensorflow.python.tools import freeze_graph
from tensorflow.python.saved_model import tag_constants

input_saved_model_dir = export_path
output_node_names = "dense/Softmax"
input_binary = True
input_saver_def_path = False
restore_op_name = None
filename_tensor_name = None
clear_devices = False
input_meta_graph = False
checkpoint_path = None
input_graph_filename = None
saved_model_tags = tag_constants.SERVING
output_graph_filename = "./frozenGraph.pb"

freeze_graph.freeze_graph(input_graph_filename, input_saver_def_path,
                            input_binary, checkpoint_path, output_node_names,
                              restore_op_name, filename_tensor_name,
                              output_graph_filename, clear_devices, "", "", "",
                              input_meta_graph, input_saved_model_dir,
                            saved_model_tags)

但我得到了错误:

NotFoundError Traceback (most recent call last)
NotFoundError: Key module/MobilenetV2/Conv/BatchNorm/beta not found in checkpoint
[[node save_2/RestoreV2 (defined at /usr/local/lib/python3.6/dist-packages/tensorflow_hub/native_module.py:451) ]]

它还提到了这个错误

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/saving/saveable_object_util.py in op_list_to_dict(op_list, convert_variable_to_tensor)
    286         if name in names_to_saveables:
    287           raise ValueError("At least two variables have the same name: %s" %
--> 288                            name)
    289         names_to_saveables[name] = var
    290 

ValueError: At least two variables have the same name: dense/bias
4

0 回答 0