This was a project of mine that was built using PyTorch to classify the images from the CIFAR-100 dataset. I attempted to build my own model without using any pretrained model from online, in an effort to improve my machine learning skills and understanding. The final model achieves close to 70% test accuracy.
The model is deployed using a full stack web application being powered by FastAPI on the backend for serving the model and a React + TypeScript frontend. Drag and drop any image of your choice onto the frontend and see what the model predicted for you!
Navigate to the /backend folder and run
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
Make sure Redis server is also running on your machine for background jobs to work. The redis server can be started by running the Docker image locally on port 6379.
Navigate to the /frontend folder and run
npm start
Topics that I learned while doing this project:
- Convolutional Neural Network (CNN) architecture
- Image transforms from PyTorch
- Max Pooling and BatchNorm2d
- Tensor operations in the classifier
- Optimizing dataloader operations in PyTorch
- Calculating metrics like precision and recall using torchmetrics
- Using torch compile to compile my model
- How to use AdamW optimizer and setting its parameters
- Cosine learning rate schedulers and how to optimize it
- Using GradScalar for mixed precision training
- Using early stopping when model reaches plateau in training
- Validation using model.eval() every few epochs
- Saving my model and making sure state dictionaries don't have missing keys
- Fusing layers during evaluation
- Pruning models
- Optimizing CUDA
- How to serve a model and do inference in FastAPI.
- Using thread pool for backend serving
- Learned how to use psutil library
- Learned 5 new API security headers and why they are important.
- Using Kaiming init for initializing neural networks
- Test Time Augmentation for improving test time accuracy
- Trying to minimize the memory of a model by garbage collection and reduced precision
- Implementing OAuth 2.0 connection to GitHub, on frontend and backend
- Deploying a model on HuggingFace Spaces
- Learning how to log hyperparameters onto MLflow
- Use a HuggingFace pretrained model for image captioning
- Use WebSockets to stream tokens from backend to frontend for image captioning
- Use Redis to manage background jobs for image captioning
- Use Dataclasses in Python
