Skip to content

Commit

Permalink
Add KaNN test files (#1333) (#1408)
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzroeder committed Dec 13, 2024
1 parent 8066068 commit 4b558f0
Show file tree
Hide file tree
Showing 9 changed files with 457 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ const update = async () => {
'caffe', 'caffe2', 'circle', 'cntk', 'coreml',
'dlc', 'dnn',
'gguf',
'keras',
'kann', 'keras',
'mnn', 'mslite', 'megengine',
'nnabla',
'onnx', 'om',
Expand Down
2 changes: 2 additions & 0 deletions publish/electron-builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
{ "ext": "hd5", "name": "Keras Model" },
{ "ext": "hdf5", "name": "Keras Model" },
{ "ext": "hn", "name": "Hailo Model" },
{ "ext": "kann", "name": "KaNN Model" },
{ "ext": "kgraph", "name": "KaNN Model" },
{ "ext": "keras", "name": "Keras Model" },
{ "ext": "kmodel", "name": "Kendryte Model" },
{ "ext": "lite", "name": "TensorFlow Lite Model" },
Expand Down
2 changes: 1 addition & 1 deletion source/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ base.Metadata = class {
'paddle', 'pdiparams', 'pdmodel', 'pdopt', 'pdparams', 'nb',
'pkl', 'pickle', 'joblib', 'safetensors',
'ptl', 't7',
'dlc', 'uff', 'armnn',
'dlc', 'uff', 'armnn', 'kann', 'kgraph',
'mnn', 'ms', 'ncnn', 'om', 'tm', 'mge', 'tmfile', 'tnnproto', 'xmodel', 'kmodel', 'rknn',
'tar', 'zip'
];
Expand Down
86 changes: 86 additions & 0 deletions source/kann-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[
{
"name": "Transpose",
"category": "Transform"
},
{
"name": "Substraction",
"category": "Transform"
},
{
"name": "LayerNorm",
"category": "Normalization"
},
{
"name": "ConvolutionCV2",
"category": "Layer"
},
{
"name": "ReLU",
"category": "Activation"
},
{
"name": "Resize",
"category": "Shape"
},
{
"name": "ResizeNearestAsymFloor",
"category": "Shape"
},
{
"name": "Exp",
"category": "Activation"
},
{
"name": "Mish",
"category": "Activation"
},
{
"name": "Stddev",
"category": "Normalization"
},
{
"name": "AvgPooling",
"category": "Pool"
},
{
"name": "HardSigmoid",
"category": "Activation"
},
{
"name": "SeLU",
"category": "Activation"
},
{
"name": "LRN",
"category": "Normalization"
},
{
"name": "GeLU",
"category": "Activation"
},
{
"name": "Reshape",
"category": "Shape"
},
{
"name": "Tanh",
"category": "Activation"
},
{
"name": "MaxPooling",
"category": "Pool"
},
{
"name": "DepthwiseConvolution",
"category": "Layer"
},
{
"name": "Softmax",
"category": "Activation"
},
{
"name": "SiLU",
"category": "Activation"
}
]
101 changes: 101 additions & 0 deletions source/kann-schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@

export const kann = {};

kann.Model = class Model {

static identifier(reader) {
return reader.identifier === 'KaNN';
}

static create(reader) {
return kann.Model.decode(reader, reader.root);
}

static decode(reader, position) {
const $ = new kann.Model();
$.graph = reader.tables(position, 4, kann.Graph);
return $;
}
};

kann.Graph = class Graph {

static decode(reader, position) {
const $ = new kann.Graph();
$.arcs = reader.tables(position, 4, kann.Arc);
$.nodes = reader.tables(position, 6, kann.Node);
$.inputs = reader.strings_(position, 8);
$.outputs = reader.strings_(position, 10);
return $;
}
};

kann.Arc = class Arc {

static decode(reader, position) {
const $ = new kann.Arc();
$.name = reader.string_(position, 4, null);
$.type = reader.string_(position, 6, null);
$.attributes = reader.tables(position, 8, kann.Attribute);
return $;
}
};

kann.Node = class Node {

static decode(reader, position) {
const $ = new kann.Node();
$.name = reader.string_(position, 4, null);
$.type = reader.string_(position, 6, null);
$.inputs = reader.strings_(position, 8);
$.outputs = reader.strings_(position, 10);
$.attributes = reader.tables(position, 12, kann.Attribute);
$.tensor = reader.table(position, 14, kann.Param);
$.relu = reader.bool_(position, 16, false);
$.params = reader.tables(position, 18, kann.Param);
return $;
}
};

kann.Param = class Param {

static decode(reader, position) {
const $ = new kann.Param();
$.name = reader.string_(position, 4, null);
$.type = reader.string_(position, 6, null);
$.shape = reader.array(position, 8, Int32Array);
$.value = reader.table(position, 10, kann.Data);
$.scale = reader.table(position, 12, kann.Data);
$.zero_point = reader.table(position, 14, kann.Data);
return $;
}
};

kann.Attribute = class Attribute {

static decode(reader, position) {
const $ = new kann.Attribute();
$.name = reader.string_(position, 4, null);
$.type = reader.string_(position, 6, null);
$.value = reader.table(position, 8, kann.Data);
$.attributes = reader.tables(position, 10, kann.Attribute);
return $;
}
};

kann.Data = class Data {

static decode(reader, position) {
const $ = new kann.Data();
$.type = reader.string_(position, 4, null);
$.value_string = reader.string_(position, 6, null);
$.value_float = reader.float64_(position, 8, 0);
$.value_int = reader.int64_(position, 10, 0n);
$.value_uint = reader.uint64_(position, 12, 0n);
$.list_string = reader.strings_(position, 14);
$.list_float = reader.array(position, 16, Float64Array);
$.list_int = reader.int64s_(position, 18);
$.list_uint = reader.uint64s_(position, 20);
return $;
}
};
Loading

0 comments on commit 4b558f0

Please sign in to comment.