SciTech-BigDataAIML-Tensorflow-Introduction to graphs and tf.function
-
Graphs
are data structures that contain:a set of tf.Operation objects
,
which representingunits of computation
;- and
tf.Tensor objects
,
which represent theunits of data
thatflow between operations
.
-
Graphs
are defined in atf.Graph
context. Since these graphs are data structures, they can be saved, run, and restored all without the original Python code. -
The benefits of graphs:
In short, graphs are extremely useful and let your TensorFlow run fast, run in parallel, and run efficiently on multiple devices.
However, you still want to define your machine learning models (or other computations) in Python for convenience, and then automatically construct graphs when you need them.- TensorFlow uses graphs as the format for saved models when it exports them from Python.
- With a graph, you have a great deal of flexibility. You can use your TensorFlow graph in environments that don't have a Python interpreter, like mobile applications, embedded devices, and backend servers.
- Graphs are also easily optimized, allowing the compiler to do transformations like:
Statically infer the value of tensors by folding constant nodes in your computation ("constant folding").
Separate sub-parts of a computation that are independent and split them between threads or devices.
Simplify arithmetic operations by eliminating common subexpressions.
There is an entire optimization system, Grappler, to perform this and other speedups.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)