Views
No views yet
bu/acre). It is packaged for inference using Hugging Face Transformers and has been tested for deployment through FlexServ.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.training_code directory composes the source code for data preparation, model training, evaluation, and inference.1
2@article{Khaki2020CNNRNN,
3 author = {Khaki, Saeed and Wang, Liang and Archontoulis, Sotirios V.},
4 title = {A CNN-RNN Framework for Crop Yield Prediction},
5 journal = {Frontiers in Plant Science},
6 volume = {10},
7 pages = {1750},
8 year = {2020},
9 doi = {10.3389/fpls.2019.01750},
10 publisher = {Frontiers Media SA}
11}
12prcpsradswetmaxtminvpconfig.json.20, 24, 28, 32, 36, 40, 44, 48, 5252 represents full-season inference.text-classification pipeline as its serving interface. This is an interface choice for inference compatibility; the underlying prediction task remains regression.text-classification interface.1JSON-formatted input string
2 ↓
3YieldTokenizer
4 ↓
5weather + soil + crop + cutoff tensors
6 ↓
7Yield Estimation Transformer
8 ↓
9scalar yield prediction
10 ↓
11YIELD_BU_ACRE scorescore returned by the pipeline is therefore a yield estimate in bu/acre, not a classification probability.1.
2├── README.md
3├── LICENSE
4├── component-info.yaml
5├── training_code/
6├── config.json
7├── configuration_yield.py
8├── model.safetensors
9├── modeling_yield.py
10├── requirements.txt
11├── sample_input_weekly.json
12├── tokenization_yield.py
13├── tokenizer_config.json
14└── yield_transformer.pysample_input_weekly.jsontrust_remote_code=Truetext-classification pipeline:1import json
2from transformers import pipeline
3
4pipe = pipeline(
5 "text-classification",
6 model="ICICLE-AI/yield-estimation",
7 tokenizer="ICICLE-AI/yield-estimation",
8 trust_remote_code=True,
9)
10
11with open("sample_input_weekly.json") as f:
12 sample = json.load(f)
13
14prediction = pipe(json.dumps(sample))
15
16print(prediction)1[
2 {
3 "label": "YIELD_BU_ACRE",
4 "score": 165.1769561767578
5 }
6]score is the predicted corn yield in bushels per acre.1{
2 "crop": "corn",
3 "weather_format": "weekly",
4 "cutoff": 52,
5 "weather": {
6 "prcp": ["52 weekly values"],
7 "srad": ["52 weekly values"],
8 "swe": ["52 weekly values"],
9 "tmax": ["52 weekly values"],
10 "tmin": ["52 weekly values"],
11 "vp": ["52 weekly values"]
12 },
13 "soil": {
14 "bdod_mean_0-5cm": 0.0,
15 "...": "remaining soil features"
16 }
17}config.json.1Task: text-classification
2Model: ICICLE-AI/yield-estimationinputs field expects a string. Therefore, the structured yield input must be supplied as a JSON-formatted string, rather than directly as a nested JSON object.1{
2 "task": "text-classification",
3 "inputs": "{\"crop\":\"corn\",\"weather_format\":\"weekly\",\"cutoff\":52,\"weather\":{...},\"soil\":{...}}",
4 "parameters": {},
5 "model": "ICICLE-AI/yield-estimation"
6}1[
2 {
3 "label": "YIELD_BU_ACRE",
4 "score": 165.1769561767578
5 }
6]score is the estimated yield in bu/acre.1python - <<'PY'
2import json
3from transformers import pipeline
4
5with open("sample_input_weekly.json") as f:
6 sample = json.load(f)
7
8pipe = pipeline(
9 "text-classification",
10 model=".",
11 tokenizer=".",
12 trust_remote_code=True,
13)
14
15print(pipe(json.dumps(sample)))
16PY[{'label': 'YIELD_BU_ACRE', 'score': 165.1769561767578}]1git clone https://huggingface.co/ICICLE-AI/yield-estimation
2cd yield-estimation/training_code1conda create -n yield_hf python=3.10
2conda activate yield_hfpip install -r requirements.txtrequirements.txt[K, W]K is the number of temporal observations;W = 6 is the number of weather variables.[S]S = 661weather + soil + crop information
2 ↓
3 transformer model
4 ↓
5 predicted corn yieldbu/acre).1.
2├── README.md
3├── requirements.txt
4├── training.slurm
5│
6├── checkpoints/
7│ ├── config.json
8│ ├── metrics.json
9│ └── model.safetensors
10│
11├── config/
12│ ├── __init__.py
13│ └── config.py
14│
15├── data/
16│ ├── __init__.py
17│ ├── dataset.py
18│ └── preprocessing.py
19│
20├── examples/
21│ └── sample_input_weekly.json
22│
23├── hf/
24│ ├── __init__.py
25│ ├── auto.py
26│ ├── configuration_yield.py
27│ └── modeling_yield.py
28│
29├── models/
30│ ├── __init__.py
31│ └── unimodal_ws_crossattn.py
32│
33├── scripts/
34│ ├── __init__.py
35│ ├── prepare_cornbelt.py
36│ ├── train_hf.py
37│ ├── evaluate_hf.py
38│ └── inference_hf.py
39│
40└── training/
41 ├── __init__.py
42 └── engine.pydata/ — dataset loading and preprocessingmodels/ — core neural network architecturetraining/ — training and evaluation utilitieshf/ — Hugging Face AutoClass-compatible regression wrapper used by the training repositoryscripts/ — data preparation, training, evaluation, and inference entry pointscheckpoints/ — final trained checkpoint and configurationexamples/ — example structured model inputtraining.slurm — example HPC training jobscripts/prepare_cornbelt.py1data/
2└── cornbelt/
3 ├── train.h5
4 ├── val.h5
5 └── test.h51prcp
2srad
3swe
4tmax
5tmin
6vpscripts/train_hf.py20,24,28,32,36,40,44,48,521python scripts/train_hf.py \
2 --train_file data/cornbelt/train.h5 \
3 --val_file data/cornbelt/val.h5 \
4 --test_file data/cornbelt/test.h5 \
5 --weather_vars prcp,srad,swe,tmax,tmin,vp \
6 --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 \
7 --crop corn \
8 --time_agg weekly \
9 --train_cutoffs 20,24,28,32,36,40,44,48,52 \
10 --eval_cutoffs 20,24,28,32,36,40,44,48,52 \
11 --epochs 30 \
12 --lr 3e-5 \
13 --batch_size 32 \
14 --out_dir checkpointscheckpoints/1config.json
2model.safetensors
3metrics.jsonYieldDataset and provide separate training, validation, and test files.1python scripts/train_hf.py \
2 --train_file <path/to/train.h5> \
3 --val_file <path/to/val.h5> \
4 --test_file <path/to/test.h5> \
5 --weather_vars <comma-separated-weather-variables> \
6 --soil_vars <comma-separated-soil-variables> \
7 --crop <crop-name> \
8 --time_agg weekly \
9 --train_cutoffs <comma-separated-training-cutoffs> \
10 --eval_cutoffs <comma-separated-evaluation-cutoffs> \
11 --epochs <number-of-epochs> \
12 --lr <learning-rate> \
13 --batch_size <batch-size> \
14 --out_dir <output-directory>training.slurmsbatch training.slurmscripts/evaluate_hf.py1python scripts/evaluate_hf.py \
2 --hf_model_dir checkpoints \
3 --test_file data/cornbelt/test.h5 \
4 --cutoffs 20,24,28,32,36,40,44,48,52 \
5 --batch_size 64 \
6 --output_csv checkpoints/test_predictions.csv \
7 --metrics_json checkpoints/test_metrics.jsonscripts/inference_hf.pyexamples/sample_input_weekly.json1{
2 "crop": "corn",
3 "weather_format": "weekly",
4 "cutoff": 52,
5 "weather": {
6 "prcp": [],
7 "srad": [],
8 "swe": [],
9 "tmax": [],
10 "tmin": [],
11 "vp": []
12 },
13 "soil": {
14 "bdod_mean_0-5cm": 0.0
15 }
16}1python scripts/inference_hf.py \
2 --hf_model_dir checkpoints \
3 --single_sample_json examples/sample_input_weekly.json \
4 --cutoff 52 \
5 --output_csv inference_prediction.csv1sample_idx,cutoff,y_pred
20,52,<predicted_yield>text-classification task to expose the regression model as a FlexServ inference service.