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. 기타

  • 여러 데이터를 한 번에 인퍼런스 할 경우 고려하기
  • 인퍼런스가 돌 때 추가 호출이 올 경우 고려하기
  • 배치성, 실시간성, 큐에 넣고 한 번에 동작 등 여러 시나리오 고려 하기
Owner
Ben Seo
데린이
Ben Seo
Nerf pl - NeRF (Neural Radiance Fields) and NeRF in the Wild using pytorch-lightning

nerf_pl Update: an improved NSFF implementation to handle dynamic scene is open! Update: NeRF-W (NeRF in the Wild) implementation is added to nerfw br

AI葵 1.8k Dec 30, 2022
Pytorch codes for Feature Transfer Learning for Face Recognition with Under-Represented Data

FTLNet_Pytorch Pytorch codes for Feature Transfer Learning for Face Recognition with Under-Represented Data 1. Introduction This repo is an unofficial

1 Nov 04, 2020
A repository for benchmarking neural vocoders by their quality and speed.

License The majority of VocBench is licensed under CC-BY-NC, however portions of the project are available under separate license terms: Wavenet, Para

Meta Research 177 Dec 12, 2022
Re-implememtation of MAE (Masked Autoencoders Are Scalable Vision Learners) using PyTorch.

mae-repo PyTorch re-implememtation of "masked autoencoders are scalable vision learners". In this repo, it heavily borrows codes from codebase https:/

Peng Qiao 1 Dec 14, 2021
Transformer model implemented with Pytorch

transformer-pytorch Transformer model implemented with Pytorch Attention is all you need-[Paper] Architecture Self-Attention self_attention.py class

Mingu Kang 12 Sep 03, 2022
Running Google MoveNet Multipose Tracking models on OpenVINO.

MoveNet MultiPose Tracking on OpenVINO

60 Nov 17, 2022
Neural network for stock price prediction

neural_network_for_stock_price_prediction Neural networks for stock price predic

2 Feb 04, 2022
A curated list of the latest breakthroughs in AI (in 2021) by release date with a clear video explanation, link to a more in-depth article, and code.

2021: A Year Full of Amazing AI papers- A Review 📌 A curated list of the latest breakthroughs in AI by release date with a clear video explanation, l

Louis-François Bouchard 2.9k Dec 31, 2022
An original implementation of "MetaICL Learning to Learn In Context" by Sewon Min, Mike Lewis, Luke Zettlemoyer and Hannaneh Hajishirzi

MetaICL: Learning to Learn In Context This includes an original implementation of "MetaICL: Learning to Learn In Context" by Sewon Min, Mike Lewis, Lu

Meta Research 141 Jan 07, 2023
A flexible and extensible framework for gait recognition.

A flexible and extensible framework for gait recognition. You can focus on designing your own models and comparing with state-of-the-arts easily with the help of OpenGait.

Shiqi Yu 335 Dec 22, 2022
A Joint Video and Image Encoder for End-to-End Retrieval

Frozen️ in Time ❄️ ️️️️ ⏳ A Joint Video and Image Encoder for End-to-End Retrieval project page | arXiv | webvid-data Repository containing the code,

225 Dec 25, 2022
Pytorch cuda extension of grid_sample1d

Grid Sample 1d pytorch cuda extension of grid sample 1d. Since pytorch only supports grid sample 2d/3d, I extend the 1d version for efficiency. The fo

lyricpoem 24 Dec 03, 2022
3D AffordanceNet is a 3D point cloud benchmark consisting of 23k shapes from 23 semantic object categories, annotated with 56k affordance annotations and covering 18 visual affordance categories.

3D AffordanceNet This repository is the official experiment implementation of 3D AffordanceNet benchmark. 3D AffordanceNet is a 3D point cloud benchma

49 Dec 01, 2022
Gesture-Volume-Control - This Python program can adjust the system's volume by using hand gestures

Gesture-Volume-Control This Python program can adjust the system's volume by usi

VatsalAryanBhatanagar 1 Dec 30, 2021
Code of the paper "Part Detector Discovery in Deep Convolutional Neural Networks" by Marcel Simon, Erik Rodner and Joachim Denzler

Part Detector Discovery This is the code used in our paper "Part Detector Discovery in Deep Convolutional Neural Networks" by Marcel Simon, Erik Rodne

Computer Vision Group Jena 17 Feb 22, 2022
Code for the paper "Offline Reinforcement Learning as One Big Sequence Modeling Problem"

Trajectory Transformer Code release for Offline Reinforcement Learning as One Big Sequence Modeling Problem. Installation All python dependencies are

Michael Janner 266 Dec 27, 2022
Pytorch implementation of TailCalibX : Feature Generation for Long-tail Classification

TailCalibX : Feature Generation for Long-tail Classification by Rahul Vigneswaran, Marc T. Law, Vineeth N. Balasubramanian, Makarand Tapaswi [arXiv] [

Rahul Vigneswaran 34 Jan 02, 2023
PiRank: Learning to Rank via Differentiable Sorting

PiRank: Learning to Rank via Differentiable Sorting This repository provides a reference implementation for learning PiRank-based models as described

54 Dec 17, 2022
Tutorial in Python targeted at Epidemiologists. Will discuss the basics of analysis in Python 3

Python-for-Epidemiologists This repository is an introduction to epidemiology analyses in Python. Additionally, the tutorials for my library zEpid are

Paul Zivich 120 Nov 17, 2022
TensorFlow implementation of "Learning from Simulated and Unsupervised Images through Adversarial Training"

Simulated+Unsupervised (S+U) Learning in TensorFlow TensorFlow implementation of Learning from Simulated and Unsupervised Images through Adversarial T

Taehoon Kim 569 Dec 29, 2022