未验证 提交 ff057a44 编写于 作者: P Peter Pan 提交者: GitHub

refactor: put netron into a single monorepo (#658)

上级 7ae0dfc7
...@@ -9,7 +9,7 @@ module.exports = { ...@@ -9,7 +9,7 @@ module.exports = {
ecmaVersion: 2018, ecmaVersion: 2018,
sourceType: 'module' sourceType: 'module'
}, },
ignorePatterns: ['node_modules/', 'dist/', 'output/', '_next', 'packages/core/public/netron'], ignorePatterns: ['node_modules/', 'dist/', 'output/', '_next'],
rules: { rules: {
'no-console': 'warn', 'no-console': 'warn',
'sort-imports': 'error' 'sort-imports': 'error'
......
...@@ -38,19 +38,19 @@ ...@@ -38,19 +38,19 @@
"version": "yarn format && git add -A" "version": "yarn format && git add -A"
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "3.1.0", "@typescript-eslint/eslint-plugin": "3.2.0",
"@typescript-eslint/parser": "3.1.0", "@typescript-eslint/parser": "3.2.0",
"eslint": "7.1.0", "eslint": "7.2.0",
"eslint-config-prettier": "6.11.0", "eslint-config-prettier": "6.11.0",
"eslint-plugin-prettier": "3.1.3", "eslint-plugin-prettier": "3.1.3",
"eslint-plugin-react": "7.20.0", "eslint-plugin-react": "7.20.0",
"eslint-plugin-react-hooks": "4.0.0", "eslint-plugin-react-hooks": "4.0.0",
"husky": "4.2.5", "husky": "4.2.5",
"lerna": "3.22.0", "lerna": "3.22.1",
"lint-staged": "10.2.8", "lint-staged": "10.2.9",
"prettier": "2.0.5", "prettier": "2.0.5",
"rimraf": "3.0.2", "rimraf": "3.0.2",
"typescript": "3.9.3", "typescript": "3.9.5",
"yarn": "1.22.4" "yarn": "1.22.4"
}, },
"engines": { "engines": {
......
...@@ -41,11 +41,11 @@ ...@@ -41,11 +41,11 @@
"yargs": "15.3.1" "yargs": "15.3.1"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "14.0.10", "@types/node": "14.0.13",
"@types/yargs": "15.0.5", "@types/yargs": "15.0.5",
"cross-env": "7.0.2", "cross-env": "7.0.2",
"ts-node": "8.10.2", "ts-node": "8.10.2",
"typescript": "3.9.3" "typescript": "3.9.5"
}, },
"engines": { "engines": {
"node": ">=10", "node": ">=10",
......
...@@ -230,7 +230,7 @@ const Graph = React.forwardRef<GraphRef, GraphProps>( ...@@ -230,7 +230,7 @@ const Graph = React.forwardRef<GraphRef, GraphProps>(
<Content> <Content>
<iframe <iframe
ref={iframe} ref={iframe}
src={`${process.env.PUBLIC_PATH ?? ''}/netron/index.html`} src={`${process.env.PUBLIC_PATH ?? ''}/_next/static/netron/index.html`}
frameBorder={0} frameBorder={0}
scrolling="no" scrolling="no"
marginWidth={0} marginWidth={0}
......
...@@ -46,6 +46,7 @@ module.exports = { ...@@ -46,6 +46,7 @@ module.exports = {
}, },
webpack: config => { webpack: config => {
const WorkerPlugin = require('worker-plugin'); const WorkerPlugin = require('worker-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
config.resolve = config.resolve || {}; config.resolve = config.resolve || {};
config.resolve.alias = config.resolve.alias || {}; config.resolve.alias = config.resolve.alias || {};
...@@ -61,6 +62,16 @@ module.exports = { ...@@ -61,6 +62,16 @@ module.exports = {
...(config.plugins || []), ...(config.plugins || []),
new WorkerPlugin({ new WorkerPlugin({
globalObject: 'self' globalObject: 'self'
}),
new CopyWebpackPlugin({
patterns: [
{
context: path.dirname(require('enhanced-resolve').sync(__dirname, '@visualdl/netron')),
from: '**/*',
to: 'static/netron',
toType: 'dir'
}
]
}) })
]; ];
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
}, },
"dependencies": { "dependencies": {
"@visualdl/i18n": "2.0.0-beta.43", "@visualdl/i18n": "2.0.0-beta.43",
"@visualdl/netron": "2.0.0-beta.43",
"@visualdl/wasm": "2.0.0-beta.43", "@visualdl/wasm": "2.0.0-beta.43",
"bignumber.js": "9.0.0", "bignumber.js": "9.0.0",
"echarts": "4.8.0", "echarts": "4.8.0",
...@@ -48,7 +49,7 @@ ...@@ -48,7 +49,7 @@
"nprogress": "0.2.0", "nprogress": "0.2.0",
"polished": "3.6.4", "polished": "3.6.4",
"prop-types": "15.7.2", "prop-types": "15.7.2",
"query-string": "6.12.1", "query-string": "6.13.0",
"react": "16.13.1", "react": "16.13.1",
"react-dom": "16.13.1", "react-dom": "16.13.1",
"react-hooks-worker": "0.9.0", "react-hooks-worker": "0.9.0",
...@@ -66,7 +67,7 @@ ...@@ -66,7 +67,7 @@
"@types/file-saver": "2.0.1", "@types/file-saver": "2.0.1",
"@types/lodash": "4.14.155", "@types/lodash": "4.14.155",
"@types/mime-types": "2.1.0", "@types/mime-types": "2.1.0",
"@types/node": "14.0.10", "@types/node": "14.0.13",
"@types/nprogress": "0.2.0", "@types/nprogress": "0.2.0",
"@types/react": "16.9.35", "@types/react": "16.9.35",
"@types/react-dom": "16.9.8", "@types/react-dom": "16.9.8",
...@@ -75,11 +76,13 @@ ...@@ -75,11 +76,13 @@
"babel-plugin-emotion": "10.0.33", "babel-plugin-emotion": "10.0.33",
"babel-plugin-styled-components": "1.10.7", "babel-plugin-styled-components": "1.10.7",
"babel-plugin-typescript-to-proptypes": "1.3.2", "babel-plugin-typescript-to-proptypes": "1.3.2",
"copy-webpack-plugin": "6.0.2",
"core-js": "3.6.5", "core-js": "3.6.5",
"cross-env": "7.0.2", "cross-env": "7.0.2",
"css-loader": "3.5.3", "css-loader": "3.5.3",
"enhanced-resolve": "4.1.1",
"ora": "4.0.4", "ora": "4.0.4",
"typescript": "3.9.3", "typescript": "3.9.5",
"worker-plugin": "4.0.3" "worker-plugin": "4.0.3"
}, },
"engines": { "engines": {
......
...@@ -221,7 +221,6 @@ const Graphs: NextI18NextPage = () => { ...@@ -221,7 +221,6 @@ const Graphs: NextI18NextPage = () => {
style={{ style={{
display: 'none' display: 'none'
}} }}
accept=".onnx, .pb, .meta, .tflite, .lite, .tfl, .bin, .keras, .h5, .hd5, .hdf5, .json, .model, .mar, .params, .param, .armnn, .mnn, .ncnn, .nn, .dnn, .cmf, .mlmodel, .caffemodel, .pbtxt, .prototxt, .pkl, .pt, .pth, .t7, .joblib, .cfg, .xml"
/> />
</Content> </Content>
</> </>
......
[
{
"name": "InputLayer",
"schema": {
"bindings": [
{ "name": "layerBindingId", "type": "int", "src": "layerBindingId" }
]
}
},
{
"name": "OutputLayer",
"schema": {
"category": "Tensor",
"bindings": [
{ "name": "layerBindingId", "type": "int", "src": "layerBindingId" }
]
}
},
{
"name": "Pooling2dLayer",
"schema": {
"category": "Pool",
"attributes": [
{ "name": "type", "type": "string", "src": "poolType", "src_type": "PoolingAlgorithm"},
{ "name": "padding", "type": "string", "src": ["padTop", "padRight", "padBottom", "padLeft"] },
{ "name": "width", "type": "string", "src": "poolWidth" },
{ "name": "height", "type": "string", "src": "poolHeight" },
{ "name": "stride", "type": "string", "src": ["strideX", "strideY"] },
{ "name": "outputShapeRounding", "type": "string", "src": "outputShapeRounding", "src_type": "OutputShapeRounding"},
{ "name": "paddingMethod", "type": "string", "src": "paddingMethod", "src_type": "PaddingMethod"},
{ "name": "dataLayout", "type": "string", "src": "dataLayout", "src_type": "DataLayout" }
]
}
},
{
"name": "ReshapeLayer",
"schema": {
"category": "Shape",
"attributes": [
{ "name": "targetShape", "type": "string", "src": "targetShape" }
]
}
},
{
"name": "SoftmaxLayer",
"schema": {
"category": "Activation",
"attributes": [
{ "name": "beta", "type": "float", "src": "beta" }
]
}
},
{
"name": "Convolution2dLayer",
"schema": {
"category": "Layer",
"inputs": [
{ "name": "weight", "src": "weights" },
{ "name": "bias", "src": "biases" }
],
"attributes": [
{ "name": "padding", "type": "string", "src": ["padTop", "padRight", "padBottom", "padLeft"] },
{ "name": "stride", "type": "string", "src": ["strideX", "strideY"] },
{ "name": "dilation", "type": "string", "src": ["dilationX", "dilationY"] },
{ "name": "dataLayout", "type": "string", "src": "dataLayout", "src_type": "DataLayout" }
]
}
},
{
"name": "DepthwiseConvolution2dLayer",
"schema": {
"category": "Layer",
"inputs": [
{ "name": "weight", "src": "weights" },
{ "name": "bias", "src": "biases" }
],
"attributes": [
{ "name": "padding", "type": "string", "src": ["padTop", "padRight", "padBottom", "padLeft"] },
{ "name": "stride", "type": "string", "src": ["strideX", "strideY"] },
{ "name": "dilation", "type": "string", "src": ["dilationX", "dilationY"] },
{ "name": "dataLayout", "type": "string", "src": "dataLayout", "src_type": "DataLayout" }
]
}
},
{
"name": "ActivationLayer",
"schema": {
"category": "Activation",
"attributes": [
{ "name": "function", "type": "string", "src": "activationFunction", "src_type": "ActivationFunction" },
{ "name": "a", "type": "float", "src": "a" },
{ "name": "b", "type": "float", "src": "b" }
]
}
},
{
"name": "PermuteLayer",
"schema": {
"category": "Shape",
"attributes": [
{ "name": "dimMappings", "type": "string", "src": "dimMappings" }
]
}
},
{
"name": "FullyConnectedLayer",
"schema": {
"category": "Layer",
"inputs": [
{ "name": "weights", "src": "weights" },
{ "name": "biases", "src": "biases" }
],
"attributes": [
{ "name": "transposeWeightsMatrix", "type": "bool", "src": "transposeWeightsMatrix" }
]
}
},
{
"name": "ConstantLayer",
"schema": {
"category": "Constant",
"inputs": [
{ "name": "input", "src": "input" }
]
}
},
{
"name": "SpaceToBatchNdLayer",
"schema": {
"category": "Layer",
"attributes": [
{ "name": "blockShape", "type": "string", "src": "blockShape" },
{ "name": "padList", "type": "string", "src": "padList" },
{ "name": "dataLayout", "type": "string", "src": "dataLayout", "src_type": "DataLayout" }
]
}
},
{
"name": "BatchToSpaceNdLayer",
"schema": {
"category": "Layer",
"attributes": [
{ "name": "blockShape", "type": "string", "src": "blockShape" },
{ "name": "crops", "type": "string", "src": "crops" },
{ "name": "dataLayout", "type": "string", "src": "dataLayout", "src_type": "DataLayout" }
]
}
},
{
"name": "DivisionLayer",
"schema": {
"category": "Layer"
}
},
{
"name": "MinimumLayer",
"schema": {
"category": "Layer"
}
},
{
"name": "EqualLayer",
"schema": {
"category": "Layer"
}
},
{
"name": "MaximumLayer",
"schema": {
"category": "Layer"
}
},
{
"name": "NormalizationLayer",
"schema": {
"category": "Normalization",
"attributes": [
{ "name": "normChannelType", "type": "string", "src": "normChannelType", "src_type": "NormalizationAlgorithmChannel" },
{ "name": "normMethodType", "type": "string", "src": "normMethodType", "src_type": "NormalizationAlgorithmMethod" },
{ "name": "normSize", "type": "uint", "src": "normSize" },
{ "name": "alpha", "type": "float", "src": "alpha" },
{ "name": "beta", "type": "float", "src": "beta" },
{ "name": "k", "type": "float", "src": "k" },
{ "name": "dataLayout", "type": "string", "src": "dataLayout", "src_type": "DataLayout" }
]
}
},
{
"name": "PadLayer",
"schema": {
"category": "Layer",
"attributes": [
{ "name": "padList", "type": "uint", "src": "padList" },
{ "name": "padValue", "type": "float", "src": "padValue" }
]
}
},
{
"name": "RsqrtLayer",
"schema": {
"category": "Layer"
}
},
{
"name": "FloorLayer",
"schema": {
"category": "Layer"
}
},
{
"name": "BatchNormalizationLayer",
"schema": {
"category": "Normalization",
"inputs": [
{ "name": "mean", "src": "mean" },
{ "name": "variance", "src": "variance" },
{ "name": "beta", "src": "beta" },
{ "name": "gamma", "src": "gamma" }
],
"attributes": [
{ "name": "eps", "type": "float", "src": "eps" },
{ "name": "dataLayout", "type": "string", "src": "dataLayout", "src_type": "DataLayout" }
]
}
},
{
"name": "GreaterLayer",
"schema": {
"category": "Layer",
"attributes": [
]
}
},
{
"name": "ResizeBilinearLayer",
"schema": {
"category": "Layer",
"attributes": [
{ "name": "targetWidth", "type": "uint", "src": "targetWidth" },
{ "name": "targetHeight", "type": "uint", "src": "targetHeight" },
{ "name": "dataLayout", "type": "string", "src": "dataLayout", "src_type": "DataLayout" }
]
}
},
{
"name": "SubtractionLayer",
"schema": {
}
},
{
"name": "StridedSliceLayer",
"schema": {
"category": "Tensor",
"attributes": [
{ "name": "begin", "type": "int", "src": "begin" },
{ "name": "end", "type": "int", "src": "end" },
{ "name": "stride", "type": "int", "src": "stride" },
{ "name": "beginMask", "type": "int", "src": "beginMask" },
{ "name": "endMask", "type": "int", "src": "endMask" },
{ "name": "shrinkAxisMask", "type": "int", "src": "shrinkAxisMask" },
{ "name": "ellipsisMask", "type": "int", "src": "ellipsisMask" },
{ "name": "newAxisMask", "type": "int", "src": "newAxisMask" },
{ "name": "dataLayout", "type": "string", "src": "dataLayout", "src_type": "DataLayout" }
]
}
},
{
"name": "GatherLayer",
"schema": {
"category": "Tensor"
}
},
{
"name": "MeanLayer",
"schema": {
"attributes": [
{ "name": "axis", "type": "uint", "src": "axis" },
{ "name": "keepDims", "type": "bool", "src": "keepDims" }
]
}
},
{
"name": "MergerLayer",
"schema": {
"category": "Tensor"
}
},
{
"name": "L2NormalizationLayer",
"schema": {
"category": "Normalization",
"attributes": [
{ "name": "eps", "type": "float", "src": "eps" },
{ "name": "dataLayout", "type": "string", "src": "dataLayout", "src_type": "DataLayout" }
]
}
},
{
"name": "SplitterLayer",
"schema": {
"category": "Tensor",
"attributes": [
{ "name": "concatAxis", "type": "uint", "src": "concatAxis" },
{ "name": "numViews", "type": "uint", "src": "numViewes" },
{ "name": "numDimensions", "type": "uint", "src": "numDimensions" }
]
}
},
{
"name": "DetectionPostProcessLayer",
"schema": {
"category": "Custom",
"attributes": [
{ "name": "maxDetections", "type": "uint", "src": "maxDetections" },
{ "name": "maxClassesPerDetection", "type": "uint", "src": "maxClassesPerDetection" },
{ "name": "detectionsPerClass", "type": "uint", "src": "detectionsPerClass" },
{ "name": "nmsScoreThreshold", "type": "float", "src": "nmsScoreThreshold" },
{ "name": "numIouThreshold", "type": "float", "src": "nmsIouThreshold" },
{ "name": "numClasses", "type": "uint", "src": "numClasses" },
{ "name": "useRegularNms", "type": "bool", "src": "useRegularNms" },
{ "name": "scaleX", "type": "float", "src": "scaleX" },
{ "name": "scaleY", "type": "float", "src": "scaleY" },
{ "name": "scaleW", "type": "float", "src": "scaleW" },
{ "name": "scaleH", "type": "float", "src": "scaleH" }
]
}
},
{
"name": "LstmLayer",
"schema": {
"category": "Layer",
"inputs": [
{ "name": "inputToForgetWeights1", "src": "inputToForgetWeights1" },
{ "name": "inputToCellWeights1", "src": "inputToCellWeights1" },
{ "name": "inputToOutputWeights1", "src": "inputToOutputWeights1" },
{ "name": "recurrentToForgetWeights1", "src": "recurrentToForgetWeights1" },
{ "name": "recurrentToCellWeights1", "src": "recurrentToCellWeights1" },
{ "name": "recurrentToOutputWeights1", "src": "recurrentToOutputWeights1" },
{ "name": "forgetGateBias1", "src": "forgetGateBias1" },
{ "name": "cellBias1", "src": "cellBias1" },
{ "name": "outputGateBias1", "src": "outputGateBias1" },
{ "name": "inputToInputWeights1", "src": "inputToInputWeights1" },
{ "name": "recurrentToInputWeights1", "src": "recurrentToInputWeights1" },
{ "name": "cellToInputWeights1", "src": "cellToInputWeights1" },
{ "name": "inputGateBias1", "src": "inputGateBias1" },
{ "name": "projectionWeights1", "src": "projectionWeights1" },
{ "name": "projectionBias1", "src": "projectionBias1" },
{ "name": "cellToForgetWeights1", "src": "cellToForgetWeights1" },
{ "name": "cellToOutputWeights1", "src": "cellToOutputWeights1" },
{ "name": "inputLayerNormWeights1", "src": "inputLayerNormWeights1" },
{ "name": "forgetLayerNormWeights1", "src": "forgetLayerNormWeights1" },
{ "name": "cellLayerNormWeights1", "src": "cellLayerNormWeights1" },
{ "name": "outputLayerNormWeights1", "src": "outputLayerNormWeights1" }
],
"attributes": [
{ "name": "activationFunc", "type": "uint", "src": "activationFunc" },
{ "name": "clippingThresCell", "type": "float", "src": "clippingThresCell" },
{ "name": "clippingThresProj", "type": "float", "src": "clippingThresProj" },
{ "name": "cifgEnabled", "type": "bool", "src": "cifgEnabled" },
{ "name": "peepholeEnabled", "type": "bool", "src": "peepholeEnabled" },
{ "name": "projectionEnabled", "type": "bool", "src": "projectionEnabled" },
{ "name": "layerNormEnabled", "type": "bool", "src": "layerNormEnabled" }
]
}
},
{
"name": "QuantizeLayer",
"schema": {
"category": "Layer"
}
},
{
"name": "DequantizeLayer",
"schema": {
"category": "Layer"
}
},
{
"name": "MergeLayer",
"schema": {
"category": "Layer"
}
},
{
"name": "SwitchLayer",
"schema": {
"category": "Layer"
}
},
{
"name": "ConcatLayer",
"schema": {
"category": "Tensor",
"attributes": [
{ "name": "concatAxis", "type": "uint", "src": "concatAxis" },
{ "name": "numViews", "type": "uint", "src": "numViewes" },
{ "name": "numDimensions", "type": "uint", "src": "numDimensions" }
]
}
},
{
"name": "SpaceToDepthLayer",
"schema": {
"category": "Layer",
"attributes": [
{ "name": "blockSize", "type": "uint", "src": "blockSize" },
{ "name": "dataLayout", "type": "string", "src": "dataLayout", "src_type": "DataLayout" }
]
}
},
{
"name": "PreluLayer",
"schema": {
"category": "Layer"
}
},
{
"name": "TransposeConvolution2dLayer",
"schema": {
"category": "Layer",
"inputs": [
{ "name": "weight", "src": "weights" },
{ "name": "bias", "src": "biases" }
],
"attributes": [
{ "name": "padding", "type": "string", "src": ["padTop", "padRight", "padBottom", "padLeft"] },
{ "name": "stride", "type": "string", "src": ["strideX", "strideY"] },
{ "name": "dataLayout", "type": "string", "src": "dataLayout", "src_type": "DataLayout" }
]
}
},
{
"name": "ResizeLayer",
"schema": {
"category": "Layer",
"attributes": [
{ "name": "targetWidth", "type": "uint", "src": "targetWidth" },
{ "name": "targetHeight", "type": "uint", "src": "targetHeight" },
{ "name": "method", "type": "string", "src": "method", "src_type": "ResizeMethod" },
{ "name": "dataLayout", "type": "string", "src": "dataLayout", "src_type": "DataLayout" }
]
}
},
{
"name": "StackLayer",
"schema": {
"category": "Layer",
"attributes": [
{ "name": "axis", "type": "uint", "src": "axis" },
{ "name": "numInputs", "type": "uint", "src": "numInputs" },
{ "name": "inputShape", "type": "uint", "src": "inputShape" }
]
}
},
{
"name": "QuantizedLstmLayer",
"schema": {
"category": "Layer",
"inputs": [
{ "name": "inputToInputWeights1", "src": "inputToInputWeights1" },
{ "name": "inputToForgetWeights1", "src": "inputToForgetWeights1" },
{ "name": "inputToCellWeights1", "src": "inputToCellWeights1" },
{ "name": "inputToOutputWeights1", "src": "inputToOutputWeights1" },
{ "name": "recurrentToInputWeights1", "src": "recurrentToInputWeights1" },
{ "name": "recurrentToForgetWeights1", "src": "recurrentToForgetWeights1" },
{ "name": "recurrentToCellWeights1", "src": "recurrentToCellWeights1" },
{ "name": "recurrentToOutputWeights1", "src": "recurrentToOutputWeights1" },
{ "name": "inputGateBias1", "src": "inputGateBias1" },
{ "name": "forgetGateBias1", "src": "forgetGateBias1" },
{ "name": "cellBias1", "src": "cellBias1" },
{ "name": "outputGateBias1", "src": "outputGateBias1" }
]
}
}
]
/* jshint esversion: 6 */
/* eslint "indent": [ "error", 4, { "SwitchCase": 1 } ] */
var armnn = armnn || {};
var base = base || require('./base');
var flatbuffers = flatbuffers || require('flatbuffers').flatbuffers;
var long = long || { Long: require('long') };
armnn.ModelFactory = class {
match(context) {
const extension = context.identifier.split('.').pop().toLowerCase();
if (extension == 'armnn') {
return true;
}
return false;
}
open(context, host) {
return host.require('./armnn-schema').then((schema) => {
const identifier = context.identifier;
let model = null;
try {
const buffer = context.buffer;
const byteBuffer = new flatbuffers.ByteBuffer(buffer);
armnn.schema = schema.armnn_schema;
model = armnn.schema.SerializedGraph.getRootAsSerializedGraph(byteBuffer);
}
catch (error) {
host.exception(error, false);
const message = error && error.message ? error.message : error.toString();
throw new armnn.Error(message.replace(/\.$/, '') + " in '" + identifier + "'.");
}
return armnn.Metadata.open(host).then((metadata) => {
try {
return new armnn.Model(model, metadata);
}
catch (error) {
const message = error && error.message ? error.message : error.toString();
throw new new armnn.Error(message.replace(/\.$/, '') + " in '" + identifier + "'.");
}
});
});
}
};
armnn.Model = class {
constructor(model, metadata) {
this._graphs = [];
this._graphs.push(new armnn.Graph(model, metadata));
}
get format() {
return 'Arm NN';
}
get description() {
return '';
}
get graphs() {
return this._graphs;
}
};
armnn.Graph = class {
constructor(graph, metadata) {
this._name = '';
this._nodes = [];
this._inputs = [];
this._outputs = [];
// generate parameters
const args = {};
for (let j = 0; j < graph.layersLength(); j++) {
let base = armnn.Node.getBase(graph.layers(j));
for (let i = 0 ; i < base.outputSlotsLength() ; i++) {
const key = base.index().toString() + ':' + i.toString();
args[key] = new armnn.Argument(key, base.outputSlots(i).tensorInfo(), null);
}
}
for (let j = 0; j < graph.layersLength(); j++) {
this._nodes.push(new armnn.Node(graph.layers(j), args, metadata));
}
for (let k = 0; k < graph.inputIdsLength(); k++) {
// need to do something?
}
for (let l = 0; l < graph.outputIdsLength(); l++) {
// need to do something?
}
}
get name() {
return this._name;
}
get groups() {
return false;
}
get inputs() {
return this._inputs;
}
get outputs() {
return this._outputs;
}
get nodes() {
return this._nodes;
}
};
armnn.Node = class {
constructor(layer, args, metadata) {
this._metadata = metadata;
this._type = armnn.schema.LayerName[layer.layerType()];
this._name = '';
this._outputs = [];
this._inputs = [];
this._attributes = [];
const base = armnn.Node.getBase(layer);
if (base) {
this._name = base.layerName();
for (let i = 0; i < base.inputSlotsLength(); i++) {
const connection = base.inputSlots(i).connection();
const sourceLayerIndex = connection.sourceLayerIndex();
const sourceOutputIndex = connection.outputSlotIndex();
const argument = args[sourceLayerIndex.toString() + ':' + sourceOutputIndex.toString()];
this._inputs.push(new armnn.Parameter('input', [ argument ]));
}
for (let j = 0; j < base.outputSlotsLength(); j++) {
const argument = args[base.index().toString() + ':' + j.toString()];
this._outputs.push(new armnn.Parameter('output', [ argument ]));
}
}
const schema = this._metadata.type(this._type);
if (schema) {
const _layer = armnn.Node.castLayer(layer);
if (schema.bindings) {
for (let i = 0 ; i < schema.bindings.length ; i++) {
const binding = schema.bindings[i];
const value = _layer.base()[binding.src]();
this._attributes.push(new armnn.Attribute(binding.name, binding.type, value));
}
}
if (schema.attributes) {
for (const attribute of schema.attributes) {
const value = this.packAttr(_layer, attribute);
this._attributes.push(new armnn.Attribute(attribute.name, attribute.type, value));
}
}
if (schema.inputs) {
for (let i = 0 ; i < schema.inputs.length ; i++) {
const input = schema.inputs[i];
const initializer = _layer[input.src]();
if (initializer) {
const args = [ new armnn.Argument('', null, initializer) ];
this._inputs.push(new armnn.Parameter(input.name, args));
}
}
}
}
}
get type() {
return this._type.replace(/Layer$/, '');
}
get name() {
return this._name;
}
get domain() {
return null;
}
get metadata() {
return this._metadata.type(this._type);
}
get group() {
return null;
}
get inputs() {
return this._inputs;
}
get outputs() {
return this._outputs;
}
get attributes() {
return this._attributes;
}
static castLayer(layer) {
let layerType = layer.layerType();
for (const k of Object.keys(armnn.schema.Layer)) {
if (layerType == armnn.schema.Layer[k]) {
return layer.layer(new armnn.schema[k]);
}
}
return null;
}
static getBase(layer) {
layer = armnn.Node.castLayer(layer);
return (layer.base().base)? layer.base().base() : layer.base();
}
getAttr(descriptor, key) {
if (typeof descriptor[key] == "undefined")
return "undefined";
const values = descriptor[key]();
if (Array.isArray(values)) {
return values.join(", ");
}
else {
return values;
}
}
packAttr(layer, attr) {
const descriptor = layer === null ? null : layer.descriptor();
const key = attr.src;
const type = attr.src_type;
if (typeof type != "undefined") {
let value = this.getAttr(descriptor, key);
if (typeof armnn.schema[type + "Name"] != "undefined") {
return armnn.schema[type + "Name"][value];
}
else {
return value;
}
}
else if (Array.isArray(key)) {
let values = [];
for (let i = 0 ; i < key.length ; i++) {
values.push(this.getAttr(descriptor, key[i]));
}
return values.join(", ");
}
else {
return this.getAttr(descriptor, key);
}
}
static makeKey(layer_id, index) {
return layer_id.toString() + "_" + index.toString();
}
};
armnn.Attribute = class {
constructor(name, type, value) {
this._name = name;
this._value = value;
this._visible = true;
switch (type) {
case 'int': this._type = 'int32'; break;
case 'uint': this._type = 'uint32'; break;
case 'float': this._type = 'float32'; break;
case 'string': this._type = 'string'; break;
}
}
get name() {
return this._name;
}
get type() {
return this._type;
}
get value() {
return this._value;
}
get visible() {
return this._visible == false ? false : true;
}
};
armnn.Parameter = class {
constructor(name, args) {
this._name = name;
this._arguments = args;
}
get name() {
return this._name;
}
get visible() {
return true;
}
get arguments() {
return this._arguments;
}
};
armnn.Argument = class {
constructor(name, tensorInfo, initializer) {
if (typeof name !== 'string') {
throw new armnn.Error("Invalid argument identifier '" + JSON.stringify(name) + "'.");
}
const info = initializer ? initializer.info() : tensorInfo;
this._name = name;
this._type = new armnn.TensorType(info);
this._initializer = initializer ? new armnn.Tensor(info, initializer) : null;
if (this._type.dataType.startsWith('q') && info) {
this._scale = info.quantizationScale();
this._zeroPoint = info.quantizationOffset();
}
}
get name() {
return this._name;
}
get type() {
return this._type;
}
get quantization() {
if (this._scale !== undefined && this._zeroPoint !== undefined) {
return this._scale.toString() + ' * ' + (this._zeroPoint == 0 ? 'q' : ('(q - ' + this._zeroPoint.toString() + ')'));
}
return undefined;
}
get initializer() {
return this._initializer;
}
};
armnn.Tensor = class {
constructor(tensorInfo, tensor) {
this._name = '';
this._type = new armnn.TensorType(tensorInfo);
this._kind = 'Initializer';
let data = null;
if (tensor.dataType() == armnn.schema.ConstTensorData.ByteData)
data = tensor.data(new armnn.schema.ByteData);
else if (tensor.dataType() == armnn.schema.ConstTensorData.ShortData)
data = tensor.data(new armnn.schema.ShortData);
else if (tensor.dataType() == armnn.schema.ConstTensorData.IntData)
data = tensor.data(new armnn.schema.IntData);
else if (tensor.dataType() == armnn.schema.ConstTensorData.LongData)
data = tensor.data(new armnn.schema.LongData);
this._data = data.dataLength() > 0 ? data.dataArray() : null;
}
get name() {
return this._name;
}
get kind() {
return this._kind;
}
get type() {
return this._type;
}
get state() {
return this._context().state;
}
get value() {
let context = this._context();
if (context.state) {
return null;
}
context.limit = Number.MAX_SAFE_INTEGER;
return this._decode(context, 0);
}
toString() {
let context = this._context();
if (context.state) {
return '';
}
context.limit = 10000;
let value = this._decode(context, 0);
return JSON.stringify(value, null, 4);
}
_context() {
let context = {};
context.state = null;
context.index = 0;
context.count = 0;
if (this._data == null) {
context.state = 'Tensor data is empty.';
return context;
}
context.dataType = this._type.dataType;
context.shape = this._type.shape.dimensions;
context.data = new DataView(this._data.buffer, this._data.byteOffset, this._data.byteLength);
return context;
}
_decode(context, dimension) {
let shape = context.shape;
if (shape.length == 0) {
shape = [ 1 ];
}
let size = shape[dimension];
let results = [];
if (dimension == shape.length - 1) {
for (let i = 0; i < size; i++) {
if (context.count > context.limit) {
results.push('...');
return results;
}
switch (context.dataType) {
case 'float16':
results.push(context.data.getFloat16(context.index, true));
context.index += 2;
context.count++;
break;
case 'float32':
results.push(context.data.getFloat32(context.index, true));
context.index += 4;
context.count++;
break;
case 'quint8':
results.push(context.data.getUint8(context.index));
context.index += 1;
context.count++;
break;
case 'qint16':
results.push(context.data.getInt16(context.index, true));
context.index += 2;
context.count++;
break;
case 'int32':
results.push(context.data.getInt32(context.index, true));
context.index += 4;
context.count++;
break;
case 'boolean':
results.push(context.data.getInt8(context.index));
context.index += 1;
context.count++;
break;
default:
break;
}
}
}
else {
for (let j = 0; j < size; j++) {
if (context.count > context.limit) {
results.push('...');
return results;
}
results.push(this._decode(context, dimension + 1));
}
}
if (context.shape.length == 0) {
return results[0];
}
return results;
}
};
armnn.TensorType = class {
constructor(tensorInfo) {
const dataType = tensorInfo.dataType();
switch (dataType) {
case 0: this._dataType = 'float16'; break;
case 1: this._dataType = 'float32'; break;
case 2: this._dataType = 'quint8'; break; // QuantisedAsymm8
case 3: this._dataType = 'int32'; break;
case 4: this._dataType = 'boolean'; break;
case 5: this._dataType = 'qint16'; break; // QuantisedSymm16
case 6: this._dataType = 'quint8'; break; // QAsymmU8
case 7: this._dataType = 'qint16'; break; // QSymmS16
default: throw new armnn.Error("Unknown data type '" + dataType + "'.");
}
let dimensions = [];
let dimensionsLength = tensorInfo.dimensionsLength();
if (dimensionsLength > 0) {
for (let i = 0; i < dimensionsLength; i++) {
dimensions.push(tensorInfo.dimensions(i));
}
}
this._shape = new armnn.TensorShape(dimensions);
}
get dataType() {
return this._dataType;
}
get shape() {
return this._shape;
}
toString() {
return this.dataType + this._shape.toString();
}
};
armnn.TensorShape = class {
constructor(dimensions) {
this._dimensions = dimensions;
}
get dimensions() {
return this._dimensions;
}
toString() {
if (!this._dimensions || this._dimensions.length == 0) {
return '';
}
return '[' + this._dimensions.map((dimension) => dimension.toString()).join(',') + ']';
}
};
armnn.Metadata = class {
static open(host) {
if (armnn.Metadata._metadata) {
return Promise.resolve(armnn.Metadata._metadata);
}
return host.request(null, 'armnn-metadata.json', 'utf-8').then((data) => {
armnn.Metadata._metadata = new armnn.Metadata(data);
return armnn.Metadata._metadata;
}).catch(() => {
armnn.Metadata._metadata = new armnn.Metadata(null);
return armnn.Metadata._metadata;
});
}
constructor(data) {
this._map = {};
if (data) {
let items = JSON.parse(data);
if (items) {
for (const item of items) {
if (item.name && item.schema) {
item.schema.name = item.name;
this._map[item.name] = item.schema;
}
}
}
}
}
type(name) {
return this._map[name];
}
attribute(type, name) {
const schema = this.type(type);
if (schema) {
let attributeMap = schema.attributeMap;
if (!attributeMap) {
attributeMap = {};
if (schema.attributes) {
for (const attribute of schema.attributes) {
attributeMap[attribute.name] = attribute;
}
}
schema.attributeMap = attributeMap;
}
let attributeSchema = attributeMap[name];
if (attributeSchema) {
return attributeSchema;
}
}
return null;
}
};
armnn.Error = class extends Error {
constructor(message) {
super(message);
this.name = 'Error loading Arm NN model.';
}
};
if (typeof module !== 'undefined' && typeof module.exports === 'object') {
module.exports.ModelFactory = armnn.ModelFactory;
}
/* eslint "indent": [ "error", 4, { "SwitchCase": 1 } ] */
// Experimental
var barracuda = barracuda || {};
var base = base || require('./base');
var long = long || { Long: require('long') };
barracuda.ModelFactory = class {
match(context) {
const identifier = context.identifier;
const extension = identifier.split('.').pop().toLowerCase();
if (extension === 'nn') {
const buffer = context.buffer;
if (buffer.length > 12 && buffer[0] <= 0x10 && buffer.subarray(1, 8).every((v) => v == 0x00)) {
return true;
}
}
return false;
}
open(context /*, host */) {
return barracuda.Metadata.open().then((metadata) => {
try {
const nn = new barracuda.NNModel(context.buffer);
return new barracuda.Model(metadata, nn);
}
catch (error) {
const identifier = context.identifier.toLowerCase();
const message = error && error.message ? error.message : error.toString();
throw new barracuda.Error(message.replace(/\.$/, '') + " in '" + identifier + "'.");
}
});
}
};
barracuda.Model = class {
constructor(metadata, nn) {
this._version = nn.version.toString();
this._graphs = [ new barracuda.Graph(metadata, nn) ];
}
get format() {
return "Barracuda v" + this._version;
}
get graphs() {
return this._graphs;
}
};
barracuda.Graph = class {
constructor(metadata, nn) {
this._inputs = [];
this._outputs = [];
this._nodes = [];
for (const input of nn.inputs) {
this._inputs.push(new barracuda.Parameter(input.name, [
new barracuda.Argument(input.name, new barracuda.TensorType(4, new barracuda.TensorShape(input.shape)))
]));
}
for (const output of nn.outputs) {
this._outputs.push(new barracuda.Parameter(output, [
new barracuda.Argument(output)
]));
}
const layers = [];
const initializers = new Map();
for (const layer of nn.layers) {
if (layer.type !== 255 || layer.inputs.length > 0) {
layers.push(layer);
}
else {
for (const tensor of layer.tensors) {
initializers.set(tensor.name, new barracuda.Tensor(tensor));
}
}
}
for (const layer of layers) {
this._nodes.push(new barracuda.Node(metadata, layer, initializers));
}
}
get name() {
return '';
}
get inputs() {
return this._inputs;
}
get outputs() {
return this._outputs;
}
get nodes() {
return this._nodes;
}
};
barracuda.Parameter = class {
constructor(name, args) {
this._name = name;
this._arguments = args;
}
get name() {
return this._name;
}
get visible() {
return true;
}
get arguments() {
return this._arguments;
}
};
barracuda.Argument = class {
constructor(name, type, initializer) {
this._name = name;
this._type = type || null;
this._initializer = initializer || null;
}
get name() {
return this._name;
}
get type() {
return this._type;
}
get initializer() {
return this._initializer;
}
};
barracuda.Node = class {
constructor(metadata, layer, initializers) {
this._name = layer.name;
this._metadata = metadata.type(layer.type) || { name: layer.type.toString() };
this._type = this._metadata.name;
this._inputs = [];
this._outputs = [];
this._attributes = [];
const inputs = Array.prototype.slice.call(this._metadata.inputs || [ 'input' ]);
if (this._metadata.inputs && this._metadata.inputs.length === 1 && this._metadata.inputs[0] === 'inputs') {
this._inputs.push(new barracuda.Parameter('inputs', layer.inputs.map((input) => {
const initializer = initializers.has(input) ? initializers.get(input) : null;
return new barracuda.Argument(input, initializer ? initializer.type : null, initializer);
})));
}
else {
for (let i = 0; i < layer.inputs.length; i++) {
const input = layer.inputs[i];
const initializer = initializers.has(input) ? initializers.get(input) : null;
this._inputs.push(new barracuda.Parameter(inputs.length > 0 ? inputs.shift() : i.toString(), [
new barracuda.Argument(input, initializer ? initializer.type : null, initializer)
]));
}
}
for (let i = 0; i < layer.tensors.length; i++) {
const tensor = layer.tensors[i];
const initializer = new barracuda.Tensor(tensor);
this._inputs.push(new barracuda.Parameter(inputs.length > 0 ? inputs.shift() : i.toString(), [
new barracuda.Argument(tensor.name, initializer.type, initializer)
]));
}
this._outputs.push(new barracuda.Parameter('output', [
new barracuda.Argument(this._name)
]));
if (this._type === 'Activation') {
if (!barracuda.Activation[layer.activation]) {
throw new barracuda.Error("Unknown activation '" + layer.activation + "'.");
}
this._type = barracuda.Activation[layer.activation];
}
else if (layer.activation !== 0) {
throw new barracuda.Error("Unsupported activation '" + layer.activation + "' for type '" + this._type + "'.");
}
const attribute = (name, type, value, defaultValue) => {
if (Array.isArray(defaultValue) && Array.isArray(value) && value.length == defaultValue.length && value.every((v, i) => v === defaultValue[i])) {
return;
}
if (typeof defaultValue == 'function' && defaultValue(value)) {
return;
}
if (defaultValue === value) {
return;
}
this._attributes.push(new barracuda.Attribute(name, type, value));
};
attribute('strides', 'int32[]', layer.strides, []);
attribute('pads', 'int32[]', layer.pads, (value) => Array.isArray(value) && (value.every((v) => v === 0) || value.every((v) => v === -1)));
attribute('size', 'int32[]', layer.pool_size, []);
attribute('alpha', 'float32', layer.alpha, 1);
attribute('beta', 'float32', layer.beta, 0);
attribute('axis', 'int32', layer.axis, -1);
}
get type() {
return this._type;
}
get name() {
return this._name;
}
get metadata() {
return this._metadata;
}
get attributes() {
return this._attributes;
}
get inputs() {
return this._inputs;
}
get outputs() {
return this._outputs;
}
};
barracuda.Attribute = class {
constructor(name, type, value) {
this._name = name;
this._type = type;
this._value = value;
}
get type() {
return this._type;
}
get name() {
return this._name;
}
get value() {
return this._value;
}
get visible() {
return true;
}
};
barracuda.Tensor = class {
constructor(tensor) {
this._type = new barracuda.TensorType(tensor.itemsize, new barracuda.TensorShape(tensor.shape));
this._data = tensor.data;
}
get kind() {
return '';
}
get type() {
return this._type;
}
get state() {
return this._context().state || null;
}
get value() {
const context = this._context();
if (context.state) {
return null;
}
context.limit = Number.MAX_SAFE_INTEGER;
return this._decode(context, 0);
}
toString() {
const context = this._context();
if (context.state) {
return '';
}
context.limit = 10000;
const value = this._decode(context, 0);
return JSON.stringify(value, null, 4);
}
_context() {
const context = {};
context.index = 0;
context.count = 0;
context.state = null;
if (this._type.dataType == '?') {
context.state = 'Tensor has unknown data type.';
return context;
}
if (!this._type.shape || (this._type.shape.dimensions && this._type.shape.dimensions.length == 0)) {
context.state = 'Tensor has no dimensions.';
return context;
}
if (!this._data) {
context.state = 'Tensor data is empty.';
return context;
}
switch (this._type.dataType) {
case 'float32':
context.data = new DataView(this._data.buffer, this._data.byteOffset, this._data.byteLength);
break;
default:
context.state = 'Tensor data type is not implemented.';
break;
}
context.dataType = this._type.dataType;
context.shape = this._type.shape.dimensions;
return context;
}
_decode(context, dimension) {
const shape = context.shape.length == 0 ? [ 1 ] : context.shape;
const results = [];
const size = shape[dimension];
if (dimension == shape.length - 1) {
for (let i = 0; i < size; i++) {
if (context.count > context.limit) {
results.push('...');
return results;
}
switch (this._type.dataType) {
case 'float32':
results.push(context.data.getFloat32(context.index, true));
context.index += 4;
context.count++;
break;
}
}
}
else {
for (let j = 0; j < size; j++) {
if (context.count > context.limit) {
results.push('...');
return results;
}
results.push(this._decode(context, dimension + 1));
}
}
if (context.shape.length == 0) {
return results[0];
}
return results;
}
};
barracuda.TensorType = class {
constructor(itemsize, shape) {
switch (itemsize) {
case 4: this._dataType = 'float32'; break;
default: throw new barracuda.Error("Unsupported data type size '" + itemsize.toString() + "'.");
}
this._shape = shape;
}
get dataType() {
return this._dataType;
}
get shape() {
return this._shape;
}
toString() {
return this._dataType + this._shape.toString();
}
};
barracuda.TensorShape = class {
constructor(dimensions) {
this._dimensions = dimensions;
}
get dimensions() {
return this._dimensions;
}
toString() {
return this._dimensions ? ('[' + this._dimensions.map((dimension) => dimension ? dimension.toString() : '?').join(',') + ']') : '';
}
};
barracuda.NNModel = class {
constructor(buffer) {
// https://github.com/Unity-Technologies/ml-agents/blob/master/ml-agents/mlagents/trainers/barracuda.py
// https://github.com/Unity-Technologies/ml-agents/blob/master/ml-agents/mlagents/trainers/tensorflow_to_barracuda.py
const reader = new barracuda.BinaryReader(buffer);
this._version = reader.int32();
reader.int32();
this._inputs = [];
const modelInputsLength = reader.int32();
for (let i = 0; i < modelInputsLength; i++) {
this._inputs.push({
name: reader.string(),
shape: reader.shape()
});
}
this._outputs = reader.strings();
this._memories = [];
const memoriesLength = reader.int32();
for (let i = 0; i < memoriesLength; i++) {
// debugger;
this._memories.push({
shape: reader.shape(),
in: reader.string(),
out: reader.string()
});
}
this._layers = [];
const layersLength = reader.int32();
for (let i = 0; i < layersLength; i++) {
const layer = {};
layer.name = reader.string();
layer.type = reader.int32();
layer.activation = reader.int32();
reader.int32();
reader.int32();
layer.pads = reader.int32s();
layer.strides = reader.int32s();
layer.pool_size = reader.int32s();
layer.axis = reader.int32();
layer.alpha = reader.float32();
layer.beta = reader.float32();
reader.int32();
layer.inputs = reader.strings();
layer.tensors = [];
const tensorsLength = reader.int32();
for (let j = 0; j < tensorsLength; j++) {
layer.tensors.push({
name: reader.string(),
shape: reader.shape(),
offset: reader.int64(),
itemsize: reader.int32(),
length: reader.int32()
});
}
this._layers.push(layer);
}
for (const layer of this._layers) {
for (const tensor of layer.tensors) {
tensor.data = reader.bytes(tensor.offset * tensor.itemsize, tensor.length * tensor.itemsize);
}
}
}
get version() {
return this._version;
}
get inputs() {
return this._inputs;
}
get outputs() {
return this._outputs;
}
get memories() {
return this._memories;
}
get layers() {
return this._layers;
}
};
barracuda.Activation = {
0: "Linear", 1: "Relu", 2: "Softmax", 3: "Tanh", 4: "Sigmoid", 5: "Elu", 6: "Relu6", 7: "LeakyRelu",
8: "Selu", 9: "Swish", 10: "LogSoftmax", 11: "Softplus", 12: "Softsign",
100: "Abs", 101: "Neg", 102: "Ceil", 104: "Floor", 111: "Sqrt", 113: "Exp", 114: "Log",
200: "Acos", 201: "Acosh", 202: "Asin", 203: "Asinh", 204: "Atan", 205: "Atanh", 206: "Cos", 207: "Cosh", 208: "Sin", 209: "Sinh", 210: "Tan"
};
barracuda.BinaryReader = class {
constructor(buffer) {
this._buffer = buffer;
this._dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
this._position = 0;
}
skip(offset) {
this._position += offset;
if (this._position > this._buffer.length) {
throw new barracuda.Error('Expected ' + (this._position - this._buffer.length) + ' more bytes. The file might be corrupted. Unexpected end of file.');
}
}
bytes(offset, length) {
const start = this._position + offset;
const end = start + length;
if (end > this._buffer.length) {
throw new barracuda.Error('Expected ' + (end - this._buffer.length) + ' more bytes. The file might be corrupted. Unexpected end of file.');
}
return this._buffer.slice(start, end);
}
int32() {
const position = this._position;
this.skip(4);
return this._dataView.getInt32(position, true);
}
int32s() {
const values = [];
const count = this.int32();
for (let i = 0; i < count; i++) {
values.push(this.int32());
}
return values;
}
int64() {
const value = this.int32();
if (this.int32() !== 0) {
throw new barracuda.Error('Invalid int64 value.');
}
return value;
}
float32() {
const position = this._position;
this.skip(4);
return this._dataView.getFloat32(position, true);
}
string() {
let text = '';
const size = this.int32();
let position = this._position;
this.skip(size);
for (let i = 0; i < size; i++) {
text += String.fromCharCode(this._buffer[position++]);
}
return text;
}
strings() {
const values = [];
const length = this.int32();
for (let i = 0; i < length; i++) {
values.push(this.string());
}
return values;
}
shape() {
return this.int32s();
}
};
barracuda.Metadata = class {
static open() {
barracuda.Metadata._metadata = barracuda.Metadata._metadata || new barracuda.Metadata();
return Promise.resolve(barracuda.Metadata._metadata);
}
constructor() {
this._map = new Map();
this._register(0, 'Nop', '');
this._register(1, 'Dense', 'Layer', [ 'input', 'kernel', 'bias' ]);
this._register(2, 'MatMul', '', [ 'input', 'kernel', 'bias' ]);
this._register(20, 'Conv2D', 'Layer', [ 'input', 'kernel', 'bias' ]);
this._register(21, 'DepthwiseConv2dNative', 'Layer', [ 'input', 'kernel', 'bias' ]);
this._register(22, 'Conv2DBackpropInput', '');
this._register(23, 'Upsample2D', '');
this._register(25, 'MaxPool', 'Pool');
this._register(26, 'AvgPool', 'Pool');
this._register(28, 'GlobalAvgPool', 'Pool');
this._register(29, 'Pad', '');
this._register(50, 'Activation', 'Activation');
this._register(51, 'ScaleBias', 'Normalization', [ 'input', 'scale', 'bias' ]);
this._register(52, 'InstanceNormalization', 'Normalization');
this._register(53, 'LRN', 'Normalization');
this._register(64, 'RandomStandardNormal', '');
this._register(65, 'RandomUniform', '');
this._register(67, 'OneHot', '');
this._register(100, 'Add', '', [ 'inputs' ]);
this._register(101, 'Sub', '', [ 'inputs' ]);
this._register(102, 'Mul', '', [ 'inputs' ]);
this._register(103, 'RealDiv', '', [ 'inputs' ]);
this._register(104, 'Pow', '', [ 'inputs' ]);
this._register(110, 'Minimum', '', [ 'inputs' ]);
this._register(111, 'Maximum', '', [ 'inputs' ]);
this._register(124, 'Max', '', [ 'inputs' ]);
this._register(125, 'Mean', '', [ 'inputs' ]);
this._register(126, 'Min', '', [ 'inputs' ]);
this._register(127, 'Prod', '', [ 'inputs' ]);
this._register(128, 'Sum', '', [ 'inputs' ]);
this._register(200, 'Flatten', 'Shape');
this._register(201, 'Reshape', 'Shape');
this._register(210, 'Concat', 'Tensor', [ 'inputs' ]);
this._register(211, 'StridedSlice', 'Shape');
}
_register(id, name, category, inputs) {
this._map.set(id, { name: name, category: category, inputs: inputs });
}
type(name) {
if (this._map.has(name)) {
return this._map.get(name);
}
return null;
}
};
barracuda.Error = class extends Error {
constructor(message) {
super(message);
this.name = 'Error loading Barracuda model.';
}
};
if (typeof module !== 'undefined' && typeof module.exports === 'object') {
module.exports.ModelFactory = barracuda.ModelFactory;
}
/* jshint esversion: 6 */
var base = base || {};
if (typeof window !== 'undefined' && typeof window.Long != 'undefined') {
window.long = { Long: window.Long };
}
if (!DataView.prototype.getFloat16) {
DataView.prototype.getFloat16 = function(byteOffset, littleEndian) {
const value = this.getUint16(byteOffset, littleEndian);
const e = (value & 0x7C00) >> 10;
let f = value & 0x03FF;
if (e == 0) {
f = 0.00006103515625 * (f / 1024);
}
else if (e == 0x1F) {
f = f ? NaN : Infinity;
}
else {
f = DataView.__float16_pow[e] * (1 + (f / 1024));
}
return value & 0x8000 ? -f : f;
};
DataView.__float16_pow = {
1: 1/16384, 2: 1/8192, 3: 1/4096, 4: 1/2048, 5: 1/1024, 6: 1/512, 7: 1/256, 8: 1/128,
9: 1/64, 10: 1/32, 11: 1/16, 12: 1/8, 13: 1/4, 14: 1/2, 15: 1, 16: 2,
17: 4, 18: 8, 19: 16, 20: 32, 21: 64, 22: 128, 23: 256, 24: 512,
25: 1024, 26: 2048, 27: 4096, 28: 8192, 29: 16384, 30: 32768, 31: 65536
};
}
if (!DataView.prototype.setFloat16) {
DataView.prototype.setFloat16 = function(byteOffset, value, littleEndian) {
DataView.__float16_float[0] = value;
value = DataView.__float16_int[0];
const s = (value >>> 16) & 0x8000;
const e = (value >>> 23) & 0xff;
const f = value & 0x7fffff;
const v = s | DataView.__float16_base[e] | (f >> DataView.__float16_shift[e]);
this.setUint16(byteOffset, v, littleEndian);
};
DataView.__float16_float = new Float32Array(1);
DataView.__float16_int = new Uint32Array(DataView.__float16_float.buffer, 0, DataView.__float16_float.length);
DataView.__float16_base = new Uint32Array(256);
DataView.__float16_shift = new Uint32Array(256);
for (let i = 0; i < 256; ++i) {
let e = i - 127;
if (e < -27) {
DataView.__float16_base[i] = 0x0000;
DataView.__float16_shift[i] = 24;
}
else if (e < -14) {
DataView.__float16_base[i] = 0x0400 >> -e - 14;
DataView.__float16_shift[i] = -e - 1;
}
else if (e <= 15) {
DataView.__float16_base[i] = e + 15 << 10;
DataView.__float16_shift[i] = 13;
}
else if (e < 128) {
DataView.__float16_base[i] = 0x7c00;
DataView.__float16_shift[i] = 24;
}
else {
DataView.__float16_base[i] = 0x7c00;
DataView.__float16_shift[i] = 13;
}
}
}
if (!DataView.prototype.getBits) {
DataView.prototype.getBits = function(offset, bits /*, signed */) {
offset = offset * bits;
const available = (this.byteLength << 3) - offset;
if (bits > available) {
throw new RangeError();
}
let value = 0;
let index = 0;
while (index < bits) {
const remainder = offset & 7;
const size = Math.min(bits - index, 8 - remainder);
value <<= size;
value |= (this.getUint8(offset >> 3) >> (8 - size - remainder)) & ~(0xff << size);
offset += size;
index += size;
}
return value;
};
}
[
{
"name": "Dropout",
"schema": {
"category": "Dropout"
}
},
{
"name": "Linear",
"schema": {
"category": "Layer",
"inputs": [
{ "name": "inputs" },
{ "name": "weight" },
{ "name": "bias" }
]
}
},
{
"name": "NormalizeScale",
"schema": {
"category": "Normalization",
"inputs": [
{ "name": "inputs" },
{ "name": "w" }
]
}
},
{
"name": "ReLU",
"schema": {
"category": "Activation"
}
},
{
"name": "Scale",
"schema": {
"category": "Layer",
"inputs": [
{ "name": "inputs" },
{ "name": "weight" },
{ "name": "bias" }
]
}
},
{
"name": "SoftMax",
"schema": {
"category": "Activation"
}
},
{
"name": "SpatialBatchNormalization",
"schema": {
"category": "Normalization"
}
},
{
"name": "SpatialConvolution",
"schema": {
"category": "Layer",
"inputs": [
{ "name": "inputs" },
{ "name": "weight" },
{ "name": "bias" }
]
}
},
{
"name": "SpatialCrossMapLRN",
"schema": {
"category": "Normalization"
}
},
{
"name": "SpatialDilatedConvolution",
"schema": {
"category": "Layer",
"inputs": [
{ "name": "inputs" },
{ "name": "weight" },
{ "name": "bias" }
]
}
},
{
"name": "SpatialAveragePooling",
"schema": {
"category": "Pool"
}
},
{
"name": "SpatialMaxPooling",
"schema": {
"category": "Pool"
}
},
{
"name": "Transpose",
"schema": {
"category": "Shape"
}
},
{
"name": "InferReshape",
"schema": {
"category": "Shape"
}
}
]
\ No newline at end of file
/* jshint esversion: 6 */
/* eslint "indent": [ "error", 4, { "SwitchCase": 1 } ] */
// Experimental
var bigdl = bigdl || {};
var long = long || { Long: require('long') };
var protobuf = protobuf || require('protobufjs');
bigdl.ModelFactory = class {
match(context) {
const identifier = context.identifier;
const extension = identifier.split('.').pop().toLowerCase();
if (extension == 'model' || extension == 'bigdl') {
const tags = context.tags('pb');
if (tags.has(2) && tags.has(7) && tags.has(8) && tags.has(9) && tags.has(10) && tags.has(11) && tags.has(12)) {
return true;
}
}
}
open(context, host) {
return host.require('./bigdl-proto').then(() => {
return bigdl.Metadata.open(host).then((metadata) => {
const identifier = context.identifier;
try {
// https://github.com/intel-analytics/BigDL/blob/master/spark/dl/src/main/resources/serialization/bigdl.proto
bigdl.proto = protobuf.roots.bigdl.com.intel.analytics.bigdl.serialization;
const module = bigdl.proto.BigDLModule.decode(context.buffer);
return new bigdl.Model(metadata, module);
}
catch (error) {
host.exception(error, false);
const message = error && error.message ? error.message : error.toString();
throw new bigdl.Error(message.replace(/\.$/, '') + " in '" + identifier + "'.");
}
});
});
}
};
bigdl.Model = class {
constructor(metadata, module) {
this._version = module && module.version ? module.version : '';
this._graphs = [];
this._graphs.push(new bigdl.Graph(metadata, module));
}
get format() {
return 'BigDL' + (this._version ? ' v' + this._version : '');
}
get graphs() {
return this._graphs;
}
};
bigdl.Graph = class {
constructor(metadata, module) {
this._type = module.moduleType;
this._inputs = [];
this._outputs = [];
this._nodes = [];
this._loadModule(metadata, '', module);
}
_loadModule(metadata, group, module) {
switch (module.moduleType) {
case 'com.intel.analytics.bigdl.nn.StaticGraph': {
this._loadStaticGraph(metadata, group, module);
break;
}
case 'com.intel.analytics.bigdl.nn.Sequential': {
this._loadSequential(metadata, group, module);
break;
}
case 'com.intel.analytics.bigdl.nn.Input': {
this._inputs.push(new bigdl.Parameter(module.name, [
new bigdl.Argument(module.name)
]));
break;
}
default: {
this._nodes.push(new bigdl.Node(metadata, group, module));
break;
}
}
}
_loadSequential(metadata, group, module) {
group = group.length > 0 ? group + '.' + module.namePostfix : module.namePostfix;
for (const submodule of module.subModules) {
this._loadModule(metadata, group, submodule);
}
}
_loadStaticGraph(metadata, group, module) {
group = group.length > 0 ? group + '.' + module.namePostfix : module.namePostfix;
for (const submodule of module.subModules) {
this._loadModule(metadata, group, submodule);
}
}
get groups() {
return this._groups || false;
}
get type() {
return this._type;
}
get inputs() {
return this._inputs;
}
get outputs() {
return this._outputs;
}
get nodes() {
return this._nodes;
}
};
bigdl.Parameter = class {
constructor(name, args) {
this._name = name;
this._arguments = args;
}
get name() {
return this._name;
}
get visible() {
return true;
}
get arguments() {
return this._arguments;
}
};
bigdl.Argument = class {
constructor(name, type, initializer) {
if (typeof name !== 'string') {
throw new bigdl.Error("Invalid argument identifier '" + JSON.stringify(name) + "'.");
}
this._name = name;
this._type = type || null;
this._initializer = initializer || null;
}
get name() {
return this._name;
}
get type() {
if (this._initializer) {
return this._initializer.type;
}
return this._type;
}
get initializer() {
return this._initializer;
}
};
bigdl.Node = class {
constructor(metadata, group, module) {
this._metadata = metadata;
this._group = group;
this._type = module.moduleType.split('.').pop();
this._name = module.name;
this._attributes = [];
this._inputs = [];
this._outputs = [];
this._inputs.push(new bigdl.Parameter('input', module.preModules.map((id) => new bigdl.Argument(id, null, null))));
const schema = metadata.type(this.type);
const inputs = (schema && schema.inputs) ? schema.inputs.slice() : [];
inputs.shift();
if (module.weight) {
inputs.shift();
this._inputs.push(new bigdl.Parameter('weight', [
new bigdl.Argument('', null, new bigdl.Tensor(module.weight))
]));
}
if (module.bias) {
inputs.shift();
this._inputs.push(new bigdl.Parameter('bias', [
new bigdl.Argument('', null, new bigdl.Tensor(module.bias))
]));
}
if (module.parameters && module.parameters.length > 0) {
for (const parameter of module.parameters) {
const input = inputs.shift();
const inputName = input ? input.name : this._inputs.length.toString();
this._inputs.push(new bigdl.Parameter(inputName, [
new bigdl.Argument('', null, new bigdl.Tensor(parameter))
]));
}
}
for (const key of Object.keys(module.attr)) {
const value = module.attr[key];
if (key === 'module_numerics' || key === 'module_tags') {
continue;
}
if (value.dataType === bigdl.proto.DataType.TENSOR) {
if (value.value) {
this._inputs.push(new bigdl.Parameter(key, [ new bigdl.Argument('', null, new bigdl.Tensor(value.tensorValue)) ]));
}
continue;
}
if (value.dataType === bigdl.proto.DataType.REGULARIZER && value.value === undefined) {
continue;
}
if (value.dataType === bigdl.proto.DataType.ARRAY_VALUE && value.arrayValue.datatype === bigdl.proto.DataType.TENSOR) {
this._inputs.push(new bigdl.Parameter(key, value.arrayValue.tensor.map((tensor) => new bigdl.Argument('', null, new bigdl.Tensor(tensor)))));
continue;
}
this._attributes.push(new bigdl.Attribute(metadata.attribute(this._type, key), key, value));
}
const output = this._name || this._type + module.namePostfix;
this._outputs.push(new bigdl.Parameter('output', [
new bigdl.Argument(output, null, null)
]));
}
get group() {
return this._group;
}
get type() {
return this._type;
}
get metadata() {
return this._metadata.type(this._type);
}
get name() {
return this._name;
}
get inputs() {
return this._inputs;
}
get outputs() {
return this._outputs;
}
get attributes() {
return this._attributes;
}
};
bigdl.Attribute = class {
constructor(schema, name, value) {
this._name = name;
switch (value.dataType) {
case bigdl.proto.DataType.INT32: {
this._type = 'int32';
this._value = value.int32Value;
break;
}
case bigdl.proto.DataType.FLOAT: {
this._type = 'float32';
this._value = value.floatValue;
break;
}
case bigdl.proto.DataType.DOUBLE: {
this._type = 'float64';
this._value = value.doubleValue;
break;
}
case bigdl.proto.DataType.BOOL: {
this._type = 'boolean';
this._value = value.boolValue;
break;
}
case bigdl.proto.DataType.REGULARIZER: {
this._value = value.value;
break;
}
case bigdl.proto.DataType.MODULE: {
this._value = value.bigDLModule;
break;
}
case bigdl.proto.DataType.NAME_ATTR_LIST: {
this._value = value.nameAttrListValue;
break;
}
case bigdl.proto.DataType.ARRAY_VALUE: {
switch (value.arrayValue.datatype) {
case bigdl.proto.DataType.INT32: {
this._type = 'int32[]';
this._value = value.arrayValue.i32;
break;
}
case bigdl.proto.DataType.FLOAT: {
this._type = 'float32[]';
this._value = value.arrayValue.flt;
break;
}
case bigdl.proto.DataType.STRING: {
this._type = 'string[]';
this._value = value.arrayValue.str;
break;
}
case bigdl.proto.DataType.TENSOR: {
this._type = 'tensor[]';
this._value = value.arrayValue.tensor;
break;
}
default: {
throw new bigdl.Error("Unsupported attribute array data type '" + value.arrayValue.datatype + "'.");
}
}
break;
}
case bigdl.proto.DataType.DATA_FORMAT: {
this._dataType = 'InputDataFormat';
switch (value.dataFormatValue) {
case 0: this._value = 'NCHW'; break;
case 1: this._value = 'NHWC'; break;
}
break;
}
default: {
throw new bigdl.Error("Unsupported attribute data type '" + value.dataType + "'.");
}
}
}
get type() {
return '';
}
get name() {
return this._name;
}
get value() {
return this._value;
}
get visible() {
return true;
}
};
bigdl.Tensor = class {
constructor(tensor) {
this._type = new bigdl.TensorType(tensor.datatype, new bigdl.TensorShape(tensor.size));
}
get kind() {
return 'Parameter';
}
get type() {
return this._type;
}
get state() {
return 'Not supported.';
}
get value() {
return null;
}
toString() {
return '';
}
};
bigdl.TensorType = class {
constructor(dataType, shape) {
switch (dataType) {
case bigdl.proto.DataType.FLOAT: this._dataType = 'float32'; break;
case bigdl.proto.DataType.DOUBLE: this._dataType = 'float64'; break;
default: throw new bigdl.Error("Unsupported tensor type '" + dataType + "'.");
}
this._shape = shape;
}
get dataType() {
return this._dataType;
}
get shape() {
return this._shape;
}
toString() {
return (this.dataType || '?') + this._shape.toString();
}
};
bigdl.TensorShape = class {
constructor(dimensions) {
this._dimensions = dimensions.map((dimension) => {
if (dimension && long.Long.isLong(dimension)) {
return dimension.toNumber();
}
return dimension;
});
}
get dimensions() {
return this._dimensions;
}
toString() {
return this._dimensions ? ('[' + this._dimensions.map((dimension) => dimension.toString()).join(',') + ']') : '';
}
};
bigdl.Metadata = class {
static open(host) {
if (bigdl.Metadata._metadata) {
return Promise.resolve(bigdl.Metadata._metadata);
}
return host.request(null, 'bigdl-metadata.json', 'utf-8').then((data) => {
bigdl.Metadata._metadata = new bigdl.Metadata(data);
return bigdl.Metadata._metadata;
}).catch(() => {
bigdl.Metadata._metadata = new bigdl.Metadata(null);
return bigdl.Metadata._metadata;
});
}
constructor(data) {
this._map = {};
this._attributeCache = {};
if (data) {
const items = JSON.parse(data);
if (items) {
for (const item of items) {
if (item.name && item.schema) {
item.schema.name = item.name;
this._map[item.name] = item.schema;
}
}
}
}
}
type(name) {
return this._map[name] || null;
}
attribute(type, name) {
let map = this._attributeCache[type];
if (!map) {
map = {};
const schema = this.type(type);
if (schema && schema.attributes && schema.attributes.length > 0) {
for (const attribute of schema.attributes) {
map[attribute.name] = attribute;
}
}
this._attributeCache[type] = map;
}
return map[name] || null;
}
};
bigdl.Error = class extends Error {
constructor(message) {
super(message);
this.name = 'Error loading BigDL model.';
}
};
if (typeof module !== 'undefined' && typeof module.exports === 'object') {
module.exports.ModelFactory = bigdl.ModelFactory;
}
/* jshint esversion: 6 */
/* eslint "indent": [ "error", 4, { "SwitchCase": 1 } ] */
// Experimental BSON JavaScript reader
var bson = {};
var long = long || { Long: require('long') };
// http://bsonspec.org/spec.html
bson.Reader = class {
constructor(buffer) {
this._asciiDecoder = new TextDecoder('ascii');
this._utf8Decoder = new TextDecoder('utf-8');
this._buffer = buffer;
this._position = 0;
this._view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
}
read() {
return this.document();
}
document(isArray) {
const start = this._position;
const size = this.int32();
if (size < 5 || start + size > this._buffer.length || this._buffer[start + size - 1] != 0x00) {
throw new bson.Reader('Invalid BSON size.');
}
let element = isArray ? [] : {};
let index = 0;
for (;;) {
const type = this.byte();
if (type == 0x00) {
break;
}
const key = this.cstring();
let value = null;
switch (type) {
case 0x01:
value = this.double();
break;
case 0x02:
value = this.string();
break;
case 0x03:
value = this.document(false);
break;
case 0x04:
value = this.document(true);
break;
case 0x05:
value = this.binary();
break;
case 0x08:
value = this.boolean();
break;
case 0x0A:
value = null;
break;
case 0x10:
value = this.int32();
break;
case 0x11:
value = this.uint64();
break;
case 0x12:
value = this.int64();
break;
default:
throw new bson.Error("Unknown value type '" + type + "'.");
}
if (isArray) {
if (index !== parseInt(key, 10)) {
throw new bson.Error("Invalid array index '" + key + "'.");
}
element.push(value);
index++;
}
else {
element[key] = value;
}
}
return element;
}
cstring() {
const end = this._buffer.indexOf(0x00, this._position);
const value = this._asciiDecoder.decode(this._buffer.subarray(this._position, end));
this._position = end + 1;
return value;
}
string() {
const end = this.int32() + this._position - 1;
const value = this._utf8Decoder.decode(this._buffer.subarray(this._position, end));
this._position = end;
if (this.byte() != '0x00') {
throw new bson.Error('String missing terminal 0.');
}
return value;
}
binary() {
const size = this.int32();
const subtype = this.byte();
const data = this._buffer.subarray(this._position, this._position + size);
this._position += size;
switch (subtype) {
case 0x00:
return data;
default:
throw new bson.Error("Unknown binary subtype '" + subtype + "'.");
}
}
boolean() {
const value = this.byte();
switch (value) {
case 0x00: return false;
case 0x01: return true;
default: throw new bson.Error("Invalid boolean value '" + value + "'.");
}
}
byte() {
return this._buffer[this._position++];
}
int32() {
const value = this._view.getInt32(this._position, true);
this._position += 4;
return value;
}
int64() {
const low = this._view.getUint32(this._position, true);
const hi = this._view.getUint32(this._position + 4, true);
this._position += 8;
return new long.Long(low, hi, false).toNumber();
}
uint64() {
const low = this._view.getUint32(this._position, true);
const hi = this._view.getUint32(this._position + 4, true);
this._position += 8;
return new long.Long(low, hi, true).toNumber();
}
};
bson.Error = class extends Error {
constructor(message) {
super(message);
this.name = 'BSON Error';
}
};
if (typeof module !== 'undefined' && typeof module.exports === 'object') {
module.exports.Reader = bson.Reader;
}
\ No newline at end of file
[
{
"name": "Convolution",
"schema": {
"category": "Layer",
"inputs": [
{ "name": "input" },
{ "name": "filter" },
{ "name": "bias" }
],
"outputs": [
{ "name": "output" }
],
"attributes": [
{ "name": "bias_term", "visible": false },
{ "name": "weight_filler", "visible": false },
{ "name": "bias_filler", "visible": false },
{ "name": "num_output", "visible": false },
{ "name": "pad", "default": [0] },
{ "name": "kernel_size", "default": [] },
{ "name": "stride", "default": [1] },
{ "name": "dilation", "default": [] },
{ "name": "group", "default": 1 }
]
}
},
{
"name": "Deconvolution",
"schema": {
"category": "Layer",
"inputs": [
{ "name": "input" },
{ "name": "filter" },
{ "name": "bias" }
],
"outputs": [
{ "name": "output" }
],
"attributes": [
{ "name": "bias_term", "visible": false },
{ "name": "weight_filler", "visible": false },
{ "name": "bias_filler", "visible": false },
{ "name": "num_output", "visible": false },
{ "name": "pad", "default": [] },
{ "name": "kernel_size", "default": [] },
{ "name": "stride", "default": [] },
{ "name": "dilation", "default": [] }
]
}
},
{
"name": "DepthwiseConvolution",
"schema": {
"category": "Layer",
"attributes": [
{ "name": "bias_term", "visible": false },
{ "name": "weight_filler", "visible": false },
{ "name": "bias_filler", "visible": false },
{ "name": "num_output", "visible": false }
],
"inputs": [
{ "name": "input" },
{ "name": "filter" },
{ "name": "bias" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "ConvolutionDepthwise",
"schema": {
"category": "Layer",
"attributes": [
{ "name": "pad", "default": [0] },
{ "name": "kernel_size", "default": [] },
{ "name": "stride", "default": [1] },
{ "name": "bias_term", "visible": false },
{ "name": "weight_filler", "visible": false },
{ "name": "bias_filler", "visible": false },
{ "name": "num_output", "visible": false }
],
"inputs": [
{ "name": "input" },
{ "name": "filter" },
{ "name": "bias" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "InnerProduct",
"schema": {
"category": "Layer",
"inputs": [
{ "name": "input" },
{ "name": "weights" },
{ "name": "bias" }
],
"outputs": [
{ "name": "output" }
],
"attributes": [
{ "name": "bias_term", "visible": false },
{ "name": "weight_filler", "visible": false },
{ "name": "bias_filler", "visible": false },
{ "name": "num_output", "visible": false }
]
}
},
{
"name": "Scale",
"schema": {
"category": "Layer",
"inputs": [
{ "name": "input" },
{ "name": "scale" },
{ "name": "bias" }
],
"outputs": [
{ "name": "output" }
],
"attributes": [
{ "name": "filler", "visible": false },
{ "name": "bias_term", "visible": false },
{ "name": "bias_filler", "visible": false }
]
}
},
{
"name": "Dropout",
"schema": {
"category": "Dropout",
"attributes": [
{ "name": "dropout_ratio", "default": 0.5 }
],
"inputs": [
{ "name": "input" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "Flatten",
"schema": {
"category": "Shape",
"inputs": [
{ "name": "input" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "LRN",
"schema": {
"category": "Normalization",
"attributes": [
{ "name": "local_size", "type": "uint32", "default": 5 },
{ "name": "alpha", "type": "float32", "default": 0.0001 },
{ "name": "beta", "type": "float32", "default": 0.75 }
],
"inputs": [
{ "name": "input" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "BatchNorm",
"schema": {
"category": "Normalization",
"attributes": [
{ "name": "use_global_stats", "visible": false },
{ "name": "eps", "default": 1e-5 }
],
"inputs": [
{ "name": "input" },
{ "name": "gamma" },
{ "name": "beta" },
{ "name": "mean" },
{ "name": "variance" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "BN",
"schema": {
"category": "Normalization",
"inputs": [
{ "name": "input" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "Sigmoid",
"schema": {
"category": "Activation",
"inputs": [
{ "name": "input" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "Softmax",
"schema": {
"category": "Activation",
"inputs": [
{ "name": "input" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "SoftmaxLoss",
"schema": {
"category": "Activation",
"inputs": [
{ "name": "input" },
{ "name": "labels" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "SoftmaxWithLoss",
"schema": {
"category": "Activation",
"inputs": [
{ "name": "input" },
{ "name": "labels" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "ContrastiveLossParameter",
"schema": {
"attributes": [
{ "name": "margin", "default": 1.0 },
{ "name": "legacy_version", "default": false }
]
}
},
{
"name": "ReLU",
"schema": {
"category": "Activation",
"inputs": [
{ "name": "input" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "PReLU",
"schema": {
"category": "Activation",
"inputs": [
{ "name": "input" },
{ "name": "slope" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "Concat",
"schema": {
"category": "Tensor",
"inputs": [
{ "name": "inputs", "option": "variadic" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "Split",
"schema": {
"category": "Tensor",
"inputs": [
{ "name": "input" }
],
"outputs": [
{ "name": "outputs", "option": "variadic" }
]
}
},
{
"name": "Eltwise",
"schema": {
"attributes": [
{ "name": "operation", "default": 1 }
],
"inputs": [
{ "name": "inputs", "option": "variadic" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "Pooling",
"schema": {
"category": "Pool",
"attributes": [
{ "name": "pool", "default": 0 }
],
"inputs": [
{ "name": "input" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "Crop",
"schema": {
"category": "Data",
"inputs": [
{ "name": "data" },
{ "name": "size" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "Data",
"schema": {
"category": "Data",
"outputs": [
{ "name": "data" },
{ "name": "label" }
]
}
},
{
"name": "DummyData",
"schema": {
"category": "Data",
"outputs": [
{ "name": "data" }
]
}
},
{
"name": "AnnotatedData",
"schema": {
"category": "Data",
"outputs": [
{ "name": "data" }
]
}
},
{
"name": "HDF5Data",
"schema": {
"category": "Data",
"outputs": [
{ "name": "data" }
]
}
},
{
"name": "ImageData",
"schema": {
"category": "Data",
"outputs": [
{ "name": "data" },
{ "name": "label" }
]
}
},
{
"name": "WindowData",
"schema": {
"category": "Data",
"outputs": [
{ "name": "data" },
{ "name": "label" }
]
}
},
{
"name": "Slice",
"schema": {
"category": "Tensor",
"attributes": [
{ "name": "axis", "default": 1 }
],
"inputs": [
{ "name": "input" }
],
"outputs": [
{ "name": "outputs", "option": "variadic" }
]
}
},
{
"name": "EuclideanLoss",
"schema": {
"inputs": [
{ "name": "predictions" },
{ "name": "targets" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "Accuracy",
"schema": {
"inputs": [
{ "name": "predictions" },
{ "name": "labels" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "LSTM",
"schema": {
"category": "Layer",
"inputs": [
{ "name": "input" },
{ "name": "weights" },
{ "name": "h_0" },
{ "name": "c_0" }
],
"outputs": [
{ "name": "output" },
{ "name": "h_T" },
{ "name": "c_T" }
],
"attributes": [
{ "name": "weight_filler", "visible": false },
{ "name": "bias_filler", "visible": false },
{ "name": "num_output", "visible": false }
]
}
},
{
"name": "Reshape",
"schema": {
"category": "Shape",
"inputs": [
{ "name": "data" }
],
"outputs": [
{ "name": "reshaped" }
]
}
},
{
"name": "ColorConv",
"schema": {
"inputs": [
{ "name": "input" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "Permute",
"schema": {
"category": "Shape",
"inputs": [
{ "name": "input" }
],
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "Parameter",
"schema": {
"outputs": [
{ "name": "output" }
]
}
},
{
"name": "Python",
"schema": {
}
}
]
\ No newline at end of file
此差异已折叠。
此差异已折叠。
因为 它太大了无法显示 source diff 。你可以改为 查看blob
!function(t,i){"object"==typeof exports&&"object"==typeof module?module.exports=i():"function"==typeof define&&define.amd?define([],i):"object"==typeof exports?exports.Long=i():t.Long=i()}("undefined"!=typeof self?self:this,function(){return function(t){function i(e){if(n[e])return n[e].exports;var r=n[e]={i:e,l:!1,exports:{}};return t[e].call(r.exports,r,r.exports,i),r.l=!0,r.exports}var n={};return i.m=t,i.c=n,i.d=function(t,n,e){i.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:e})},i.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(n,"a",n),n},i.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},i.p="",i(i.s=0)}([function(t,i){function n(t,i,n){this.low=0|t,this.high=0|i,this.unsigned=!!n}function e(t){return!0===(t&&t.__isLong__)}function r(t,i){var n,e,r;return i?(t>>>=0,(r=0<=t&&t<256)&&(e=l[t])?e:(n=h(t,(0|t)<0?-1:0,!0),r&&(l[t]=n),n)):(t|=0,(r=-128<=t&&t<128)&&(e=f[t])?e:(n=h(t,t<0?-1:0,!1),r&&(f[t]=n),n))}function s(t,i){if(isNaN(t))return i?p:m;if(i){if(t<0)return p;if(t>=c)return q}else{if(t<=-v)return _;if(t+1>=v)return E}return t<0?s(-t,i).neg():h(t%d|0,t/d|0,i)}function h(t,i,e){return new n(t,i,e)}function u(t,i,n){if(0===t.length)throw Error("empty string");if("NaN"===t||"Infinity"===t||"+Infinity"===t||"-Infinity"===t)return m;if("number"==typeof i?(n=i,i=!1):i=!!i,(n=n||10)<2||36<n)throw RangeError("radix");var e;if((e=t.indexOf("-"))>0)throw Error("interior hyphen");if(0===e)return u(t.substring(1),i,n).neg();for(var r=s(a(n,8)),h=m,o=0;o<t.length;o+=8){var g=Math.min(8,t.length-o),f=parseInt(t.substring(o,o+g),n);if(g<8){var l=s(a(n,g));h=h.mul(l).add(s(f))}else h=h.mul(r),h=h.add(s(f))}return h.unsigned=i,h}function o(t,i){return"number"==typeof t?s(t,i):"string"==typeof t?u(t,i):h(t.low,t.high,"boolean"==typeof i?i:t.unsigned)}t.exports=n;var g=null;try{g=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch(t){}n.prototype.__isLong__,Object.defineProperty(n.prototype,"__isLong__",{value:!0}),n.isLong=e;var f={},l={};n.fromInt=r,n.fromNumber=s,n.fromBits=h;var a=Math.pow;n.fromString=u,n.fromValue=o;var d=4294967296,c=d*d,v=c/2,w=r(1<<24),m=r(0);n.ZERO=m;var p=r(0,!0);n.UZERO=p;var y=r(1);n.ONE=y;var b=r(1,!0);n.UONE=b;var N=r(-1);n.NEG_ONE=N;var E=h(-1,2147483647,!1);n.MAX_VALUE=E;var q=h(-1,-1,!0);n.MAX_UNSIGNED_VALUE=q;var _=h(0,-2147483648,!1);n.MIN_VALUE=_;var B=n.prototype;B.toInt=function(){return this.unsigned?this.low>>>0:this.low},B.toNumber=function(){return this.unsigned?(this.high>>>0)*d+(this.low>>>0):this.high*d+(this.low>>>0)},B.toString=function(t){if((t=t||10)<2||36<t)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(_)){var i=s(t),n=this.div(i),e=n.mul(i).sub(this);return n.toString(t)+e.toInt().toString(t)}return"-"+this.neg().toString(t)}for(var r=s(a(t,6),this.unsigned),h=this,u="";;){var o=h.div(r),g=h.sub(o.mul(r)).toInt()>>>0,f=g.toString(t);if(h=o,h.isZero())return f+u;for(;f.length<6;)f="0"+f;u=""+f+u}},B.getHighBits=function(){return this.high},B.getHighBitsUnsigned=function(){return this.high>>>0},B.getLowBits=function(){return this.low},B.getLowBitsUnsigned=function(){return this.low>>>0},B.getNumBitsAbs=function(){if(this.isNegative())return this.eq(_)?64:this.neg().getNumBitsAbs();for(var t=0!=this.high?this.high:this.low,i=31;i>0&&0==(t&1<<i);i--);return 0!=this.high?i+33:i+1},B.isZero=function(){return 0===this.high&&0===this.low},B.eqz=B.isZero,B.isNegative=function(){return!this.unsigned&&this.high<0},B.isPositive=function(){return this.unsigned||this.high>=0},B.isOdd=function(){return 1==(1&this.low)},B.isEven=function(){return 0==(1&this.low)},B.equals=function(t){return e(t)||(t=o(t)),(this.unsigned===t.unsigned||this.high>>>31!=1||t.high>>>31!=1)&&(this.high===t.high&&this.low===t.low)},B.eq=B.equals,B.notEquals=function(t){return!this.eq(t)},B.neq=B.notEquals,B.ne=B.notEquals,B.lessThan=function(t){return this.comp(t)<0},B.lt=B.lessThan,B.lessThanOrEqual=function(t){return this.comp(t)<=0},B.lte=B.lessThanOrEqual,B.le=B.lessThanOrEqual,B.greaterThan=function(t){return this.comp(t)>0},B.gt=B.greaterThan,B.greaterThanOrEqual=function(t){return this.comp(t)>=0},B.gte=B.greaterThanOrEqual,B.ge=B.greaterThanOrEqual,B.compare=function(t){if(e(t)||(t=o(t)),this.eq(t))return 0;var i=this.isNegative(),n=t.isNegative();return i&&!n?-1:!i&&n?1:this.unsigned?t.high>>>0>this.high>>>0||t.high===this.high&&t.low>>>0>this.low>>>0?-1:1:this.sub(t).isNegative()?-1:1},B.comp=B.compare,B.negate=function(){return!this.unsigned&&this.eq(_)?_:this.not().add(y)},B.neg=B.negate,B.add=function(t){e(t)||(t=o(t));var i=this.high>>>16,n=65535&this.high,r=this.low>>>16,s=65535&this.low,u=t.high>>>16,g=65535&t.high,f=t.low>>>16,l=65535&t.low,a=0,d=0,c=0,v=0;return v+=s+l,c+=v>>>16,v&=65535,c+=r+f,d+=c>>>16,c&=65535,d+=n+g,a+=d>>>16,d&=65535,a+=i+u,a&=65535,h(c<<16|v,a<<16|d,this.unsigned)},B.subtract=function(t){return e(t)||(t=o(t)),this.add(t.neg())},B.sub=B.subtract,B.multiply=function(t){if(this.isZero())return m;if(e(t)||(t=o(t)),g){return h(g.mul(this.low,this.high,t.low,t.high),g.get_high(),this.unsigned)}if(t.isZero())return m;if(this.eq(_))return t.isOdd()?_:m;if(t.eq(_))return this.isOdd()?_:m;if(this.isNegative())return t.isNegative()?this.neg().mul(t.neg()):this.neg().mul(t).neg();if(t.isNegative())return this.mul(t.neg()).neg();if(this.lt(w)&&t.lt(w))return s(this.toNumber()*t.toNumber(),this.unsigned);var i=this.high>>>16,n=65535&this.high,r=this.low>>>16,u=65535&this.low,f=t.high>>>16,l=65535&t.high,a=t.low>>>16,d=65535&t.low,c=0,v=0,p=0,y=0;return y+=u*d,p+=y>>>16,y&=65535,p+=r*d,v+=p>>>16,p&=65535,p+=u*a,v+=p>>>16,p&=65535,v+=n*d,c+=v>>>16,v&=65535,v+=r*a,c+=v>>>16,v&=65535,v+=u*l,c+=v>>>16,v&=65535,c+=i*d+n*a+r*l+u*f,c&=65535,h(p<<16|y,c<<16|v,this.unsigned)},B.mul=B.multiply,B.divide=function(t){if(e(t)||(t=o(t)),t.isZero())throw Error("division by zero");if(g){if(!this.unsigned&&-2147483648===this.high&&-1===t.low&&-1===t.high)return this;return h((this.unsigned?g.div_u:g.div_s)(this.low,this.high,t.low,t.high),g.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?p:m;var i,n,r;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return p;if(t.gt(this.shru(1)))return b;r=p}else{if(this.eq(_)){if(t.eq(y)||t.eq(N))return _;if(t.eq(_))return y;return i=this.shr(1).div(t).shl(1),i.eq(m)?t.isNegative()?y:N:(n=this.sub(t.mul(i)),r=i.add(n.div(t)))}if(t.eq(_))return this.unsigned?p:m;if(this.isNegative())return t.isNegative()?this.neg().div(t.neg()):this.neg().div(t).neg();if(t.isNegative())return this.div(t.neg()).neg();r=m}for(n=this;n.gte(t);){i=Math.max(1,Math.floor(n.toNumber()/t.toNumber()));for(var u=Math.ceil(Math.log(i)/Math.LN2),f=u<=48?1:a(2,u-48),l=s(i),d=l.mul(t);d.isNegative()||d.gt(n);)i-=f,l=s(i,this.unsigned),d=l.mul(t);l.isZero()&&(l=y),r=r.add(l),n=n.sub(d)}return r},B.div=B.divide,B.modulo=function(t){if(e(t)||(t=o(t)),g){return h((this.unsigned?g.rem_u:g.rem_s)(this.low,this.high,t.low,t.high),g.get_high(),this.unsigned)}return this.sub(this.div(t).mul(t))},B.mod=B.modulo,B.rem=B.modulo,B.not=function(){return h(~this.low,~this.high,this.unsigned)},B.and=function(t){return e(t)||(t=o(t)),h(this.low&t.low,this.high&t.high,this.unsigned)},B.or=function(t){return e(t)||(t=o(t)),h(this.low|t.low,this.high|t.high,this.unsigned)},B.xor=function(t){return e(t)||(t=o(t)),h(this.low^t.low,this.high^t.high,this.unsigned)},B.shiftLeft=function(t){return e(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?h(this.low<<t,this.high<<t|this.low>>>32-t,this.unsigned):h(0,this.low<<t-32,this.unsigned)},B.shl=B.shiftLeft,B.shiftRight=function(t){return e(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?h(this.low>>>t|this.high<<32-t,this.high>>t,this.unsigned):h(this.high>>t-32,this.high>=0?0:-1,this.unsigned)},B.shr=B.shiftRight,B.shiftRightUnsigned=function(t){if(e(t)&&(t=t.toInt()),0===(t&=63))return this;var i=this.high;if(t<32){return h(this.low>>>t|i<<32-t,i>>>t,this.unsigned)}return 32===t?h(i,0,this.unsigned):h(i>>>t-32,0,this.unsigned)},B.shru=B.shiftRightUnsigned,B.shr_u=B.shiftRightUnsigned,B.toSigned=function(){return this.unsigned?h(this.low,this.high,!1):this},B.toUnsigned=function(){return this.unsigned?this:h(this.low,this.high,!0)},B.toBytes=function(t){return t?this.toBytesLE():this.toBytesBE()},B.toBytesLE=function(){var t=this.high,i=this.low;return[255&i,i>>>8&255,i>>>16&255,i>>>24,255&t,t>>>8&255,t>>>16&255,t>>>24]},B.toBytesBE=function(){var t=this.high,i=this.low;return[t>>>24,t>>>16&255,t>>>8&255,255&t,i>>>24,i>>>16&255,i>>>8&255,255&i]},n.fromBytes=function(t,i,e){return e?n.fromBytesLE(t,i):n.fromBytesBE(t,i)},n.fromBytesLE=function(t,i){return new n(t[0]|t[1]<<8|t[2]<<16|t[3]<<24,t[4]|t[5]<<8|t[6]<<16|t[7]<<24,i)},n.fromBytesBE=function(t,i){return new n(t[4]<<24|t[5]<<16|t[6]<<8|t[7],t[0]<<24|t[1]<<16|t[2]<<8|t[3],i)}}])});
//# sourceMappingURL=long.js.map
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
/>
<title>Netron</title>
<link rel="stylesheet" type="text/css" href="view-grapher.css" />
<style>
html {
-ms-text-size-adjust: 100%;
-moz-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
text-rendering: optimizeLegibility;
-webkit-text-rendering: optimizeLegibility;
-moz-text-rendering: optimizeLegibility;
-ms-text-rendering: optimizeLegibility;
-o-text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased;
-ms-font-smoothing: antialiased;
-o-font-smoothing: antialiased;
}
body {
overflow: hidden;
margin: 0;
width: 100vw;
height: 100vh;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', 'Ubuntu', 'Droid Sans',
sans-serif, 'PingFang SC';
font-size: 12px;
text-rendering: geometricPrecision;
}
.graph {
overflow: auto;
width: 100%;
height: 100%;
}
.canvas {
display: block;
position: absolute;
text-rendering: geometricPrecision;
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
}
</style>
</head>
<body>
<div id="graph" class="graph">
<svg id="canvas" class="canvas" preserveaspectratio="xMidYMid meet" width="100%" height="100%"></svg>
</div>
<script type="text/javascript" src="deps/d3.min.js"></script>
<script type="text/javascript" src="deps/dagre.min.js"></script>
<script type="text/javascript" src="deps/protobuf.min.js"></script>
<script type="text/javascript" src="deps/prototxt.js"></script>
<script type="text/javascript" src="deps/flatbuffers.js"></script>
<script type="text/javascript" src="deps/marked.min.js"></script>
<script type="text/javascript" src="deps/pako.min.js"></script>
<script type="text/javascript" src="deps/long.js"></script>
<script type="text/javascript" src="base.js"></script>
<script type="text/javascript" src="zip.js"></script>
<script type="text/javascript" src="gzip.js"></script>
<script type="text/javascript" src="tar.js"></script>
<script type="text/javascript" src="view-grapher.js"></script>
<script type="text/javascript" src="view-sidebar.js"></script>
<script type="text/javascript" src="view.js"></script>
<script type="text/javascript" src="index.js"></script>
</body>
</html>
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册