Code Monkey home page Code Monkey logo

imageclassification's Introduction

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.

imageclassification's People

Contributors

sajalkmr avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.