Skip to content

Conversation

@R-Mob
Copy link

@R-Mob R-Mob commented Dec 11, 2025

Summary

This PR adds JSON export functionality to Netron, allowing users to export neural network models as structured JSON files for programmatic analysis and integration.

Features

✨ Export complete model structure including:

  • Model metadata (format, version, producer, description)
  • All graphs with nodes, inputs, and outputs
  • Node types, attributes, and connections
  • Tensor shapes and data types

✨ Support for all model formats (ONNX, TensorFlow, PyTorch, etc.)
✨ Proper handling of BigInt values and complex nested structures
✨ Available in both desktop (Electron) and browser versions

Changes

  • view.js: Implemented comprehensive JSON serialization methods

    • _serializeModelToJson() - Main serialization entry point
    • _serializeGraph() - Graph structure serialization
    • _serializeNode() - Node serialization with inputs/outputs/attributes
    • _serializeType() - Type and shape serialization with BigInt handling
    • Added JSON export handling in export() method
  • app.js: Added JSON to export file type filters in Electron save dialog

  • Menu options:

    • Desktop: File → Export... → Select JSON (Ctrl/Cmd+Shift+E)
    • Browser: File → Export as JSON (Ctrl/Cmd+Shift+J)

Testing

✅ Tested with ONNX models (squeezenet)
✅ Verified BigInt serialization for model versions and tensor dimensions
✅ Built and tested macOS app successfully
✅ Verified JSON output is valid and properly formatted

Use Cases

This enhancement enables:

  • Programmatic inspection of model structures
  • Model documentation and analysis
  • Integration with other tools and workflows
  • Debugging and validation of model architectures

Example Output

The exported JSON includes structured data like:

{
  "format": "ONNX v8",
  "producer": "pytorch v2.0",
  "graphs": [{
    "name": "main",
    "nodes": [{
      "name": "conv1",
      "type": {
        "name": "Conv",
        "category": "Layer"
      },
      "inputs": [...],
      "outputs": [...],
      "attributes": [...]
    }]
  }]
}

@R-Mob R-Mob force-pushed the feature/json-export branch from 7d14ab5 to 6fc59cd Compare December 11, 2025 16:39
This commit adds the ability to export neural network models as JSON,
providing a structured representation of the model's graph, nodes,
tensors, and attributes.

Features:
- Export model metadata (format, version, producer, description)
- Serialize complete graph structure with all nodes
- Include node types, inputs, outputs, and attributes
- Serialize tensor shapes and data types
- Handle BigInt values in model properties
- Support for both desktop (Electron) and browser environments

Changes:
- Add JSON export option to File menu (Ctrl/Cmd+Shift+E for desktop,
  Ctrl/Cmd+Shift+J for browser)
- Implement comprehensive JSON serialization methods in view.js
- Add JSON file type filter to Electron save dialog
- Handle edge cases like BigInt serialization and nested structures

The JSON export provides a programmatic way to inspect and analyze
model structures, useful for debugging, documentation, and integration
with other tools.
@R-Mob R-Mob force-pushed the feature/json-export branch from 6fc59cd to 014c5e0 Compare December 11, 2025 16:46
@lutzroeder
Copy link
Owner

lutzroeder commented Dec 12, 2025

Hi @R-Mob, thank you for the pull request.

Can you explain the scenario you are using this for and would onnx2json be an option?

- Add parentheses around arrow function parameters
- Fix brace style formatting for else-if blocks
- Ensure code follows project's ESLint rules
@R-Mob
Copy link
Author

R-Mob commented Dec 12, 2025

Hi @R-Mob, thank you for the pull request.

Can you explain the scenario you are using this for and would onnx2json be an option?

Hi @lutzroeder, thank you for reviewing!

Use Case:
I wanted a way to export model structures directly from Netron's UI for programmatic analysis and documentation. Having this built into Netron provides several advantages:

  1. Universal Support: Works with all model formats that Netron already supports (ONNX, TensorFlow, PyTorch, CoreML, etc.), not just ONNX
  2. Integrated Workflow: Export JSON without switching tools or command-line utilities
  3. Visualization + Export: Users can visually inspect the model in Netron and then export the same view to JSON
  4. Cross-platform: Works in both desktop and browser versions

Why not onnx2json:
While onnx2json is great for ONNX-specific workflows, this feature:

  • Supports all model formats Netron handles
  • Provides a GUI option for non-technical users
  • Exports Netron's processed/normalized model structure
  • Doesn't require separate tool installation

This makes it useful for model documentation, debugging, integration testing, and educational purposes where users want to programmatically inspect models they're already viewing in Netron.

@lutzroeder
Copy link
Owner

@R-Mob makes sense. The main concern here is setting expectations around scope and long-term maintenance.

Export and model conversion is fundamentally different from visualization. To do this properly, Netron would need a stable intermediate representation, introducing yet another custom deep learning model format, tests, infrastructure to support many export formats, and full platform coverage for desktop, browser and server and dedicated maintainers to support this long-term. Model export and conversion also tends to require much stricter, format-complete support than Netron’s current “best-effort for visualization” approach, which risks pulling the project into low-EV corner cases better handled by format- or vendor-specific tools.

Happy to discuss concrete, narrowly scoped use cases. The challenge is how to avoid the slippery slope of “nice to haves” duplicating properly resourced vendor-specific tools and how to clearly separate one user’s special needs from the broader ecosystem of export and model conversion requirements.

@R-Mob
Copy link
Author

R-Mob commented Dec 13, 2025

@lutzroeder Thank you for the detailed explanation - I completely understand your concerns about scope creep and maintenance burden.

You're absolutely right that this could lead down a slippery slope of feature requests for comprehensive model conversion/export functionality, which is not Netron's core mission and would be better handled by format-specific tools.

Reconsidering the Scope:
After your feedback, I realize my implementation may be too broad. Let me propose a more narrowly scoped alternative that stays true to Netron's visualization focus:

Option 1: Graph Metadata Export Only ( good solution for this issue - #1461 )

  • Export only what's currently displayed in the UI (node names, types, connections)
  • Purely for documentation/diagramming purposes
  • No tensor data, no weights, no model conversion capabilities
  • Just a JSON representation of the visual graph structure users already see
  • Clear disclaimer: "Visualization export only - not for model reconstruction"

Option 2: Close the PR
If even Option 1 risks setting wrong expectations or creates maintenance overhead, I'm happy to close this PR. I appreciate you taking the time to review and explain the architectural concerns.

My Actual Use Case:
I wanted to document model architectures I was reviewing in Netron by exporting the graph structure (nodes/connections) for reports and presentations. I can achieve this using screenshots or by using onnx2json for ONNX models specifically.

Please let me know if Option 1 makes sense as a more focused feature, or if you'd prefer I close this PR. Either way, thank you for maintaining such a valuable tool!

@lutzroeder lutzroeder force-pushed the main branch 21 times, most recently from dfd86c1 to 66df945 Compare December 17, 2025 13:47
@lutzroeder lutzroeder force-pushed the main branch 30 times, most recently from 5573e79 to debc283 Compare January 6, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants