|
| 1 | +import { onnx } from '../onnx_exporter.js' |
| 2 | +import { getConstNodeName } from '../utils.js' |
| 3 | + |
| 4 | +/** |
| 5 | + * Handle aranda layer |
| 6 | + */ |
| 7 | +export default { |
| 8 | + /** |
| 9 | + * Export to onnx object. |
| 10 | + * @param {onnx.ModelProto} model Model object |
| 11 | + * @param {import("../../graph").LayerObject & {type: 'aranda'}} obj Node object |
| 12 | + */ |
| 13 | + export(model, obj) { |
| 14 | + const input = Array.isArray(obj.input) ? obj.input[0] : obj.input |
| 15 | + const node_exp = new onnx.NodeProto() |
| 16 | + node_exp.setOpType('Exp') |
| 17 | + node_exp.addInput(input) |
| 18 | + node_exp.addOutput(obj.name + '_exp') |
| 19 | + |
| 20 | + const tensor_l = new onnx.TensorProto() |
| 21 | + tensor_l.setName(obj.name + '_l') |
| 22 | + tensor_l.setDataType(onnx.TensorProto.DataType.FLOAT) |
| 23 | + tensor_l.setDimsList([1]) |
| 24 | + tensor_l.setFloatDataList([obj.l ?? 2]) |
| 25 | + |
| 26 | + const tensor1 = getConstNodeName(model, 1) |
| 27 | + |
| 28 | + const node_mult = new onnx.NodeProto() |
| 29 | + node_mult.setOpType('Mul') |
| 30 | + node_mult.addInput(obj.name + '_exp') |
| 31 | + node_mult.addInput(obj.name + '_l') |
| 32 | + node_mult.addOutput(obj.name + '_mult') |
| 33 | + |
| 34 | + const node_add = new onnx.NodeProto() |
| 35 | + node_add.setOpType('Add') |
| 36 | + node_add.addInput(obj.name + '_mult') |
| 37 | + node_add.addInput(tensor1) |
| 38 | + node_add.addOutput(obj.name + '_add') |
| 39 | + |
| 40 | + const node_reciprocal = new onnx.NodeProto() |
| 41 | + node_reciprocal.setOpType('Reciprocal') |
| 42 | + node_reciprocal.addInput(obj.name + '_add') |
| 43 | + node_reciprocal.addOutput(obj.name + '_reciprocal') |
| 44 | + |
| 45 | + const node_reciprocal_pow = new onnx.NodeProto() |
| 46 | + node_reciprocal_pow.setOpType('Reciprocal') |
| 47 | + node_reciprocal_pow.addInput(obj.name + '_l') |
| 48 | + node_reciprocal_pow.addOutput(obj.name + '_reciprocal_pow') |
| 49 | + |
| 50 | + const node_pow = new onnx.NodeProto() |
| 51 | + node_pow.setOpType('Pow') |
| 52 | + node_pow.addInput(obj.name + '_reciprocal') |
| 53 | + node_pow.addInput(obj.name + '_reciprocal_pow') |
| 54 | + node_pow.addOutput(obj.name + '_pow') |
| 55 | + |
| 56 | + const node_sub = new onnx.NodeProto() |
| 57 | + node_sub.setOpType('Sub') |
| 58 | + node_sub.addInput(tensor1) |
| 59 | + node_sub.addInput(obj.name + '_pow') |
| 60 | + node_sub.addOutput(obj.name) |
| 61 | + |
| 62 | + const graph = model.getGraph() |
| 63 | + graph.addInitializer(tensor_l) |
| 64 | + graph.addNode(node_exp) |
| 65 | + graph.addNode(node_mult) |
| 66 | + graph.addNode(node_add) |
| 67 | + graph.addNode(node_reciprocal) |
| 68 | + graph.addNode(node_reciprocal_pow) |
| 69 | + graph.addNode(node_pow) |
| 70 | + graph.addNode(node_sub) |
| 71 | + }, |
| 72 | +} |
0 commit comments