Skip to content

Commit e1adc5f

Browse files
authored
Use ONNX proto instance (#666)
1 parent 8abf35a commit e1adc5f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+888
-534
lines changed

lib/model/nns/onnx/onnx_importer.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ export default class ONNXImporter {
2323
if (buffer instanceof ArrayBuffer) {
2424
buffer = new Uint8Array(buffer)
2525
}
26-
const modelProto = onnx.ModelProto.deserializeBinary(buffer)
27-
const model = modelProto.toObject()
26+
const model = onnx.ModelProto.deserializeBinary(buffer)
27+
const graph = model.getGraph()
2828

2929
const nodes = []
30-
for (const node of model.graph.inputList) {
30+
for (const node of graph.getInputList()) {
3131
nodes.push(...input.import(model, node))
3232
}
33-
for (const node of model.graph.nodeList) {
34-
const opType = node.opType
33+
for (const node of graph.getNodeList()) {
34+
const opType = node.getOpType()
3535
if (!operators[opType]) {
3636
try {
3737
const module = await import(`./operators/${opType.toLowerCase()}.js`)
@@ -44,7 +44,7 @@ export default class ONNXImporter {
4444
const op = operators[opType]
4545
nodes.push(...op.import(model, node))
4646
}
47-
for (const node of model.graph.outputList) {
47+
for (const node of graph.getOutputList()) {
4848
nodes.push(...output.import(model, node))
4949
}
5050
return nodes

lib/model/nns/onnx/operators/abs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export default {
1010
/**
1111
* Import from onnx object.
1212
*
13-
* @param {onnx.ModelProto.AsObject} model Model object
14-
* @param {onnx.NodeProto.AsObject} node Node object
13+
* @param {onnx.ModelProto} model Model object
14+
* @param {onnx.NodeProto} node Node object
1515
* @returns {object[]} Objects represented a layer
1616
*/
1717
import(model, node) {
18-
return [{ type: 'abs', input: [node.inputList[0]], name: node.outputList[0] }]
18+
return [{ type: 'abs', input: [node.getInputList()[0]], name: node.getOutputList()[0] }]
1919
},
2020
}

lib/model/nns/onnx/operators/acos.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export default {
1010
/**
1111
* Import from onnx object.
1212
*
13-
* @param {onnx.ModelProto.AsObject} model Model object
14-
* @param {onnx.NodeProto.AsObject} node Node object
13+
* @param {onnx.ModelProto} model Model object
14+
* @param {onnx.NodeProto} node Node object
1515
* @returns {object[]} Objects represented a layer
1616
*/
1717
import(model, node) {
18-
return [{ type: 'acos', input: [node.inputList[0]], name: node.outputList[0] }]
18+
return [{ type: 'acos', input: [node.getInputList()[0]], name: node.getOutputList()[0] }]
1919
},
2020
}

lib/model/nns/onnx/operators/acosh.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export default {
1010
/**
1111
* Import from onnx object.
1212
*
13-
* @param {onnx.ModelProto.AsObject} model Model object
14-
* @param {onnx.NodeProto.AsObject} node Node object
13+
* @param {onnx.ModelProto} model Model object
14+
* @param {onnx.NodeProto} node Node object
1515
* @returns {object[]} Objects represented a layer
1616
*/
1717
import(model, node) {
18-
return [{ type: 'acosh', input: [node.inputList[0]], name: node.outputList[0] }]
18+
return [{ type: 'acosh', input: [node.getInputList()[0]], name: node.getOutputList()[0] }]
1919
},
2020
}

lib/model/nns/onnx/operators/add.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ export default {
1111
/**
1212
* Import from onnx object.
1313
*
14-
* @param {onnx.ModelProto.AsObject} model Model object
15-
* @param {onnx.NodeProto.AsObject} node Node object
14+
* @param {onnx.ModelProto} model Model object
15+
* @param {onnx.NodeProto} node Node object
1616
* @returns {object[]} Objects represented a layer
1717
*/
1818
import(model, node) {
1919
return [
20-
...requireTensor(model, node.inputList),
21-
{ type: 'add', input: node.inputList, name: node.outputList[0] },
20+
...requireTensor(model, node.getInputList()),
21+
{ type: 'add', input: node.getInputList(), name: node.getOutputList()[0] },
2222
]
2323
},
2424
}

lib/model/nns/onnx/operators/and.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export default {
1010
/**
1111
* Import from onnx object.
1212
*
13-
* @param {onnx.ModelProto.AsObject} model Model object
14-
* @param {onnx.NodeProto.AsObject} node Node object
13+
* @param {onnx.ModelProto} model Model object
14+
* @param {onnx.NodeProto} node Node object
1515
* @returns {object[]} Objects represented a layer
1616
*/
1717
import(model, node) {
18-
return [{ type: 'and', input: node.inputList, name: node.outputList[0] }]
18+
return [{ type: 'and', input: node.getInputList(), name: node.getOutputList()[0] }]
1919
},
2020
}

lib/model/nns/onnx/operators/argmax.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ export default {
1111
/**
1212
* Import from onnx object.
1313
*
14-
* @param {onnx.ModelProto.AsObject} model Model object
15-
* @param {onnx.NodeProto.AsObject} node Node object
14+
* @param {onnx.ModelProto} model Model object
15+
* @param {onnx.NodeProto} node Node object
1616
* @returns {object[]} Objects represented a layer
1717
*/
1818
import(model, node) {
1919
const attrs = { axis: 0, keepdims: 1, select_last_index: 0 }
20-
for (const attribute of node.attributeList) {
21-
attrs[attribute.name] = loadAttribute(attribute)
20+
for (const attribute of node.getAttributeList()) {
21+
attrs[attribute.getName()] = loadAttribute(attribute)
2222
}
2323
if (attrs.select_last_index) {
2424
throw new Error(`Invalid attribute 'select_last_index' value ${attrs.select_last_index}.`)
2525
}
2626
return [
2727
{
2828
type: 'argmax',
29-
input: [node.inputList[0]],
30-
name: node.outputList[0],
29+
input: [node.getInputList()[0]],
30+
name: node.getOutputList()[0],
3131
axis: attrs.axis,
3232
keepdims: !!attrs.keepdims,
3333
},

lib/model/nns/onnx/operators/argmin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ export default {
1111
/**
1212
* Import from onnx object.
1313
*
14-
* @param {onnx.ModelProto.AsObject} model Model object
15-
* @param {onnx.NodeProto.AsObject} node Node object
14+
* @param {onnx.ModelProto} model Model object
15+
* @param {onnx.NodeProto} node Node object
1616
* @returns {object[]} Objects represented a layer
1717
*/
1818
import(model, node) {
1919
const attrs = { axis: 0, keepdims: 1, select_last_index: 0 }
20-
for (const attribute of node.attributeList) {
21-
attrs[attribute.name] = loadAttribute(attribute)
20+
for (const attribute of node.getAttributeList()) {
21+
attrs[attribute.getName()] = loadAttribute(attribute)
2222
}
2323
if (attrs.select_last_index) {
2424
throw new Error(`Invalid attribute 'select_last_index' value ${attrs.select_last_index}.`)
2525
}
2626
return [
2727
{
2828
type: 'argmin',
29-
input: [node.inputList[0]],
30-
name: node.outputList[0],
29+
input: [node.getInputList()[0]],
30+
name: node.getOutputList()[0],
3131
axis: attrs.axis,
3232
keepdims: !!attrs.keepdims,
3333
},

lib/model/nns/onnx/operators/asin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export default {
1010
/**
1111
* Import from onnx object.
1212
*
13-
* @param {onnx.ModelProto.AsObject} model Model object
14-
* @param {onnx.NodeProto.AsObject} node Node object
13+
* @param {onnx.ModelProto} model Model object
14+
* @param {onnx.NodeProto} node Node object
1515
* @returns {object[]} Objects represented a layer
1616
*/
1717
import(model, node) {
18-
return [{ type: 'asin', input: [node.inputList[0]], name: node.outputList[0] }]
18+
return [{ type: 'asin', input: [node.getInputList()[0]], name: node.getOutputList()[0] }]
1919
},
2020
}

lib/model/nns/onnx/operators/asinh.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export default {
1010
/**
1111
* Import from onnx object.
1212
*
13-
* @param {onnx.ModelProto.AsObject} model Model object
14-
* @param {onnx.NodeProto.AsObject} node Node object
13+
* @param {onnx.ModelProto} model Model object
14+
* @param {onnx.NodeProto} node Node object
1515
* @returns {object[]} Objects represented a layer
1616
*/
1717
import(model, node) {
18-
return [{ type: 'asinh', input: [node.inputList[0]], name: node.outputList[0] }]
18+
return [{ type: 'asinh', input: [node.getInputList()[0]], name: node.getOutputList()[0] }]
1919
},
2020
}

0 commit comments

Comments
 (0)