Binary image classifier to detect whether an image contains a DIY sensor (sensor) or not (no_sensor).
SensorImageGuard/
├── train_sensor_model.py
├── predict_sensor.py
├── requirements.txt
├── .gitignore
└── img/
├── img_sensors/
└── img_negatives/
├── hard/
│ ├── selected/
│ └── fetch_hard_negatives.py
└── soft/
├── all/
├── selected/
└── select_random_soft.py
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt- Positive class (
sensor=1):img/img_sensors/ - Negative class (
no_sensor=0):img/img_negatives/hard/selected/img/img_negatives/soft/selected/
Supported formats: .jpg, .jpeg, .png, .bmp, .webp, .tif, .tiff
source .venv/bin/activate
python train_sensor_model.py \
--sensor-dir img/img_sensors \
--negative-dirs img/img_negatives/hard/selected img/img_negatives/soft/selected \
--output model.h5By default, training uses:
--val-split 0.2--test-split 0.1
After training, the script prints:
- best validation AUC (
Best val_auc) - final test metrics:
lossaccuracyaucprecisionrecall
source .venv/bin/activate
python predict_sensor.py path/to/image.jpg --model model.h5 --image-size 128Output:
label: sensororlabel: no_sensorsensor_probability: <float>
- The model output layer is
sensor_probability(sigmoid). sensor_probability >= 0.5maps to labelsensor..h5is used intentionally in this project.