## 3 Materials and Methods
### Framework Overview
#### 3.2.3 Triplet Constraint for Feature Constraint  
In [14], the authors make an assumption that spatial images that are close spatially should have similar features to those that are far apart. However, this assumption is not very reasonable. And we believe that regions with similar crop yields should have similar features learned by the 3D convolutional neural network. Conversely, the features learned through the 3D convolutional neural network should be far apart for regions with large differences in crop yield. Thus, the metric learning strategy [17] is applied in this paper to learn discriminative features. The structure of the triplet network for discriminative feature learning is shown in Figure 5.  
\begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**Layer Name** & **Operation** & **Filters** & **Kernel Size** & **Stride** & **Padding** \\ \hline Conv\_BN\_1 & Conv3D+BN & 32 & \(3\times 3\times 3\) & \(2\times 2\times 2\) & \(1\times 1\times 1\) \\ \hline Conv\_BN\_2 & Conv3D+BN & 64 & \(3\times 3\times 2\) & \(2\times 2\times 2\) & \(1\times 1\times 1\) \\ \hline Conv\_BN\_3 & Conv3D+BN & 128 & \(3\times 3\times 2\) & \(2\times 2\times 2\) & \(1\times 1\times 1\) \\ \hline Conv\_BN\_4 & Conv3D+BN & 256 & \(3\times 3\times 3\) & \(2\times 1\times 1\) & \(1\times 1\times 1\) \\ \hline Conv\_BN\_5 & Conv3D+BN & 512 & \  
Generally, a triplet contains an anchor image, a positive image and a negative image. In our task, \(x^{a}\) has similar crop yield with \(x^{p}\), while \(x^{a}\) and \(x^{n}\) have large differences in crop yield. That is to say, \(x^{a}\) is an anchor image, \(x^{p}\) is a positive image, and \(x^{n}\) is a negative image. And by using the embedding function, a triplet is mapped to a high-dimensional space. In the proposed method, \(x^{a}\), \(x^{p}\), and \(x^{n}\) are respectively fed into the network to obtain the deep features, i.e., \(f(x^{a})\), \(f(x^{p})\), and \(f(x^{n})\) in layer Fc_7, respectively, for crop yield estimation. The triplets should satisfy the distance constraint in the embedding space:  
\[D(x^{a},x^{p})+\alpha<D(x^{a},x^{n})\forall(x^{a},x^{p},x^{n}) \tag{2}\]  
where \(\alpha\) is the constant margin value greater than 0. The above formula enforces the Euclidean distance between the positive pair \((x^{a},x^{p})\) smaller than that of the negative pair \((x^{a},x^{n})\) by a certain margin \(\alpha\). The Euclidean distance between the positive or negative pair can be computed as follows, which has been proven effective for metric learning [18].  
\[D(x^{a},x^{p})=\left\|f(x^{a})-f(x^{p})\right\|_{2} \tag{3}\]  
\[D(x^{a},x^{n})=\left\|f(x^{a})-f(x^{n})\right\|_{2} \tag{4}\]  
Then, the triplet network is optimized by the triplet loss to enforce the features \(f(x^{a})\) and \(f(x^{p})\) to get closer and closer, while \(f(x^{a})\) and \(f(x^{n})\) have large differences.  
\[L=h(D(x^{a},x^{p})-D(x^{a},x^{n})+\alpha) \tag{5}\]  
where \(h(x)\) utilizes the hinge loss function, i.e., \(h(x)=\max(0,x)\). And we can see that the triplet loss can enforce the learned features of samples with similar yields to be closer, while the learned features of samples with different yields have larger separability. Thus, the discriminative feature learning in the crop yield prediction task can be facilitated by the above constraints.