0

我目前将 TF1 和 TF2 object-detection-api 模型保存为 FrozenGraphs,然后运行 ​​TF1 样式(加载 graph/sess.run,尽管我使用的是 tensorflow 2.5.0)。

我发现对于类似的模型,TF2 FrozenGraphs 的运行速度要慢得多。我知道 TF1 和 TF2 模型之间的实现存在差异,但这是否解释了差异?

或者 TF2 模型是否需要以不同的特定方式运行?

例如,TF2 的 SSD_Mobilenet_V2 运行速度比 TF1 的 SSD_Mobilenet_V2 慢 50% 左右(输入大小、输出类数相同)。

我对 TF1 模型使用通常的 TF1 导出器 (exporter.py:_export_inference_graph())。对于 TF2,我在 exporter_lib_v2.py 中有一个 export_inference_graph() 的修改版本。(创建concrete_function后,我将变量转换为常量,然后转换为frozen_graph并保存)

concrete_function = detection_module.__call__.get_concrete_function()
status.assert_existing_objects_matched()

frozen_func = convert_to_constants.convert_variables_to_constants_v2(
    concrete_function
)
output_graph_def = frozen_func.graph.as_graph_def()
frozen_graph = output_graph_def.SerializeToString()

if output_pb is not None:
    with gfile.GFile(output_pb, "wb") as f:
        f.write(frozen_graph)
4

0 回答 0