Skip to content

🍎 🧠 Fruit Image Classifier Using Convolutional Neural Networks

License

Notifications You must be signed in to change notification settings

maacpiash/Connery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Connery API is offline due to Heroku ending free hosting. It will come back online soon. Thank you for checking out the repo.

Connery

Fruit Image Classifier Using Convolutional Neural Networks

API Swagger macOS build status Ubuntu build status Windows build status .NET Core SDK version 3.1 (LTS)

Technical details

The project is developed using ML.NET. The web API is developed using ASP.NET Core. Both these frameworks are free, cross-platform, and open-source.

The solution is divided into four projects:

The model used here is trained via applying transfer learning on Google's Inception V3 model. Both the training and the generation of code (for training and consuming the model) was done using Visual Studio's ML.NET Model Builder extension.

The trained model can classify images into the following eight labels:

  • fresh_apple
  • fresh_banana
  • fresh_mango
  • fresh_orange
  • rotten_apple
  • rotten_banana
  • rotten_mango
  • rotten_orange

During the post-training evaluation, the model showed 89.02% accuracy.

back to top

How to use the application

The application, which is hosted on Heroku, is a ReSTful API. The API endpoint is /image. This endpoint can be called via a POST method, with request-body of type form-data, with the field image containing the image file.

Using curl, the command should be:

curl -X POST "https://connery-api.herokuapp.com/Image" -H  "accept: */*" -H  "Content-Type: multipart/form-data" -F "image=@<image-path>;type=image/jpeg"

Using Postman, the configuration is like this:

postman-screenshot

The applicaton can also be used using Swagger, which has a GUI. Go to this address, then click on POST > Try it out > Browse... > Execute. After a few seconds, the result would be shown in the "Response body" section.

swagger-screenshot

back to top

How to run the application on local machine

Running binaries

Pre-built binaries for Windows (x64/x86), macOS, and Linux (x64/arm) can be found in the releases section. Please download the suitable zip file and run the publish/Connery.WebApi file. For Windows builds, it's the publish/Connery.WebApi.exe file. The app can now be accessed from https://localhost:5001 or http://localhost:5000. There is also an Assets.zip file, which contains the images used for training and testing.

Building from source

Compilation and building of the project would require .NET Core SDK (version 3.1), which can be downloaded from Microsoft's website here. This would also require MLModel.zip file, which can be found in the releases section. Then,

  • clone this repository
  • go into the folder
  • make a directory in webapi folder named wwwroot (Connery/webapi/wwwroot)
  • move the MLModel.zip file inside wwwroot directory
  • run the following command:
dotnet run -p webapi/Connery.WebApi.csproj

back to top

How to train and test the model

If you want to train the model on your own machine, please download Assets.zip file from the releases section. Then, unzip it inside a directory named assets inside the root directory. Besides this directory, there should be an empty directory in the root folder named workspace, where the trained model will be.

The file organization should be like this:

Connery/
├───assets/
│   ├───img_data/
│   │   ├───fresh_apple/
│   │   ├───fresh_banana/
│   │   ├───fresh_mango/
│   │   ├───fresh_orange/
│   │   ├───rotten_apple/
│   │   ├───rotten_banana/
│   │   ├───rotten_mango/
│   │   └───rotten_orange/
│   └───img_test/
├───lib/
│   └───Connery.Lib.csproj
├───testing/
│   └───Connery.Testing.csproj
├───training/
│   └───Connery.Training.csproj
├───webapi/
│   └───Connery.WebApi.csproj
├───workspace/
└───Connery.sln

Training

To train the model, run the following command:

dotnet run -p training/Connery.Training.csproj

This will train the model from the images in assets/img_data folder and save the model at workspace/MLModel.zip path.

Testing

Now, to test the model you just trained, run the following command:

dotnet run -p testing/Connery.Testing.csproj

This will test the model using the images in assets/img_test folder.

back to top

Acknowledgement

This project was originally implemented as a course project during my CSE499 course at North South University over two semesters in 2018. I would like to thank my course supervisor, Dr. Rashedur M. Rahman. Without his generous guidance, we would not have been able to get our research published.

DOI

Twitter Follow

back to top