Files
radiacode/train/entrypoint.sh
Jacquin Antoine 0847a3fc80 Fix: CsI(Tl) non-linear response correction + detector calibration overhaul
Root cause of Am-241 misidentification: the Radiacode 103's CsI(Tl) crystal
shifts low-energy peaks upward (59.5 keV → 71.6 keV for Am-241) due to
non-proportional scintillation response. The model was trained on theoretical
peak positions and couldn't match the shifted real peaks.

Changes:
- Add inverse CsI(Tl) non-linear correction to inference pipeline
  (radiacode_monitor.py, web/config.py, test_detection.py)
  E_apparent = E_true * (1 + 0.37 * exp(-E_true/100))
  Corrects channel mapping so peaks appear at theoretical energies
- Fix energy calibration: DetectorConfig now uses E = 0.33 + 2.97*ch
  with 1023 channels, matching the real detector (was energy_min=20,
  skip_first_channel=True, different channel width)
- Add K-escape peaks for CsI(Tl) iodine X-ray escape (E - 28.5 keV)
- Add asymmetric peak shapes for low-energy tails (< 200 keV)
- Add log1p normalization in dataset and inference (replaces max-norm)
- Add background-subtracted training mode (subtract_background flag)
- Add low-signal augmentation (0.01-5 Bq activities, 30-300s durations)
- Update docker-compose.yml: batch_size=32, duration=30-300s,
  CSI_NONLINEAR_ALPHA/BETA env vars for detect and web
- Web dashboard: apply CsI correction to displayed spectra
- Various UI fixes (Chart.js width, zoom/pan, isotope lines)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-21 17:35:22 +02:00

66 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
set -e
DATA_DIR="${DATA_DIR:-/data/synthetic}"
MODEL_DIR="${MODEL_DIR:-/models}"
NUM_SAMPLES="${NUM_SAMPLES:-50000}"
EPOCHS="${EPOCHS:-100}"
BATCH_SIZE="${BATCH_SIZE:-32}"
LEARNING_RATE="${LEARNING_RATE:-0.001}"
DETECTOR="${DETECTOR:-radiacode_103}"
MIN_DURATION="${MIN_DURATION:-30}"
MAX_DURATION="${MAX_DURATION:-300}"
SEED="${SEED:-42}"
MEASURED_BACKGROUND_PATH="${MEASURED_BACKGROUND_PATH:-}"
echo "============================================"
echo " Radiacode 103 — Pipeline d'entraînement"
echo "============================================"
echo " Data dir : $DATA_DIR"
echo " Model dir : $MODEL_DIR"
echo " Samples : $NUM_SAMPLES"
echo " Detector : $DETECTOR"
echo " Duration : $MIN_DURATION-$MAX_DURATION s"
echo " Epochs : $EPOCHS"
echo " Batch size : $BATCH_SIZE"
echo " Learning rate: $LEARNING_RATE"
echo "============================================"
MEASURED_BG_ARG=""
if [ -n "$MEASURED_BACKGROUND_PATH" ] && [ -f "$MEASURED_BACKGROUND_PATH" ]; then
MEASURED_BG_ARG="--measured_background $MEASURED_BACKGROUND_PATH"
echo "Using measured background: $MEASURED_BACKGROUND_PATH"
fi
echo ""
echo "=== Phase 1 : Génération des spectres synthétiques ==="
python -m vega_ml.synthetic_spectra.generate_spectra \
--num_samples "$NUM_SAMPLES" \
--output_dir "$DATA_DIR" \
--detector "$DETECTOR" \
--min_duration "$MIN_DURATION" \
--max_duration "$MAX_DURATION" \
--seed "$SEED" \
$MEASURED_BG_ARG
echo ""
echo "=== Phase 2 : Entraînement du VegaModel ==="
python -m vega_ml.training.vega.run_training \
--data-dir "$DATA_DIR" \
--model-dir "$MODEL_DIR" \
--epochs "$EPOCHS" \
--batch-size "$BATCH_SIZE" \
--learning-rate "$LEARNING_RATE"
echo ""
echo "=== Entraînement terminé ==="
echo "Fichiers modèle :"
ls -lh "$MODEL_DIR/"
echo ""
echo "Copie de l'index des isotopes..."
if [ -f "$MODEL_DIR/vega_isotope_index.txt" ]; then
echo " vega_isotope_index.txt présent"
else
echo " ATTENTION : vega_isotope_index.txt absent"
fi