A collection of isolated TensorFlow learning projects for exploring different machine learning concepts and techniques.
- 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
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
git clone https://github.com/KaueReinbold/tensor-flow.git
cd tensor-flowpython -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate# Production dependencies
pip install -r requirements.txt
# Development dependencies (optional)
pip install -r requirements-dev.txt# See all available learning examples
python -m src.index list-examples# 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# Show available commands
python -m src.index --help
# Show help for MNIST example
python -m src.index mnist --help- 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
- Use the template in
src/examples/_template/ - Follow the established structure
- Add CLI commands to
src/index.py - Include comprehensive documentation
Each example uses a flexible configuration system. You can modify settings in several ways:
# MNIST Example
EPOCHS=10
BATCH_SIZE=64
LEARNING_RATE=0.001
MODEL_SAVE_PATH=models/mnist_model.h5python -m src.index mnist train --epochs 15 --batch-size 128Modify the default values in each example's config.py file.
# Run all tests
python scripts.py test
# Or using pytest directly
pytest tests/ -v# Format code
python scripts.py format
# Lint code
python scripts.py lintThe 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
# 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 predictTypical performance on MNIST dataset:
- Training Accuracy: ~99%
- Test Accuracy: ~97-98%
- Training Time: ~2-3 minutes (CPU)
- Inference Speed: ~1ms per sample
# 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- Create Structure: Copy the template from
src/examples/_template/ - Implement Logic: Add your specific machine learning logic
- Add CLI Commands: Extend the main CLI in
src/index.py - Update Configuration: Customize
config.pyfor your needs - Write Documentation: Include learning objectives and usage
- Add Tests: Include unit tests in the
tests/directory
- Isolation: Each example should be self-contained
- Shared Resources: Use
src.sharedfor common utilities - Documentation: Clear explanations and learning objectives
- Configuration: Flexible and well-documented settings
Config: Main configuration classModelConfig: Model architecture settingsTrainingConfig: Training parametersDataConfig: Data processing settings
DataLoader: Handles data loading and preprocessingMNISTClassifier: Model architecture and compilationTrainer: Training logic and evaluationMNISTPredictor: Inference and prediction utilities
-
TensorFlow Import Error
pip uninstall tensorflow pip install tensorflow>=2.15.0 -
CUDA/GPU Issues
# For GPU support pip install tensorflow[and-cuda] -
Memory Issues
- Reduce batch size in configuration
- Use validation split to reduce memory usage
This project is licensed under the MIT License - see the LICENSE file for details.
- TensorFlow team for the excellent deep learning framework
- MNIST dataset creators for the benchmark dataset
- Open source community for the tools and libraries used
Kaue Reinbold
- GitHub: @KaueReinbold
- Email: your.email@example.com
β Star this repository if you find it helpful!