Skip to content

TensorFlow Troubleshooting

This guide covers common TensorFlow 2.x installation and runtime issues, including:

  • Installation with GPU support
  • TensorRT integration problems
  • Keras compatibility issues
  • TensorBoard profiler bugs

Upgrade pip to latest version
pip install --upgrade pip
Install TensorFlow with GPU support
python3 -m pip install 'tensorflow[and-cuda]'

This automatically installs compatible CUDA libraries.

Verify TensorFlow GPU support
python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

Expected output:

[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

If you see an empty list [], check:

  1. NVIDIA drivers are installed - see Driver Installation
  2. CUDA version compatibility
  3. Environment activation - see Environment Setup

TensorFlow cannot find TensorRT even after installation, showing CUDA errors or warnings.

Step 1: Install TensorRT

Install TensorRT for Python
pip install nvidia-pyindex
pip install nvidia-tensorrt

Step 2: Fix Library Path

Add TensorRT to library path
# Replace 'user' with your username and adjust Python version as needed
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"/home/user/miniconda3/envs/tf/lib/python3.11/site-packages/tensorrt_libs/"

# Make it persistent by adding to ~/.bashrc or conda environment activation script
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"/home/user/miniconda3/envs/tf/lib/python3.11/site-packages/tensorrt_libs/"' >> ~/.bashrc

Error: AttributeError: module 'keras' has no attribute 'ops'

Section titled “Error: AttributeError: module 'keras' has no attribute 'ops'”

Cause: Version mismatch between Keras and TensorFlow

Solutions:

Import from TensorFlow
# Instead of: import keras
from tensorflow import keras

# This ensures version compatibility

Symptoms: TensorBoard profiler shows “No profile data was found” even though profiling ran successfully.

Root Cause: Log file structure bug in TensorBoard profiler.

Solution:

Fix profile log structure
# Move profile logs up one directory level
# From: logs/train/plugins/profile/...
# To: logs/plugins/profile/...

cd logs
mv train/plugins/profile/* plugins/profile/ 2>/dev/null || true
mv validation/plugins/profile/* plugins/profile/ 2>/dev/null || true

The profile logs should be at the same directory level as train and validation directories, not inside them.

GitHub Discussion

Detailed Solution Guide