Converting an Original Model or Offline Model File into a JSON File

Overview

If you cannot view parameter details of your original model or offline model, you can convert it into a JSON file.

Procedure

This section takes the TensorFlow ResNet-50 network model for illustration. Click here to download the model file (*.pb) of the ResNet-50 network.

  • Convert an original model file into a JSON file.

    A command example is as follows:

    atc --mode=1 --om=$HOME/module/resnet50_tensorflow*.pb  --json=$HOME/module/out/tf_resnet50.json  --framework=3
    • --mode: specifies the running mode. The value 1 indicates that an original model or offline model file is converted into a JSON file. In this example, an original model file is converted into a JSON file.
    • --om: specifies the path of the ResNet-50 model file.
    • --json: specifies the path and name of the JSON file.
    • --framework: specifies the original framework type. The value 3 indicates TensorFlow.
  • Convert an offline model file into a JSON file.
    The prerequisite for this scenario is that you have obtained the OM offline model file by referring to Converting an Open-Source TensorFlow Model to an Offline Model. A command example is as follows:
    atc --mode=1 --om=$HOME/module/out/tf_resnet50.om  --json=$HOME/module/out/tf_resnet50.json
    • --mode: specifies the running mode. The value 1 indicates that an original model or offline model file is converted into a JSON file. In this example, an offline model file is converted into a JSON file.
    • --om: specifies the directory where the offline model file is stored.
For details about the options, see Command Line Options. If the following information is displayed, the conversion is successful. If the model conversion fails, locate the fault by referring to "Error Codes".
1
ATC run success, welcome to the next use.

After successful execution, you can check the JSON file in the path specified by --json. The following is part of the JSON file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
  "node": [
    {
      "attr": [
        {
          "key": "shape",
          "value": {
            "shape": {
              "dim": [
                {
                  "size": 1
                },
                {
                  "size": 224
                },
                {
                  "size": 224
                },
                {
                  "size": 3
                }
              ]
            }
          }
        },
        {
          "key": "dtype",
          "value": {
            "type": "DT_FLOAT"
          }
        }
      ],
      "name": "Placeholder",
      "op": "Placeholder"
    },