tfjs@latest:2 Uncaught (in promise) Error: Argument 'b' passed to 'mul' must be a Tensor or TensorLike, but got 'null'
sayakpaul opened this issue · 0 comments
sayakpaul commented
I am currently taking the Browser-based Models with TensorFlow.js course. I am only stuck in the Week 1 exercise.
Here's the code:
<html>
<head></head>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>
<script lang="js">
async function run(){
const trainingUrl = 'wdbc-train.csv';
const trainingData = tf.data.csv(trainingUrl, {
columnConfigs: {
diagnosis: {
isLabel: true
}
}
});
const convertedTrainingData =
trainingData.map(({xs, ys}) => {
// console.log(trainingData);
return{ xs: Object.values(xs), ys: Object.values(ys)};
}).batch(10);
// const testingUrl = 'wdbc-test.csv';
// const testingData = tf.data.csv(testingUrl, {
// columnConfigs: {
// diagnosis: {
// isLabel: true
// }
// }
// });
// const convertedTestingData =
// testingData.map(({xs, ys}) => {
// return{ xs: Object.values(xs), ys: Object.values(ys)};
// }).batch(10);
const numOfFeatures = 30;
// console.log(numOfFeatures);
const model = tf.sequential();
model.add(tf.layers.dense({inputShape: [numOfFeatures], activation: "relu", units: 20}))
model.add(tf.layers.dense({activation: "relu", units: 20}))
model.add(tf.layers.dense({activation: "relu", units: 10}))
model.add(tf.layers.dense({activation: "relu", units: 5}))
model.add(tf.layers.dense({activation: "sigmoid", units: 1}));
model.compile({loss: "binaryCrossentropy", optimizer: tf.train.rmsprop(), metrics: ["accuracy"]});
model.summary();
//console.log(convertedTrainingData);
await model.fitDataset(convertedTrainingData,
{epochs:100,
callbacks:{
onEpochEnd: async(epoch, logs) =>{
console.log("Epoch: " + epoch + " Loss: " + logs.loss);
}
}});
// await model.fitDataset(convertedTrainingData,
// {epochs:100,
// validationData: convertedTestingData,
// callbacks:{
// onEpochEnd: async(epoch, logs) =>{
// console.log("Epoch: " + epoch + " Loss: " + logs.loss + " Accuracy: " + logs.acc);
// }
// }});
// await model.save('downloads://my_model');
}
run();
</script>
<body>
</body>
</html>
And here's the console log:
tfjs@latest:2 _________________________________________________________________
tfjs@latest:2 Layer (type) Output shape Param #
tfjs@latest:2 =================================================================
tfjs@latest:2 dense_Dense1 (Dense) [null,20] 620
tfjs@latest:2 _________________________________________________________________
tfjs@latest:2 dense_Dense2 (Dense) [null,20] 420
tfjs@latest:2 _________________________________________________________________
tfjs@latest:2 dense_Dense3 (Dense) [null,10] 210
tfjs@latest:2 _________________________________________________________________
tfjs@latest:2 dense_Dense4 (Dense) [null,5] 55
tfjs@latest:2 _________________________________________________________________
tfjs@latest:2 dense_Dense5 (Dense) [null,1] 6
tfjs@latest:2 =================================================================
tfjs@latest:2 Total params: 1311
tfjs@latest:2 Trainable params: 1311
tfjs@latest:2 Non-trainable params: 0
tfjs@latest:2 _________________________________________________________________
tfjs@latest:2 Uncaught (in promise) Error: Argument 'b' passed to 'mul' must be a Tensor or TensorLike, but got 'null'
at Ke (tfjs@latest:2)
at mul_ (tfjs@latest:2)
at Object.mul (tfjs@latest:2)
at t.mul (tfjs@latest:2)
at tfjs@latest:2
at tfjs@latest:2
at t.scopedRun (tfjs@latest:2)
at t.tidy (tfjs@latest:2)
at We (tfjs@latest:2)
at tfjs@latest:2
Ke @ tfjs@latest:2
mul_ @ tfjs@latest:2
mul @ tfjs@latest:2
t.mul @ tfjs@latest:2
(anonymous) @ tfjs@latest:2
(anonymous) @ tfjs@latest:2
t.scopedRun @ tfjs@latest:2
t.tidy @ tfjs@latest:2
We @ tfjs@latest:2
(anonymous) @ tfjs@latest:2
e.applyGradients @ tfjs@latest:2
e.minimize @ tfjs@latest:2
(anonymous) @ tfjs@latest:2
(anonymous) @ tfjs@latest:2
(anonymous) @ tfjs@latest:2
(anonymous) @ tfjs@latest:2
o @ tfjs@latest:2
async function (async)
run @ wdbc_exercise.html:53
(anonymous) @ wdbc_exercise.html:73
I am absolutely running out of options here to debug this. Help would be appreciated. Thanks!