TensorFlow Examples - Deploy & Usage Guide
1. Prerequisites
Required Software
- Python 3.7+ (TensorFlow 2.0+ requires Python 3.7 or higher)
- pip (Python package manager)
- Jupyter Notebook (for running the example notebooks)
Hardware Requirements
- Minimum: 4GB RAM, any modern CPU
- Recommended for deep learning: 8GB+ RAM, GPU with CUDA support for accelerated training
Optional Dependencies
- TensorFlow with GPU support: Requires NVIDIA GPU with CUDA toolkit installed
- TensorBoard: For visualization (included with TensorFlow)
2. Installation
Step 1: Clone the Repository
git clone https://github.com/aymericdamien/TensorFlow-Examples.git
cd TensorFlow-Examples
Step 2: Create and Activate Virtual Environment (Recommended)
python -m venv tf-examples-env
source tf-examples-env/bin/activate # On Windows: tf-examples-env\Scripts\activate
Step 3: Install Dependencies
pip install -r requirements.txt
Step 4: Install TensorFlow
For CPU-only version:
pip install tensorflow
For GPU-enabled version (if you have compatible NVIDIA hardware):
pip install tensorflow-gpu
Step 5: Install Jupyter (if not already installed)
pip install jupyter
3. Configuration
Environment Setup
No specific environment variables are required for basic usage. However, you may want to configure:
GPU Usage (Optional)
If using GPU, ensure CUDA and cuDNN are properly installed. TensorFlow will automatically detect and use available GPUs.
Memory Management
For systems with limited memory, you can configure TensorFlow to limit GPU memory growth:
import tensorflow as tf
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
try:
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)
except RuntimeError as e:
print(e)
4. Build & Run
Running Examples Locally
Option 1: Using Jupyter Notebook
jupyter notebook
This will open a browser window. Navigate to the tensorflow_v2/notebooks/ directory and open any .ipynb file to run examples interactively.
Option 2: Running Individual Scripts
Some examples are also available as Python scripts. Run them directly:
python tensorflow_v2/examples/helloworld.py
Development Workflow
- Open a notebook from the
tensorflow_v2/notebooks/directory - Run cells sequentially using
Shift+Enter - Modify code to experiment with different parameters
- Save changes using
Ctrl+Sor the File menu
Production Usage
For production deployment, convert notebooks to Python scripts:
jupyter nbconvert --to script notebook_name.ipynb
5. Deployment
Cloud Platforms
Google Colab (Recommended for Beginners)
- Upload the notebook files directly to Google Colab
- No installation required
- Free GPU/TPU access available
- Access via:
File > Upload Notebook
Google Cloud AI Platform
- Package your trained model using SavedModel format
- Deploy as a prediction endpoint
- Use TensorFlow Serving for serving models
AWS SageMaker
- Create a new notebook instance
- Upload the repository
- Use built-in TensorFlow containers
Azure Machine Learning
- Create a new compute instance
- Clone the repository
- Use Azure's managed TensorFlow environments
Local Deployment Options
Docker Container
Create a Dockerfile for reproducible environments:
FROM tensorflow/tensorflow:latest
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
CMD ["jupyter", "notebook", "--ip=0.0.0.0", "--no-browser", "--allow-root"]
Build and run:
docker build -t tf-examples .
docker run -p 8888:8888 tf-examples
6. Troubleshooting
Common Issues and Solutions
Issue: ImportError: No module named 'tensorflow'
Solution: Ensure TensorFlow is installed in the correct Python environment. Check with pip list | grep tensorflow.
Issue: CUDA out of memory
Solution: Reduce batch size, use smaller models, or enable memory growth as shown in the Configuration section.
Issue: Jupyter notebook won't start
Solution: Check if Jupyter is installed (pip show jupyter). Try running python -m jupyter notebook.
Issue: TensorFlow compatibility issues
Solution: Verify TensorFlow version compatibility. This repository supports TF v1 & v2. Ensure you're using the correct examples for your TensorFlow version.
Issue: Slow performance on CPU
Solution: Consider using Google Colab for free GPU access, or install the GPU-enabled TensorFlow version if you have compatible hardware.
Issue: ModuleNotFoundError for specific datasets
Solution: Some examples require additional datasets. Follow the dataset loading instructions in each notebook, or download datasets manually to the specified paths.
Issue: Jupyter kernel dies during long training
Solution: Increase kernel timeout settings, or run long training jobs as standalone Python scripts instead of notebooks.
Performance Optimization Tips
- Use GPU acceleration when available
- Enable XLA compilation for performance-critical operations
- Use mixed precision training for faster training on compatible hardware
- Profile your models using TensorBoard to identify bottlenecks
Getting Help
- Check the TensorFlow official documentation
- Review the specific notebook's comments for dataset requirements
- Search the repository's issues for similar problems
- For TF v1 examples, refer to the separate v1 directory as mentioned in the README