In TensorFlow, constants are values that don’t change during the execution of the program. They are useful for creating nodes in the computational graph with fixed values. Constants are created using tf.constant.
Variables, on the other hand, maintain state across sessions and are used for parameters in machine learning models. They can be updated during the training process. Variables are created using tf.Variable
Graphs and sessions
A computational graph is a series of TensorFlow operations arranged into a graph of nodes. Each node represents an operation, and edges represent the data (tensors) flowing between these operations.
Sessions
A session is used to execute the operations defined in the computational graph. It allocates resources (such as GPU memory) and manages the execution of operations.
Graph: The blueprint of operations and data flow.
Session: The runtime environment for executing the graph.
Graphs and Sessions in TensorFlow 2.x
In TensorFlow 2.x, eager execution is enabled by default, making the framework more intuitive and user-friendly. Operations are executed immediately as they are called from Python. However, you can still create graphs and sessions using tf.function for more complex or performance-critical scenarios.
Transitioning from TensorFlow 1.x to 2.x
In TensorFlow 1.x, you explicitly define the graph and then create a session to execute it.
In TensorFlow 2.x, eager execution is the default mode, and you can use tf.function to create a graph if needed.
Tensorboard
TensorBoard is a suite of visualization tools provided by TensorFlow that enables you to inspect and understand your machine learning workflows.