Tflearn+Django+React Native = Image Classification in productionIntroductionErkebulan DuisebayBlockedUnblockFollowFollowingApr 17It is indisputable that creating model and exploring data is interesting but we have to admit that it is quite difficult to show result of the hard work.
Here we want to share with our experience how we implement image classification model with Tflearn and how we deliver it to the production.
We hope that the simple idea that people will use your product will motivate you and spark your desire for study this field.
We divide the tutorial for 3 section because we thought that some of you just may interest in one particular part.
First section we will explain how we implement model, secondly we want to explain how we create API for mobile with Django, lastly we will explain how we create mobile app with RN.
Generally we will create mobile app that will serve for taking cat or dog picture and after that it will be send it to our server and CNN will classify it.
TechnologiesTflearn —TFlearn is a modular and transparent deep learning library built on top of Tensorflow.
It was designed to provide a higher-level API to TensorFlow in order to facilitate and speed-up experimentations, while remaining fully transparent and compatible with it.
Django — Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
React Native — React Native is an open-source mobile application framework created by Facebook.
It is used to develop applications for Android, IOS.
CNN with TflearnFirst of all, we need to gather images for train.
We use Kaggle to find images, they provide with 25000 images of cats and dogs previously labeled.
The first things that we need to importHere we import all necessary libraries for our p reprocessing stage.
Here cv2 stands opencv for image processing.
This functions designed to generate train and test data for our model.
Generally they just take picture and resize it to fixed IMG_SIZE and then store them with labels and id for train and test correspondingly.
Here we create model with 8 hidden layer.
For detailed explanation of how CNN work you can find it here.
We successfully finish our model creation stage now we need to integrate it with our back-end.
Integrating with DjangoDjango is framework written in python for fast back-end creation.
However it is quite intimidating to explain how create app step by step, that is why we decide to explain main parts, other basic configurations you can easily find in documentation.
I pass all this project creation and app creation stages.
Here also important to remember that we do not need any DB (in our case ) that is why you can ignore migrations staff.
Here we will create module named CNN, inside we have class with prediction method.
The method will be used to image classification.
As you notice we create model object and load our previously trained model.
py we create classify method for classification which will accept POST request with file data included, after that we will predict the result.
Here we configure path to our view and that is it).
Now we need to publish our simple back-end to the hosting.
We use Heroku for simplicity.
We upload this picture to our back-end serverPostman for testing our simple APIWe test it and It works perfectly.
You can also test it here till Heroku is free.
Building Mobile appFor simple development you need a set up expo for local machine then need to install all necessary packages.
DependencyHonestly there so many extra packages for such simple project but we decide to create mobile app which will be easily scalable.
Generally we use Redux for state management but if your project pretty simple and consist 3–4 pages just use component state.
Firstly we decide to show all steps but then we changed our mind because it is out of topic.
That is why here we left link to RN tutorial where you can learn basics of RN.
Here you can witness simple logic how we send image to the server and get response.
As we mentioned you can easily create any app with RN after you learn basics then add some actions like this to implement fetching from server.
ConclusionWhen you begin to see big picture every thing going to be considerably easy.
We hope that we help you to see whole process in big picture.
However we understand that we don’t give you detailed tutorial how to create mobile app or how to load Django to Heroku, but on the internet you can find thousands of detailed tutorials about this parts.
As you can see our application is pretty simple and our application architecture is not effective.
Only when we finish this project we come to new idea which will boost our effectiveness.
The better solution is make classification on the client side and when we update our model and increase our precision we can update it on client mobile app.
Generally client will send request to server only when they need to update their model instead of sending request for each image.
The model creation tutorials was taken from other sources.
Yes we agree that it is a tip of the iceberg but, you can find link to GitHub repository where you can explore the project in detail.
ReferencesHere Django implementation of the backend.
CNN implementationReact Native implementation.. More details