Upload folder using huggingface_hub
Browse files- README.md +72 -0
- metrics.json +66 -0
- milk_nir_pls.onnx +3 -0
README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-4.0
|
| 3 |
+
library_name: onnx
|
| 4 |
+
tags:
|
| 5 |
+
- nir-spectroscopy
|
| 6 |
+
- chemometrics
|
| 7 |
+
- dairy
|
| 8 |
+
- milk
|
| 9 |
+
- pls
|
| 10 |
+
- edge-ai
|
| 11 |
+
datasets:
|
| 12 |
+
- zenodo/8263430
|
| 13 |
+
metrics:
|
| 14 |
+
- rmse
|
| 15 |
+
- r_squared
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# Raw-milk composition from NIR transmittance (PLS, ONNX)
|
| 19 |
+
|
| 20 |
+
Predicts **fat, protein and lactose (%)** of raw cow milk from a long-wave NIR transmittance spectrum
|
| 21 |
+
(960–1690 nm, 256 pixels, ~2.86 nm/pixel). Preprocessing is inside the model: feed raw transmittance, get percentages.
|
| 22 |
+
|
| 23 |
+
Built by [Amazeng](https://amazeng.com.tr) as an open reference model for on-farm and in-line milk analysis on edge hardware.
|
| 24 |
+
|
| 25 |
+
## Usage
|
| 26 |
+
|
| 27 |
+
```python
|
| 28 |
+
import numpy as np, onnxruntime as ort
|
| 29 |
+
|
| 30 |
+
sess = ort.InferenceSession("milk_nir_pls.onnx")
|
| 31 |
+
t = np.asarray(spectra, dtype=np.float32) # (batch, 256) transmittance, 960 -> 1690 nm
|
| 32 |
+
fat, protein, lactose = sess.run(None, {"transmittance": t})[0].T
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
**Input:** dark/white-corrected transmittance `(S - D) / (W - D)`, 256 values on the wavelength grid of the training
|
| 36 |
+
spectrometer (960–1690 nm). A different spectrometer must resample to this grid **and** be recalibrated (see Limitations).
|
| 37 |
+
|
| 38 |
+
**Inside the model:** transmittance → absorbance (−log10) → SNV → Savitzky–Golay 1st derivative (window 15, order 2)
|
| 39 |
+
→ one PLS regression per target, collapsed to a single linear layer. 7.7 KB, three outputs.
|
| 40 |
+
|
| 41 |
+
## Results
|
| 42 |
+
|
| 43 |
+
Temporal split: trained on weeks 1–6 (n=894), tested on weeks 7–8 (n=330) — a calibration used in the weeks after it was built.
|
| 44 |
+
|
| 45 |
+
| Target | RMSE (%) | R² | PLS components |
|
| 46 |
+
|---|---|---|---|
|
| 47 |
+
| Fat | 0.112 | 0.979 | 19 |
|
| 48 |
+
| Protein | 0.063 | 0.965 | 39 |
|
| 49 |
+
| Lactose | 0.126 | 0.48 | 36 |
|
| 50 |
+
|
| 51 |
+
A 1D-CNN trained on the same data was worse on every released target (fat R² 0.95, protein 0.41); with ~900 spectra,
|
| 52 |
+
linear chemometrics wins.
|
| 53 |
+
|
| 54 |
+
## Limitations
|
| 55 |
+
|
| 56 |
+
- **One instrument, one farm, eight weeks** (41 Holstein cows, Belgium, 2017). Expect a bias on any other spectrometer
|
| 57 |
+
or herd; recalibrate with your own reference samples before trusting absolute values.
|
| 58 |
+
- **Lactose is weak** (R² ~0.5, sensitive to the PLS component count). Use fat and protein; treat lactose as indicative.
|
| 59 |
+
- **Not included:** somatic cell count and urea. Neither was predictable from these spectra (test R² ≤ 0.13);
|
| 60 |
+
SCC > 200k cells/mL screening reached only AUC 0.76. This model is **not** a mastitis or bacteria test.
|
| 61 |
+
- Not a substitute for certified laboratory analysis.
|
| 62 |
+
|
| 63 |
+
## Training data and attribution
|
| 64 |
+
|
| 65 |
+
J.A. Diaz-Olivares, I. Adriaens, E. Stevens, W. Saeys, B. Aernouts — *Near-infrared spectra dataset of milk composition
|
| 66 |
+
in transmittance mode*, Zenodo, [10.5281/zenodo.8263430](https://doi.org/10.5281/zenodo.8263430), CC BY 4.0.
|
| 67 |
+
Data in Brief (2023) 109767, [10.1016/j.dib.2023.109767](https://doi.org/10.1016/j.dib.2023.109767).
|
| 68 |
+
|
| 69 |
+
Related: Diaz-Olivares et al., *Online milk composition analysis with an on-farm near-infrared sensor*,
|
| 70 |
+
Comput. Electron. Agric. 178 (2020) 105734.
|
| 71 |
+
|
| 72 |
+
This model is released under CC BY 4.0. Cite the dataset above when you use it.
|
metrics.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"split": "train weeks 1-6 (n=894), test weeks 7-8 (n=330)",
|
| 3 |
+
"pls": {
|
| 4 |
+
"Fat": {
|
| 5 |
+
"rmse": 0.11183657606466905,
|
| 6 |
+
"r2": 0.9791059615618545,
|
| 7 |
+
"rpd": 6.918131351470947
|
| 8 |
+
},
|
| 9 |
+
"Prot": {
|
| 10 |
+
"rmse": 0.06288773017244294,
|
| 11 |
+
"r2": 0.9646598907421994,
|
| 12 |
+
"rpd": 5.319441795349121
|
| 13 |
+
},
|
| 14 |
+
"Lact": {
|
| 15 |
+
"rmse": 0.12580625033959672,
|
| 16 |
+
"r2": 0.4784692290799788,
|
| 17 |
+
"rpd": 1.3847137689590454
|
| 18 |
+
},
|
| 19 |
+
"logSCC": {
|
| 20 |
+
"rmse": 0.5589001108519704,
|
| 21 |
+
"r2": 0.09509268925551306,
|
| 22 |
+
"rpd": 1.0512304306030273,
|
| 23 |
+
"auc_scc>200k": 0.763937575030012
|
| 24 |
+
},
|
| 25 |
+
"Urea": {
|
| 26 |
+
"rmse": 4.512190080604686,
|
| 27 |
+
"r2": -0.16566286259174,
|
| 28 |
+
"rpd": 0.9262186884880066
|
| 29 |
+
}
|
| 30 |
+
},
|
| 31 |
+
"cnn": {
|
| 32 |
+
"Fat": {
|
| 33 |
+
"rmse": 0.17650680243968964,
|
| 34 |
+
"r2": 0.9479551911354065,
|
| 35 |
+
"rpd": 4.383400917053223
|
| 36 |
+
},
|
| 37 |
+
"Prot": {
|
| 38 |
+
"rmse": 0.2565610706806183,
|
| 39 |
+
"r2": 0.411810040473938,
|
| 40 |
+
"rpd": 1.3038908243179321
|
| 41 |
+
},
|
| 42 |
+
"Lact": {
|
| 43 |
+
"rmse": 0.13689003884792328,
|
| 44 |
+
"r2": 0.38252532482147217,
|
| 45 |
+
"rpd": 1.2725956439971924
|
| 46 |
+
},
|
| 47 |
+
"logSCC": {
|
| 48 |
+
"rmse": 0.5491849780082703,
|
| 49 |
+
"r2": 0.12627851963043213,
|
| 50 |
+
"rpd": 1.0698268413543701,
|
| 51 |
+
"auc_scc>200k": 0.7145258103241295
|
| 52 |
+
},
|
| 53 |
+
"Urea": {
|
| 54 |
+
"rmse": 4.5135016441345215,
|
| 55 |
+
"r2": -0.16634070873260498,
|
| 56 |
+
"rpd": 0.9259495139122009
|
| 57 |
+
}
|
| 58 |
+
},
|
| 59 |
+
"pls_components": {
|
| 60 |
+
"Fat": 19,
|
| 61 |
+
"Prot": 39,
|
| 62 |
+
"Lact": 36,
|
| 63 |
+
"logSCC": 17,
|
| 64 |
+
"Urea": 6
|
| 65 |
+
}
|
| 66 |
+
}
|
milk_nir_pls.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c50fa0862b6072f393bbc4735e5fee0904740e3adea6f1a5a176c6b7d60d6d31
|
| 3 |
+
size 7686
|