forked from microsoft/onnxruntime-inference-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtensor-properties.js
More file actions
37 lines (27 loc) · 784 Bytes
/
tensor-properties.js
File metadata and controls
37 lines (27 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const ort = require('onnxruntime-node');
// following code also works for onnxruntime-web.
const Tensor = ort.Tensor;
const myTensors = getMyTensors();
//
// get dimensions and size from tensor
//
const dims_0 = myTensors[0].dims; // [2, 3, 4]
const size_0 = myTensors[0].size; // 24
//
// get type from tensor
//
const type_1 = myTensors[1].type; // 'bool'
//
// get data (typed array) from tensor
//
const data_2 = myTensors[2].data; // Int32Array(6)
function getMyTensors() {
const buffer01 = new Float32Array(24).fill(1);
return [
new Tensor('float32', buffer01, [2, 3, 4]),
new Tensor('bool', [true], []),
new Tensor('int32', [1, 2, 3, 4, 5, 6], [2, 3])
];
}