-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add JSON export functionality for models #1524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
7d14ab5 to
6fc59cd
Compare
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.
6fc59cd to
014c5e0
Compare
- Add parentheses around arrow function parameters - Fix brace style formatting for else-if blocks - Ensure code follows project's ESLint rules
Hi @lutzroeder, thank you for reviewing! Use Case:
Why not onnx2json:
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. |
|
@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. |
|
@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: Option 1: Graph Metadata Export Only ( good solution for this issue - #1461 )
Option 2: Close the PR My Actual Use Case: 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! |
dfd86c1 to
66df945
Compare
5573e79 to
debc283
Compare
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:
✨ 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 handlingexport()methodapp.js: Added JSON to export file type filters in Electron save dialog
Menu options:
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:
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": [...] }] }] }