How mhw32/derm-ai works
Project type and purpose
• Project type: A backend API service wrapping a deep-learning model (PyTorch) for skin-disease classification. It includes an offline data-scraping + training pipeline and an online inference service (Flask) deployed (via Procfile/runtime.txt) to Heroku.
• Purpose:
– Offline: scrape raw images, precompute embeddings, train a fine-tuned ResNet152 + custom FC layers, produce a “best” model file.
– Online: expose a single POST /predict endpoint that accepts a base64 image and returns a predicted class + score.
File structure
Top-level:
• run.py → entrypoint for the Flask app
• scraper.py → scripts to download/prepare raw images
• train.py → training script for the model
• setup.sh → installs dependencies; downloads raw images & embeddings; pulls pretrained model
• model.py → defines the PyTorch network architecture (ResNet152 + 2 FC layers)
• config.py → centralizes paths, hyperparameters, environment flags
• requirements.txt → Python dependencies (Flask, torch, torchvision, etc.)
• Procfile + runtime.txt → deployment config for Heroku
• trained_models/ → serialized model checkpoint (model_best.pth.tar)
Subfolders:
• app/ → Flask application package
– views.py → HTTP routes (POST /predict)
– helper.py → image decoding, preprocessing logic
• utils/ → shared utilities
– data.py → dataset loaders, transforms
– embeddings.py → code to generate ResNet152 embeddings
No traditional database; models and data live on the file system.
Pull additional insights from README
• Uses pretrained ResNet152 from ImageNet; fine-tune by adding 2 FC layers
• Accuracy ~53% on held-out test data
• Single endpoint: /predict expects { "image": "<base64>" }, returns { "class": X, "score": Y }
a. Main components
1. Client (Consumer of the API)
2. Web/API Layer
– Flask app (run.py → app/views.py → uses helper.py)
3. Inference Engine
– model.py loads model_best.pth.tar using PyTorch
– utils/data.py & helper.py handle transforms (resize, normalize)
4. Offline Pipeline
– Scraper (scraper.py) to pull images from DermNet
– Embedding generator (utils/embeddings.py) to precompute ResNet features
– Training module (train.py) which uses data.py and model.py to train & save checkpoint
5. File Storage
– Raw images (train/, test/)
– Embeddings (train_emb/, test_emb/)
– Trained model (trained_models/)
6. Deployment
– Heroku (Procfile, runtime.txt)
– setup.sh for one-click bootstrap
b. Relationships & interactions
– Client → (HTTP POST) → Flask API /predict
– API layer → loads model checkpoint → performs inference → returns JSON
– Offline pipeline components chained: Scraper → Raw image store → Embedding generator → Embedding store → Trainer → Model store
– Deployment config picks up run.py, requirements.txt, runtime.txt
c. Architectural patterns / design principles
– Separation of concerns:
• API layer vs. ML logic vs. data utilities
– Reuse of pretrained model (transfer learning)
– Monolithic service (single process), but logically layered
– Offline vs. online components clearly separated
d. Key technologies / frameworks
– Flask (web framework)
– PyTorch + torchvision (deep learning)
– Heroku (PaaS for deployment)
– Python scripting (scraper, training, setup)
Key reminders
• Python modules that perform distinct roles (app/, utils/, model.py, scraper.py, train.py).
• Both offline and online workflows and how they share the model artifact.