Reputation: 397
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
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