Text Classification
Transformers
Safetensors
yield-weather-soil
crop-yield
multi-temporal
regression
yield-estimation
custom_code
Instructions to use ICICLE-AI/yield-estimation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ICICLE-AI/yield-estimation with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="ICICLE-AI/yield-estimation", trust_remote_code=True)# Load model directly from transformers import AutoModelForSequenceClassification model = AutoModelForSequenceClassification.from_pretrained("ICICLE-AI/yield-estimation", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -13,15 +13,18 @@ license: mit
|
|
| 13 |
|
| 14 |
# Yield Estimation Transformer
|
| 15 |
|
| 16 |
-
A Hugging Face Transformers model for county-level corn yield estimation using multi-temporal weather observations and static soil properties.
|
| 17 |
|
| 18 |
The model combines weekly weather time-series with static soil features to estimate corn yield in bushels per acre (`bu/acre`). It is packaged for inference using Hugging Face Transformers and has been tested for deployment through FlexServ.
|
| 19 |
|
| 20 |
-
The Hugging Face `text-classification` task is used as the FlexServ-compatible serving interface. The underlying model performs
|
|
|
|
|
|
|
| 21 |
|
| 22 |
### Tags
|
|
|
|
| 23 |
|
| 24 |
-
- Crop Yield Estimation
|
| 25 |
- Digital Agriculture
|
| 26 |
- Transformers
|
| 27 |
- Multi-Temporal Modeling
|
|
@@ -29,9 +32,12 @@ The Hugging Face `text-classification` task is used as the FlexServ-compatible s
|
|
| 29 |
- Hugging Face Transformers
|
| 30 |
- FlexServ
|
| 31 |
|
|
|
|
|
|
|
| 32 |
### License
|
| 33 |
|
| 34 |
-
|
|
|
|
| 35 |
|
| 36 |
## References
|
| 37 |
|
|
@@ -64,7 +70,7 @@ FlexServ documentation: https://zhangwei217245.github.io/FlexServ/
|
|
| 64 |
|
| 65 |
This work was developed as part of the ICICLE AI Institute.
|
| 66 |
|
| 67 |
-
*National Science Foundation (NSF) AI
|
| 68 |
|
| 69 |
## Issue reporting
|
| 70 |
|
|
@@ -80,7 +86,7 @@ Sarikaa Sridhar: sridhar.86@buckeyemail.osu.edu
|
|
| 80 |
|
| 81 |
### Overview
|
| 82 |
|
| 83 |
-
The Yield Estimation Transformer is a pretrained model for county-level corn yield estimation. It combines
|
| 84 |
|
| 85 |
The model accepts six weekly weather variables:
|
| 86 |
|
|
@@ -103,20 +109,6 @@ A cutoff determines how many weeks of weather information are available to the m
|
|
| 103 |
|
| 104 |
For deployment through FlexServ, the model uses the Hugging Face `text-classification` pipeline as its serving interface. This is an interface choice for inference compatibility; the underlying prediction task remains regression.
|
| 105 |
|
| 106 |
-
### Prerequisites
|
| 107 |
-
|
| 108 |
-
- Python 3.10+
|
| 109 |
-
- PyTorch
|
| 110 |
-
- Hugging Face Transformers
|
| 111 |
-
- Dependencies listed in `requirements.txt`
|
| 112 |
-
- FlexServ environment for service deployment
|
| 113 |
-
|
| 114 |
-
Because the repository provides custom model configuration, tokenizer, and architecture code, Hugging Face loading requires:
|
| 115 |
-
|
| 116 |
-
```python
|
| 117 |
-
trust_remote_code=True
|
| 118 |
-
```
|
| 119 |
-
|
| 120 |
---
|
| 121 |
|
| 122 |
# How-To Guides
|
|
@@ -154,6 +146,9 @@ The repository contains the files required for standalone Hugging Face and FlexS
|
|
| 154 |
```text
|
| 155 |
.
|
| 156 |
βββ README.md
|
|
|
|
|
|
|
|
|
|
| 157 |
βββ config.json
|
| 158 |
βββ configuration_yield.py
|
| 159 |
βββ model.safetensors
|
|
@@ -171,26 +166,10 @@ A complete inference example is provided in:
|
|
| 171 |
sample_input_weekly.json
|
| 172 |
```
|
| 173 |
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
Clone the model repository:
|
| 177 |
-
|
| 178 |
-
```bash
|
| 179 |
-
git clone https://huggingface.co/ICICLE-AI/yield-estimation
|
| 180 |
-
cd yield-estimation
|
| 181 |
-
```
|
| 182 |
-
|
| 183 |
-
Create and activate a Python environment:
|
| 184 |
-
|
| 185 |
-
```bash
|
| 186 |
-
conda create -n yield_hf python=3.10
|
| 187 |
-
conda activate yield_hf
|
| 188 |
-
```
|
| 189 |
-
|
| 190 |
-
Install the required dependencies:
|
| 191 |
|
| 192 |
-
```
|
| 193 |
-
|
| 194 |
```
|
| 195 |
|
| 196 |
### Usage
|
|
@@ -329,6 +308,352 @@ Expected output for the included sample is approximately:
|
|
| 329 |
[{'label': 'YIELD_BU_ACRE', 'score': 165.1769561767578}]
|
| 330 |
```
|
| 331 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
---
|
| 333 |
|
| 334 |
# Explanation
|
|
|
|
| 13 |
|
| 14 |
# Yield Estimation Transformer
|
| 15 |
|
| 16 |
+
A Hugging Face custom pipeline using Transformers model for county-level corn yield estimation using multi-temporal weather observations and static soil properties.
|
| 17 |
|
| 18 |
The model combines weekly weather time-series with static soil features to estimate corn yield in bushels per acre (`bu/acre`). It is packaged for inference using Hugging Face Transformers and has been tested for deployment through FlexServ.
|
| 19 |
|
| 20 |
+
The Hugging Face `text-classification` task is used as the FlexServ-compatible serving interface. The underlying model performs regression, and the returned `score` represents predicted corn yield in `bu/acre`.
|
| 21 |
+
|
| 22 |
+
The `training_code` directory composes the source code for data preparation, model training, evaluation, and inference.
|
| 23 |
|
| 24 |
### Tags
|
| 25 |
+
**Tags:** Digital-Agriculture, Foundation-AI
|
| 26 |
|
| 27 |
+
- In-season Crop Yield Estimation
|
| 28 |
- Digital Agriculture
|
| 29 |
- Transformers
|
| 30 |
- Multi-Temporal Modeling
|
|
|
|
| 32 |
- Hugging Face Transformers
|
| 33 |
- FlexServ
|
| 34 |
|
| 35 |
+
For guidance on what to include in Tutorials, How-To Guides, Explanation, and Reference, see [DiΓ‘taxis](https://diataxis.fr/).
|
| 36 |
+
|
| 37 |
### License
|
| 38 |
|
| 39 |
+
[](https://opensource.org/licenses/MIT)
|
| 40 |
+
This project is released under the MIT License. The full text is available in [LICENSE](LICENSE).
|
| 41 |
|
| 42 |
## References
|
| 43 |
|
|
|
|
| 70 |
|
| 71 |
This work was developed as part of the ICICLE AI Institute.
|
| 72 |
|
| 73 |
+
*National Science Foundation (NSF) funded AI institute for Intelligent Cyberinfrastructure with Computational Learning in the Environment (ICICLE) (OAC 2112606)*
|
| 74 |
|
| 75 |
## Issue reporting
|
| 76 |
|
|
|
|
| 86 |
|
| 87 |
### Overview
|
| 88 |
|
| 89 |
+
The Yield Estimation Transformer is a pretrained model for in-season county-level corn yield estimation. It combines temporal weekly weather observations with static soil properties and produces a scalar yield prediction in bushels per acre.
|
| 90 |
|
| 91 |
The model accepts six weekly weather variables:
|
| 92 |
|
|
|
|
| 109 |
|
| 110 |
For deployment through FlexServ, the model uses the Hugging Face `text-classification` pipeline as its serving interface. This is an interface choice for inference compatibility; the underlying prediction task remains regression.
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
---
|
| 113 |
|
| 114 |
# How-To Guides
|
|
|
|
| 146 |
```text
|
| 147 |
.
|
| 148 |
βββ README.md
|
| 149 |
+
βββ LICENSE
|
| 150 |
+
βββ component-info.yaml
|
| 151 |
+
βββ training_code/
|
| 152 |
βββ config.json
|
| 153 |
βββ configuration_yield.py
|
| 154 |
βββ model.safetensors
|
|
|
|
| 166 |
sample_input_weekly.json
|
| 167 |
```
|
| 168 |
|
| 169 |
+
Because the repository provides custom model configuration, tokenizer, and architecture code, Hugging Face loading requires:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
+
```python
|
| 172 |
+
trust_remote_code=True
|
| 173 |
```
|
| 174 |
|
| 175 |
### Usage
|
|
|
|
| 308 |
[{'label': 'YIELD_BU_ACRE', 'score': 165.1769561767578}]
|
| 309 |
```
|
| 310 |
|
| 311 |
+
### Training own model
|
| 312 |
+
|
| 313 |
+
#### Installation
|
| 314 |
+
|
| 315 |
+
Clone the model repository:
|
| 316 |
+
|
| 317 |
+
```bash
|
| 318 |
+
git clone https://huggingface.co/ICICLE-AI/yield-estimation
|
| 319 |
+
cd yield-estimation/training_code
|
| 320 |
+
```
|
| 321 |
+
|
| 322 |
+
Create and activate a Python environment:
|
| 323 |
+
|
| 324 |
+
```bash
|
| 325 |
+
conda create -n yield_hf python=3.10
|
| 326 |
+
conda activate yield_hf
|
| 327 |
+
```
|
| 328 |
+
|
| 329 |
+
Install the required dependencies:
|
| 330 |
+
|
| 331 |
+
```bash
|
| 332 |
+
pip install -r requirements.txt
|
| 333 |
+
```
|
| 334 |
+
|
| 335 |
+
#### Prerequisites
|
| 336 |
+
|
| 337 |
+
- Python 3.10+
|
| 338 |
+
- PyTorch
|
| 339 |
+
- Hugging Face Transformers
|
| 340 |
+
- Dependencies listed in `requirements.txt`
|
| 341 |
+
|
| 342 |
+
For GPU training, a CUDA-compatible PyTorch environment is recommended.
|
| 343 |
+
|
| 344 |
+
The included SLURM script can be used on a compatible HPC system.
|
| 345 |
+
|
| 346 |
+
#### Problem Description
|
| 347 |
+
|
| 348 |
+
The objective is to estimate county-level corn yield from weather and soil information.
|
| 349 |
+
|
| 350 |
+
Each sample contains two primary sources of information:
|
| 351 |
+
|
| 352 |
+
1. multi-temporal weather observations;
|
| 353 |
+
2. static soil properties.
|
| 354 |
+
|
| 355 |
+
The weather input is represented as:
|
| 356 |
+
|
| 357 |
+
```text
|
| 358 |
+
[K, W]
|
| 359 |
+
```
|
| 360 |
+
|
| 361 |
+
where:
|
| 362 |
+
|
| 363 |
+
- `K` is the number of temporal observations;
|
| 364 |
+
- `W = 6` is the number of weather variables.
|
| 365 |
+
|
| 366 |
+
The static soil input is represented as:
|
| 367 |
+
|
| 368 |
+
```text
|
| 369 |
+
[S]
|
| 370 |
+
```
|
| 371 |
+
|
| 372 |
+
where:
|
| 373 |
+
|
| 374 |
+
```text
|
| 375 |
+
S = 66
|
| 376 |
+
```
|
| 377 |
+
|
| 378 |
+
The model learns a regression function of the form:
|
| 379 |
+
|
| 380 |
+
```text
|
| 381 |
+
weather + soil + crop information
|
| 382 |
+
β
|
| 383 |
+
transformer model
|
| 384 |
+
β
|
| 385 |
+
predicted corn yield
|
| 386 |
+
```
|
| 387 |
+
|
| 388 |
+
The predicted value is expressed in bushels per acre (`bu/acre`).
|
| 389 |
+
|
| 390 |
+
The model supports multi-temporal estimation by evaluating the weather sequence at different seasonal cutoffs.
|
| 391 |
+
|
| 392 |
+
#### Repository Structure
|
| 393 |
+
|
| 394 |
+
The final repository is organized as follows:
|
| 395 |
+
|
| 396 |
+
```text
|
| 397 |
+
.
|
| 398 |
+
βββ README.md
|
| 399 |
+
βββ requirements.txt
|
| 400 |
+
βββ training.slurm
|
| 401 |
+
β
|
| 402 |
+
βββ checkpoints/
|
| 403 |
+
β βββ config.json
|
| 404 |
+
β βββ metrics.json
|
| 405 |
+
β βββ model.safetensors
|
| 406 |
+
β
|
| 407 |
+
βββ config/
|
| 408 |
+
β βββ __init__.py
|
| 409 |
+
β βββ config.py
|
| 410 |
+
β
|
| 411 |
+
βββ data/
|
| 412 |
+
β βββ __init__.py
|
| 413 |
+
β βββ dataset.py
|
| 414 |
+
β βββ preprocessing.py
|
| 415 |
+
β
|
| 416 |
+
βββ examples/
|
| 417 |
+
β βββ sample_input_weekly.json
|
| 418 |
+
β
|
| 419 |
+
βββ hf/
|
| 420 |
+
β βββ __init__.py
|
| 421 |
+
β βββ auto.py
|
| 422 |
+
β βββ configuration_yield.py
|
| 423 |
+
β βββ modeling_yield.py
|
| 424 |
+
β
|
| 425 |
+
βββ models/
|
| 426 |
+
β βββ __init__.py
|
| 427 |
+
β βββ unimodal_ws_crossattn.py
|
| 428 |
+
β
|
| 429 |
+
βββ scripts/
|
| 430 |
+
β βββ __init__.py
|
| 431 |
+
β βββ prepare_cornbelt.py
|
| 432 |
+
β βββ train_hf.py
|
| 433 |
+
β βββ evaluate_hf.py
|
| 434 |
+
β βββ inference_hf.py
|
| 435 |
+
β
|
| 436 |
+
βββ training/
|
| 437 |
+
βββ __init__.py
|
| 438 |
+
βββ engine.py
|
| 439 |
+
```
|
| 440 |
+
|
| 441 |
+
The major components are:
|
| 442 |
+
|
| 443 |
+
- `data/` β dataset loading and preprocessing
|
| 444 |
+
- `models/` β core neural network architecture
|
| 445 |
+
- `training/` β training and evaluation utilities
|
| 446 |
+
- `hf/` β Hugging Face AutoClass-compatible regression wrapper used by the training repository
|
| 447 |
+
- `scripts/` β data preparation, training, evaluation, and inference entry points
|
| 448 |
+
- `checkpoints/` β final trained checkpoint and configuration
|
| 449 |
+
- `examples/` β example structured model input
|
| 450 |
+
- `training.slurm` β example HPC training job
|
| 451 |
+
|
| 452 |
+
#### Data Preparation
|
| 453 |
+
|
| 454 |
+
The USA County Level Crop Yield public dataset is used for training, validation and testing. The data preparation workflow is implemented in:
|
| 455 |
+
|
| 456 |
+
```text
|
| 457 |
+
scripts/prepare_cornbelt.py
|
| 458 |
+
```
|
| 459 |
+
|
| 460 |
+
After preparation, the expected dataset structure is:
|
| 461 |
+
|
| 462 |
+
```text
|
| 463 |
+
data/
|
| 464 |
+
βββ cornbelt/
|
| 465 |
+
βββ train.h5
|
| 466 |
+
βββ val.h5
|
| 467 |
+
βββ test.h5
|
| 468 |
+
```
|
| 469 |
+
|
| 470 |
+
The model uses the following six weather variables:
|
| 471 |
+
|
| 472 |
+
```text
|
| 473 |
+
prcp
|
| 474 |
+
srad
|
| 475 |
+
swe
|
| 476 |
+
tmax
|
| 477 |
+
tmin
|
| 478 |
+
vp
|
| 479 |
+
```
|
| 480 |
+
|
| 481 |
+
The 66 soil variables used by the final checkpoint are recorded in the model configuration.
|
| 482 |
+
|
| 483 |
+
#### Training
|
| 484 |
+
|
| 485 |
+
The primary training entry point is:
|
| 486 |
+
|
| 487 |
+
```text
|
| 488 |
+
scripts/train_hf.py
|
| 489 |
+
```
|
| 490 |
+
|
| 491 |
+
The final model uses multi-cutoff training with:
|
| 492 |
+
|
| 493 |
+
```text
|
| 494 |
+
20,24,28,32,36,40,44,48,52
|
| 495 |
+
```
|
| 496 |
+
|
| 497 |
+
An example training command is:
|
| 498 |
+
|
| 499 |
+
```bash
|
| 500 |
+
python scripts/train_hf.py \
|
| 501 |
+
--train_file data/cornbelt/train.h5 \
|
| 502 |
+
--val_file data/cornbelt/val.h5 \
|
| 503 |
+
--test_file data/cornbelt/test.h5 \
|
| 504 |
+
--weather_vars prcp,srad,swe,tmax,tmin,vp \
|
| 505 |
+
--soil_vars bdod_mean_0-5cm,bdod_mean_5-15cm,bdod_mean_15-30cm,bdod_mean_30-60cm,bdod_mean_60-100cm,bdod_mean_100-200cm,cec_mean_0-5cm,cec_mean_5-15cm,cec_mean_15-30cm,cec_mean_30-60cm,cec_mean_60-100cm,cec_mean_100-200cm,cfvo_mean_0-5cm,cfvo_mean_5-15cm,cfvo_mean_15-30cm,cfvo_mean_30-60cm,cfvo_mean_60-100cm,cfvo_mean_100-200cm,clay_mean_0-5cm,clay_mean_5-15cm,clay_mean_15-30cm,clay_mean_30-60cm,clay_mean_60-100cm,clay_mean_100-200cm,nitrogen_mean_0-5cm,nitrogen_mean_5-15cm,nitrogen_mean_15-30cm,nitrogen_mean_30-60cm,nitrogen_mean_60-100cm,nitrogen_mean_100-200cm,ocd_mean_0-5cm,ocd_mean_5-15cm,ocd_mean_15-30cm,ocd_mean_30-60cm,ocd_mean_60-100cm,ocd_mean_100-200cm,ocs_mean_0-5cm,ocs_mean_5-15cm,ocs_mean_15-30cm,ocs_mean_30-60cm,ocs_mean_60-100cm,ocs_mean_100-200cm,phh2o_mean_0-5cm,phh2o_mean_5-15cm,phh2o_mean_15-30cm,phh2o_mean_30-60cm,phh2o_mean_60-100cm,phh2o_mean_100-200cm,sand_mean_0-5cm,sand_mean_5-15cm,sand_mean_15-30cm,sand_mean_30-60cm,sand_mean_60-100cm,sand_mean_100-200cm,silt_mean_0-5cm,silt_mean_5-15cm,silt_mean_15-30cm,silt_mean_30-60cm,silt_mean_60-100cm,silt_mean_100-200cm,soc_mean_0-5cm,soc_mean_5-15cm,soc_mean_15-30cm,soc_mean_30-60cm,soc_mean_60-100cm,soc_mean_100-200cm \
|
| 506 |
+
--crop corn \
|
| 507 |
+
--time_agg weekly \
|
| 508 |
+
--train_cutoffs 20,24,28,32,36,40,44,48,52 \
|
| 509 |
+
--eval_cutoffs 20,24,28,32,36,40,44,48,52 \
|
| 510 |
+
--epochs 30 \
|
| 511 |
+
--lr 3e-5 \
|
| 512 |
+
--batch_size 32 \
|
| 513 |
+
--out_dir checkpoints
|
| 514 |
+
```
|
| 515 |
+
|
| 516 |
+
The final checkpoint is stored in:
|
| 517 |
+
|
| 518 |
+
```text
|
| 519 |
+
checkpoints/
|
| 520 |
+
```
|
| 521 |
+
|
| 522 |
+
The checkpoint includes:
|
| 523 |
+
|
| 524 |
+
```text
|
| 525 |
+
config.json
|
| 526 |
+
model.safetensors
|
| 527 |
+
metrics.json
|
| 528 |
+
```
|
| 529 |
+
#### Training on Your Own Data
|
| 530 |
+
|
| 531 |
+
The training pipeline can also be used to train a new yield estimation model on a compatible dataset.
|
| 532 |
+
|
| 533 |
+
Prepare the dataset in the HDF5 format expected by `YieldDataset` and provide separate training, validation, and test files.
|
| 534 |
+
|
| 535 |
+
The weather and soil variables supplied to the training command must correspond to the variables available in the prepared dataset.
|
| 536 |
+
|
| 537 |
+
A general training command is:
|
| 538 |
+
|
| 539 |
+
```bash
|
| 540 |
+
python scripts/train_hf.py \
|
| 541 |
+
--train_file <path/to/train.h5> \
|
| 542 |
+
--val_file <path/to/val.h5> \
|
| 543 |
+
--test_file <path/to/test.h5> \
|
| 544 |
+
--weather_vars <comma-separated-weather-variables> \
|
| 545 |
+
--soil_vars <comma-separated-soil-variables> \
|
| 546 |
+
--crop <crop-name> \
|
| 547 |
+
--time_agg weekly \
|
| 548 |
+
--train_cutoffs <comma-separated-training-cutoffs> \
|
| 549 |
+
--eval_cutoffs <comma-separated-evaluation-cutoffs> \
|
| 550 |
+
--epochs <number-of-epochs> \
|
| 551 |
+
--lr <learning-rate> \
|
| 552 |
+
--batch_size <batch-size> \
|
| 553 |
+
--out_dir <output-directory>
|
| 554 |
+
```
|
| 555 |
+
|
| 556 |
+
#### SLURM Training
|
| 557 |
+
|
| 558 |
+
An example SLURM job is provided in:
|
| 559 |
+
|
| 560 |
+
```text
|
| 561 |
+
training.slurm
|
| 562 |
+
```
|
| 563 |
+
|
| 564 |
+
Submit it using:
|
| 565 |
+
|
| 566 |
+
```bash
|
| 567 |
+
sbatch training.slurm
|
| 568 |
+
```
|
| 569 |
+
|
| 570 |
+
#### Evaluation
|
| 571 |
+
|
| 572 |
+
The trained checkpoint can be evaluated using:
|
| 573 |
+
|
| 574 |
+
```text
|
| 575 |
+
scripts/evaluate_hf.py
|
| 576 |
+
```
|
| 577 |
+
|
| 578 |
+
For the final multi-cutoff model:
|
| 579 |
+
|
| 580 |
+
```bash
|
| 581 |
+
python scripts/evaluate_hf.py \
|
| 582 |
+
--hf_model_dir checkpoints \
|
| 583 |
+
--test_file data/cornbelt/test.h5 \
|
| 584 |
+
--cutoffs 20,24,28,32,36,40,44,48,52 \
|
| 585 |
+
--batch_size 64 \
|
| 586 |
+
--output_csv checkpoints/test_predictions.csv \
|
| 587 |
+
--metrics_json checkpoints/test_metrics.json
|
| 588 |
+
```
|
| 589 |
+
|
| 590 |
+
Evaluation is performed independently at the configured seasonal cutoffs.
|
| 591 |
+
|
| 592 |
+
The evaluation process:
|
| 593 |
+
|
| 594 |
+
1. loads the final trained checkpoint;
|
| 595 |
+
2. loads the test dataset;
|
| 596 |
+
3. applies the normalization statistics stored in the checkpoint configuration;
|
| 597 |
+
4. performs inference at the requested cutoffs;
|
| 598 |
+
5. computes evaluation metrics;
|
| 599 |
+
6. save predictions and metrics to disk.
|
| 600 |
+
|
| 601 |
+
#### Inference
|
| 602 |
+
|
| 603 |
+
Inference using the trained checkpoint is implemented in:
|
| 604 |
+
|
| 605 |
+
```text
|
| 606 |
+
scripts/inference_hf.py
|
| 607 |
+
```
|
| 608 |
+
|
| 609 |
+
An example structured input is provided in:
|
| 610 |
+
|
| 611 |
+
```text
|
| 612 |
+
examples/sample_input_weekly.json
|
| 613 |
+
```
|
| 614 |
+
|
| 615 |
+
The sample follows the general structure:
|
| 616 |
+
|
| 617 |
+
```json
|
| 618 |
+
{
|
| 619 |
+
"crop": "corn",
|
| 620 |
+
"weather_format": "weekly",
|
| 621 |
+
"cutoff": 52,
|
| 622 |
+
"weather": {
|
| 623 |
+
"prcp": [],
|
| 624 |
+
"srad": [],
|
| 625 |
+
"swe": [],
|
| 626 |
+
"tmax": [],
|
| 627 |
+
"tmin": [],
|
| 628 |
+
"vp": []
|
| 629 |
+
},
|
| 630 |
+
"soil": {
|
| 631 |
+
"bdod_mean_0-5cm": 0.0
|
| 632 |
+
}
|
| 633 |
+
}
|
| 634 |
+
```
|
| 635 |
+
|
| 636 |
+
The complete sample file contains the required weather sequence and soil variables.
|
| 637 |
+
|
| 638 |
+
Run single-sample inference with:
|
| 639 |
+
|
| 640 |
+
```bash
|
| 641 |
+
python scripts/inference_hf.py \
|
| 642 |
+
--hf_model_dir checkpoints \
|
| 643 |
+
--single_sample_json examples/sample_input_weekly.json \
|
| 644 |
+
--cutoff 52 \
|
| 645 |
+
--output_csv inference_prediction.csv
|
| 646 |
+
```
|
| 647 |
+
|
| 648 |
+
The output contains the predicted yield for the requested cutoff.
|
| 649 |
+
|
| 650 |
+
For example:
|
| 651 |
+
|
| 652 |
+
```text
|
| 653 |
+
sample_idx,cutoff,y_pred
|
| 654 |
+
0,52,<predicted_yield>
|
| 655 |
+
```
|
| 656 |
+
|
| 657 |
---
|
| 658 |
|
| 659 |
# Explanation
|