0
0
TensorFlowml~20 mins

Type casting in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Type Casting Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
TensorFlow Type Casting Output
What is the output of this TensorFlow code snippet?
TensorFlow
import tensorflow as tf
x = tf.constant([1.7, 2.3, 3.9])
y = tf.cast(x, tf.int32)
print(y.numpy())
A[1 3 4]
B[2 3 4]
C[1 2 3]
D[2 2 3]
Attempts:
2 left
💡 Hint
Casting from float to int truncates the decimal part.
Model Choice
intermediate
2:00remaining
Choosing Correct TensorFlow Data Type for Image Pixels
You have image pixel values ranging from 0 to 255. Which TensorFlow data type is best to store these pixels efficiently without losing information?
Atf.uint8
Btf.float32
Ctf.int32
Dtf.bool
Attempts:
2 left
💡 Hint
Pixels are whole numbers between 0 and 255.
🔧 Debug
advanced
2:00remaining
Debugging TensorFlow Type Casting Error
What error will this TensorFlow code raise?
TensorFlow
import tensorflow as tf
x = tf.constant(['1', '2', '3'])
y = tf.cast(x, tf.int32)
AAttributeError: 'Tensor' object has no attribute 'astype'
BTypeError: Cannot cast string to int32
CNo error, output: [1 2 3]
DValueError: invalid literal for int() with base 10
Attempts:
2 left
💡 Hint
Casting strings directly to integers is not supported in TensorFlow.
Metrics
advanced
2:00remaining
Effect of Type Casting on Model Accuracy
You cast your model's output tensor from float64 to float32 before calculating accuracy. What is the most likely effect?
AModel training stops with a type mismatch error
BAccuracy improves significantly due to faster computation
CAccuracy drops to zero due to data corruption
DAccuracy remains almost the same with minor precision loss
Attempts:
2 left
💡 Hint
Float32 has less precision than float64 but is usually enough for accuracy calculations.
🧠 Conceptual
expert
2:00remaining
Why Use tf.cast in TensorFlow Pipelines?
Which is the best reason to use tf.cast in a TensorFlow data pipeline?
ATo convert data types for compatibility with model input requirements
BTo automatically normalize data values between 0 and 1
CTo increase the size of tensors for better model performance
DTo change tensor shapes dynamically during training
Attempts:
2 left
💡 Hint
Models expect inputs in specific data types.