Chapter 4: Installation & Setup¶
“A neural net’s journey begins with a single tensor.”
4.1 Preparing Your Workspace¶
Let’s keep things clean and self-contained. You’ll be using a virtual environment inside your TensorFlow folder for local experimentation.
✅ Step-by-step:
step 1. Navigate to your project folder
cd C:\Users\Clay\Desktop\Tutorials\TensorFlow
python -m venv tf_env
- On CMD:
.\tf_env\Scripts\activate
- On PowerShell:
step 4. Upgrade pip & install TensorFlow (with GPU support)
.\tf_env\Scripts\Activate.ps1
pip install --upgrade pip pip install tensorflow[and-cuda]
⚠️ This will install ~2.5 GB of GPU-enabled TensorFlow with pre-bundled CUDA & cuDNN (no manual install needed in TF 2.15+).
4.2 Verifying Installation & GPU Access¶
Create a file called check_tf_gpu.py
:
import tensorflow as tf
def print_gpu_info():
print("TensorFlow version:", tf.__version__)
gpus = tf.config.list_physical_devices('GPU')
print("Num GPUs Available:", len(gpus))
for gpu in gpus:
print("GPU Detected:", gpu.name)
if __name__ == '__main__':
print_gpu_info()
python check_tf_gpu.py
✅ Expected Output:
TensorFlow version: 2.x.x
Num GPUs Available: 1
GPU Detected: NVIDIA GeForce RTX 4050 Laptop GPU
4.3 Bonus: Enable Dynamic GPU Memory Growth¶
Prevent TensorFlow from hoarding all your GPU VRAM upfront:
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
try:
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)
print("Memory growth enabled on GPU.")
except RuntimeError as e:
print(e)
4.4 Optional: Freeze Your Environment¶
To create a portable list of all packages:
pip freeze > requirements.txt
“A neural net’s journey begins with a single tensor.”