Deploy pytorch classification model using Flask and Streamlit

Overview

Tomato Disease Classification Model Deploy




1. Streamlit이란?

  • 데모 형식으로 웹을 만들 수 있는 프레임워크
  • 단점 : Interactive (파라미터, input shape, batch size 등 사용자가 화면에서 선택 할 경우) 한 동작이 발생 할 경우 새로 고침이 됨 -> form과 submit 이용해야 함



2. How to run

1-1) 플라스크 API 서버 (모델 서빙) : python flask_server.py
  • 터미널을 열어 플라스크 API 서버 (모델 서빙)을 먼저 실행 합니다.
1-2) (Option) 플라스크 API 서버 (모델 서빙) 테스트 : python flask_test.py
  • '필요 시' 터미널을 열어 플라스크 API 서버 (모델 서빙)을 테스트 합니다.
2-1) Streamlit : streamlit run streamlit.py
  • 터미널을 열어 Stremlit으로 개발 된 데모 웹 페이지를 실행 합니다.
2-2) 사용자는 http://127.0.0.1:5000/으로 웹 페이지에 접근 가능 합니다.



3. DIR 구조 설명

  • inference/ : 인퍼런스가 진행 되는 로직입니다. (학습 된 모델을 폴더 구조에 넣어 두고 > 모델을 미리 정의 해 둔 틀에 끼워서 로드 한 후 > 정규화 해서 > 요청이 들어 올 때 마다 결과 출력 하여 반환)
  • inference_image/ : 인퍼런스 할 이미지를 담는 곳입니다. (테스트 용)
  • model/ : 학습 된 모델 '틀'을 담는 곳입니다.
  • trained_model/ : 학습 된 모델을 담는 곳입니다.
  • flask_server.py : 플라스크 API 서버 (모델 서빙) 실행 파일
  • flask_test.py : 플라스크 API 서버 (모델 서빙) 테스트 파일
  • requirements.txt : 필요 라이브러리 설치
  • streamlit.py : 스트림릿 데모 웹 페이지



4. 프로젝트 진행 순서

1) 토마토 잎 분류 best 모델 저장
2) 플라스크 API 서버 (모델 서빙) 개발
3) 플라스크 API 서버 (모델 서빙) 테스트
4) 스트림릿 데모 웹 페이지 개발



5. 아키텍쳐 설명

1) 인퍼런스 로직 (PyTorch)
  • 학습 된 모델 로드 (나의 best 모델을 로컬 특정 폴더에 위치 시키기!)
  • 인풋 이미지 정규화
  • Request 발생 시 인퍼런스 결과 반환

2) 모델 서빙 (Flask)
  • Request 이미지 파일
  • 인퍼런스 로직 적용
  • 요청이 들어 올 때 마다 인퍼런스 결과 반환

3) 웹 페이지 (Streamlit)
  • 사용자가 이미지 업로드
  • 플라스크 API 서버로 이미지 request
  • 인퍼런스 진행 된 response 결과 파싱
  • Streamlit 화면에 뿌림



6. 기타

  • 여러 데이터를 한 번에 인퍼런스 할 경우 고려하기
  • 인퍼런스가 돌 때 추가 호출이 올 경우 고려하기
  • 배치성, 실시간성, 큐에 넣고 한 번에 동작 등 여러 시나리오 고려 하기
You might also like...
Step by Step on how to create an vision recognition model using LOBE.ai, export the model and run the model in an Azure Function
Step by Step on how to create an vision recognition model using LOBE.ai, export the model and run the model in an Azure Function

Step by Step on how to create an vision recognition model using LOBE.ai, export the model and run the model in an Azure Function

This project deploys a yolo fastest model in the form of tflite on raspberry 3b+. The model is from another repository of mine called -Trash-Classification-Car
This project deploys a yolo fastest model in the form of tflite on raspberry 3b+. The model is from another repository of mine called -Trash-Classification-Car

