# Deep Instance Segmentation of Laboratory Animals in Thermal Images
## 2 Methods
### Learning Configurations  
We made two training and one testing manually segmented datasets. The only difference between training sets was their size: 200 and 500 images respectively. The smaller set was used for the transfer-learning training, where we used pre-trained network: Mask R-CNN with a ResNet-Feature Pyramid Network (FPN) backbone 50 layers deep trained on the COCO dataset [36], and similarly TensorMask with a ResNet-FPN backbone 50 layers deep [37], both implementations from Detectron2 v0.1.2.  
The 500 images were used for training the whole architectures from random initialization. In this training the number of training iterations had to be increased so models could converge. However, even despite the very large number of iterations, the TensorMask architecture sometimes had convergence problems: the loss function increased over time. In such cases we have used normalization techniques according to [38], and replaced Frozen Batch Normalization with Group Normalization [39]. Group Normalization's accuracy was insensitive to batch sizes [39] and allowed for successful TensorMask model training from scratch.  
The testing set consisted of 50 images not included in the training sets. Images in all data-sets depicted two rodents during physical contact of varying degrees: from a small part of the body contact (e.g., nose-to-nose) to the body overlapping and covering.  
For every training model we performed three independent training sessions. Json files with ground-truth rat regions were manually created for every training and testing set using the VGG Image Annotator (VIA) [40]. The regions were marked on a zoomed image by a set of points forming a closed polygon.  
To compare the trained and commonly available models, we tested the inference using weights pre-trained on MS COCO Dataset [20], Citicscapes [41] and LVIS [42] and not trained on our database. We have also used two different Python3 implementations of Mask R-CNN (Mask R-CNN2.1 [36], Detectron2 v0.1.2 [37]) and one for TensorMask Detectron2 v0.1.2 [37].  
In total, we tested 24 different model configurations for pre-trained learning and 22 for training from scratch.  
For both models and both training methods with the best segmentation results 3-fold cross-validation was performed. The first fold was made for all the model configurations. The second  
Figure 2: Range selection: (**a**) histogram of one frame raw thermal data with values of: minimal rodent’s surface thermal value named \(maxOtsu_{thires}\), marked with red solid line; the minimum values for images _ch2_ and _ch3_ marked as green (\(T_{2}\)) and blue (\(T_{3}\)) lines respectively, (**b**) orig image of the whole thermal range, (**c**) ch1 image of the first range: \(maxOtsu_{thres}\) to \(T_{max}\), (**d**) ch2 image of the second range: \(T_{2}\) to \(T_{max}\), (**e**) ch3 image of the third range: \(T_{3}\) to \(T_{max}\).  
and third folds used the whole testing data-set from the first fold in their training sets and replaced the training set with 50 different images selected from the training set of the first fold.  
All experiments were performed using NVIDIA DGX-1 Station with Ubuntu 18.