RoAdCast - Flask + PyTorch CNN starter
This project contains a minimal Flask app and a small PyTorch CNN scaffold so you can train and run a model directly from VS Code.
Quick setup (Windows PowerShell):
- Create and activate a virtual environment
python -m venv .venv
.\.venv\Scripts\Activate.ps1
- Install dependencies
pip install -r requirements.txt
- Dataset layout
Image dataset (folder-per-class):
data/ class1/ img1.jpg class2/ img2.jpg
CSV dataset (single file):
data.csv (expects a label column and numeric feature columns)
Train commands:
Image training (default cnn):
python train.py data --epochs 5 --batch-size 16
CSV/tabular training (MLP):
python train.py data.csv --model-type mlp --epochs 20 --batch-size 64
The model will be saved as model.pth in the repo root (best validation checkpoint).
Run the Flask app (for local testing):
python app.py
Predict using curl (or Postman). Example with curl in PowerShell:
curl -X POST -F "image=@path\to\image.jpg" http://127.0.0.1:5000/predict
VS Code tips
- Open this folder in VS Code.
- Use the Python extension and select the
.venvinterpreter. - Use the Run panel to add a launch configuration that runs
app.pyortrain.py. - For long training runs, run training in the terminal (not the debugger) and monitor logs.
Notes & next steps
- The SimpleCNN uses 224x224 input and expects at least two maxpool steps; adjust
models.pyif you want smaller inputs. - Add better transforms and augmentation in
data.pyfor better performance. - If GPU is available, PyTorch will use it automatically if installed with CUDA.