An open API service indexing awesome lists of open source software.

https://github.com/sajalkmr/imageclassification

Build a CNN Image classifier model using your own images with Tensorflow
https://github.com/sajalkmr/imageclassification

cnn cnn-classification cnn-keras cnn-model deep-learning image-classification jupyter-notebook keras machine-learning opencv python tensorflow

Last synced: 3 months ago
JSON representation

Build a CNN Image classifier model using your own images with Tensorflow

Awesome Lists containing this project

README

          

Image Classifier


This project provides a script to train a convolutional neural network (CNN) on a dataset of images. The script is written in Python and uses TensorFlow and OpenCV. The model can classify images into different classes based on the dataset provided.

Requirements



  • Tensorflow

  • Tensorflow-gpu

  • OpenCV-python

  • Matplotlib

Usage



  1. Clone or download the repository.

  2. Make sure that you have the required libraries installed.

  3. Place your dataset in a directory called 'training_data'

  4. Open the Jupyter notebook by running the command "jupyter notebook" in your terminal in the directory.

  5. Locate and open the training_model.ipynb notebook
  6. Make sure that the kernel for the notebook is set to Python 3.

  7. Run the cells in the notebook to train the model on your dataset.

  8. The script will create a unique folder with the current date and time in the format dd.mm.yyyy hhmmss-train_results for storing the model files and training results.

  9. To use this script, you will need to place your dataset of images in a directory called 'training_data'. The script expects the images to be organized into different subfolders within the 'training_data' directory, one for each class. For example, if you have two classes, "class1" and "class2", you should create two subfolders within the 'training_data' directory named "class1" and "class2" and place the corresponding images in each folder. Make sure that the images are in jpeg, jpg, bmp, or png format.




Example file structure:




    training_data/
    class1/
    image1.jpg
    image2.jpg
    ...
    class2/
    image1.jpg
    image2.jpg
    ...

Model architecture


The model architecture is a convolutional neural network (CNN) with the following layers:



  • Conv2D with 16 filters of size (3,3), stride of 1, and ReLU activation

  • MaxPooling2D

  • Conv2D with 32 filters of size (3,3), stride of 1, and ReLU activation

  • MaxPooling2D

  • Conv2D with 16 filters of size (3,3), stride of 1, and ReLU activation

  • MaxPooling2D

  • Flatten layer

  • Dense layer with 128 units and ReLU activation

  • Dense layer with the number of units equal to the number of classes in the dataset and softmax activation


You can change the architecture of the model, training parameters, and data set path accordingly.


Files saved after training


The script will save the following files in the unique folder created after training:



  • The trained model file in the format model.h5

  • A plot figure of a batch of the training images and their labels in the format batch_result.jpg

  • An Accuracy and a Loss chart as accuracy_chart.jpg and loss_chart.jpg


  • A file with the training and validation accuracy and loss values in the format histroy.json

  • Final summary and result as .txt



Training Results


The following images are examples of the results generated by the script after training.








Note



  • This script is set to work with images of size 256x256, you can change the image size accordingly.

  • The script automatically loads the images and splits them into train, validation, and test sets.




Contributing


If you want to contribute to this project, please feel free to submit a pull request.





Licence


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

References

The code for this project is greatly inspired by Nicholas Renotte.

Examples


You can find an example of a pre-trained model in the model folder, which was trained to classify images as notes and non-notes from WhatsApp images. You can use this pre-trained model as a starting point for fine-tuning on your own dataset or as a reference for comparison to your own model's performance. The model is trained using two classes (notes and non-notes) and is available in this repository NotesSeparator.