在 TensorFlow 中冻结图形是什么意思? [英] What does freezing a graph in TensorFlow mean?

查看:42
本文介绍了在 TensorFlow 中冻结图形是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 NN API 和 TensorFlow 的初学者.

I am a beginner in NN APIs and TensorFlow.

我正在尝试以 protobuff 格式 (.pb) 保存我的训练模型,有很多博客解释了如何将模型保存为 protobuff.我不明白的一件事是在将图形保存为 protobuff 之前冻结图形的重要性是什么?我读到冻结将变量转换为常量,这是否意味着该模型不再可训练?冻结对模型还有什么作用?那个模型冻结后会丢失什么?任何人都可以解释或提供一些关于冻结细节的提示吗?

I am trying to save my trained model in protobuff format (.pb), there are many blogs explaining how to save the model as protobuff. One thing I did not understand is what is the importance of freezing the graph before saving it as protobuff? I read that freezing coverts variable to constants, does that mean the model is not trainable anymore? What else will freezing do on models? What is that model loses after freezing? Can anyone please explain or give some pointers on details of freezing?

推荐答案

这只是您问题的部分答案.

This is only a partial answer to your question.

冻结图很容易优化.例如,在进行推理(前向传播)时,您可以将一些层融合在一起.这不能用在变量和操作之间分离的图(非冻结图)来完成.为什么要将层融合在一起?有多种原因.特定于硬件:在一组张量中一起计算多个操作可能更容易,特定于您的 cpu 或 gpu 的结构.TensorRT 是一个图优化器,例如从冻结图开始工作(这里有关于 tensorRT 完成的图优化的更多信息:https://devblogs.nvidia.com/tensorrt-integration-speeds-tensorflow-inference/).该软件执行图形优化以及特定于硬件的优化.

A freezed graph is easily optimizable. When doing inference (forward propagation) for instance you can fuse some of the layers together. This you can't do with a graph separated between variables and operations (a not frozen graph). Why would you want to fuse layers together? There are multiple reasons. Going hardware specific: it might be easier to compute a number of operations together in a group of tensors, specific to the structure of your cpu or gpu. TensorRT is a graph optimizer for instance that works starting from a frozen graph (here more info on graph optimizations done by tensorRT: https://devblogs.nvidia.com/tensorrt-integration-speeds-tensorflow-inference/ ). This software does graph optimizations as well as hardware specific ones.

据我所知,您可以解冻图形.我只对它们进行了优化,所以我没有使用这个功能.但这里有它的代码:https://gist.github.com/tokestermw/795cc1fd6d0b3c906e>

As far as I understand you can unfreeze a graph. I have only worked optimizing them, so I haven't use this feature. But here there is code for it: https://gist.github.com/tokestermw/795cc1fd6d0c9069b20204cbd133e36b

这是另一个可能有用的问题:TensorFlow:有吗一种将冻结图转换为检查点模型的方法?不过还没有得到答复.

Here is another question that might be useful: TensorFlow: Is there a way to convert a frozen graph into a checkpoint model? It has not yet been answered though.

这篇关于在 TensorFlow 中冻结图形是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