## 2 Materials and Methods
### Weighted Loss Function  
In cell segmentation, there is a very important spatial class imbalance issue that must be accounted for in any loss calculation. The number of background pixels separating cells is very small, but their correct classification is crucial for accurate segmentation and cell labeling. Without proper weighting of pixel-wise loss, a classifier can attain a very low loss by simply learning to separate colonies from the background. A weighted loss function that emphasizes the accurate prediction of the areas between cells is crucial to train the semantic segmentation of cells from background. Cross-entropy is a very common loss function in machine learning, and it has been adapted to computer vision problems as a pixel-wise calculation. To account for the spatial class imbalance, we use a weighted pixel-wise cross-entropy loss function, first described in [25]. First, we generate a class imbalance weight matrix (\(w_{c}\)) and scale it so that the weight for every cell is \(1\). Next, a weight matrix favouring pixels near multiple cells with higher weights is calculated using the following equation:  
\[w_{p}(x)=w_{0}\cdot\exp\biggl{(}-\frac{(d_{1}(x)+d_{2}(x))^{2}}{2\sigma^{2}} \biggr{)}, \tag{1}\]  
where \(x\) is the location of a pixel point; \(d(x)\) is defined as the distance from pixel \(x\) to the nearest pixel belonging to a cell, \(d_{1}(x)\) and \(d_{2}(x)\) are thus the distances in pixels from the current pixel to the nearest two cells; \(w_{0}\) and \(\sigma\) are manually set parameters (in our training process, they were both set to 10). To create the final weight map, the two weight matrices are added together,  
\[w(x)=w_{c}(x)+w_{p}(x), \tag{2}\]  
to get the final weight map for a training image. The weight map for one of the training images is shown in Figure 4. Each pixel is weighted by its proximity to cells. Therefore, the pixels between cells have a very high weight. Figure 2: A visual description of the modified U-Net architecture applied in this work. Images in the down-sampling stage are orange and images in the up-sampling stage are blue. The pixel-wise class prediction output is yellow. Solid horizontal arrows indicate convolutional operations that do not change the height or width of the inference tensor. Vertical arrows indicate operations that reduce or increase the size of the inference tensor. Skip connections are represented by a dashed black arrow. The resolution of each tensor is shown on the left, and the feature depth at each level is shown on the right. The depth corresponds to the layer depth of each individual tensor in the row, tensors that result from skip connections have twice the depth. The output depth corresponds to the number of classes in the classification problem, in our case the dimensions of the output is \(1024\times 1024\times 2\). Figure 4: (**B**) The weighted loss matrix used to bias the pixel-wise cross-entropy loss and the (**A**) microscopy image for which it was generated. The pixel color in (**B**) indicates the final weight taking into account class imbalance and proximity to cells. The image was obtained using a 60X oil immersion objective. A 5 \(\upmu\)m scale bar is presents to show the scale of yeast cells. Figure 3: Flowchart diagram describing the YeastNet platform from start to finish. Orange parallelograms indicate objects such as images or arrays, green diamonds indicate decision points and blue rectangles indicate processes. The data construction section involves the acquisition of microscopy images, manual labeling of cells to produce ground-truth masks, as well as the calculation of loss weight maps. The training loop runs for 1000 epochs, with a validation step at the end of every epoch. If the intersection over union (IoU) accuracy of the network on the validation dataset is higher than the previous best parameter set, the new parameters are saved. In this sequence, the YeastNet parameters that achieve the highest IoU obtained on the validation dataset after 1000 epochs are the saved parameters.