Reputation: 1774
I want to create a feature tensor of multiple images, using tf.browser.fromPixels.
const image1 = new ImageData(1, 1);
image1.data[0] = 100;
image1.data[1] = 150;
image1.data[2] = 200;
image1.data[3] = 255;
const image2 = new ImageData(1, 1);
image2.data[0] = 200;
image2.data[1] = 250;
image2.data[2] = 200;
image2.data[3] = 255;
const imageTensor1 = tf.browser.fromPixels(image1);
const imageTensor2 = tf.broser.fromPixels(image2);
// How do I now get imageTensor1 and imageTensor2 into one merged tensor?
const featureData = ???
How can I now merge two tensors into one tensor, contain information about both images? Are there any operations like tensor.push() or anything available? Do I need to keep the values as a array and only merge it into one tensor in the end?
Upvotes: 1
Views: 990
Reputation: 232
You can concatenate tensors with tf.concat(tensors, axis?)
const a = tf.tensor1d([1, 2]);
const b = tf.tensor1d([3, 4]);
a.concat(b);
Or with multiple tensors
const a = tf.tensor1d([1, 2]);
const b = tf.tensor1d([3, 4]);
const c = tf.tensor1d([5, 6]);
tf.concat([a, b, c]);
Upvotes: 2
Reputation: 1774
Actually I learned that there is no need to do that in the first place, because model.fit() accepts an array of tensors, too. So you can just create an array out of multiple tensors.
https://js.tensorflow.org/api/latest/#tf.LayersModel.fit
Upvotes: 0