Yash Singhal
Yash Singhal

Reputation: 397

Uncaught (in promise) Error: Received an array of 30 Tensors, but expected 1 to match the input keys dense_Dense1_input

I recognize this is the issue of the shape mismatch between the Model expecting the input Shape and the Dimensions of my Tensor. However I tried tinkering with the inputShape argument and nothing is helping ,

I m getting the same error " Received an array of 30 Tensors, but expected 1 to match the input keys dense_Dense1_input

const trainingUrl = "/data/wdbc-train.csv";
const trainingData = tf.data.csv(trainingUrl, {
  columnConfigs: {
    diagnosis: {
      isLabel: true,
    },
  },
});
const convertedTrainingData = trainingData.map(({ xs, ys }) => {
  return { xs: Object.values(xs), ys: Object.values(ys) };
});
const numOfFeatures = (await trainingData.columnNames()).length - 1;

const model = tf.sequential();
model.add(
  tf.layers.dense({ inputShape: [numOfFeatures], activation: "relu", units: 5 })
);
model.add(tf.layers.dense({ units: 1, activation: "sigmoid" }));
await model.fitDataset(convertedTrainingData, {
  epochs: 100,
  callbacks: {
    onEpochEnd: async (epoch, logs) => {
      console.log(
        "Epoch: " + epoch + " Loss: " + logs.loss + " Accuracy: " + logs.acc
      );
    },
  },
});

The no of columns is 30

Upvotes: 2

Views: 367

Answers (1)

yudhiesh
yudhiesh

Reputation: 6799

I think that you just forgot to batch the tf.data.csv() object using batch().

const convertedTrainingData = trainingData
  .map(({ xs, ys }) => {
    return { xs: Object.values(xs), ys: Object.values(ys) };
  })
  .batch(10);

Upvotes: 4

Related Questions