An image classification app boilerplate to serve your deep learning models asap!

Overview

Image 🖼 Classification App Boilerplate

Have you been puzzled by tons of videos, blogs and other resources on the internet and don't know where and how to deploy your AI models?

Won't it be nice if you could have a template where you just insert your trained model files, edit some promo text and Voila, it's done.

Well, look no further because this repository makes it as easy for you as it sounds!

How to use this project? 🤔 🤔 :

NOTE: For now, we are exclusively focused on image classification models built using tensorflow/pytorch. Later we would expand to models dealing with text and speech data as well as training using MXNet or a julia environment

  • I assume you have Python(with Anaconda) installed in your operating system and set to path. If not, please visit this. Using GIT along with Python is highly recommended for version control and deployment

A. Fetching our template and setting it up:

  1. Open GitHub

  2. Log in with your credentials. [ Create an account if you have not done it already]

  3. Open the terminal/command prompt on your system

  4. Move to a suitable location where you want to keep the project files locally

Example: cd Desktop/projects

  1. Clone this repository.
git clone --depth 1 https://github.com/smaranjitghose/img_ai_app_boilerplate.git
  1. Navigate inside your cloned copy of the template
cd img_ai_app_boilerplate
  1. Now, let's fetch our dependencies to run our app. [A python package called StreamLit is at the heart of this app]
 pip install -r requirements.txt
  1. Now, let's put our model files inside the app.

B. Integrating our Trained Model:

  1. Open the model sub-directory
cd model
start .
  1. Paste your Keras.h5 model files there

  2. Shoot up your favorite code editor/IDE (I prefer VSCode).

    code . [Type this in the terminal to open VSCode if you already have it installed]

  3. Now open the file img_classifier.py.

  4. Search for the variable labels in the code and set its' value as per the labels of the dataset used for training your model. [say if you are doing Cats Vs Dogs classification, then labels = {0: "Cats", 1: "Dogs"} ]

    NOTE: This is totally dependent on your model training

  5. Update the value of the variable model with the path of your model file.

    [say model = tensorflow.keras.models.load_model('model/catsvsdogs.h5')]

  6. Save the changes.

C. Frontend and Content Changes

Continuing with changes to the User Interface or the frontend of our app please follow the steps mentioned below:

Home Page 🏡

  1. Open app.py.

  2. Search for st.title and update the Title of the app as per your application's needs.

    [say st.title('Our Cats vs Dogs Classifier')]

  3. Now search for variable page_title and update it with the same. This will tweak the SEO.

    [say page_title="Cats Vs Dogs",]

  4. If you have some affiliation or maybe the app is made completely by you (perhaps with a group of your friends/colleagues) as a pet project, you can reflect that in the app by searching for st.subheader and updating it

    [say st.subheader("By John Doe and Jane Doe")]

^^ Delete any or all code that you won't use from the above

