Data-preparation pipeline for the open-source malaria cell dataset (27,558 thin blood-smear cell images, split evenly between parasitized and uninfected). The project loads, explores, preprocesses, splits, and augments the images so they are ready for a model.
anomaly-detection-in-malaria-images/
├── datasets/ # downloaded dataset (created on first run)
├── requirements.txt # Python dependencies (pinned lockfile)
├── tasks/
│ └── PREPROCESSING.md # full pipeline reference (all steps in one doc)
├── src/
│ └── anomaly_detection/
│ ├── __init__.py # suppresses noisy TensorFlow logs
│ ├── __main__.py # app entry point — calls prepare_data()
│ ├── config.py # paths, split ratios, BATCH_SIZE, VISUALIZE
│ └── data/
│ ├── __main__.py # run the data pipeline standalone
│ ├── pipeline.py # prepare_data() — orchestrates the steps
│ ├── load.py # load the dataset
│ ├── visualize.py # show sample images
│ ├── preprocess.py # resize / normalize
│ ├── split.py # train / val / test split
│ └── augment.py # augment training data
└── README.md
Developed and tested on:
- OS: macOS
- Python: 3.9
- Virtual environment:
venv(see setup below)
Other platforms should work too, as long as the dependencies in requirements.txt
install cleanly.
Create and activate a virtual environment, then install the dependencies:
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txtThe package lives inside src/, so Python needs to be told to look there. Set the
PYTHONPATH export first, then run the package:
export PYTHONPATH=src
python3 -m anomaly_detectionOr as a single line:
PYTHONPATH=src python3 -m anomaly_detectionTo run only the data pipeline (load → split → preprocess → augment) for standalone testing, without the rest of the app:
PYTHONPATH=src python3 -m anomaly_detection.data
PYTHONPATH=srctells Python to also search thesrc/folder for packages, which is whereanomaly_detectionlives. Run these commands from the project root.
On the first run, the dataset (~337 MB) downloads into the datasets/ folder. This
happens once; later runs read the cached data.
The full step-by-step data-preparation workflow (import, load, visualize, preprocess,
split, augment) is documented in tasks/PREPROCESSING.md.
Edit src/anomaly_detection/config.py:
VISUALIZE— setTrueto pop up the sample / preprocessing / augmentation image windows; setFalseto run the pipeline without any plots.BATCH_SIZE— how many images to process;0uses the full dataset, a positive number works on a smaller subset to run faster.TRAIN_SET_SIZE,VAL_SET_SIZE,TEST_SIZE— the split ratios (default 70/15/15).DATA_DIR— absolute path to thedatasets/folder (computed automatically).
Based on the Educative project Anomaly Detection in Medical Images (Python, TF & PyTorch).