# Effective Risk Detection for Natural Gas Pipelines Using Low-Resolution Satellite Images
## 3 Change Detection with Transformers
Consecutive difference modules also receive the output of previous difference modules. The difference module is a CNN that learns the differences during training. The last module is the decoder, which produces the binary change map shown on the right side of Figure 2. All features outputted by the difference modules on all scales are fed through an MLP and are upsampled. A softmax layer outputs the binary change map, including a change and non-change class. Note that the model can be easily extended to work with multiple change classes [16], e.g., vegetation and construction changes. Providing the model with semantic knowledge would certainly improve the performance and would be a fruitful direction for further research. Figure 3: **Extracting tokens**: In ChangeFormer, a convolutional neural network (CNN) produces \(C\) feature maps of size \(H/4\times W/4\) from the input image. A token corresponds to one pixel along the feature map dimension \(C\) (marked in red). In our scenario, we use RGB remote sensing imagery. At the end of Section 1, we mentioned that hyperspectral data would be an interesting future research direction. The ChangeFormer architecture could be extended for hyperspectral data by changing the input channels and number of feature maps \(C\) to align with the hyperspectral bands. We argue that scaling the model to 12-band PlanetScope hyperspectral data should increase the memory footprint of the model as well as inference times but would likely be computationally feasible. In some cases, though, hyperspectral data come with considerably more bands, where these adjustments would not be feasible anymore, and other techniques are necessary. Lastly, empirical validation has to show whether such adjustments are sufficient and whether there will be a benefit of using them. **Trading precision for recall**: In pipeline risk detection, our primary concern is capturing all relevant changes (recall) while keeping the number of false positives, also called false alarms, low (precision). It is hard to pinpoint what is more unacceptable: missing a change or predicting a non-existent one. A missed change could lead to severe power outages. On the other side, false positives must be checked on-site by the pipeline provider, which can also be costly. Weighing these against each other suggests that we do not want to miss a change but can tolerate some false positives. Moreover, a human in the loop can filter out false positives by comparing the model's predicted change on the _before_ and _after_ images. Therefore, in this work, we prioritize higher recall and are willing to accept lower precision, although we would like to point out that models with a good balance between precision and recall are most desirable. In [9], the loss function used to train ChangeFormer was the cross-entropy loss, which trades recall and precision equally. As argued, we can tolerate a lower precision if our recall is high enough. Thus, to shift predictive performance towards the recall, we can train ChangeFormer with the weighted cross-entropy defined as:  
\[L_{WeightClassEntropy}=-ay\log(\hat{g})-(1-y)\log(1-\hat{g}) \tag{2}\]  
with weighting parameter \(\alpha\), ground truth \(y\), and prediction \(\hat{g}\). The first part of the equation (\(y\log(\hat{y})\)) is the entropy of the change class and the second part (\((1-y)\log(1-\hat{y})\)) is the entropy of the non-change class, both of which we want to minimize. During training, the weighting parameter \(\alpha\) shifts how much a missed change contributes relative to a false alarm towards the total loss. A value of one means an equal contribution. Selecting a value larger than one would lead to a bigger loss when a change is not detected, e.g., the model is trained more not to miss a change rather than to avoid false alarms. Vice versa, if we want to reduce the number of false alarms and are okay to miss some of the changes, we can pick a value smaller than one.