Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@justinchuby
Copy link
Member

@justinchuby justinchuby commented Aug 23, 2023

Description

Create serializers to the json format and register the json and onnxjson extensions to it.

import onnx
model = onnx.load_model("onnx/backend/test/data/light/light_resnet50.onnx")
onnx.save_model(model, "resnet50.json")

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

Signed-off-by: Justin Chu <[email protected]>
@justinchuby justinchuby requested a review from a team as a code owner August 23, 2023 21:07
@justinchuby justinchuby requested a review from jcwchen August 23, 2023 21:08
Signed-off-by: Justin Chu <[email protected]>
Copy link
Member

@jcwchen jcwchen left a 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?

@justinchuby
Copy link
Member Author

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.

@justinchuby
Copy link
Member Author

onnxjson? onnx.json?

onnx.json is easier for editors
onnxjson is easier when we check extensions and work with paths.

I can add both json and onnxjson.

@justinchuby justinchuby added this to the 1.15 milestone Aug 24, 2023
@justinchuby justinchuby added this pull request to the merge queue Aug 24, 2023
Merged via the queue into onnx:main with commit 2a7d8e9 Aug 24, 2023
@justinchuby justinchuby deleted the justinchu/json branch August 24, 2023 19:11
@snnn
Copy link
Contributor

snnn commented Aug 25, 2023

Thanks for the enhancement! I was wondering does JSON serialization/deserialization have 2GB limit as well?

Internally protobuf still use int instead of sizes_t as array length type.

corwinjoy pushed a commit to corwinjoy/onnx that referenced this pull request Sep 5, 2023
### 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]>
corwinjoy pushed a commit to corwinjoy/onnx that referenced this pull request Sep 5, 2023
### 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]>
corwinjoy pushed a commit to corwinjoy/onnx that referenced this pull request Sep 5, 2023
### 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]>
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.

4 participants