結構梳理詳見:Pytorch&先後端工做梳理html
如下介紹先後端對接的json文件前端
描述:包含全部基礎的網絡層,已經in和out節點json
{ "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可缺省該屬性 } }
描述:在sequential中用以描述canvas鏈接的文件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可缺省 } }
描述:核心的封裝結構,有明確且單一的輸入和輸出節點後端
{ "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" ] } }
描述:一種封裝的網絡結構,多個相同的層封裝在一塊兒,注意其中的canvas只有一個網絡
{ "type": "modulelist", "name": "multiple layers", //對於modulelist爲用戶在保存網絡層時爲網絡層取的名字 "attribute": { //對於modulelist不須要指定in "canvas_%d": "sequential1.json", //這裏能夠是sequential.json或者base.json等,只能是一個 "num": 10 } }
描述:一種封裝的網絡結構,至關於一個多路選擇器,從衆多canvas中選擇一個ide
{ "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" } } }
描述:靜態變量。後續可能添加數據模塊(數據加強,打亂等)學習
{ "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 }
描述:前端最後給後端傳的全部數據code
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格式,爲了後端的向下兼容
{ "canvas": "sequential.json", "static": "static.json" }