Deploy-yolo-fastest-tflite-on-raspberry 觉得有用的话可以顺手点个star嗷 这个项目将垃圾分类小车中的tflite模型移植到了树莓派3b+上面。 该项目主要是为了记录在树莓派部署yolo fastest tflite的流程 (之后有时间会尝试用C++部署来提升

Implement face detection, and age and gender classification, and emotion classification.
Implement face detection, and age and gender classification, and emotion classification.

YOLO Keras Face Detection Implement Face detection, and Age and Gender Classification, and Emotion Classification. (image from wider face dataset) Ove

Image Classification - A research on image classification and auto insurance claim prediction, a systematic experiments on modeling techniques and approaches

A research on image classification and auto insurance claim prediction, a systematic experiments on modeling techniques and approaches

A python-image-classification web application project, written in Python and served through the Flask Microframework. This Project implements the VGG16 covolutional neural network, through Keras and Tensorflow wrappers, to make predictions on uploaded images.  Keywords : Streamlit, BertTokenizer, BertForMaskedLM, Pytorch
Keywords : Streamlit, BertTokenizer, BertForMaskedLM, Pytorch

Next Word Prediction Keywords : Streamlit, BertTokenizer, BertForMaskedLM, Pytorch 🎬 Project Demo ✔ Application is hosted on Streamlit. You can see t

PyTorch trainer and model for Sequence Classification

PyTorch-trainer-and-model-for-Sequence-Classification After cloning the repository, modify your training data so that the training data is a .csv file

A python-image-classification web application project, written in Python and served through the Flask Microframework
A python-image-classification web application project, written in Python and served through the Flask Microframework

A python-image-classification web application project, written in Python and served through the Flask Microframework. This Project implements the VGG16 covolutional neural network, through Keras and Tensorflow wrappers, to make predictions on uploaded images.

Deploy tensorflow graphs for fast evaluation and export to tensorflow-less environments running numpy.
Deploy tensorflow graphs for fast evaluation and export to tensorflow-less environments running numpy.

Deploy tensorflow graphs for fast evaluation and export to tensorflow-less environments running numpy. Now with tensorflow 1.0 support. Evaluation usa

Owner
Ben Seo
데린이
Ben Seo
Using Streamlit to host a multi-page tool with model specs and classification metrics, while also accepting user input values for prediction.

Predicitng_viability Using Streamlit to host a multi-page tool with model specs and classification metrics, while also accepting user input values for

Gopalika Sharma 1 Nov 8, 2021
Streamlit App For Product Analysis - Streamlit App For Product Analysis

Streamlit_App_For_Product_Analysis Здравствуйте! Перед вами дашборд, позволяющий

Grigory Sirotkin 1 Jan 10, 2022
🍅🍅🍅YOLOv5-Lite: lighter, faster and easier to deploy. Evolved from yolov5 and the size of model is only 1.7M (int8) and 3.3M (fp16). It can reach 10+ FPS on the Raspberry Pi 4B when the input size is 320×320~

YOLOv5-Lite:lighter, faster and easier to deploy Perform a series of ablation experiments on yolov5 to make it lighter (smaller Flops, lower memory, a

pogg 1.5k Jan 5, 2023
Example how to deploy deep learning model with aiohttp.

aiohttp-demos Demos for aiohttp project. Contents Imagetagger Deep Learning Image Classifier URL shortener Toxic Comments Classifier Moderator Slack B

aio-libs 661 Jan 4, 2023
Simple-Image-Classification - Simple Image Classification Code (PyTorch)

Simple-Image-Classification Simple Image Classification Code (PyTorch) Yechan Kim This repository contains: Python3 / Pytorch code for multi-class ima

Yechan Kim 8 Oct 29, 2022
This repo is about to create the Streamlit application for given ML model.

HR-Attritiion-using-Streamlit This repo is about to create the Streamlit application for given ML model. Problem Statement: Managing peoples at workpl

Pavan Giri 0 Dec 10, 2021
Implementation of STAM (Space Time Attention Model), a pure and simple attention model that reaches SOTA for video classification

STAM - Pytorch Implementation of STAM (Space Time Attention Model), yet another pure and simple SOTA attention model that bests all previous models in

Phil Wang 109 Dec 28, 2022
Patient-Survival - Using Python, I developed a Machine Learning model using classification techniques such as Random Forest and SVM classifiers to predict a patient's survival status that have undergone breast cancer surgery.

Patient-Survival - Using Python, I developed a Machine Learning model using classification techniques such as Random Forest and SVM classifiers to predict a patient's survival status that have undergone breast cancer surgery.

Nafis Ahmed 1 Dec 28, 2021
Hl classification bc - A Network-Based High-Level Data Classification Algorithm Using Betweenness Centrality

A Network-Based High-Level Data Classification Algorithm Using Betweenness Centr

Esteban Vilca 3 Dec 1, 2022
In this project we investigate the performance of the SetCon model on realistic video footage. Therefore, we implemented the model in PyTorch and tested the model on two example videos.

Contrastive Learning of Object Representations Supervisor: Prof. Dr. Gemma Roig Institutions: Goethe University CVAI - Computational Vision & Artifici

Dirk Neuhäuser 6 Dec 8, 2022