Hi,
I’m a beginner and trying to create and train a simple model, but I’ve been stuck for more than 3 days and keep receiving this error message:
“Size(448) must match the product of shape 7 when executing model.fit(…)”
Here is some information that may be helpful:
- Input shape:
inputShape = [7]
- Train dataset input shape:
trainX.shape = [887,7]
- Train dataset output shape:
ytrainData = [887]
Can anyone please help with this issue?
Here is the script:
function get_model() {
const model = tf.sequential();
model.add(
tf.layers.dense({
inputShape: 7,
units: 124,
activation: "relu",
// kernelInitializer: "leCunNormal",
})
);
model.add(tf.layers.dense({ units: 64, activation: "relu" }));
model.add(tf.layers.dense({ units: 32, activation: "relu" }));
model.add(tf.layers.dense({ units: 1, activation: "sigmoid" }));
model.summary();
return model;
}
async function train() {
const model = await get_model();
const data = await load_process_data();
const Xtrain = data[0];
const ytrain = data[1];
model.compile({
optimizer: "adam",
loss: "binaryCrossentropy",
metrics: ["accuracy"],
});
model.fit(Xtrain, ytrain, {
epochs: 20,
callbacks: {
onEpochEnd: async (epoch, logs) => {
console.log(logs.loss);
console.log(`EPOCH (${epoch + 1}): Train Accuracy: ${logs}`);
},
},
});
}