reox8623 downloadsDraw ONNX models written as text in onnx code blocks as Netron-style graphs, with a button to flip each one between the graph and its source.
See the structure of an ONNX model in your notes. Write the model as text in an
onnx code block and it's drawn as a graph in the style of Netron, in
Reading view and Live Preview, on desktop and mobile. The plugin only draws models; it never runs
them.
```onnx
<ir_version: 8, opset_import: ["" : 17]>
cnn (float[N, 3, 32, 32] x) => (float[N, 10] y) {
c = Conv <kernel_shape = [3, 3], pads = [1, 1, 1, 1]> (x, w)
r = Relu (c)
p = GlobalAveragePool (r)
y = Gemm <transB = 1> (p, fc_w, fc_b)
}
```
To install by hand instead, download main.js, manifest.json and styles.css from the
latest release into
<your vault>/.obsidian/plugins/onnx-graph-preview/, then enable the plugin.
Put the model in a code block tagged onnx, in any of these forms:
onnx.save with format="pbtxt".MessageToJson for a ModelProto.The plugin recognises the form by itself. A binary .onnx file can't go in a note; convert it to
text first, for example with onnx.printer.to_text(model) in Python.
Each operator is a box headed with its type, listing its settings and the weights it uses. Inputs
and outputs are rounded pills, and arrows are labelled with tensor shapes. Placement is automatic.
The branches of If and the body of Loop are named but not drawn, and functions aren't drawn.
Add options in braces after onnx:
```onnx {caption="Figure 1: The stem" align="center" direction="right"}
stem (float[N, 3, 224, 224] x) => (float[N, 64, 56, 56] y) {
c = Conv <kernel_shape = [7, 7], strides = [2, 2], pads = [3, 3, 3, 3]> (x, w)
r = Relu (c)
y = MaxPool <kernel_shape = [3, 3], strides = [2, 2], pads = [1, 1, 1, 1]> (r)
}
```
| Option | What it does |
|---|---|
direction |
down (the default) or right: which way the graph flows. |
caption |
Text shown under the graph. |
align |
left, center or right. |
alt |
A description read aloud by screen readers. |
class |
A CSS class, for styling the graph with a CSS snippet. |
Put each value in quotes. Values are plain text, not Markdown. If an option is misspelled, it's
ignored and the graph still appears; only a direction other than down or right is shown as
an error.
Graphs follow your theme. In a dark theme, boxes turn dark, text and arrows are lightened to read, and Netron's colours keep their hue. In a light theme, graphs appear on a white card with Netron's exact colours.
To always show the exact colours on a white card, turn off Follow dark themes in the plugin's settings.
| Setting | What it does |
|---|---|
| Layout timeout | How long laying out a graph may take before it's shown as an error. 3 seconds by default, from 0.5 to 60. |
| Follow dark themes | On by default. Turn off to keep every graph on a white card. |
| Debug logging | Writes ignored options, and parts of a model that weren't drawn, to the developer console. |
| Command | What it does |
|---|---|
| Show every diagram in this note | Switches every block in the note back from text to graph. |
| Restart renderer | Starts the graph engine afresh and redraws open notes. |
Graphs are drawn on your device, inside Obsidian. The plugin doesn't connect to the internet, doesn't collect any data, doesn't read or write any files, and never runs a model.
Models are read by Netron, created by Lutz Roeder, and laid out by the Eclipse Layout Kernel through elkjs. The licenses of the software built into this plugin are listed in THIRD_PARTY_NOTICES.md.
Released under the MIT License. To build or change the plugin, see DEVELOPMENT.md.