Training and evaluation

Training adjusts model parameters using examples and a loss function. Validation informs choices such as hyperparameters and stopping time. The test set evaluates the final procedure after those choices are fixed.

A reliable sequence

  1. Define the prediction target and the unit of independence.
  2. Split the data before fitting preprocessing or selecting a model.
  3. Fit using training data and choose settings using validation data.
  4. Evaluate the frozen procedure on the held-out test data.

For repeated observations of plants, an image-level random split can place the same plant in both training and test sets. A plant-level split is more appropriate when the goal is performance on unseen plants.

Evaluation mode

model.eval()
with torch.inference_mode():
    predictions = model(test_inputs)

Evaluation mode changes the behavior of layers such as dropout and batch normalization. Disabling gradient recording reduces the work required during inference. These operations serve different purposes.

Try it

Write down the grouping variable for your own dataset. Check whether any group appears in more than one partition.