0
0
PyTorchml~10 mins

Mobile deployment (PyTorch Mobile) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load a PyTorch model for mobile deployment.

PyTorch
import torch

model = torch.jit.load([1])
model.eval()
Drag options to blanks, or click blank then click option'
A"model.pt"
Bmodel.pt
Ctorch_model.pt
D'model.pth'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the file path string.
Using the wrong file extension like '.pth' instead of '.pt'.
2fill in blank
medium

Complete the code to convert a PyTorch model to TorchScript for mobile deployment.

PyTorch
import torch

scripted_model = torch.jit.[1](model)
scripted_model.save("model.pt")
Drag options to blanks, or click blank then click option'
Atrace
Bload
Cscript
Dsave
Attempts:
3 left
💡 Hint
Common Mistakes
Using torch.jit.trace instead of torch.jit.script for models with control flow.
Confusing save and load methods.
3fill in blank
hard

Fix the error in the code to run inference on a mobile model.

PyTorch
input_tensor = torch.randn(1, 3, 224, 224)
output = model.[1](input_tensor)
print(output)
Drag options to blanks, or click blank then click option'
Acall
Bforward
Crun
Dpredict
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like predict or run.
Trying to call the model object directly without parentheses.
4fill in blank
hard

Fill both blanks to prepare input and run inference on a mobile model.

PyTorch
input_data = torch.randn([1])
output = model.[2](input_data)
print(output)
Drag options to blanks, or click blank then click option'
A1, 3, 224, 224
Bforward
Cpredict
D3, 224, 224
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong input shape missing batch dimension.
Using incorrect method names for inference.
5fill in blank
hard

Fill all three blanks to save a scripted model and load it for mobile deployment.

PyTorch
scripted_model = torch.jit.[1](model)
scripted_model.[2]("model.pt")
loaded_model = torch.jit.[3]("model.pt")
Drag options to blanks, or click blank then click option'
Ascript
Bsave
Cload
Dtrace
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up save and load methods.
Using trace instead of script for models with control flow.