-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Support JSON as a serialization target #5523
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
Conversation
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
d3025f2 to
eb32c2c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the enhancement! I was wondering does JSON serialization/deserialization have 2GB limit as well?
|
I don't think there is one, but it's also not realistic to have big models in json because the text representation is less efficient. |
|
onnxjson? onnx.json? onnx.json is easier for editors I can add both json and onnxjson. |
Signed-off-by: Justin Chu <[email protected]>
Internally protobuf still use int instead of sizes_t as array length type. |
### Description
Create serializers to the `json` format and register the `json` and
`onnxjson` extensions to it.
```python
import onnx
model = onnx.load_model("onnx/backend/test/data/light/light_resnet50.onnx")
onnx.save_model(model, "resnet50.json")
```
yields
```json
{
"ir_version": "3",
"producer_name": "onnx-caffe2",
"producer_version": "",
"domain": "",
"model_version": "0",
"doc_string": "",
"graph": {
"node": [
{
"input": [
"gpu_0/conv1_w_0__SHAPE"
],
"output": [
"gpu_0/conv1_w_0"
],
"op_type": "ConstantOfShape",
"attribute": [
{
"name": "value",
"t": {
"dims": [
"1"
],
"data_type": 1,
"float_data": [
0.02
],
"name": ""
},
"type": "TENSOR"
}
]
},
{
"input": [
"gpu_0/pred_b_0__SHAPE"
],
"output": [
"gpu_0/pred_b_0"
],
"op_type": "ConstantOfShape",
"attribute": [
{
"name": "value",
"t": {
"dims": [
"1"
],
"data_type": 1,
"float_data": [
0.02
],
"name": ""
},
"type": "TENSOR"
}
]
},
{
"input": [
"gpu_0/pred_w_0__SHAPE"
],
"output": [
"gpu_0/pred_w_0"
],
"op_type": "ConstantOfShape",
"attribute": [
{
"name": "value",
"t": {
"dims": [
"1"
],
"data_type": 1,
"float_data": [
0.02
],
"name": ""
},
"type": "TENSOR"
}
]
},
...
```
### Motivation and Context
A more familiar text representation for free from protobuf using
https://googleapis.dev/python/protobuf/latest/google/protobuf/json_format.html
---------
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Corwin Joy <[email protected]>
### Description
Create serializers to the `json` format and register the `json` and
`onnxjson` extensions to it.
```python
import onnx
model = onnx.load_model("onnx/backend/test/data/light/light_resnet50.onnx")
onnx.save_model(model, "resnet50.json")
```
yields
```json
{
"ir_version": "3",
"producer_name": "onnx-caffe2",
"producer_version": "",
"domain": "",
"model_version": "0",
"doc_string": "",
"graph": {
"node": [
{
"input": [
"gpu_0/conv1_w_0__SHAPE"
],
"output": [
"gpu_0/conv1_w_0"
],
"op_type": "ConstantOfShape",
"attribute": [
{
"name": "value",
"t": {
"dims": [
"1"
],
"data_type": 1,
"float_data": [
0.02
],
"name": ""
},
"type": "TENSOR"
}
]
},
{
"input": [
"gpu_0/pred_b_0__SHAPE"
],
"output": [
"gpu_0/pred_b_0"
],
"op_type": "ConstantOfShape",
"attribute": [
{
"name": "value",
"t": {
"dims": [
"1"
],
"data_type": 1,
"float_data": [
0.02
],
"name": ""
},
"type": "TENSOR"
}
]
},
{
"input": [
"gpu_0/pred_w_0__SHAPE"
],
"output": [
"gpu_0/pred_w_0"
],
"op_type": "ConstantOfShape",
"attribute": [
{
"name": "value",
"t": {
"dims": [
"1"
],
"data_type": 1,
"float_data": [
0.02
],
"name": ""
},
"type": "TENSOR"
}
]
},
...
```
### Motivation and Context
A more familiar text representation for free from protobuf using
https://googleapis.dev/python/protobuf/latest/google/protobuf/json_format.html
---------
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Corwin Joy <[email protected]>
### Description
Create serializers to the `json` format and register the `json` and
`onnxjson` extensions to it.
```python
import onnx
model = onnx.load_model("onnx/backend/test/data/light/light_resnet50.onnx")
onnx.save_model(model, "resnet50.json")
```
yields
```json
{
"ir_version": "3",
"producer_name": "onnx-caffe2",
"producer_version": "",
"domain": "",
"model_version": "0",
"doc_string": "",
"graph": {
"node": [
{
"input": [
"gpu_0/conv1_w_0__SHAPE"
],
"output": [
"gpu_0/conv1_w_0"
],
"op_type": "ConstantOfShape",
"attribute": [
{
"name": "value",
"t": {
"dims": [
"1"
],
"data_type": 1,
"float_data": [
0.02
],
"name": ""
},
"type": "TENSOR"
}
]
},
{
"input": [
"gpu_0/pred_b_0__SHAPE"
],
"output": [
"gpu_0/pred_b_0"
],
"op_type": "ConstantOfShape",
"attribute": [
{
"name": "value",
"t": {
"dims": [
"1"
],
"data_type": 1,
"float_data": [
0.02
],
"name": ""
},
"type": "TENSOR"
}
]
},
{
"input": [
"gpu_0/pred_w_0__SHAPE"
],
"output": [
"gpu_0/pred_w_0"
],
"op_type": "ConstantOfShape",
"attribute": [
{
"name": "value",
"t": {
"dims": [
"1"
],
"data_type": 1,
"float_data": [
0.02
],
"name": ""
},
"type": "TENSOR"
}
]
},
...
```
### Motivation and Context
A more familiar text representation for free from protobuf using
https://googleapis.dev/python/protobuf/latest/google/protobuf/json_format.html
---------
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Corwin Joy <[email protected]>
Description
Create serializers to the
jsonformat and register thejsonandonnxjsonextensions to it.yields
{ "ir_version": "3", "producer_name": "onnx-caffe2", "producer_version": "", "domain": "", "model_version": "0", "doc_string": "", "graph": { "node": [ { "input": [ "gpu_0/conv1_w_0__SHAPE" ], "output": [ "gpu_0/conv1_w_0" ], "op_type": "ConstantOfShape", "attribute": [ { "name": "value", "t": { "dims": [ "1" ], "data_type": 1, "float_data": [ 0.02 ], "name": "" }, "type": "TENSOR" } ] }, { "input": [ "gpu_0/pred_b_0__SHAPE" ], "output": [ "gpu_0/pred_b_0" ], "op_type": "ConstantOfShape", "attribute": [ { "name": "value", "t": { "dims": [ "1" ], "data_type": 1, "float_data": [ 0.02 ], "name": "" }, "type": "TENSOR" } ] }, { "input": [ "gpu_0/pred_w_0__SHAPE" ], "output": [ "gpu_0/pred_w_0" ], "op_type": "ConstantOfShape", "attribute": [ { "name": "value", "t": { "dims": [ "1" ], "data_type": 1, "float_data": [ 0.02 ], "name": "" }, "type": "TENSOR" } ] }, ...Motivation and Context
A more familiar text representation for free from protobuf using https://googleapis.dev/python/protobuf/latest/google/protobuf/json_format.html