Reinforcement Learning
stable-baselines3
deep-reinforcement-learning
agricultural-ai
weather-modelling
curriculum-learning
edge-ai
Instructions to use DHDRL/monsoon-rl with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- stable-baselines3
How to use DHDRL/monsoon-rl with stable-baselines3:
from huggingface_sb3 import load_from_hub checkpoint = load_from_hub( repo_id="DHDRL/monsoon-rl", filename="{MODEL FILENAME}.zip", ) - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,71 +1,101 @@
|
|
| 1 |
---
|
| 2 |
license: agpl-3.0
|
|
|
|
| 3 |
tags:
|
| 4 |
-
- reinforcement-learning
|
| 5 |
-
-
|
| 6 |
-
-
|
| 7 |
-
-
|
| 8 |
-
-
|
| 9 |
-
|
| 10 |
-
- edge-ai
|
| 11 |
---
|
| 12 |
|
| 13 |
-
# Agricultural Weather-Risk RL β Permutation-Invariant GRU
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
## What is included
|
| 18 |
|
| 19 |
-
- `weather_forecast_env.py` β Gymnasium
|
| 20 |
-
- `gru_weather_policy.py` β Permutation-invariant GRU
|
| 21 |
-
- `train_curriculum.py`
|
| 22 |
-
- `crop_risk_scorer.py` β Deterministic, economics-calibrated risk scoring
|
| 23 |
-
- `climatology.py` + `indonesia_zones.py` β
|
| 24 |
-
- `
|
| 25 |
-
- `mnn_export.py` + `edge_wrapper.cpp` β ONNX export and C++
|
| 26 |
-
- `era5_data_pipeline.py` β Multi-source data pipeline (ERA5 / Open-Meteo / synthetic) with graceful degradation.
|
| 27 |
|
| 28 |
-
## Key
|
| 29 |
|
| 30 |
-
The
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
|
| 37 |
-
|
| 38 |
|
| 39 |
-
##
|
| 40 |
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
| Transition | n_zones change | Tensors transferred | Behavior |
|
| 44 |
-
|-------------------------|----------------|---------------------|------------------------------|
|
| 45 |
-
| normal β monsoon | 2 β 3 | 61/63 | Action head reinitialized |
|
| 46 |
-
| monsoon β drought | 3 β 3 | 63/63 | Full transfer |
|
| 47 |
-
| drought β heatwave | 3 β 4 | 61/63 | Action head reinitialized |
|
| 48 |
-
| heatwave β humidity | 4 β 4 | 63/63 | Full transfer |
|
| 49 |
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
### Training
|
| 55 |
-
```bash
|
| 56 |
-
python train_curriculum.py --phase all --output-dir ./runs --device cuda --seed 42
|
| 57 |
-
Inference (after training)
|
| 58 |
-
Pythonfrom sb3_contrib import MaskablePPO
|
| 59 |
-
model = MaskablePPO.load("runs/humidity/models/final_humidity.zip")
|
| 60 |
-
Edge Export
|
| 61 |
-
Bashpython mnn_export.py --checkpoint runs/humidity/models/final_humidity.zip \
|
| 62 |
-
--output weather_rl_model.mnn --quantize int8 --n-zones 4
|
| 63 |
Dependencies
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
stable-baselines3 >= 2.0
|
| 67 |
-
sb3-contrib >= 2.0
|
| 68 |
-
gymnasium >= 0.29
|
| 69 |
-
numpy
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: agpl-3.0
|
| 3 |
+
library_name: stable-baselines3
|
| 4 |
tags:
|
| 5 |
+
- deep-reinforcement-learning
|
| 6 |
+
- agricultural-ai
|
| 7 |
+
- weather-modelling
|
| 8 |
+
- curriculum-learning
|
| 9 |
+
- edge-ai
|
| 10 |
+
pipeline_tag: reinforcement-learning
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# Agricultural Weather-Risk RL β MaskablePPO + Permutation-Invariant GRU
|
| 14 |
|
| 15 |
+
Budget-constrained multi-zone weather-risk inspection for Indonesian rice
|
| 16 |
+
zones. A Gymnasium environment tracks per-zone beliefs under a scarce
|
| 17 |
+
inspection budget; a **permutation-invariant GRU** feature extractor supports
|
| 18 |
+
curriculum phases with changing `n_zones`; deterministic crop-risk scoring
|
| 19 |
+
grounds rewards and product alerts. Intended path includes ONNX β MNN export
|
| 20 |
+
for edge inference.
|
| 21 |
+
|
| 22 |
+
This card describes the training stack and architecture. It is a research
|
| 23 |
+
codebase, not a production alerting service.
|
| 24 |
|
| 25 |
## What is included
|
| 26 |
|
| 27 |
+
- `weather_forecast_env.py` β Gymnasium env (belief map, action masks, triage/scarce/full budget modes, per-episode zone-order shuffle, real `EpisodeContext` injection)
|
| 28 |
+
- `gru_weather_policy.py` β Permutation-invariant GRU extractor (shared per-zone processing + aggregation; most weights independent of `n_zones`)
|
| 29 |
+
- `train_curriculum.py` / `train_kaggle.py` β Curriculum and standalone training (`--budget-mode triage|scarce|full`)
|
| 30 |
+
- `crop_risk_scorer.py` β Deterministic, economics-calibrated risk scoring
|
| 31 |
+
- `climatology.py` + `indonesia_zones.py` β Per-zone climatology and 14 grounded Indonesian agricultural zones
|
| 32 |
+
- `evaluate_checkpoint_real.py` β Real-trajectory eval (L1 labels, belief Ξ, zero_inspect control)
|
| 33 |
+
- `mnn_export.py` + `edge_wrapper.cpp` β ONNX/MNN export and C++ edge runtime with external GRU hidden state
|
|
|
|
| 34 |
|
| 35 |
+
## Key technical note
|
| 36 |
|
| 37 |
+
The GRU extractor is designed so that changing `n_zones` across curriculum
|
| 38 |
+
phases only requires reinitializing the action head; the bulk of the policy
|
| 39 |
+
parameters transfer. That enables multi-phase runs without full restarts when
|
| 40 |
+
entity count changes.
|
| 41 |
|
| 42 |
+
**Full-tour episode length (`n_zones + 1`) is not evidence of zone-selection
|
| 43 |
+
skill.** Under triage (`max_steps = max(1, n_zones - 1)`), the agent must leave
|
| 44 |
+
at least one zone unvisited. Allocation claims require a triage-trained
|
| 45 |
+
checkpoint evaluated under shuffle, not full-tour belief or length metrics.
|
| 46 |
|
| 47 |
+
## How to use
|
| 48 |
|
| 49 |
+
### Train (triage default)
|
| 50 |
|
| 51 |
+
```bash
|
| 52 |
+
python train_kaggle.py \
|
| 53 |
+
--out ./run_nz2_triage \
|
| 54 |
+
--n-zones 2 \
|
| 55 |
+
--budget-mode triage \
|
| 56 |
+
--steps 100000 \
|
| 57 |
+
--clean-episode-ratio 0.90 \
|
| 58 |
+
--event-spatial-correlation 0.85 \
|
| 59 |
+
--device auto
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
Load and act
|
| 63 |
+
Pythonfrom sb3_contrib import MaskablePPO
|
| 64 |
|
| 65 |
+
model = MaskablePPO.load("run_nz2_triage/final_model.zip")
|
| 66 |
+
# obs from WeatherForecastEnv; pass action_masks= for MaskablePPO
|
| 67 |
+
action, _ = model.predict(obs, action_masks=masks, deterministic=True)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
Edge export (optional)
|
| 71 |
+
Bashpython mnn_export.py \
|
| 72 |
+
--checkpoint run_nz2_triage/final_model.zip \
|
| 73 |
+
--output weather_rl_model.mnn \
|
| 74 |
+
--quantize int8 \
|
| 75 |
+
--n-zones 2
|
| 76 |
+
Validation (what is and is not shown)
|
| 77 |
+
|
| 78 |
+
ClaimStatusWeight transfer across n_zones changes (most tensors)Supported by curriculum designFull-tour training converges on length / belief movementObserved on earlier runs; not allocation skillTriage + shuffle avoids fixed physical zone lock-inObserved (slot preference can remain)Risk-conditioned zone choice under triageNot yet demonstratedProduct skill vs curated L1 impact labelsScorer/product path exists; quote only with L1 density caveats
|
| 79 |
+
Synthetic triage EV under current defaults (cleanβ0.90, max_steps=1) shows
|
| 80 |
+
only a weak dirty-day advantage for selecting the correct zone; overall return
|
| 81 |
+
still favours always-inspect. Longer training under the same reward does not
|
| 82 |
+
substitute for a stronger selection signal or calibrated clean ratio.
|
| 83 |
+
Limitations
|
| 84 |
+
|
| 85 |
+
Research stack, not SLA. No on-call, feed uptime, or regulatory certification.
|
| 86 |
+
Synthetic-heavy training. Real claims need held-out product metrics and L1 coverage honesty (unlabeled days excluded from P/R/F1).
|
| 87 |
+
Full-tour β triage. Do not cite full-tour belief_R or ep_len β n_zones+1 as zone-selection skill.
|
| 88 |
+
Triage allocation open. A triage-trained policy under shuffle has not been shown to beat zero_inspect on L1 belief movement and choose zones by contemporaneous risk rather than a fixed action slot.
|
| 89 |
+
Edge path is export-oriented. MNN/C++ wrapper is provided; not validated here as a production edge deployment.
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
Dependencies
|
| 92 |
+
texttorch>=2.0
|
| 93 |
+
gymnasium>=0.29
|
| 94 |
+
stable-baselines3>=2.0
|
| 95 |
+
sb3-contrib>=2.0
|
| 96 |
+
numpy>=1.24
|
| 97 |
|
| 98 |
+
GPU recommended for training; CPU is viable for short runs and inference.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
+
License
|
| 101 |
+
AGPL-3.0. See repository for full terms.
|