evaluate¶
training.evaluate
¶
Fine-tuned model evaluation: 4-condition protocol on the QLoRA-adapted LFM2.5-VL-1.6B.
Runs the same 4-condition ablation protocol as ablation, but loads the
ORION QLoRA adapter on top of the base model via PEFT. Comparing outputs from
the two scripts quantifies the effect of fine-tuning on each input channel.
Conditions:
| ID | Name | Image | Coordinates | Tests |
|---|---|---|---|---|
| A | Full system | Real | Real | Nominal end-to-end accuracy |
| B | Vision only | Real | Stripped | Visual-feature reliance |
| C | Blind LLM | Gaussian noise | Real | Coordinate memorisation |
| D | Sensor conflict | Real | Spoofed | Vision-vs-telemetry trust |
The key difference from ablation is the model loading path: this script
loads the base LFM2.5-VL-1.6B, then grafts the QLoRA adapter from
orion_lora_weights/ using peft.PeftModel. It also handles
device_map explicitly (CUDA / MPS / CPU) to avoid an accelerate
crash with LFM2's config.
Optionally, pass --quantized-model to evaluate the Q4_K_M GGUF model
via llama.cpp's built-in HTTP server (OpenAI-compatible API) instead of
PyTorch+PEFT. This measures accuracy degradation from quantization using
the exact same test protocol.
Usage:
# make sure LoRA weights are placed in ``./orion_lora_weights/`` and the
# dataset is in ``../data/orion_dataset/``
cd ground_segment/training
# PyTorch + PEFT (default)
uv run evaluate.py # test split (default)
uv run evaluate.py --file val # validation split
# Quantized GGUF via llama-server (start server first):
# ../llama.cpp/build/bin/llama-server -m ./orion-q4_k_m.gguf --mmproj ./orion-mmproj-f16.gguf -c 4096 -ngl 0
uv run evaluate.py --quantized-model http://localhost:8080
See the validation and ablation studies guide for how to interpret each condition and compare against the base-model results.
extract_json(text)
¶
Extract the first JSON object from VLM output, falling back to an ERROR dict.
Scans text for the outermost {…} pair and attempts json.loads.
If the model produced blank output, hallucinated prose, or malformed JSON,
returns a sentinel {"category": "ERROR", "reason": "…"} so that the
caller always gets a dict with a category key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
Raw decoded string from the VLM's generation output. |
required |
Returns:
| Type | Description |
|---|---|
|
A dict with at least a |
|
|
or |
Source code in ground_segment/training/evaluate.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
main()
¶
Run the 4-condition evaluation protocol on the fine-tuned ORION model.
Loads the base LFM2.5-VL-1.6B, grafts the QLoRA adapter from
orion_lora_weights/, then evaluates every sample in the chosen
split under all four conditions (A-D). Prints per-class recall/precision
tables for Conditions A-C and a vision-vs-coordinate trust breakdown
for Condition D.
Source code in ground_segment/training/evaluate.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
print_confusion_matrix(truths, preds, condition_name)
¶
Print per-class recall/precision and aggregate accuracy for one condition.
Iterates over the three triage classes (HIGH, MEDIUM, LOW), computing recall and precision for each, then prints overall accuracy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
truths
|
List of ground-truth category strings. |
required | |
preds
|
List of predicted category strings (same length as truths). |
required | |
condition_name
|
Human-readable label printed as the section header
(e.g. |
required |
Source code in ground_segment/training/evaluate.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
run_inference(model, processor, image, prompt)
¶
Run a single image+prompt through the fine-tuned VLM and return parsed JSON plus raw text.
Applies the processor's chat template, runs greedy generation with a
200-token cap, then parses the output via extract_json. Unlike the
base-model ablation variant, this resolves the device from the model's
own parameters to handle CUDA, MPS, and CPU transparently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Fine-tuned |
required | |
processor
|
Matching |
required | |
image
|
PIL Image (512x512 RGB) to classify. |
required | |
prompt
|
Text prompt including classification instructions and (optionally) GPS coordinates. |
required |
Returns:
| Type | Description |
|---|---|
|
A |
|
|
and raw is the full decoded generation string. |
Source code in ground_segment/training/evaluate.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
run_inference_gguf(server_url, image, prompt)
¶
Run a single image+prompt through the quantized GGUF model via llama-server's OpenAI-compatible API.
Source code in ground_segment/training/evaluate.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |