Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load an ONNX model using ONNX Runtime.
Computer Vision
import onnxruntime as ort session = ort.InferenceSession([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the model filename without quotes causes a NameError.
Trying to use onnx.load instead of passing the file path.
✗ Incorrect
The InferenceSession expects the model file path as a string.
2fill in blank
mediumComplete the code to prepare input data for ONNX Runtime inference.
Computer Vision
import numpy as np input_name = session.get_inputs()[0].name input_data = np.random.rand(1, 3, 224, 224).astype([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
float64 causes type mismatch errors.Using integer types when the model expects floats.
✗ Incorrect
ONNX models usually expect input data as 32-bit floats (float32).
3fill in blank
hardFix the error in the code to run inference and get the output.
Computer Vision
outputs = session.run(None, [1]) print(outputs[0])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing inputs as a list or tuple causes runtime errors.
Passing only the input data without the input name.
✗ Incorrect
The run method expects a dictionary mapping input names to input data.
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps input names to numpy arrays.
Computer Vision
inputs = { [1]: np.array(value) for [2], value in input_data.items() } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for the key and the iteration variable.
Not using a colon between key and value.
✗ Incorrect
Dictionary comprehension syntax: {key: value for key, value in dict.items()}.
5fill in blank
hardFill all three blanks to extract output names, run inference, and print the first output.
Computer Vision
output_names = [output.name for output in session.get_outputs()] results = session.run([1], [2]) print(results[3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing inputs as a list instead of a dictionary.
Not specifying output names in the run method.
Trying to print results without indexing.
✗ Incorrect
Use output_names to specify outputs, input dictionary for inputs, and index [0] to print first output.