fix(ANSModelPackage): read the head off the graph, not off the package's word
A package whose family says "yolo" may hold an end-to-end export. Boxes took the family from the backend marker, and the marker names the runtime, not the head — so a fast yolo26 export arrived declared as plain yolo while its graph emits [1, N, 6] with the NMS inside it. Decoding that as a [1, 4+nc, N] grid reads coordinates as confidences: detections everywhere, and nothing that looks like a failure. OpenModelPackage now reads the first output's dims from the model it has just decrypted, and corrects the family with the reason in the warning rather than swapping it silently. It costs nothing there: the bytes are in hand. The legacy marker is left alone, so anything converting back to a zip still writes what ANSCORE expects. A two-class v8 export is [1, 6, 8400] and must not be mistaken for one, which is why the 6 has to be the last axis with a detection count before it. Both cases are tested, and the package this Mac exported before the writer was fixed now reads as yolo10 here too. 46 checks, no failures. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -217,16 +217,28 @@ inline bool OpenModelPackage(const std::string& path, OpenedModel& out,
|
||||
out.name = m.value("project", std::string());
|
||||
if (out.name.empty()) out.name = path;
|
||||
|
||||
// A package written before manifests carried an input size still has to
|
||||
// answer, and the model in hand is the thing that knows. It costs nothing
|
||||
// here: the bytes are already decrypted.
|
||||
if (out.inputWidth <= 0 || out.inputHeight <= 0) {
|
||||
onnxshape::InputShape shape;
|
||||
// WHAT AN OLDER PACKAGE CANNOT TELL US, and its model can. The input
|
||||
// size, when the manifest predates the field; and the head, because a
|
||||
// package whose family is "yolo" may hold an end-to-end export — the box
|
||||
// used to take the family from the backend marker, and the marker names
|
||||
// the runtime rather than the head. It costs nothing to ask here: the
|
||||
// bytes are already decrypted.
|
||||
{
|
||||
onnxshape::GraphShape g;
|
||||
std::string swhy;
|
||||
if (onnxshape::fromMemory(out.model.data(), out.model.size(), shape,
|
||||
swhy)) {
|
||||
out.inputWidth = shape.width;
|
||||
out.inputHeight = shape.height;
|
||||
if (onnxshape::graphFromMemory(out.model.data(), out.model.size(), g,
|
||||
swhy)) {
|
||||
if (out.inputWidth <= 0 || out.inputHeight <= 0) {
|
||||
out.inputWidth = g.input.width;
|
||||
out.inputHeight = g.input.height;
|
||||
}
|
||||
if (g.endToEnd() && out.family == "yolo") {
|
||||
out.family = "yolo10";
|
||||
out.warning = out.warning.empty()
|
||||
? "this package says family yolo, but its head is "
|
||||
"end-to-end; reading it as yolo10"
|
||||
: out.warning;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user