Connery API is offline due to Heroku ending free hosting. It will come back online soon. Thank you for checking out the repo.
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:
lib/Connery.Lib.csproj
: .NET Standard (class library) project that contains all the data structures for training, testing, and consuming the model.training/Connery.training.csproj
: .NET Core console application that trains the model.testing/Connery.testing.csproj
: .NET Core console application that tests the model with some images that were not used for training.webapi/Connery.WebApi.csproj
: ASP.NET Core web API (ReSTful) that receives an image via a POST request and returns the class of the image, with probability score.
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.
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:
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.
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.
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 namedwwwroot
(Connery/webapi/wwwroot
) - move the
MLModel.zip
file insidewwwroot
directory - run the following command:
dotnet run -p webapi/Connery.WebApi.csproj
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
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.
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.
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.