This also would seem something trivial but I've been searching the web and experimenting for a frustrating amount of time.
In onnx runtime web I create a tensor, i.e:
const a = new ort.Tensor('float32', array, [2, 10])
With array being some 20-element float32 array.
I can't seem to find a way to access the data using the standard format a[0] to retrieve an array of size 10. This is quite shocking to me.
The tensor has a dims property with the correct shape and a data property with the 1-dimensional 20 element array.
Within the examples supplied by onnx, I can see them using Array.prototype.slice
to access the data, which seems inconvenient and in my mind, defeats the purpose of having a Tensor object to begin with.
So my question is, what's the recommended way of accessing the data using these Tensor instances?
Here is a sample on how I'm accessing the array data to illustrate the problem.
for (j = 1 ; j < results.logits.dims[1] - 1; j++) {
const s = j* results.logits.dims[2];
const e = s + results.logits.dims[2]
const arr = results.logits.data.slice(s, e)
const probs = softmax(arr)
const label = argmax(probs)
I dislike having to calculate manually the access function for the element at the position [i, j].
Thanks a ton for your help!