Skip to content

Rust-Cameroon/malaria-model

Repository files navigation

Malaria Detection CNN (Rust + Burn)

Rust License: MIT Build Status Tensor Operations/s WebAssembly Ready Telemedicine

AI system for malaria detection from blood smear images
Implemented in Rust (Burn) with an Axum inference API and a Yew web UI.

Overview

This model predicts:

  • Infected vs Uninfected (gating)
  • Species: Falciparum, Malariae, Ovale, Vivax (plus an internal Uninfected class)
  • Stage presence (multi-label): Ring (R), Trophozoite (T), Schizont (S), Gametocyte (G)

Stage labels are weak (image-level presence inferred from filename tokens) and are treated as presence probabilities.

Repository Layout

  • src/bin/mpidb_prep.rs: crop generation + manifest.csv writer
  • src/training.rs: training entry point
  • src/bin/server.rs: inference API (Axum)
  • inference-ui/: web UI (Yew)
  • DEV_GUIDE.md: detailed crop/manifest strategy

Requirements

  • Rust toolchain
  • UI: trunk + target wasm32-unknown-unknown

Data Preparation (Crops + Manifest)

This project trains from a CSV manifest generated by mpidb_prep.

Expected input folders:

  1. MP-IDB species dataset (infected) (one folder per species):
data/
├── Falciparum/
│   ├── img/...
│   └── gt/...
├── Malariae/
│   ├── img/...
│   └── gt/...
├── Ovale/
│   ├── img/...
│   └── gt/...
└── Vivax/
    ├── img/...
    └── gt/...
  1. Uninfected negatives:
data/
└── Uninfected/
    ├── cell_1.png
    ├── cell_2.png
    └── ...

Generate crops + manifest.csv:

cargo run --bin mpidb_prep -- data mpidb_crops 128 25

Outputs:

  • mpidb_crops/<Species>/*.png (infected crops)
  • mpidb_crops/Uninfected/*.png (uninfected crops)
  • mpidb_crops/manifest.csv

Manifest schema:

crop_path,infected,species,stage_r,stage_t,stage_s,stage_g,source_image_id

For a detailed explanation of the cropping strategy and leakage-safe splitting, see:

  • DEV_GUIDE.md

Training

cargo run --release

Training reads the manifest path configured in src/config.rs:

  • mpidb_crops/manifest.csv

Inference API (Rust)

Start the server:

MODEL_PATH=./malaria-model.bin cargo run --bin server

Endpoints:

  • GET /healthok
  • POST /predictmultipart/form-data with field image (or file)

Example request:

curl -X POST http://localhost:8080/predict -F "image=@./some_image.png"

Example response:

{
  "infected": true,
  "predicted_species": "Falciparum",
  "species_probabilities": [0.87, 0.05, 0.03, 0.02, 0.03],
  "stage_probabilities": [0.92, 0.15, 0.08, 0.02]
}

Inference UI (Yew)

rustup target add wasm32-unknown-unknown
cargo install trunk

cd inference-ui
trunk serve --open

License

MIT. See LICENSE.