# Federating Medical Deep Learning Models from Private Jupyter Notebooks to Distributed Institutions
## 4 Case Study: Histological Image Analysis
### Federated Implementation  
To integrate an FL pipeline in the computational pathology use case, we apply the Notebook Federator solution illustrated in Figure 1. More precisely, to carry out this implementation on this first use case scenario in realistic conditions, the model was first trained locally on private data at a single collaborating institution before being adapted and deployed for the federation by means of the Notebook Federator.  
As one of the requirements of the proposed system is for it to be reproducible and easily implementable for future collaborations, we aim to give a detailed explanation of the steps undertaken to perform that federated implementation, starting from a centralized setup; in other words, the inner workings of the proposed solution. These specific steps are highlighted in Figure 3.  
\begin{table}
\begin{tabular}{c c c c} \hline \hline  & \(I_{A}\) & \(I_{B}\) & \(I_{C}\) \\ \hline \# WSIs & 10 & 6 & 8 \\ \# tumorous patches & 1554 & 2627 & 1005 \\ \# non-tumorous patches & 5609 & 4694 & 3979 \\ \hline \hline \end{tabular}
\end{table}
Table 1: Details of the histological image data used in this use case. Note that non-tumorous patches were then randomly undersampled to balance the dataset before training each model.  
Figure 2: Examples of the type of histological patches used in this case study: (**a**) tumorous patches extracted from the annotated region made by dermatopathologists; (**b**) non-tumorous patches.  
First, we fill the Jupyter template provided on NaaVRE (Figure 3(1)) and define a standardized and automated data preparation protocol adapted to the specific type of data under study (Figure 3(2)). As WSI patch extraction was computed beforehand in this use case, the data loading function in the Jupyter template covers loading the patches along with their corresponding label, as well as performing an undersampling of the majority class for each set, as the dataset is clearly unbalanced (see Table 1). Then, we define a VGG16-based [24] model architecture to perform patch-level binary classification with the PyTorch 1.12 library under Python 3.6 and train it locally with the available local data at first to optimize its parameters (Figure 3(3)). To define the aggregation function to update the global model's weights when mounting the federation, we leverage the federated averaging algorithm FedAvg [25] integrated into FLOWER's strategies [18] (Figure 3(4)).  
Regarding the steps involving the federation, the filled template to share with distributed users is then containerized by means of NaaVRE's component containerizer, thus allowing their further use by clients by running the corresponding images. This specific step is illustrated in Figure 4, which shows how to efficiently containerize reusable model and aggregator components with the Notebook Federator approach. The containers can thus be downloaded and set up at each of the collaborating institutions (Figure 3(5)), and model training can start (Figure 3(6),(7)). The resulting federation (Figure 3(8)) gathers the steps defined previously and communicates across nodes by means of bidirectional gRPC streams.  
Figure 3: Step-by-step implementation of the federated pipeline, the starting point being a local institution with their corresponding local data, and the result being the federation.