From 665443317e1e0a08de9d45b4593c6c11705a347a Mon Sep 17 00:00:00 2001 From: rpalakkal Date: Wed, 12 Dec 2018 00:11:34 -0500 Subject: [PATCH] Add internal model representation documentation (#483) * added internal model documentation * added json models * renamed and put into folder * Delete data1.json * changed name and put into folder * changed folder * added another model * Rename data4.json to lenet.json * updated sample model links * moved into docs * moved into proper folder * Rename internalModels/allCNN.json to example/internalModels/allCNN.json * Rename internalModels/cifar10cnn.json to example/internalModels/cifar10cnn.json * Rename internalModels/lenet.json to example/internalModels/lenet.json * updated links --- docs/source/internalModel.md | 87 ++++++++++++++++++++++++++ example/internalModels/allCNN.json | 1 + example/internalModels/cifar10cnn.json | 1 + example/internalModels/lenet.json | 1 + 4 files changed, 90 insertions(+) create mode 100644 docs/source/internalModel.md create mode 100644 example/internalModels/allCNN.json create mode 100644 example/internalModels/cifar10cnn.json create mode 100644 example/internalModels/lenet.json diff --git a/docs/source/internalModel.md b/docs/source/internalModel.md new file mode 100644 index 000000000..c56f8713a --- /dev/null +++ b/docs/source/internalModel.md @@ -0,0 +1,87 @@ +## Internal Model Representation + +The internal model is stored in a JSON format and depending on the machine learning framework, it is generated by ``import_json.py``, ``import_prototxt.py``, or ``import_graphdef.py``. The following documentation is based on logging the model format from these files. + +### Format of Model +The model is stored under the ``"net"`` key in the dictionary, with each layer as a new sub-dictionary. Within each layer, under the layer name, there are three keys: info, connection, and params. Here is a sample format: +```sh +{"net": + {layer_name1: + {"info":{}, + "connection":{}, + "params":{} + }, + {layer_name2: + {"info":{}, + "connection":{}, + "params":{} + } +} +``` +### More Detail about Layer Format + +Here is more information about the ``"info"``, "connection", and ``"params"`` parts of the layer. +##### ``"Info"`` Section +Under the ``"info"`` section these are the two stored variables: ``"type"``, and ``"phase"``. ``"Type"`` indicates the category of layer. Here are the most common categories: +* ``Input`` +* ``Data`` +* ``Dense`` +* ``Activation`` +* ``Dropout`` +* ``Flatten`` +* ``Reshape`` +* ``Convolution`` +* ``Upsample`` +* ``Padding`` +* ``Pooling`` +* ``LocallyConnected`` +* `` Recurrent`` +* ``Embed`` + +"Phase" by default is ``null``. It may be different if the layer changes depending on whether it is being used for training or testing. + +Here is an example: +```sh +{"info": {"phase": null, "type": "Pooling"} +``` +##### ``"Connection"`` Section +Under the ``"info"`` section these are the two stored variables: ``"input"``, and ``"output"``. Since the model is not stored in order of layers, the names of the input and output layers are used to sort the model(ie. matching the output name of one layer to the input name of another layer). + +Under ``"input"``, the name of the layer that feeds into the current layer is stored. This means for the first layer(input layer), this section is empty. + +Similarly, under ``"output"``, the name of the layer that the current layer feeds into is named. This means that for the final layer, this section will be left empty. + +Here is an example: +```sh +"connection": {"input": ["embedding_1_input"], "output": ["dropout_1"]} +``` +##### ``"Params"`` Section +* In this section, depending on the type of layer, the criteria are different. There are several different params(for configuring each layer) but here are the some common params to get a sense: + +* ``"layer_type"`` - ``"1D"``, ``"2D"``, or ``"3D"`` +* ``"stride_w"``, ``"stride_l"``, ``"stride_h"`` +* ``"kernel_w"``, ``"kernel_l"``, ``"kernel_h"`` +* ``"pad_w"``, ``"pad_l"``, ``"pad_h"`` +* ``"num_output"`` +* ``"weight_filler"`` +* ``"use_bias"`` +* ``"pool"`` + +Here is an example: +```sh +"params": { + "layer_type": "2D", + "kernel_w": 2, + "pad_h": 0, + "stride_h": 2, + "stride_w": 2, + "kernel_h": 2, + "pad_w": 0, + "pool": "MAX"} +``` + + ### Example JSON Model File: +* [AllCNN.json](https://github.com/rpalakkal/Fabrik/blob/rpalakkal-internalModel/sample/internalModels/allCNN.json) +* [LeNet.json](https://github.com/rpalakkal/Fabrik/blob/rpalakkal-internalModel/sample/internalModels/lenet.json) +* [Cifar10CNN](https://github.com/rpalakkal/Fabrik/blob/rpalakkal-internalModel/sample/internalModels/cifar10cnn.json) + diff --git a/example/internalModels/allCNN.json b/example/internalModels/allCNN.json new file mode 100644 index 000000000..b6a2af9c0 --- /dev/null +++ b/example/internalModels/allCNN.json @@ -0,0 +1 @@ +{"net": {"l18": {"info": {"phase": null, "type": "ReLU"}, "connection": {"input": ["l17"], "output": ["l19"]}, "params": {"negative_slope": 0.0, "inplace": true}}, "l19": {"info": {"phase": null, "type": "Convolution"}, "connection": {"input": ["l18"], "output": ["l20"]}, "params": {"layer_type": "2D", "kernel_w": 1, "bias_filler": "constant", "stride_h": 1, "weight_filler": "xavier", "stride_w": 1, "num_output": 192, "use_bias": true, "kernel_h": 1}}, "l14": {"info": {"phase": null, "type": "Convolution"}, "connection": {"input": ["l13"], "output": ["l15"]}, "params": {"layer_type": "2D", "kernel_w": 3, "pad_h": 1, "bias_filler": "constant", "stride_h": 2, "weight_filler": "xavier", "stride_w": 2, "num_output": 192, "use_bias": true, "pad_w": 1, "kernel_h": 3}}, "l15": {"info": {"phase": null, "type": "ReLU"}, "connection": {"input": ["l14"], "output": ["l16"]}, "params": {"negative_slope": 0.0, "inplace": true}}, "l16": {"info": {"phase": null, "type": "Dropout"}, "connection": {"input": ["l15"], "output": ["l17"]}, "params": {"inplace": true}}, "l17": {"info": {"phase": null, "type": "Convolution"}, "connection": {"input": ["l16"], "output": ["l18"]}, "params": {"layer_type": "2D", "kernel_w": 3, "bias_filler": "constant", "stride_h": 1, "weight_filler": "xavier", "stride_w": 1, "num_output": 192, "use_bias": true, "kernel_h": 3}}, "l10": {"info": {"phase": null, "type": "Convolution"}, "connection": {"input": ["l9"], "output": ["l11"]}, "params": {"layer_type": "2D", "kernel_w": 3, "pad_h": 1, "bias_filler": "constant", "stride_h": 1, "weight_filler": "xavier", "stride_w": 1, "num_output": 192, "use_bias": true, "pad_w": 1, "kernel_h": 3}}, "l11": {"info": {"phase": null, "type": "ReLU"}, "connection": {"input": ["l10"], "output": ["l12"]}, "params": {"negative_slope": 0.0, "inplace": true}}, "l12": {"info": {"phase": null, "type": "Convolution"}, "connection": {"input": ["l11"], "output": ["l13"]}, "params": {"layer_type": "2D", "kernel_w": 3, "pad_h": 1, "bias_filler": "constant", "stride_h": 1, "weight_filler": "xavier", "stride_w": 1, "num_output": 192, "use_bias": true, "pad_w": 1, "kernel_h": 3}}, "l13": {"info": {"phase": null, "type": "ReLU"}, "connection": {"input": ["l12"], "output": ["l14"]}, "params": {"negative_slope": 0.0, "inplace": true}}, "l21": {"info": {"phase": null, "type": "Convolution"}, "connection": {"input": ["l20"], "output": ["l22"]}, "params": {"layer_type": "2D", "kernel_w": 1, "bias_filler": "constant", "stride_h": 1, "weight_filler": "xavier", "stride_w": 1, "num_output": 10, "use_bias": true, "kernel_h": 1}}, "l20": {"info": {"phase": null, "type": "ReLU"}, "connection": {"input": ["l19"], "output": ["l21"]}, "params": {"negative_slope": 0.0, "inplace": true}}, "l23": {"info": {"phase": null, "type": "Pooling"}, "connection": {"input": ["l22"], "output": ["l24", "l25"]}, "params": {"layer_type": "2D", "kernel_w": 0, "pad_h": 0, "stride_h": 1, "stride_w": 1, "kernel_h": 0, "pad_w": 0, "pool": "AVE"}}, "l22": {"info": {"phase": null, "type": "ReLU"}, "connection": {"input": ["l21"], "output": ["l23"]}, "params": {"negative_slope": 0.0, "inplace": true}}, "l25": {"info": {"phase": null, "type": "SoftmaxWithLoss"}, "connection": {"input": ["l23"], "output": []}, "params": {"axis": 1}}, "l24": {"info": {"phase": null, "type": "Accuracy"}, "connection": {"input": ["l23"], "output": []}, "params": {"top_k": 1, "axis": 1}}, "l6": {"info": {"phase": null, "type": "ReLU"}, "connection": {"input": ["l5"], "output": ["l7"]}, "params": {"negative_slope": 0.0, "inplace": true}}, "l7": {"info": {"phase": null, "type": "Convolution"}, "connection": {"input": ["l6"], "output": ["l8"]}, "params": {"layer_type": "2D", "kernel_w": 3, "pad_h": 1, "bias_filler": "constant", "stride_h": 2, "weight_filler": "xavier", "stride_w": 2, "num_output": 96, "use_bias": true, "pad_w": 1, "kernel_h": 3}}, "l4": {"info": {"phase": null, "type": "ReLU"}, "connection": {"input": ["l3"], "output": ["l5"]}, "params": {"negative_slope": 0.0, "inplace": true}}, "l5": {"info": {"phase": null, "type": "Convolution"}, "connection": {"input": ["l4"], "output": ["l6"]}, "params": {"layer_type": "2D", "kernel_w": 3, "pad_h": 1, "bias_filler": "constant", "stride_h": 1, "weight_filler": "xavier", "stride_w": 1, "num_output": 96, "use_bias": true, "pad_w": 1, "kernel_h": 3}}, "l2": {"info": {"phase": null, "type": "Dropout"}, "connection": {"input": ["l0", "l1"], "output": ["l3"]}, "params": {"inplace": true}}, "l3": {"info": {"phase": null, "type": "Convolution"}, "connection": {"input": ["l2"], "output": ["l4"]}, "params": {"layer_type": "2D", "kernel_w": 3, "pad_h": 1, "bias_filler": "constant", "stride_h": 1, "weight_filler": "xavier", "stride_w": 1, "num_output": 96, "use_bias": true, "pad_w": 1, "kernel_h": 3}}, "l0": {"info": {"phase": 0, "type": "Data"}, "connection": {"input": [], "output": ["l2"]}, "params": {"scale": 1.0, "batch_size": 256, "source": "cifar-10_train_lmdb", "force_color": false, "force_gray": false, "rand_skip": 0, "prefetch": 4, "mirror": false, "backend": "LMDB", "crop_size": 0}}, "l1": {"info": {"phase": 1, "type": "Data"}, "connection": {"input": [], "output": ["l2"]}, "params": {"scale": 1.0, "batch_size": 200, "source": "cifar-10_test_lmdb", "force_color": false, "force_gray": false, "rand_skip": 0, "prefetch": 4, "mirror": false, "backend": "LMDB", "crop_size": 0}}, "l8": {"info": {"phase": null, "type": "ReLU"}, "connection": {"input": ["l7"], "output": ["l9"]}, "params": {"negative_slope": 0.0, "inplace": true}}, "l9": {"info": {"phase": null, "type": "Dropout"}, "connection": {"input": ["l8"], "output": ["l10"]}, "params": {"inplace": true}}}, "result": "success", "net_name": "ALL-CNN-C"} diff --git a/example/internalModels/cifar10cnn.json b/example/internalModels/cifar10cnn.json new file mode 100644 index 000000000..f3c3e9f26 --- /dev/null +++ b/example/internalModels/cifar10cnn.json @@ -0,0 +1 @@ +{"net": {"l10": {"info": {"phase": null, "type": "ReLU"}, "connection": {"input": ["l9"], "output": ["l11"]}, "params": {"negative_slope": 0.0, "inplace": true}}, "l11": {"info": {"phase": null, "type": "Pooling"}, "connection": {"input": ["l10"], "output": ["l12"]}, "params": {"layer_type": "2D", "kernel_w": 3, "pad_h": 0, "stride_h": 2, "stride_w": 2, "kernel_h": 3, "pad_w": 0, "pool": "AVE"}}, "l12": {"info": {"phase": null, "type": "InnerProduct"}, "connection": {"input": ["l11"], "output": ["l13"]}, "params": {"weight_filler": "constant", "bias_filler": "constant", "num_output": 10, "use_bias": true}}, "l13": {"info": {"phase": null, "type": "Softmax"}, "connection": {"input": ["l12"], "output": []}, "params": {}}, "l6": {"info": {"phase": null, "type": "ReLU"}, "connection": {"input": ["l5"], "output": ["l7"]}, "params": {"negative_slope": 0.0, "inplace": true}}, "l7": {"info": {"phase": null, "type": "Pooling"}, "connection": {"input": ["l6"], "output": ["l8"]}, "params": {"layer_type": "2D", "kernel_w": 3, "pad_h": 0, "stride_h": 2, "stride_w": 2, "kernel_h": 3, "pad_w": 0, "pool": "AVE"}}, "l4": {"info": {"phase": null, "type": "LRN"}, "connection": {"input": ["l3"], "output": ["l5"]}, "params": {"alpha": 4.999999873689376e-05, "beta": 0.75, "norm_region": 1, "k": 1.0, "local_size": 3}}, "l5": {"info": {"phase": null, "type": "Convolution"}, "connection": {"input": ["l4"], "output": ["l6"]}, "params": {"layer_type": "2D", "kernel_w": 5, "pad_h": 2, "bias_filler": "constant", "stride_h": 1, "weight_filler": "constant", "stride_w": 1, "num_output": 32, "use_bias": true, "pad_w": 2, "kernel_h": 5}}, "l2": {"info": {"phase": null, "type": "Pooling"}, "connection": {"input": ["l1"], "output": ["l3"]}, "params": {"layer_type": "2D", "kernel_w": 3, "pad_h": 0, "stride_h": 2, "stride_w": 2, "kernel_h": 3, "pad_w": 0, "pool": "MAX"}}, "l3": {"info": {"phase": null, "type": "ReLU"}, "connection": {"input": ["l2"], "output": ["l4"]}, "params": {"negative_slope": 0.0, "inplace": true}}, "l0": {"info": {"phase": null, "type": "Input"}, "connection": {"input": [], "output": ["l1"]}, "params": {"dim": "1, 3, 32, 32"}}, "l1": {"info": {"phase": null, "type": "Convolution"}, "connection": {"input": ["l0"], "output": ["l2"]}, "params": {"layer_type": "2D", "kernel_w": 5, "pad_h": 2, "bias_filler": "constant", "stride_h": 1, "weight_filler": "constant", "stride_w": 1, "num_output": 32, "use_bias": true, "pad_w": 2, "kernel_h": 5}}, "l8": {"info": {"phase": null, "type": "LRN"}, "connection": {"input": ["l7"], "output": ["l9"]}, "params": {"alpha": 4.999999873689376e-05, "beta": 0.75, "norm_region": 1, "k": 1.0, "local_size": 3}}, "l9": {"info": {"phase": null, "type": "Convolution"}, "connection": {"input": ["l8"], "output": ["l10"]}, "params": {"layer_type": "2D", "kernel_w": 5, "pad_h": 2, "bias_filler": "constant", "stride_h": 1, "weight_filler": "constant", "stride_w": 1, "num_output": 64, "use_bias": true, "pad_w": 2, "kernel_h": 5}}}, "result": "success", "net_name": "Cifar10 CNN"} diff --git a/example/internalModels/lenet.json b/example/internalModels/lenet.json new file mode 100644 index 000000000..fbe581c92 --- /dev/null +++ b/example/internalModels/lenet.json @@ -0,0 +1 @@ +{"net": {"l10": {"info": {"phase": null, "type": "SoftmaxWithLoss"}, "connection": {"input": ["l8"], "output": []}, "params": {"axis": 1}}, "l6": {"info": {"phase": null, "type": "InnerProduct"}, "connection": {"input": ["l5"], "output": ["l7"]}, "params": {"weight_filler": "xavier", "bias_filler": "constant", "num_output": 500, "use_bias": true}}, "l7": {"info": {"phase": null, "type": "ReLU"}, "connection": {"input": ["l6"], "output": ["l8"]}, "params": {"negative_slope": 0.0, "inplace": true}}, "l4": {"info": {"phase": null, "type": "Convolution"}, "connection": {"input": ["l3"], "output": ["l5"]}, "params": {"layer_type": "2D", "kernel_w": 5, "bias_filler": "constant", "stride_h": 1, "weight_filler": "xavier", "stride_w": 1, "num_output": 50, "use_bias": true, "kernel_h": 5}}, "l5": {"info": {"phase": null, "type": "Pooling"}, "connection": {"input": ["l4"], "output": ["l6"]}, "params": {"layer_type": "2D", "kernel_w": 2, "pad_h": 0, "stride_h": 2, "stride_w": 2, "kernel_h": 2, "pad_w": 0, "pool": "MAX"}}, "l2": {"info": {"phase": null, "type": "Convolution"}, "connection": {"input": ["l0", "l1"], "output": ["l3"]}, "params": {"layer_type": "2D", "kernel_w": 5, "bias_filler": "constant", "stride_h": 1, "weight_filler": "xavier", "stride_w": 1, "num_output": 20, "use_bias": true, "kernel_h": 5}}, "l3": {"info": {"phase": null, "type": "Pooling"}, "connection": {"input": ["l2"], "output": ["l4"]}, "params": {"layer_type": "2D", "kernel_w": 2, "pad_h": 0, "stride_h": 2, "stride_w": 2, "kernel_h": 2, "pad_w": 0, "pool": "MAX"}}, "l0": {"info": {"phase": 0, "type": "Data"}, "connection": {"input": [], "output": ["l2"]}, "params": {"scale": 0.00390625, "batch_size": 64, "source": "examples/mnist/mnist_train_lmdb", "force_color": false, "force_gray": false, "rand_skip": 0, "prefetch": 4, "mirror": false, "backend": "LMDB", "crop_size": 0}}, "l1": {"info": {"phase": 1, "type": "Data"}, "connection": {"input": [], "output": ["l2"]}, "params": {"scale": 0.00390625, "batch_size": 100, "source": "examples/mnist/mnist_test_lmdb", "force_color": false, "force_gray": false, "rand_skip": 0, "prefetch": 4, "mirror": false, "backend": "LMDB", "crop_size": 0}}, "l8": {"info": {"phase": null, "type": "InnerProduct"}, "connection": {"input": ["l7"], "output": ["l9", "l10"]}, "params": {"weight_filler": "xavier", "bias_filler": "constant", "num_output": 10, "use_bias": true}}, "l9": {"info": {"phase": 1, "type": "Accuracy"}, "connection": {"input": ["l8"], "output": []}, "params": {"top_k": 1, "axis": 1}}}, "result": "success", "net_name": "LeNet"}