Skip to content

Commit a78b4da

Browse files
authored
Zephyr: report the host reference label alongside the top-5 (pytorch#23353)
`gen_input.py` writes `MV2_HOST_TOP1` and `MV2_HOST_LABEL` into `mv2_input.h`, but nothing reads them. The sample prints bare class IDs, so a reader cannot interpret the output on target without an ImageNet label table. This prints the recorded host prediction after the top-5 and states whether the device top-1 agrees: ``` Top-5 predictions: [1] class 258: 6.1895 [2] class 259: 4.8418 [3] class 261: 3.4442 host float32 reference: class 258 (Samoyed) -> device top-1 MATCHES ``` Guarded on both defines, so headers generated before pytorch#23300 still build. No label table is added to the target; the single string already comes from the generated header. ## Verification Flashed and run on an Alif Ensemble E8 DevKit (Cortex-M55 HP at 400 MHz + Ethos-U55, 256 MAC) with Zephyr 4.4.0 and Zephyr SDK 1.0.1, using a photograph prepared by `gen_input.py` and an INT8 model calibrated on 250 ImageNet photos. Inference completed in 28 ms and the device top-1 matched the float32 torchvision reference. Flash cost is 160 bytes. Authored with Claude.
1 parent 305638c commit a78b4da

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎zephyr/samples/mv2-ethosu/src/main.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,17 @@ void print_top_k(const std::vector<EValue>& outputs) {
269269
top_indices[j],
270270
static_cast<double>(top_values[j]));
271271
}
272+
273+
#if defined(MV2_HOST_TOP1) && defined(MV2_HOST_LABEL)
274+
// gen_input.py records what float32 torchvision predicts for this image, so
275+
// the class ID can be interpreted without an ImageNet label table on target.
276+
ET_LOG(
277+
Info,
278+
"\nhost float32 reference: class %d (%s) -> device top-1 %s",
279+
MV2_HOST_TOP1,
280+
MV2_HOST_LABEL,
281+
(top_indices[0] == MV2_HOST_TOP1) ? "MATCHES" : "DIFFERS");
282+
#endif
272283
}
273284

274285
} // namespace

0 commit comments

Comments
 (0)