Skip to main content

Alpha Hybrid CNN model for classification tasks

Project description

Alpha Hybrid Model

PyPI Version Python Versions License

A Python package for training a multi-branch Convolutional Neural Network (CNN) model that combines ResNet50V2 and DenseNet169 architectures for image classification tasks.


Table of Contents


Introduction

Alpha Hybrid Model is a Python package designed for image classification tasks using a hybrid approach that combines the strengths of ResNet50V2 and DenseNet169 architectures. By integrating these two powerful models, the Alpha Hybrid Model aims to improve classification performance through enhanced feature extraction.


Features

  • Hybrid Architecture: Combines ResNet50V2 and DenseNet169 for superior feature extraction.
  • Data Augmentation: Implements various augmentation techniques to improve model generalization.
  • Early Stopping & Learning Rate Reduction: Includes callbacks for early stopping and learning rate reduction on plateau.
  • Command-Line Interface: Easy-to-use CLI for training and evaluation.
  • Customizable Hyperparameters: Adjust learning rate, batch size, epochs, and more.
  • Training History Plotting: Option to visualize training and validation accuracy and loss.

Installation

Prerequisites

  • Python: Version 3.6 or higher.
  • TensorFlow: Version 2.x.
  • pip: Latest version recommended.

Installation via Pip

Install the package directly from PyPI:

pip install alpha_hybird_model

Note: It's recommended to use a virtual environment to avoid dependency conflicts.


Usage

Command-Line Interface

After installation, the alpha_hybird_train command becomes available.

Basic Usage

alpha_hybird_train --train_dir PATH_TO_TRAIN_DIR --val_dir PATH_TO_VAL_DIR [OPTIONS]

Options

  • --train_dir: (Required) Path to the training data directory.
  • --val_dir: (Required) Path to the validation data directory.
  • --epochs: Number of epochs to train (default: 50).
  • --batch_size: Batch size for training (default: 8).
  • --initial_lr: Initial learning rate (default: 1e-4).
  • --output_dir: Directory to save model weights and outputs (default: ./).
  • --plot: Include this flag to plot training history after training.

Help

For detailed usage instructions:

alpha_hybird_train --help

Examples

Example 1: Basic Training

alpha_hybird_train   --train_dir ./data/train   --val_dir ./data/val   --epochs 25   --batch_size 16

Example 2: Training with Custom Learning Rate and Output Directory

alpha_hybird_train   --train_dir ./data/train   --val_dir ./data/val   --epochs 30   --batch_size 32   --initial_lr 5e-5   --output_dir ./model_outputs   --plot

Data Preparation

Organize your dataset as follows:

dataset/
├── train/
│   ├── class1/
│   │   ├── image1.jpg
│   │   ├── image2.jpg
│   │   └── ...
│   └── class2/
│       ├── image1.jpg
│       ├── image2.jpg
│       └── ...
└── val/
    ├── class1/
    │   ├── image1.jpg
    │   ├── image2.jpg
    │   └── ...
    └── class2/
        ├── image1.jpg
        ├── image2.jpg
        └── ...
  • Classes: Each class should have its own subdirectory.
  • Training and Validation Data: Separate directories for training and validation datasets.

Programmatic Usage

You can also use the package within your Python scripts:

from alpha_hybird_model import build_model, plot_training_history
import tensorflow as tf

# Build the model
model = build_model(input_shape=(224, 224, 3), num_classes=2)

# Compile the model
model.compile(
    optimizer=tf.keras.optimizers.Adam(learning_rate=1e-4),
    loss='categorical_crossentropy',
    metrics=['accuracy']
)

# Proceed with custom training loop or other tasks

Project Structure

alpha_hybird_model/
├── alpha_hybird_model/
│   ├── __init__.py
│   ├── model.py
│   └── utils.py
├── scripts/
│   └── train_model.py
├── setup.py
├── README.md
├── LICENSE
└── requirements.txt
  • alpha_hybird_model/: Core package containing the model and utility functions.
  • scripts/: Contains the command-line script train_model.py.
  • setup.py: Configuration file for packaging.
  • README.md: Comprehensive documentation.
  • LICENSE: License information.
  • requirements.txt: List of package dependencies.

##Benfits of Alpha_Hybird_Model

Benefits of the Alpha Hybrid Model Over Traditional CNNs The Alpha Hybrid Model is a multi-branch CNN that combines ResNet50V2 and DenseNet169 architectures. By leveraging the unique strengths of these architectures, the Alpha Hybrid Model provides several advantages over traditional CNNs:

