## 2 Materials and Methods
### Training and Evaluation  
The training was performed with 16-bit precision floating-point numbers [39] using the Adam-Optimizer [40], and the initial learning rate was determined by using fastai's learning rate finder (Supplement S4). The learning rate was adjusted during the training according to the one-cycle policy [41]. The batch size was twelve for the pituitary adenoma classifier and 35 for the DNET-GG classifier. At first, only the randomly initialized custom head (Figure 6, Supplement S3) was trained for five epochs with a maximum learning rate of \(10^{-3}\) (Supplement S4) in both projects to not interfere with the pretrained weights of the CNN's body. Thereafter the body's layers were unfrozen, and the complete network was trained for ten epochs with differential learning rates between \(10^{-9}\) and \(10^{-6}\) for the pituitary gland adenoma classifier and between \(10^{-8}\) and \(10^{-6}\) for the DNET-GG classifier (Supplement S4) where earlier layers were trained with a lower learning rate than the later ones. The idea behind this is to maintain the basic image-classification patterns of the pretrained model and prevent overfitting. Training performance was controlled using accuracy with a threshold of \(0.5\) as a metric per tile, and the used loss function was binary cross-entropy loss. Model parameters were saved every epoch and the weights of the epoch with the best results were used for evaluation. We further evaluated model performance with five-fold cross-validation, without having any training- and validation-slide and patient overlap. After the training, predictions on the five validation sets were calculated with the corresponding model based on the combined predictions of all tiles of a case. The prediction for a case was calculated using majority voting for the pituitary gland adenoma classifier and the arithmetic mean of the raw predictions (between \(0.0\) and \(1.0\)) of all the case's tiles for the DNET-GG classifier. These results were then combined and used to calculate true and false-positive rates, which were then used to plot Receiver Operating Characteristic curves, true/false positive frequency histograms, and in conjunction with false-negative rates to plot precision-recall curves.  
Since silent corticotroph adenomas only made up \(9.7\%\) of the dataset, we decided to train a second neural net on an undersampled training set. The original training set (\(80\%\) of the complete dataset) consisted of \(226\),\(422\) tiles of which \(59\%\) were positive for LH, \(62\%\) for FSH, \(22\%\) for ACTH, and \(9.4\)\(\%\) were silent corticotroph adenomas. After the undersampling procedure, \(54\),\(713\) tiles were left of which \(43\%\) were positive for LH, \(43\%\) for FSH, \(43\%\) for ACTH, and \(39\)\(\%\) were silent corticotroph adenomas. We assured that at least \(30\) tiles per WSI were left after undersampling. Again, we used the resnext101_32x8 darchitecture. The head was trained for five epochs with a maximum learning rate of \(10^{-3}\). The complete model was then trained for ten epochs with maximum discriminative learning rates ranging from \(10^{-7}\) to \(10^{-5}\). In both cases, the one-cycle learning rate policy was used with minimum learning rates of 1/25 of the maximum learning rates.