This is a PyTorch Model Trainer Function. It trains and validates image datasets.
It also saves the model after training to avoid retraining.