A modular, end-to-end Convolutional Neural Network (CNN) for image classification built with TensorFlow/Keras.
Designed for researchers, students, and developers to train, evaluate, and deploy image classifiers efficiently.
- π― Project Overview
- πΌοΈ Project Thumbnail
- ποΈ Model Architecture
- Layer-by-Layer Description
- Model Compilation
- Summary Table
- π Accuracy & Loss Over Epochs
- βοΈ Features
- π Project Structure
- π§° Getting Started
- Prerequisites
- Installation
- π Quick Start
- Training the Model
- Using the Notebook
- π¦ Dataset Sample
- π§ Customization
- π οΈ Configuration
- π Results & Performance
- π€ Contributing
- π License
- π Acknowledgements
- π€ Author
This repository provides a complete CNN workflow for image classification:
- Load and preprocess images.
- Build a customizable CNN architecture.
- Train, validate, and evaluate the model.
- Save and use the model for predictions on new images.
- Visualize performance metrics and training curves.
Itβs designed to be modular, readable, and easy to extend for custom datasets or advanced architectures.
![]()
Visual representation of the CNN Image Classifier workflow.
The CNN model is designed for binary image classification with a simple yet effective architecture. The model is implemented using TensorFlow/Keras.
-
Input Layer
- Accepts images with shape
(height, width, channels)specified byinput_shape.
- Accepts images with shape
-
Convolutional Block 1
Conv2Dwith 32 filters, kernel size3x3, activationReLU.MaxPooling2Dwith pool size2x2to reduce spatial dimensions.
-
Convolutional Block 2
Conv2Dwith 32 filters, kernel size3x3, activationReLU.MaxPooling2Dwith pool size2x2.
-
Flatten Layer
- Converts the 2D feature maps into a 1D vector.
-
Fully Connected (Dense) Layer
- Dense layer with 128 neurons and
ReLUactivation.
- Dense layer with 128 neurons and
-
Output Layer
- Dense layer with
num_classesneurons andsigmoidactivation (binary classification).
- Dense layer with
- Optimizer: Adam
- Loss Function: Binary Crossentropy
- Metrics: Accuracy
| Layer Type | Output Shape | Parameters |
|---|---|---|
| Conv2D (32 filters) | (62, 62, 32) | 896 |
| MaxPooling2D (2x2) | (31, 31, 32) | 0 |
| Conv2D (32 filters) | (29, 29,32) | 9248 |
| MaxPooling2D (2x2) | (14, 14, 32) | 0 |
| Flatten | 6,272 | 0 |
| Dense (128 neurons) | 128 | 802,944 |
| Output Dense | 1 | 129 |
Visualizations generated during training provide insights into model performance:
Training & Validation Loss vs Epochs

- Modular CNN implementation (
src/model.py) - Data preprocessing & augmentation utilities (
src/data.py) - Notebook demonstrating full workflow (
notebook/cnn_image_classifier_main.ipynb) - Model saving and loading for inference
- Clear visualizations of metrics and predictions
| Path | Description |
|---|---|
assets/ |
Thumbnail and performance plots |
βββ cnn_image_classifier_thumbnail.png |
Project thumbnail image |
βββ accuracy_over_epochs.png |
Accuracy plot over training |
βββ loss_over_epochs.png |
Loss plot over training |
dataset/ |
Sample dataset (cats & dogs) |
βββ training_set/ |
Training images |
βββ test_set/ |
Testing images |
notebook/ |
Main Jupyter notebook |
βββ cnn_image_classifier_main.ipynb |
Contains training and evaluation |
src/ |
Modular code components |
βββ __init__.py |
Marks src/ as a Python package |
βββ model.py |
CNN architecture |
βββ data.py |
Data loading and preprocessing |
saved_model/ |
(Optional) Saved trained model |
βββ cnn_model.h5 |
Saved model file |
requirements.txt |
Python dependencies for reproducibility |
.gitignore |
Git ignore rules |
LICENSE |
Project license |
README.md |
Project documentation |
- Python β₯ 3.7
- TensorFlow 2.x
- Numpy, Matplotlib, Pandas
- (Optional) GPU for accelerated training
git clone https://github.com/ArianJr/cnn-image-classifier.git
cd cnn-image-classifier
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt# Example: run in the notebook or a script
from src.data import load_training_data, load_test_data
from src.model import build_cnn
training = load_training_data('dataset/training_set', (64, 64))
test = load_test_data('dataset/training_set', (64, 64))
model = build_cnn(input_shape=(64,64,3), num_classes=1)
history = model.fit(x=training, validation_data=test, epochs=25)Launch the Jupyter notebook for an interactive demo:
jupyter notebook notebook/cnn_image_classifier_main.ipynbThis repository includes a sample subset of the Dogs vs. Cats dataset for demonstration purposes:
train/: 200 images (100 cats, 100 dogs)test/: 50 images (25 cats, 25 dogs)
This subset is ideal for:
- Testing the modular CNN pipeline
- Validating config-driven training and evaluation
- Keeping the repository lightweight
For full-scale training, download the complete dataset from Kaggle.
- Replace or augment dataset (
dataset/folder). - Modify CNN architecture (
src/model.py). - Experiment with hyperparameters (learning rate, batch size, optimizer).
- Implement transfer learning with pretrained networks.
- Add evaluation metrics: confusion matrix, precision, recall, F1-score.
This project is designed to be easily customizable. You can modify key training parameters directly in the code files:
| Parameter | Location | Default Value |
|---|---|---|
input_shape |
model.py |
(64, 64, 3) |
epochs |
cnn_image_classifier.ipynb |
25 |
batch_size |
cnn_image_classifier.ipynb |
32 |
train_dir |
data.py |
dataset/training_set |
test_dir |
data.py |
dataset/test_set |
model_path |
cnn_image_classifier.ipynb |
saved_model/cnn_model.h5 |
These values can be adjusted to suit your dataset size, image resolution, or training goals.
| Metric | Value |
|---|---|
| Training Accuracy | 88.21% |
| Validation Accuracy | 79.10% |
| Final Training Loss | 0.2653 |
| Final Validation Loss | 0.5460 |
- Fork the repository.
- Create a feature branch (
git checkout -b feature/YourFeature). - Commit changes with clear messages.
- Open a pull request.
MIT License β see the LICENSE file for details.
- TensorFlow & Keras communities for excellent tools.
- Open-source datasets used for training.
- Tutorials and guides on CNNs that inspired this workflow.
Arian Jr
π§ Contact Me β’ π GitHub Profile
Made with β€οΈ by ArianJr
β If you found this project useful, please consider giving it a star! It helps others discover it and supports my work.
