## 2 Materials and Methods
### Overall Workflow  
In summary, a potential clinical workflow for implementing the developed algorithm can be as follows:  
1. MR simulation to acquire dynamic images of a patient;
2. Manual contouring of the tumor by experts in each dynamic image;
3. Patient-specific HPO and training of the algorithm;
4. Autocontouring during the actual treatment session.  
In step 1, an MR simulation takes place to acquire 130 dynamic images for a patient ~2 weeks prior to the actual treatment session (no motion management nor breathing guidance). In step 2, experts delineate the tumor in each dynamic image. The original 256 \(\times\) 256 patient images are then cropped into small patches (~60 \(\times\) 60) centered on the tumor to reduce the interference of background anatomy adjacent to the tumor and the number of computations. To create image patches for each patient dataset (example shown in Figure 3), prior to algorithm training, a single tumor contour (tumor ROI) that is the least impacted by motion artifacts during respiration is selected (often at the end of the exhale phase) from the 30 training images (Figure 3a,b). Also, a background region that represents the maximum anticipated range of tumor motion is delineated, by observing the tumor motion in the 30 training images (Figure 3c). Subsequently, the position of maximum cross correlation (P\({}_{\text{max}}\)) is found using the normalized cross correlation operation between the tumor ROI and the background region in each image (Figure 3d-f). The tumor ROI centered at P\({}_{\text{max}}\) is then dilated either 12 or 16 times (empirically chosen) to obtain image patches covering the possible variations in tumor size from deformation (Figure 3g-i). As a result, 130 image patches were generated.  
Figure 3: Process of creating image patches. (**a**) Example original image of P3 with red box showing tumor location, (**b**) tumor ROI manually contoured on (**a**) (enlarged for better visibility), (**c**) background region manually contoured on normalized image obtained by adding intensities of 30 training images (enlarged for better visibility), (**d**) image patch of tumor ROI, (**e**) image patch of background region, (**f**) cross correlation result between (**d**) and (**e**) with maximum at P\({}_{\text{max}}\), (**g**) placement of tumor ROI image patch centered at P\({}_{\text{max}}\), (**h**) 12-time dilation of (**g**) for unexpected large tumor motion, and (**i**) mask of manual contour corresponding to (**h**).  
In step 3, 60 consecutive image patches (30 for training, 30 for validation) and their corresponding manual contours are input into the CMA-ES optimization algorithm to search for the optimal set of hyperparameters. The U-Net, constructed and trained using the optimized hyperparameters, is evaluated by autocontouring the tumor in the remaining 70 testing images that were never seen by the algorithm. In step 4, the algorithm is used to autocontour the tumor in the actual treatment session. The algorithm consisting of HPO and autocontouring was coded in Pytorch version 1.6.0 on a 64-bit computer system (Ubuntu 18.04, Intel Core i9-7920X, 128 GB RAM) using the Python package, cma 2.7.0. The code will be available upon request for academic purposes. For faster execution of both HPO and the training of the algorithm, three graphics processing units (GPUs; NVIDIA GeForce RTX 2080 Ti) were utilized in parallel, while a single GPU was used for the final autocontouring.