# Domain Adaptation for Satellite-Borne Multispectral Cloud Detection
## 6 Adapting the Cloud Detector to the Target Domain
### TTA on Satellite Hardware  
To solve Problem 2 in Section 3.3.2, we built and ran an ONNX Runtime (ORT) [81] on a standard Linux desktop connected to a Ubotica CogniSAT-XE1 (\"XE1\" for short) [13] via USB (see Figure 5a):  
* The XE1 is a low-power edge processing device designed for SmallSat and CubeSat missions. It features the Intel Myriad 2 VPU and its main purpose is to accelerate machine learning inference.
* ORT was selected since it only requires \(\approx\) 18.1 MB (version 1.15) of disk space and supports a wide range of operating systems and programming languages.  
Prior to deploying \(f^{d}(\cdot\ ;\theta^{s})\) onto the satellite in the pre-deployment model training phase (see Figure 2), the model was converted to the ONNX format, which was then used to generate training artefacts (i.e., training, evaluation and optimiser ONNX models, as well as checkpoint states). As Figure 6 shows, these training artefacts were then deployed onto the satellite for executing the TTA algorithms on CPU. For emulating the CPU aboard the HyperScout-2 hyperspectral imager, an Advantech ARK-1123L [82] embedded computer was used. Post-deployment model testing was performed on (i) the XE1 connected to the Linux desktop (Figure 5a) and (ii) the XE1 connected to the ARK-1123L (Figure 5b).  
Figure 5: Hardware platforms used in this study. (**a**) Cloud detectors are trained on a Linux desktop before they are deployed onto the Ubotica CogniSAT-XE1. (**b**) Post-deployment, the Advantech ARK-1123L and Ubotica CogniSAT-XE1 perform TTA and cloud detection, respectively.  
Figure 6: Training artefacts and target data are used in online adaptation, which is executed on the CPU of an embedded computer aboard the satellite (in orbit). Inference is then executed on a VPU-based device.  
One well-known TTA approach [69; 71; 83; 84] is to update the BN layers of a deep network, which, in our case, is the source cloud detector \(f(\cdot\,;\theta^{s})\), in an unsupervised manner, using, in our case, the unlabelled target dataset \(\tilde{\mathcal{D}}^{t}\). The role of BN is to normalise the intermediate outputs of each layer to zero mean and unit variance. However, this normalisation effect breaks when the source and target distributions significantly differ. As described in Algorithm 2, TTA is executed by the \(\texttt{ADAPT}(\cdot)\) function but only when a batch of target samples \(\mathcal{B}\) is collected and reaches a certain (predefined) size \(n_{B}\). This function is implemented using dynamic unsupervised adaptation (DUA) [71] (see Section 6.2.1) and, alternatively, test-time entropy minimisation (Tent) [69] (see Section 6.2.2), since both methods are efficient in terms of computing power (i.e., they do not rely on supervision or processing of source data) and memory usage (i.e., they do not rely on source data or a large batch of target data to be saved on the compute hardware of the satellite).  
```
\(\theta^{t}\leftarrow\theta^{s}\)\(\triangleright\) Copy source weights to target weights \(\mathcal{B}\leftarrow\emptyset\)\(\triangleright\) Initialise current batch for\(j\gets 1\) to \(N^{t}\)do \(\mathcal{B}\leftarrow\mathcal{B}\cup x_{j}^{t}\) if\(|\mathcal{B}|=n_{B}\)then \(\theta^{t}\leftarrow\texttt{ADAPT}(\theta^{t},\mathcal{B})\) \(\mathcal{B}\leftarrow\emptyset\) endif endfor
```  
**Algorithm 2** TTA algorithm