2.3 Tensors and Operations: Constants, Variables, and Placeholders

Опубликовано: 05 Март 2026
на канале: Vivian Aranha
60
0

Constants, variables, and placeholders are fundamental elements in TensorFlow for managing tensors and building machine learning models. Constants are immutable tensors with fixed values, commonly utilized for representing unchanging values or hyperparameters in models. Variables, on the other hand, are mutable tensors whose values can be modified during the execution of a TensorFlow graph. They are crucial for holding model parameters like weights and biases that require updating during training. Placeholders, deprecated in TensorFlow 2.x, were previously employed to feed data into the computational graph during execution. However, in TensorFlow 2.x, eager execution is the default mode, eliminating the need for placeholders. Instead, data can be directly fed into the model using Python variables or NumPy arrays. Constants and variables remain essential components for defining tensors in TensorFlow, with variables serving primarily for holding model parameters during training, while placeholders have been replaced by eager execution, simplifying the process of building and executing TensorFlow graphs in TensorFlow 2.x.