Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Invalid Tensor size in TF.js #183

Open
codingMASTER398 opened this issue Mar 20, 2023 · 0 comments
Open

Invalid Tensor size in TF.js #183

codingMASTER398 opened this issue Mar 20, 2023 · 0 comments

Comments

@codingMASTER398
Copy link

I'm attempting to train this model in Tensorflow.JS, downloading it as such:

// Load the Fashion MNIST dataset
const urll = 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/';
const filenames = {
  images: 'train-images-idx3-ubyte.gz',
  labels: 'train-labels-idx1-ubyte.gz'
};

const loadFile = async (filename) => {
  const url = `${urll}${filename}`;
  const response = await fetch(url);
  const buffer = await response.arrayBuffer();
  return new Uint8Array(buffer);
};

const loadDataset = async () => {
  const [imageData, labelData] = await Promise.all([
    loadFile(filenames.images),
    loadFile(filenames.labels)
  ]);

  const imageTensor = tf.tensor(imageData.slice(16), [60000, 28, 28, 1]);
  console.log(`imageTensor.shape: ${imageTensor.shape}`);
  console.log(`imageData.byteLength: ${imageData.byteLength}`);

  const labelTensor = tf.tensor(labelData.slice(8), [60000], 'int32');
  console.log(`labelTensor.shape: ${labelTensor.shape}`);
  console.log(`labelData.byteLength: ${labelData.byteLength}`);

  return {
    images: imageTensor,
    labels: labelTensor
  };
};

As I assume the training model has 60,000 images, 28x28 in greyscale, [60000, 28, 28, 1] seems appropriate. However, I get the following error:

Error: Based on the provided shape, [60000,28,28,1], the tensor should have 47040000 values but has 26421864

Anything I've done wrong? Apologies if this isn't strictly on-topic, I don't have any other place to ask.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant