tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.25k stars 1.92k forks source link

tf.data.array() cannot consume a Tensor, despite the documentation claiming so #8300

Open AdmiralSnyder opened 2 weeks ago

AdmiralSnyder commented 2 weeks ago

System information

Describe the current behavior i am trying to create a dataset from a tensor, but that failed, see code:

Describe the expected behavior the dataset should be create-able

Standalone code to reproduce the issue

let myTensor = tf.randomUniform([100], -2, 2); // returns a tensor as docs claim
// myTensor.print(); // prints the random data in this tensor
let myDataset = tf.data.array(myTensor); // returns something null-y - definitely not a dataset made from this tensor, 
console.log(myDataset); // outputs this: r {size: null}
gaikwadrahul8 commented 2 weeks ago

Hi, @AdmiralSnyder

I apologize for the delayed response and I was trying to replicate the same behavior from my end with your code snippet and I'm getting same result for reference I have added screenshot below:

image

When I'm trying something like below it seems like working fine, if I've missed something here please let me know. Thank you for your cooperation and patience.

image

github-actions[bot] commented 6 days ago

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

AdmiralSnyder commented 6 days ago

Hey, the documentation clearly states that data.array should be able to consume a Tensor, rather than a Tensor[]:

image Quote: Parameters: items (tf.void|number|string|TypedArray|tf.Tensor|tf.Tensor[]|{[key: string]:tf.Tensor|number|string}[]) An array of elements that will be parsed as items in a dataset.

which I read as: data.array consumes these types of things:

-> and since the simple case where you enter the single tensor into the data.array function clearly doesn't work, this is either a bug in the implementation or in the documentation -> the workaround of putting the tensor between square brackets is not acceptable.