How m-hasan-code/pytorch-cnn-with-fastapi works
This is a FastAPI inference service for classifying uploaded MRI-compatible images with a pretrained four-class PyTorch CNN. The workflow is: a client uploads an image, the prediction endpoint validates and reads it, preprocessing converts it to a grayscale tensor, the model produces class probabilities, and the endpoint returns the predicted class and confidence as JSON. The CNN and serving logic are in main.py. The README describes the pretrained model, but the referenced my_model.pth file is not present in the supplied tree.
Main entry points: main.py Prediction endpoint
Components 6
API serving
- Prediction endpoint
main.py - Prediction JSON
main.py
Model inference
- Image preprocessing
main.py - CNN classifier
main.py - Model weights
Other components
- Image client
Connections 5
- Image client → Prediction endpoint: uploads image
- Prediction endpoint → Image preprocessing: preprocesses
- Prediction endpoint → CNN classifier: runs inference
- Model weights → CNN classifier: loads weights
- Prediction endpoint → Prediction JSON: returns result