Contact Page 🤳

  1. Search for the function call display_team("Your Awesome Name", "./assets/profile_pic.png","Your Awesome Affliation","[email protected]" and update the following parameters as per your own discretion:

    • Name
    • path_to_image (I would suggest storing the images inside assets/images/
    • Affiliation
    • email
  2. For adding multiple members, you can call the same function multiple times. For example:

    display_team("John Doe","./assets/john_doe.png","Stanford University","[email protected]")
    display_team("Jane Doe","./assets/jane_doe.png","Harvard University","[email protected]")

D. Storing the Images 📤 and User Feedback Online

Setting up Firebase

  • Login in to Firebase, using your Gmail ID.

  • Click on the Get Started button which will, take you to your console.

Creating a project

  • Click on Add project. Once you do so, a 3 Step process will start.

  • Enter the name of your project. (Pro tip: Keep the same name as the name of your App. It would make it easier to identify.)

  • The next step is pretty self explanatory and you may/may not choose to enable google analytics.

    • If you choose to enable google analytics, then you will have to select or create a Google Analytics account.

    • If you choose not to, then a Create project button will appear instead of Continue.

  • Once you click on Create project, you will land on Firebase Console.

Setting up Storage

  • Once you land on the Firebase Console, click on the Create Web App icon.

  • Give the name of your web app and unless required, do not select the Hosting option and click next.

  • Copy the code which appears and store in a config.txt file for later use.

  • Click on Continue to Console.

  • Once on Console, click on the Storage Option on the left panel and then click on Get Started.

  • Click Next and then select a server closest to your location.

  • Once the Storage is initiated, click on the Rules tab and change: allow read, write: if request.auth != null; to allow read, write; in the code snippet which appears on the screen.

    Note: This is only for testing purposes and in real life scenarios refrain from doing this.

  • This change basically allows us the upload and download the images without authenticating every time.

  • With this you have set up the Storage successfully. You can manage your app's cloud server from here.

Setting up Realtime Database

  1. Click on the Realtime Database Option on the left panel.

  2. Once on the page, click on Create Database button.

  3. When you click the button, there will be a prompt to set the Security rules. It is recommended to start in locked mode so as to ensure security of the data.

  4. With this you have set up the Database successfully. Now whenever a user writes a feedback, you can check it here in this database. Since this database stores data in terms of JSON files, you can also export the JSON file and use it in whichever way you like.

Linking Firebase in the App

Since everything is set up in the Firebase Console, the only thing left to do is to link the services to your app. You can do it this way:

  1. Open firebase_bro.py

  2. Remember the config.txt file which we created earlier? Open it up and copy the contents of firebaseConfig into config variable inside firebase_bro.py.

  3. Save the File.

Voila! You have Successfully set up Firebase into your app!

Removing FIREBASE 👋 👋

If you do not want to use firebase please feel free to:

  • Remove the firebase_bro.py file from the current working directory

  • Delete the following lines from the app.py file:

    • import firebase_bro.

    • firebase_bro.send_img(image) line inside the Home block of the if else condition.

    • firebase_bro.send_feedback(first_name, last_name, user_email, feedback) line inside the Feedback block of the if else condition.

  • Also remove firebase and all the lines below the comment For Handling firebase and pyrebase dependency issues in the requirements.txt

REMEMBER: The current version of the app only supports jpg, png and jpeg images as input

E. Testing 🧪 the app Locally

  • Now, we are all set to test our prototype!

  • Open the terminal/command prompt and type

$ streamlit run app.py
  • Give it a few seconds to start on your local server, load Tensorflow and other cool stuff the app requires in order to function properly.

  • Upload Your Image, Click on Predict, Verify the working

NOTE: If you face any difficulties please raise an issue and let me know

Congrats! You have successfully deployed your models

F. Hosting the App 🚛

If you wish to share this as a prototype for others to try or showcase it to your friends and collegeues, please follow these steps:

Pushing the code to GitHub

  1. Create a new github repository with an approriate name say my my_app ( DO NOT ADD LICENSE, README, CODE OF CONDUCT, GITIGNORE files at this moment)

Depending upon your preference, you can make the repository private or public

  1. Open the Terminal/Command Prompt once again

  2. Make new folder having the same name as the github repository name

mkdir my_app
  1. Now let's copy all the files of the folder containing our prototype to this folder
cp -a ./img_ai_app_boilerplate/. ./my_app/
  1. Navigate to the location of the above newly created directory

cd my_app

  1. After copying, please feel free to remove the documentation related files that are unnecessary for your prototype
rm -r Guides\
rm LICSENSE CODE_OF_CONDUCT.md CONTRIBUTING.md README.MD
rm -r assets\readme_assets\
  1. Intiatilize the directory as a git repository
git init
  1. Set remote to your repository on GitHub( Copy the link of the repository from the Address Bar)
git remote add origin https://github.com/your_github_username/my_app.git 
  1. Track and commit the current changes
git add .
git commit -m "v.0.0.1"
  1. Push the changes to your remote repository on GitHub
git push origin main
  1. Once successsfull, close the terminal.

  2. Go to GitHub and locate the repository to check if the changes are reflected

  3. Now Add your own custom:

    • README.MD file (To descibe your project in brief)
    • LICENSE file (This depends upon you. I prefer going with MIT License for my open source repositories)
    • CODE_OF_CONDUCT.MD ( GitHub already provides a template for this)
    • Short Repository Description on the right
    • Relevant Tags

Hosting using a cloud service :

Now as per your choice of hosting, please refer the following guides:

Code of Conduct

License

Future Work 🏗

  • Improve the UI of the app using custom HTML,CSS or REACT
  • Make the App more descriptive
  • Guide for Deployment to Digital Ocean
  • Guide for Deployment to GCP
  • Guide for Deployment to AWS
  • Guide for Deployment to Azure
  • Add Favicon option, Improve SEO
  • Add Multiple Pages
    • Contact Page
    • About Page
    • Feedback Page
  • Support for PyTorch models
  • Support for MXNET models
  • Support for saved_model TF format
  • Add Animations
  • Dark Mode
  • Similar Efforts for a mobile app using TFLite + Flutter ( From building to serving)
  • Experiment with TFJS

If this project helped you, do give it a 🌟 on GitHub and share your work over LinkedIN and/or Twitter by tagging me!

Comments
  • Write a guide for deploying the app to Linode 🐱‍💻

    Write a guide for deploying the app to Linode 🐱‍💻

    • Please name it Linode_Guide.MD
    • Place it inside the Guides/ directory of the master branch
    • Have a look at the other guides and elaborately describe the process ( It would be appreciated if the process of registration is also highlighted but optional)
    • Add Snapshots of the process as and where required
    • Add Useful Tips section for certain optimizations, bug fixing advice and cite corresponding references
    DWOC SWoC2021 
    opened by smaranjitghose 3
  • Tried to Clean and Organise the Readme file

    Tried to Clean and Organise the Readme file

    Made a separate guide to set up Firebase in the app and linked it to the Readme. Also edited Heroku guide for typos and in general formatting.

    Also ticked the multiple pages option in Further work since it was completed :)

    documentation hacktoberfest-accepted PR: merged slop2020 
    opened by ThenoobMario 3
  • Added Multiple Pages

    Added Multiple Pages

    #9

    Added multiple pages with Firebase support to store user feedback, along with a Feedback.MD guide which walks through the process of setting up Firebase in the app.

    Also grouped the already existing guides into its own dedicated folder for easy navigation.

    hacktoberfest-accepted PR: merged slop2020 
    opened by ThenoobMario 2
  • Remove GIFs from readme file

    Remove GIFs from readme file

    As we know that, A readme file lets you know about the repo as well as attracting contributors to contribute in it. But, readme file included in your repo is loosing grip in both of the roles, because of the GIFs mentioned in it, They create an informal image of your repo, which is not good, In order to maintain formality of your readme file, Let me remove the gifs and insert some catching sentences instead. This is regarding crosswoc,

    opened by stlyash 1
  • README BADGES

    README BADGES

    Hi @smaranjitghose

    I would like to contribute to this repository by making nice badges , Let me know if you are interested in

    Kindly do assign me

    readme1

    The above image is a example

    opened by akrish4 1
  • ADD ISSUE_TEMPLATE

    ADD ISSUE_TEMPLATE

    Hello there, I would like to add an issue template for your repository. This template would have four issues namely bug, documentation, feature, proposal. Kindly assign me this issue as a part of DWOC. THANK YOU

    opened by tharunc 1
  • Integrate Welcome and Greeting Bot

    Integrate Welcome and Greeting Bot

    Hi @smaranjitghose I would like to contribute to this project by adding a welcome and greeting bot which will comment up when any user will open up with an issue or pull-request for the first time Kindly do assign me this issue @smaranjitghose ( config file having a proper message)

    For reference, kindly check out: https://github.com/apps/welcome

    opened by akrish4 1
  • Integrate Welcome Bot

    Integrate Welcome Bot

    Hello there, I can add a welcome bot config file having a proper message that will show up when any user will open up an issue or pull-request for the first time as a part of DWOC. Please assign me this issue.
    For reference, kindly check out: https://github.com/apps/welcome THANK YOU

    opened by tharunc 1
  • Do we need a Python Linter for PRs?

    Do we need a Python Linter for PRs?

    I was just wondering that should we have a PyLint or flake8 linters for this repo to rate the code style of incoming PRs?

    PyLint score can make the life of reviews comparatively easier.

    opened by vybhav72954 0
  • I will add banner of crosswoc to the readme file

    I will add banner of crosswoc to the readme file

    I will add banner of crosswoc to the readme file. Moreover, I will associate link of the crosswoc website to its banner such that, if someone clicks the banner on readme file, it will redirect them to the website of crosswoc.

    deprecated 
    opened by stlyash 0
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    Beep boop. Your images are optimized!

    Your image file size has been reduced by 68% 🎉

    Details

    | File | Before | After | Percent reduction | |:--|:--|:--|:--| | /Guides/images/5_linode.jpg | 741.85kb | 129.37kb | 82.56% | | /Guides/images/1_linode.jpg | 764.18kb | 200.62kb | 73.75% | | /Guides/images/4_linode.jpg | 855.70kb | 224.77kb | 73.73% | | /Guides/images/3_linode.png | 236.15kb | 145.34kb | 38.46% | | /Guides/images/2_linode.png | 217.35kb | 135.28kb | 37.76% | | /Guides/images/6_linode.png | 95.12kb | 64.71kb | 31.97% | | /Guides/StreamlitDeploy.png | 47.28kb | 33.73kb | 28.65% | | /Guides/StreamlitNewAppOption.png | 28.61kb | 21.51kb | 24.81% | | | | | | | Total : | 2,986.23kb | 955.32kb | 68.01% |


    Black Lives Matter | 💰 donate | 🎓 learn | ✍🏾 sign

    📝 docs | :octocat: repo | 🙋🏾 issues | 🏅 swag | 🏪 marketplace

    PR: merged 
    opened by imgbot[bot] 0
  • TFJS template 101

    TFJS template 101

    • Work on the TFJS branch
    • Remove all python related code (eg: app.py,image_classifier.py`)
    • Remove all existing guides inside the Guides\ directory of the TFJS branch
    • Remove all dockerfiles ( Including dockerignore)
    • Write a simple code (Minimum HTML&CSS) to upload an image, load a model saved in TFJS format and give inference below (identify the label)
    • When you give the PR, send a link to the working Deploy on GitHub pages
    • Use custom trained models!!
    DWOC SWoC2021 
    opened by smaranjitghose 2
  • Technical Documentation Website

    Technical Documentation Website

    Requirements:

    • Home Page:
      • Information about Project
      • Open Source : - Programs we are a part of: info about SLOP, SWOC,DWOC - Contribution Guide - Code of Conduct - License
      • Team - Project Maintainer
        - Project Contributor
    • Getting Started:
      - Using this repo as a template on GitHub
      - Getting the source code locally
      - Model Integration
      - Updating Model Files
      - Updating the Image Classifier Script
      - Front End Changes
      - Home Page [ Of the app] - - Team Page
      - About Page - Firebase and more Pages!
      - Setup Firebase for the project
      - Store Configuration Files to reference Firebase Project
      - Setup Real time database for the project
      - Update the Contact Page
      - Setup Cloud Storage for the project - - Update the function to send images - - Remove Firebase(If not required)
    • Deployment
      - Staging, Commiting and Pushing Changes to GitHub - Cloud Services: - Heroku
      - Google Cloud Services
      - Amazon Web Services - - Microsoft Azure
      - Digital Ocean
      - Linode
      - Python Everywhere

    Directions:

    • Package to be used: mkdocs
    • Template to be followed: Material
    • Branch to be pushed: gh-pages [the deploy], master[the docs/ directory inside which the documentation would be present] - Please gitignore everything under site/

    References:

    NOTE:

    • Please only take up the this issue once you are fully comfortable with using and hosting docs with mkdocs.
    • This issue is not be done all at once but in various parts. Whenever you comment interested, just specify which part of the documentation you want to build
    • If the information for the part is not available, please wait for it be available (like Guide for Digital Ocean), this issue has be worked upon in parallel with the others. Only take up tasks for which the information is updated
    • The source code to a similar documentation is already given above, and feel free to use YouTube for learning
    DWOC SWoC2021 
    opened by smaranjitghose 7
  • Adding support for Gluon Models 🤖🛒

    Adding support for Gluon Models 🤖🛒

    • Rename the function our_image_classifier to img_class_tf in the image_classifier.py file
    • Write another function img_class_torch and define to load an image, convert it to the necessary numpy array (or any form you deem necessary, load a gluon model ( giving the PR, test it with any custom trained model and attach the video clip of the working demo), run inference and return the result.
    • Note how the labels are defined.
    • Feel free to add try-except statements for better debugging
    DWOC SWoC2021 
    opened by smaranjitghose 0
  • Adding Support for PyTorch Models 🤖

    Adding Support for PyTorch Models 🤖

    • Rename the function our_image_classifier to img_class_tf in the image_classifier.py
    • Write another function img_class_torch and define to load an image, convert it to the necessary numpy array (or any form you deem necessary, load a pytorch model (just make a blank model.pth file in the models folder for reference but before giving the PR, test it with any custom trained model and attach the video clip of the working demo), run inference and return the result.
    • Note how the labels are defined.
    • Feel free to add try catch statements for better debugging
    DWOC SWoC2021 
    opened by smaranjitghose 0
Releases(v0.0.1)
An attempt at the implementation of Glom, Geoffrey Hinton's new idea that integrates neural fields, predictive coding, top-down-bottom-up, and attention (consensus between columns)

GLOM - Pytorch (wip) An attempt at the implementation of Glom, Geoffrey Hinton's new idea that integrates neural fields, predictive coding,

Phil Wang 173 Dec 14, 2022
YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )

Yolo v4, v3 and v2 for Windows and Linux (neural networks for object detection) Paper YOLO v4: https://arxiv.org/abs/2004.10934 Paper Scaled YOLO v4:

Alexey 20.2k Jan 09, 2023
Contrastive Language-Image Pretraining

CLIP [Blog] [Paper] [Model Card] [Colab] CLIP (Contrastive Language-Image Pre-Training) is a neural network trained on a variety of (image, text) pair

OpenAI 11.5k Jan 08, 2023
Install alphafold on the local machine, get out of docker.

AlphaFold This package provides an implementation of the inference pipeline of AlphaFold v2.0. This is a completely new model that was entered in CASP

Kui Xu 73 Dec 13, 2022
Code for the TASLP paper "PSLA: Improving Audio Tagging With Pretraining, Sampling, Labeling, and Aggregation".

PSLA: Improving Audio Tagging with Pretraining, Sampling, Labeling, and Aggregation Introduction Getting Started FSD50K Recipe AudioSet Recipe Label E

Yuan Gong 84 Dec 27, 2022
StackNet is a computational, scalable and analytical Meta modelling framework

StackNet This repository contains StackNet Meta modelling methodology (and software) which is part of my work as a PhD Student in the computer science

Marios Michailidis 1.3k Dec 15, 2022
Implementation of Stochastic Image-to-Video Synthesis using cINNs.

Stochastic Image-to-Video Synthesis using cINNs Official PyTorch implementation of Stochastic Image-to-Video Synthesis using cINNs accepted to CVPR202

CompVis Heidelberg 135 Dec 28, 2022
Mmdet benchmark with python

mmdet_benchmark 本项目是为了研究 mmdet 推断性能瓶颈,并且对其进行优化。 配置与环境 机器配置 CPU:Intel(R) Core(TM) i9-10900K CPU @ 3.70GHz GPU:NVIDIA GeForce RTX 3080 10GB 内存:64G 硬盘:1T

杨培文 (Yang Peiwen) 24 May 21, 2022
Score refinement for confidence-based 3D multi-object tracking

Score refinement for confidence-based 3D multi-object tracking Our video gives a brief explanation of our Method. This is the official code for the pa

Cognitive Systems Research Group 47 Dec 26, 2022
This is the code for our paper "Iconary: A Pictionary-Based Game for Testing Multimodal Communication with Drawings and Text"

Iconary This is the code for our paper "Iconary: A Pictionary-Based Game for Testing Multimodal Communication with Drawings and Text". It includes the

AI2 6 May 24, 2022
Code for C2-Matching (CVPR2021). Paper: Robust Reference-based Super-Resolution via C2-Matching.

C2-Matching (CVPR2021) This repository contains the implementation of the following paper: Robust Reference-based Super-Resolution via C2-Matching Yum

Yuming Jiang 151 Dec 26, 2022
MGFN: Multi-Graph Fusion Networks for Urban Region Embedding was accepted by IJCAI-2022.

Multi-Graph Fusion Networks for Urban Region Embedding (IJCAI-22) This is the implementation of Multi-Graph Fusion Networks for Urban Region Embedding

202 Nov 18, 2022
Official PyTorch implementation of the paper "Graph-based Generative Face Anonymisation with Pose Preservation" in ICIAP 2021

Contents AnonyGAN Installation Dataset Preparation Generating Images Using Pretrained Model Train and Test New Models Evaluation Acknowledgments Citat

Nicola Dall'Asen 10 May 24, 2022
A video scene detection algorithm is designed to detect a variety of different scenes within a video

Scene-Change-Detection - A video scene detection algorithm is designed to detect a variety of different scenes within a video. There is a very simple definition for a scene: It is a series of logical

1 Jan 04, 2022
LOFO (Leave One Feature Out) Importance calculates the importances of a set of features based on a metric of choice,

LOFO (Leave One Feature Out) Importance calculates the importances of a set of features based on a metric of choice, for a model of choice, by iteratively removing each feature from the set, and eval

Ahmet Erdem 691 Dec 23, 2022
Scheduling BilinearRewards

Scheduling_BilinearRewards Requirement Python 3 =3.5 Structure main.py This file includes the main function. For getting the results in Figure 1, ple

junghun.kim 0 Nov 25, 2021
6D Grasping Policy for Point Clouds

GA-DDPG [website, paper] Installation git clone https://github.com/liruiw/GA-DDPG.git --recursive Setup: Ubuntu 16.04 or above, CUDA 10.0 or above, py

Lirui Wang 48 Dec 21, 2022
Dynamic Token Normalization Improves Vision Transformers

Dynamic Token Normalization Improves Vision Transformers This is the PyTorch implementation of the paper Dynamic Token Normalization Improves Vision T

Wenqi Shao 20 Oct 09, 2022
This is the official code for the paper "Ad2Attack: Adaptive Adversarial Attack for Real-Time UAV Tracking".

Ad^2Attack:Adaptive Adversarial Attack on Real-Time UAV Tracking Demo video 📹 Our video on bilibili demonstrates the test results of Ad^2Attack on se

Intelligent Vision for Robotics in Complex Environment 10 Nov 07, 2022
Few-Shot-Intent-Detection includes popular challenging intent detection datasets with/without OOS queries and state-of-the-art baselines and results.

Few-Shot-Intent-Detection Few-Shot-Intent-Detection is a repository designed for few-shot intent detection with/without Out-of-Scope (OOS) intents. It

Jian-Guo Zhang 73 Dec 26, 2022