lutzroeder/netron · error · Error

Unknown field '${tag}' ${this.location()}

Error message

Unknown field '${tag}' ${this.location()}

What it means

The caffe2 text-format (protobuf.text) reader hit a field tag that the NetDef schema does not recognize. netron installs a custom reader.field handler that only tolerates unknown fields on DeviceOption; anything else on NetDef is rejected. The outer catch immediately rewraps it as 'File format is not caffe2.NetDef'.

Source

Thrown at source/caffe2.js:174

            if (context) {
                switch (context.type) {
                    case 'caffe2.pb':
                        try {
                            const reader = await context.read('protobuf.binary');
                            return caffe2.proto.NetDef.decode(reader);
                        } catch (error) {
                            const message = error && error.message ? error.message : error.toString();
                            throw new caffe2.Error(`File format is not caffe2.NetDef (${message.replace(/\.$/, '')}).`);
                        }
                    case 'caffe2.pbtxt':
                        try {
                            const reader = await context.read('protobuf.text');
                            reader.field = function(tag, message) {
                                if (message instanceof caffe2.proto.DeviceOption) {
                                    message[tag] = this.read();
                                    return;
                                }
                                throw new Error(`Unknown field '${tag}' ${this.location()}`);
                            };
                            return caffe2.proto.NetDef.decodeText(reader);
                        } catch (error) {
                            const message = error && error.message ? error.message : error.toString();
                            throw new caffe2.Error(`File format is not caffe2.NetDef (${message.replace(/\.$/, '')}).`);
                        }
                    default:
                        throw new caffe2.Error(`Unsupported Caffe2 predict format '${context.type}'.`);
                }
            }
            return null;
        };
        const predict_net = await open(predict);
        const init_net = await open(init);
        return new caffe2.Model(metadata, predict_net, init_net);
    }
};

View on GitHub (pinned to d8a543f5f8)

Solutions

  1. Open the file with the Caffe loader instead of caffe2 (it's a Caffe v1 prototxt)
  2. Check the offending tag and line reported by this.location() and fix or remove it
  3. Regenerate the prototxt from a known-good caffe2 export
Defensive patterns

Strategy: try-catch

Validate before calling

// sniff a prototxt before opening
const first = (await file.text()).slice(0, 512);
if (/^\s*layers\s*{/m.test(first)) { /* Caffe v1 — don't use caffe2 loader */ }

Try / catch

try {
  await openAsCaffe2(file);
} catch (e) {
  if (/File format is not caffe2\.NetDef/.test(e.message)) { await openAsCaffe(file); }
}

Prevention

When it happens

Trigger: Opening a .pbtxt/prototxt with context.read('protobuf.text') where the top-level message contains a field not in caffe2.NetDef (e.g. a Caffe V1LayerParameter field like 'layers' or 'input_param').

Common situations: Trying to open a Caffe (v1) train_val.prototxt with the caffe2 loader; prototxt written by a newer/older schema; typos in hand-written prototxt.

Related errors


AI-assisted analysis of lutzroeder/netron@d8a543f5f8 (2026-08-27). Data as JSON: /api/errors/15f41d6c1be9699e. Report an issue: GitHub.