You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PT Lab 1 section 1.3 error in testing the Sequential API code #191
The current version of the code gets a name error. Here's the code:
# Test the model with example input
x_input = torch.tensor([[1, 2.]])
model_output = model(x_input)
print(f"input shape: {x_input.shape}")
print(f"output shape: {y.shape}")
print(f"output result: {y}")
and the resulting error:
NameError Traceback (most recent call last)
[<ipython-input-15-d4b3446276a7>](https://localhost:8080/#) in <cell line: 0>()
3 model_output = model(x_input)
4 print(f"input shape: {x_input.shape}")
----> 5 print(f"output shape: {y.shape}")
6 print(f"output result: {y}")
NameError: name 'y' is not defined
The code should be corrected as follows:
# Test the model with example input
x_input = torch.tensor([[1, 2.]])
y = model(x_input)
print(f"input shape: {x_input.shape}")
print(f"output shape: {y.shape}")
print(f"output result: {y}")
Cause: Two different variable names are used for the output of the model. On the third line model_output is used but in two later lines y is used. The corrected code above uses a consistent variable name of y.
Activity