zoukankan      html  css  js  c++  java
  • 前后端对接之json

    结构梳理详见:Pytorch&前后端工作梳理

    以下介绍前后端对接的json文件

    base.json

    描述:包含所有基础的网络层,已经in和out节点

    {
      "type": "base",
      //sequential表示嵌套模型,base表示单个网络层
      "name": "base_1",
      //对于base层为网络层对应的名字,默认按序号排列
      "attribute": {
        "layer_type": "pool_layer",
        //对于base attribute的结构,以pool_layer为例
        //对于输入和输出层,"layer_type":"in"/"out",仅有"left"/"right"属性
    
        "attribute": {
          "layer_type": "max_pool",
          "attribute": {
            "kernel_size": 2,
            "stride": 2,
            "padding": 0
          }
        },
        "left": "XXXpx",
        //绘制时的位置,Sequential可缺省该属性
        "Right": "XXXpx"
        //绘制时的位置,Sequential可缺省该属性
      }
    }
    

    connection.json

    描述:在sequential中用以描述canvas连接的文件

    {
      "source": {
        "id": "canvas_%d",
        "anchor_position": "Bottom"
        //("Bottom"/"Up"/"Left"/"Right"),
        //对于type=base表示箭头连接位置,对于Sequential可缺省
      },
      "target": {
        "id": "canvas_%d",
        "anchor_position": "Up"
        //("Bottom"/"Up"/"Left"/"Right"),
        //对于type=base表示箭头连接位置,对于Sequential可缺省
      }
    }
    
    

    sequential.json

    描述:核心的封装结构,有明确且单一的输入和输出节点

    {
      "type": "sequential",
      //sequential表示嵌套模型,base表示单个网络层
      "name": "sequential 01",
      //对于Sequential为用户在保存网络层时为网络层取的名字,默认按照sequential_%d来排序
      "attribute": {
        "in": "canvas_%d",
        //表示每个Sequential开始节点,即入度为0的节点,该节点一定是type="base" && attribute.layer_type = "in"
        "out": "canvas_%d",
        //表示每个Sequential结束节点,即出度为0的节点,该节点一定是type="base" && attribute.layer_type = "out"
        //对于Sequential attribute的结构
        "nets": {
          "canvas_%d": "sequential1.json",
          //这里可以是sequential.json或者base.json,modulelist.json,moduledict.json,可以有多个
          "canvas_2": "base1.json"
        },
        "nets_conn": [
          //描述每个Sequential内部的连通情况,base层没有该属性
          "connection1.json",
          "connection2.json"
        ]
      }
    }
    

    modulelist.json

    描述:一种封装的网络结构,多个相同的层封装在一起,注意其中的canvas只有一个

    {
      "type": "modulelist",
      "name": "multiple layers",
      //对于modulelist为用户在保存网络层时为网络层取的名字
      "attribute": {
        //对于modulelist不需要指定in
        "canvas_%d": "sequential1.json",
        //这里可以是sequential.json或者base.json等,只能是一个
        "num": 10
      }
    }
    

    moduledict.json

    描述:一种封装的网络结构,相当于一个多路选择器,从众多canvas中选择一个

    {
      "type": "moduledict",
      "name": "moduledict_1",
      //对于moduledict为用户在保存网络层时为网络层取的名字,默认在后面表序号
      "attribute": {
        "default": "canvas_1",
        "choose": "canvas_2",
        //moduledict相当与一个多路选择器,有一个default路,和可选的canvas
        "nets": {
          "canvas_%d": "sequential1.json",
          //这里可以是sequential.json或者base.json等,可以有多个
          "canvas_2": "base1.json"
        }
      }
    }
    

    static.json

    描述:静态变量。后续可能添加数据模块(数据增强,打乱等)

    {
      "epoch": 100,
      //全数据集训练次数 非0正数
      "learning_rate": 0.01,
      //学习率 大于0的实数
    
      "learning_rate_scheduler": {
        "name": "StepLR",
        "attribute": {
          "step_size": 50,
          "gamma": 0.1
        }
      },
      "device": "gpu",
      "data": "svhn",
      //mnist, cifar10, stl10, svhn等
    
      "optimizer": {
        "name": "Adam",
        "attribute": {
          "momentum": 0.9
        }
      },
      //SGD, RMSprop, Adam
    
      "loss": {
        "name": "CrossEntropyLoss",
        "attribute": {
          "reduction":"mean"
        }
      },
    
      "batch_size": 16
    }
    

    现修改为data.json

    描述:前端最后给后端传的所有数据

    static = {
        "epoch": epoch,
        "learning_rate": learning_rate,
        "batch_size": batch_size,
        "learning_rate_scheduler":learning_rate_scheduler,
        "device":platform,
        "data":dataset,
        "optimizer":optimizer,
        "loss":loss
    };
    
    structure = {
        "canvas": sequential,
        "static": static
    };
    
    ret = {
        "name" : $("#model_name").val(),
        "structure":structure
    }
    //这个ret是传回后端的json格式,为了后端的向下兼容
    

    原data.json 现已弃用

    {
      "canvas": "sequential.json",
      "static": "static.json"
    }
    

    inference_in.json

    推理过程输入对应的json文件:前端需要传递输入图片的路径、pkl文件的路径

    {
      "canvas": "sequential.json",
      "inference":{
        "device": "cpu",
        "input": "/media/test.jpg",
        "pkl": "/models/checkpoint_14_epoch.pkl"
      }
    }
    

    inference_out.json

    后端将输出文件保存在media中,项前端提供保存路径。其中visualize表示需要展示的图。
    output表示输出,可以是图片路径,也可以是字符串。

    {
      "visualize": "media/output1.jpg",
      "string": "time:1.147s
    input shape:[3, 624, 1270]..."
    }
    
  • 相关阅读:
    [Javascript] Broadcaster + Operator + Listener pattern -- 10. Define a Function to Set Common Behaviors in Operators
    [Java Spring] Aspect
    [Javascript] Broadcaster + Operator + Listener pattern -- 24. Design choice, ifElse or merge
    [Javascript] Broadcaster + Operator + Listener pattern -- 23. ifElse operator
    [Git] Revert to a old commit
    [Tools] Dendron
    [Java Spring] Spring Expression Language
    [Java Spring] @Profile
    [Java Spring] @Value & override properties by environment variables
    [Java Spring] Implementing Spring Security
  • 原文地址:https://www.cnblogs.com/NAG2020/p/12730705.html
Copyright © 2011-2022 走看看