1. Inference
-
making prediction with trained PyTorch model (inference);
-
一旦已训练某模型,可用来做预测,在训练/测试循环之外执行此操作的步骤相似;
|
# 1:set model in evaluation mode
model_0.eval()
# 2:setup inference mode context manager
with torch.inference_mode():
# 3:make sure calculation are done with model and data on
# the same device,in our case,we haven't setup device-agnostic
# code yet so our data and model are on the CPU by default.
# model_0.to(device)
# X_test = X_test.to(device)
y_pred = model_0(X_test)
print(y_pred)
plot_prediction(prediction=y_pred)
plt.savefig("PredictionWithTrainedModelInference.svg")
tensor([[0.8141],
[0.8256],
[0.8372],
[0.8488],
[0.8603],
[0.8719],
[0.8835],
[0.8950],
[0.9066],
[0.9182]])