Challenge - 5 Problems
TensorFlow.js Browser Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this TensorFlow.js code snippet?
Consider the following code that creates a tensor and performs a simple operation. What will be logged to the console?
TensorFlow
const tf = require('@tensorflow/tfjs'); const a = tf.tensor([1, 2, 3, 4]); const b = a.square(); b.print();
Attempts:
2 left
💡 Hint
Think about what the square() function does to each element of the tensor.
✗ Incorrect
The square() function returns a new tensor where each element is the square of the original tensor's elements. So 1²=1, 2²=4, 3²=9, 4²=16.
❓ Model Choice
intermediateWhich TensorFlow.js model is best suited for image classification in the browser?
You want to classify images directly in the browser using TensorFlow.js. Which pre-trained model is most appropriate?
Attempts:
2 left
💡 Hint
Think about models designed for images versus text or generative tasks.
✗ Incorrect
MobileNet is a lightweight convolutional neural network designed for image classification and works well in browsers.
❓ Hyperparameter
advancedWhich learning rate value is most likely to cause training instability in TensorFlow.js?
You are training a neural network in TensorFlow.js. Which learning rate below is most likely to cause the training loss to diverge?
Attempts:
2 left
💡 Hint
Higher learning rates can cause the model to overshoot minima.
✗ Incorrect
A learning rate of 1.0 is very high and will likely cause the training to diverge or oscillate.
❓ Metrics
advancedWhat does the 'accuracy' metric represent during TensorFlow.js model training?
During training, the model reports an accuracy of 0.85. What does this number mean?
Attempts:
2 left
💡 Hint
Accuracy measures how often the model's predictions are correct.
✗ Incorrect
Accuracy is the fraction of correct predictions over total predictions, so 0.85 means 85% correct.
🔧 Debug
expertWhy does this TensorFlow.js code throw an error?
Examine the code below. Why does it throw an error when run in the browser?
TensorFlow
const model = tf.sequential();
model.add(tf.layers.dense({units: 10, inputShape: [5]}));
model.compile({optimizer: 'adam', loss: 'categoricalCrossentropy'});
const xs = tf.tensor2d([[1, 2, 3, 4, 5]]);
const ys = tf.tensor2d([[0, 1, 0]]);
await model.fit(xs, ys);Attempts:
2 left
💡 Hint
Check the shape of ys compared to the model's output layer units.
✗ Incorrect
The model output layer has 10 units, but ys has shape [1,3], causing a shape mismatch error during training.
