How lunar-arun/cat-vs-dog-classifier-resnet18-with-streamlit works
Project Type and Purpose
• This is a monolithic, single‐page Streamlit application for image classification (cats vs. dogs) using a pre‐trained ResNet18 model.
• The codebase bundles the UI, file‐upload logic, model‐loading/inference logic, and assets (model weights, test images) into one process.
File Structure Analysis
Top-level:
• README.md – app description & run instructions
• app.py – entrypoint; Streamlit app definition
• requirements.txt – Python dependencies (streamlit, torch, etc.)
packages/ directory (modular organization):
• model.py – code to load the ResNet18 architecture + weights (dog_cat_classifier.pth) and perform inference
• upload.py – file‐upload handlers and preprocessing logic
• page.py – layout and page‐navigation functions for Streamlit
• default.py – default parameter values and UI constants
• ResNet18_Model/ – stored model weights
• test-images/ – sample images for local testing
Key Insights from README
• The app uses Streamlit to serve a web UI that allows users to upload images.
• On upload, the ResNet18 model (loaded from a .pth file) classifies the image and displays the result.
• No separate backend server or external database—everything runs in‐process.
Main Components
a. User Interface Layer (Streamlit Frontend)
– Components: app.py + packages/page.py + packages/default.py
– Responsibilities: render upload widget, display classification results, handle user interactions.
b. File Upload & Preprocessing
– Component: packages/upload.py
– Responsibilities: accept the image, validate/resize/convert to tensor.
c. Model Inference Engine
– Component: packages/model.py
– Responsibilities: load ResNet18 architecture, load weights (.pth), run forward pass, output probabilities or labels.
d. Local Storage
– Model weights file (dog_cat_classifier.pth)
– Static test images (packages/test-images/)
e. Runtime Environment & Dependencies
– Python interpreter, virtual environment
– Libraries: Streamlit, PyTorch, torchvision, PIL, etc.
Interactions and Data Flow
1. User uploads an image via Streamlit UI →
2. Upload handler (packages/upload.py) preprocesses and sanitizes the image →
3. Preprocessed tensor passed to Model Inference Engine (packages/model.py) →
4. Model outputs a prediction (cat vs. dog) →
5. UI layer receives result and displays it to the user.
Architectural Patterns & Design Principles
• Modularization: separate modules for UI (page.py), upload logic (upload.py), model logic (model.py), and constants (default.py).
• Single‐process monolith: no microservices or external APIs.
• Dependency injection: configuration constants in default.py can be easily modified/tested.
Final Recommendations
a. High‐Level View: UI, Inference Engine, Storage
b. Detailed View: modules within the app (page.py, upload.py, model.py, default.py)
• Component names match file names for easy cross‐reference.