Enhanced Feature Extraction:

ResNet50V2 and DenseNet169 are state-of-the-art architectures that use different methodologies for feature extraction. ResNet50V2 utilizes skip connections to avoid the vanishing gradient problem, allowing deeper layers without performance loss. DenseNet169, on the other hand, promotes feature reuse through dense connections, enabling efficient learning of both high- and low-level features. By combining these models, Alpha Hybrid Model achieves richer feature extraction, capturing a wide range of patterns and enhancing model performance in complex classification tasks. Improved Generalization with Multi-Branch Architecture:

The hybrid approach in the Alpha Hybrid Model merges the outputs of both architectures. This fusion acts as a built-in ensemble, increasing the model's robustness and reducing overfitting. This is especially advantageous in datasets with high variability, as the model learns diverse representations from both ResNet and DenseNet branches. The model's design also enables better handling of minor variations in input data, improving accuracy and generalization across unseen samples. Moderate Regularization for Stability:

The Alpha Hybrid Model employs L2 regularization and dropout to reduce overfitting, leading to a more stable and reliable model. Dropout layers encourage the model to be resilient to small feature variations, and L2 regularization helps prevent excessively high weights, which can improve generalization. Efficient Training with Adaptive Learning Rate:

The model includes callbacks for early stopping and learning rate reduction on plateau, allowing adaptive learning throughout training. This setup helps prevent overtraining and optimizes the model's training time, focusing on valuable epochs for learning and stopping once minimal improvements are detected. Higher Accuracy and Faster Convergence:

Combining ResNet50V2 and DenseNet169 has shown improvements in classification accuracy compared to using either architecture alone. The model also converges faster due to its dual-branch structure and adaptive learning approach, making it suitable for scenarios requiring efficient training and high performance. Versatility for Real-World Applications:

The Alpha Hybrid Model’s ability to capture detailed features makes it well-suited for various applications, including medical imaging, object detection, and other fields requiring high precision and adaptability. By utilizing this hybrid approach, the Alpha Hybrid Model outperforms traditional CNNs and single-architecture models, particularly in complex classification tasks where both low-level and high-level features are crucial. This unique architecture allows users to achieve robust performance with reduced risk of overfitting, making it a powerful choice for image classification tasks.

Documentation

For more detailed information, please refer to the GitHub repository.


Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the Repository: Create your own fork of the project on GitHub.

  2. Clone Your Fork:

    git clone https://github.com/ihtesham-jahangir/alpha_hybird_model.git
    
  3. Create a Feature Branch:

    git checkout -b feature/YourFeature
    
  4. Commit Your Changes:

    git commit -am 'Add a new feature'
    
  5. Push to Your Fork:

    git push origin feature/YourFeature
    
  6. Submit a Pull Request: Open a pull request to the main repository.

Reporting Issues

If you encounter any problems, please open an issue.


License

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


Contact


Acknowledgments

  • TensorFlow Community: For providing a powerful deep learning framework.
  • Keras Team: For simplifying deep learning model development.
  • Researchers and Contributors: Behind ResNet and DenseNet architectures.
  • Open Source Community: For fostering collaboration and innovation.

This README provides comprehensive information about the Alpha Hybrid Model package, ensuring users have all the necessary details to install, use, and contribute to the project.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alpha_hybird_model-0.1.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alpha_hybird_model-0.1.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file alpha_hybird_model-0.1.1.tar.gz.

File metadata

  • Download URL: alpha_hybird_model-0.1.1.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for alpha_hybird_model-0.1.1.tar.gz
Algorithm Hash digest
SHA256 be4a36048bfa782b31738008c84d9d68cb946b5d1164baa56c7b09bdb66dd7d0
MD5 b2bab952a11612d872ad6903a9f64a0c
BLAKE2b-256 8ee5bcd0446834764ef2cd758bfc5d57e01be32c225a0214117bb2b771fe5f1d

See more details on using hashes here.

File details

Details for the file alpha_hybird_model-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for alpha_hybird_model-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5b036991d0ce7ed88d4287f94f62bc0c68e81fa5be5a14642f79f80f44b12db7
MD5 4ab37f9aa1a11aa3724a06348d0845cc
BLAKE2b-256 5a2dd23f442f3ab699b9ba0d3d4ebf2b2ca0d666656649cc7e60b4c4ee9c1312

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page