Skip to content

Invalid Tensor size in TF.js #183

Description

@codingMASTER398

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions