Skip to content

DeepQuestAI/FruitsRecognitionApp

Repository files navigation

FruitsRecognitionApp


A Flask Web App for recognizing fruits, using DeepStack Custom Model APIs
DeepStackDemoImg

Classes of Fruits detected


There are 7 classes of food detected by the FruitsRecognitionApp.

Deep learning architecture


The deep learing model used in this FruitsRecognitionApp was built on a deep neural network architecture know as ResNet(Residual Neural Networks). Residual neural networks are a special kind of deep neural network architecture that makes use of residual units. Residual unit is made by joining two or three convolution neural networks together and adding the input of the previous convolutional network to the out the next convolutional network. These residual units help to solve the most difficult problems with deep neural networks know as varnishing gradients. Residual neural networks also have there challenges like diminishing feature reuse, but they have to prove to work really well when building a deep learning model. Hence they are used in this project

How FruitsRecognitionApp works


This web app is built on bootstrap, flask and jinja. The web app take the image to be classified send it to the custom model endpoint on DeepStack AI server an resturn a JSON. This JSON value contains the the true label for the image, and the model confidence score which is then displayed by the web app.
The model used used for this predictions was built with pytorch as exported to onnx with the code bellow:

load_saved_model = torch.load('<model_name>.pt')
dummy_input = torch.FloatTensor(1,3,<int:img_width>,<int:img_height>)
dummy_input = dummy_input.to(device)
torch.onnx.export(load_saved_model, dummy_input, '<onnx_name>.onnx')

The model was deployed to deepstack using the code below:

#config.json file
{"sys-version": "1.0",
    "framework":"ONNX",
    "mean":0.5,
    "std":255,
    "width":224,
    "height":224,
    "map": {
        "0" : "Apple",
        "2" : "Mango",
        "3" : "Orange",
        "1" : "Banana",
        "4" : "Strawberry",
        "5" : "Tomato",
        "6" : "Watermelon"
    }}
    
#deeploying_to_deepstack.py
import requests
from io import  open

model = open("FruitsDetect.onnx","rb").read()
config = open("config.json","rb").read()

response = requests.post("http://localhost:80/v1/vision/addmodel",
            files={"model":model,"config":config},data={"name":"FruitsDetect"}).json()

Images of an uploaded image and the displayed results uploaded fruit image return class results

Frameworks used


Pytorch:

PyTorch is software, specifically a machine learning library for the programming language Python, based on the Torch library, used for applications such as deep learning and natural language processing. It is primarily developed by Facebook's artificial-intelligence research group, and Uber's Pyro probabilistic programming language software is built on it. It is free and open-source software released under one of the BSD licenses.
https://pytorch.org/

TorchFusion:

A modern deep learning framework built on pytorch to accelerate research and development of AI systems.

pip3 install torchfusion_utils

Numpy:

NumPy is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays.

pip3 install numpy

Mathplotlib:

Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy. It provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like Tkinter, wxPython, Qt, or GTK+.

pip3 install matplotlib

Flask

Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions.

pip3 install flask

Bootstrap

Bootstrap is an open source toolkit for developing with HTML, CSS, and JS. Quickly prototype your ideas or build your entire app with our Sass variables and mixins, responsive grid system, extensive prebuilt components, and powerful plugins built on jQuery.
bootstrap

Installing DeepStack


Windows
Linux