Skip to content

This repo contains training pipeline for Tiny ImageNet dataset and REST API using FastAPI

Notifications You must be signed in to change notification settings

loopdigga96/tiny_imagenet_classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

This repo contains training pipeline on Tiny ImageNet dataset and REST API for classifier using FastAPI

Project structure

- database "contains all necessary functions for storing requests in sqlite"
- modules "contains model and dataset"
- service.py "contains FastAPI wrapper on model"
- train_solution.py "contains whole pipeline"

How to install

  • Create virtualenv with python 3.7
  • pip install -r requirements.txt
  • place dataset in ./data folder

How to train

  • python train_solution.py
  • pytorch-lightning is used for training
  • In results folder will be created folder with experiments with checkpoints and tb_logs
  • to see metrics run tensorboard --log_dir results/name_of_experiment/tb_logs
  • after training; csv file with test predictions will be created

Improvement steps

  • use pre-trained model (+28% acc)
  • resize image while using pre-trained model
  • use better backbone (efficient net)
  • use model with bigger capacity (b0 ef_net vs b4)
  • use normalization params from original ImageNet dataset
  • change optimizer to more robust Adam
  • lower lr while doing fine tuning of pretrained model
  • add scheduler ReduceLROnPlateau(patience=1, min_lr=1e-6, mode='min', factor=0.3)
  • add label smoothing stabilize training (+1% acc)

Possible improvements (that i did not tried):

  • train for longer time (Can't do that because of lack of computing power)
  • make ensemble of models (usually it helps), starting from simple probabilities averaging and take predictions from different efficient nets
  • make tricky augmentations for example from ablumentations
  • try Focal Loss (in my experinece gives an improvement)
  • increase capacity of model for example b7 efficient net (did not tried it because of my small gpu)
  • use SOTA model on ImageNet dataset according to paperswithcode for example efficient net b7 noisy student
  • make even more experiments with optimizer and schedulers. For example use LR Cyclic scheduler, lr warm up and decay
  • use Test Time Augmentations

Result:

  • model: pretrained efficeint_netb4 with label smoothing, Adam, ReduceLROnPlateau, EarlyStopping
  • final val accuaracy: 0.76
  • final csv with test predictions: download

How to run service (FastAPI):

  • download model and place it to results_folder; service will use this checkpoint in inference
  • uvicorn --host 0.0.0.0 service:app --reload
  • POST: 127.0.0.1:8000/predict/
    • curl -X POST "http://127.0.0.1:8000/predict/" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "file=@path_to_image.jpg;type=image/webp"
  • GET: 127.0.0.1:8000/get_all/
    • curl -X GET "http://127.0.0.1:8000/get_all/" -H "accept: application/json"
  • Shows nice UI where you can check all endpoints 127.0.0.1:8000/docs

About

This repo contains training pipeline for Tiny ImageNet dataset and REST API using FastAPI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages