Skip to content

KaueReinbold/tensor-flow

Repository files navigation

TensorFlow Learning Examples

A collection of isolated TensorFlow learning projects for exploring different machine learning concepts and techniques.

πŸš€ Features

  • Multiple Examples: Various isolated learning projects
  • Modern Architecture: Built with TensorFlow 2.15+ and modern Python best practices
  • Configurable: Flexible configuration system using Pydantic
  • CLI Interface: Easy-to-use command-line interface with Click
  • Comprehensive Logging: Structured logging throughout the application
  • Model Persistence: Save and load trained models
  • Testing Suite: Comprehensive unit tests with pytest
  • Docker Support: Containerized deployment ready

πŸ“ Project Structure

tensor-flow/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ index.py              # Main CLI interface
β”‚   β”œβ”€β”€ shared/               # Shared utilities
β”‚   β”‚   └── utils/
β”‚   β”‚       β”œβ”€β”€ __init__.py
β”‚   β”‚       └── logger.py     # Logging utilities
β”‚   └── examples/             # Learning examples
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ _template/        # Template for new examples
β”‚       └── mnist_classifier/ # MNIST digit classification
β”‚           β”œβ”€β”€ __init__.py
β”‚           β”œβ”€β”€ README.md
β”‚           β”œβ”€β”€ config.py     # Configuration management
β”‚           β”œβ”€β”€ data/
β”‚           β”‚   β”œβ”€β”€ __init__.py
β”‚           β”‚   └── loader.py # Data loading and preprocessing
β”‚           β”œβ”€β”€ models/
β”‚           β”‚   β”œβ”€β”€ __init__.py
β”‚           β”‚   └── classifier.py # Model architecture
β”‚           β”œβ”€β”€ training/
β”‚           β”‚   β”œβ”€β”€ __init__.py
β”‚           β”‚   └── trainer.py # Training logic
β”‚           └── inference/
β”‚               β”œβ”€β”€ __init__.py
β”‚               └── predictor.py # Inference utilities
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── test_mnist_classifier.py
β”œβ”€β”€ models/                   # Saved models directory
β”œβ”€β”€ logs/                     # Logs directory
β”œβ”€β”€ requirements.txt          # Production dependencies
β”œβ”€β”€ requirements-dev.txt      # Development dependencies
β”œβ”€β”€ pyproject.toml           # Project configuration
β”œβ”€β”€ scripts.py               # Development scripts
β”œβ”€β”€ docker-compose.yml       # Docker configuration
└── README.md               # This file

πŸ› οΈ Installation

1. Clone the repository

git clone https://github.com/KaueReinbold/tensor-flow.git
cd tensor-flow

2. Create a virtual environment

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

3. Install dependencies

# Production dependencies
pip install -r requirements.txt

# Development dependencies (optional)
pip install -r requirements-dev.txt

🎯 Quick Start

List Available Examples

# See all available learning examples
python -m src.index list-examples

MNIST Digit Classification

# Train the MNIST classifier
python -m src.index mnist train

# Custom training parameters
python -m src.index mnist train --epochs 10 --batch-size 64 --learning-rate 0.001

# Make predictions
python -m src.index mnist predict

# Show model information
python -m src.index mnist info

CLI Help

# Show available commands
python -m src.index --help

# Show help for MNIST example
python -m src.index mnist --help

πŸ“š Available Examples

1. MNIST Digit Classification (mnist)

  • Description: Neural network for handwritten digit recognition
  • Dataset: MNIST (70,000 images of digits 0-9)
  • Architecture: Dense neural network with dropout
  • Commands: train, predict, info
  • Learning Focus: Basic neural networks, image classification

Adding New Examples

  1. Use the template in src/examples/_template/
  2. Follow the established structure
  3. Add CLI commands to src/index.py
  4. Include comprehensive documentation

βš™οΈ Configuration

Each example uses a flexible configuration system. You can modify settings in several ways:

1. Environment Variables (.env file)

# MNIST Example
EPOCHS=10
BATCH_SIZE=64
LEARNING_RATE=0.001
MODEL_SAVE_PATH=models/mnist_model.h5

2. Command Line Arguments

python -m src.index mnist train --epochs 15 --batch-size 128

3. Code Configuration

Modify the default values in each example's config.py file.

πŸ§ͺ Testing

Run Tests

# Run all tests
python scripts.py test

# Or using pytest directly
pytest tests/ -v

Code Quality

# Format code
python scripts.py format

# Lint code
python scripts.py lint

πŸ“Š Model Architecture

The default model architecture:

  • Input Layer: Flatten layer for 28x28 images
  • Hidden Layer: Dense layer with 128 neurons (ReLU activation)
  • Dropout Layer: 20% dropout for regularization
  • Output Layer: Dense layer with 10 neurons (softmax activation)

Total Parameters: ~101,770 trainable parameters

🐳 Docker Usage

Build and Run with Docker Compose

# Build and start the container
docker-compose up --build

# Run training
docker-compose exec app python -m src.index train

# Run predictions
docker-compose exec app python -m src.index predict

πŸ“ˆ Performance

Typical performance on MNIST dataset:

  • Training Accuracy: ~99%
  • Test Accuracy: ~97-98%
  • Training Time: ~2-3 minutes (CPU)
  • Inference Speed: ~1ms per sample

🀝 Development

Development Scripts

# Install development dependencies
python scripts.py install-dev

# Run tests
python scripts.py test

# Format code
python scripts.py format

# Lint code
python scripts.py lint

# Clean up generated files
python scripts.py clean

# Train MNIST model
python scripts.py train

# Run MNIST predictions
python scripts.py predict

Adding New Examples

  1. Create Structure: Copy the template from src/examples/_template/
  2. Implement Logic: Add your specific machine learning logic
  3. Add CLI Commands: Extend the main CLI in src/index.py
  4. Update Configuration: Customize config.py for your needs
  5. Write Documentation: Include learning objectives and usage
  6. Add Tests: Include unit tests in the tests/ directory

Project Guidelines

  • Isolation: Each example should be self-contained
  • Shared Resources: Use src.shared for common utilities
  • Documentation: Clear explanations and learning objectives
  • Configuration: Flexible and well-documented settings

πŸ“š API Reference

Configuration Classes

  • Config: Main configuration class
  • ModelConfig: Model architecture settings
  • TrainingConfig: Training parameters
  • DataConfig: Data processing settings

Core Classes

  • DataLoader: Handles data loading and preprocessing
  • MNISTClassifier: Model architecture and compilation
  • Trainer: Training logic and evaluation
  • MNISTPredictor: Inference and prediction utilities

πŸ› Troubleshooting

Common Issues

  1. TensorFlow Import Error

    pip uninstall tensorflow
    pip install tensorflow>=2.15.0
  2. CUDA/GPU Issues

    # For GPU support
    pip install tensorflow[and-cuda]
  3. Memory Issues

    • Reduce batch size in configuration
    • Use validation split to reduce memory usage

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • TensorFlow team for the excellent deep learning framework
  • MNIST dataset creators for the benchmark dataset
  • Open source community for the tools and libraries used

πŸ“ž Contact

Kaue Reinbold


⭐ Star this repository if you find it helpful!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published