# WiGR: A Practical Wi-Fi-Based Gesture Recognition System with a Lightweight Few-Shot Network
## 3 Methods
### Overview of WiGR
#### 3.2.4 Episode-Based Training Strategy  
We adopted an episode-based training strategy [20] to train the lightweight few-shot network. In each episode, we extracted \(K\) (e.g., 5) types of gestures uniformly at random from the training set \(D\) without replacement, and took \(G\) (e.g., up to 5) samples from each gesture to simulate support set \(S\). We then took the remaining samples of each gesture to simulate testing set \(Q\). Subsequently, we used a feature extraction subnetwork \(f_{\varphi}(\cdot)\) to calculate the feature \(e\) of support sample \(x_{i}\) and the feature \(o\) of testing sample \(x_{j}\). These features were combined in-depth with the operator concate (\(e\), \(o\)). Finally, we fed these combined features into the similarity discrimination subnetwork \(g_{\varphi}(\cdot)\), which produced  
\begin{table}
\begin{tabular}{c c c c c c c c} \hline \hline
**Input** & **Operator** & **Kernel Size** & **M** & **\#Out** & **SE** & **NL** & **S** \\ \hline
1800 \(\times\) 114 \(\times\) 3 & Conv Block & \(3\times 3\) & - & 16 & False & HS & (2, 1) \\
900 \(\times\) 114 \(\times\) 16 & Mobile Block & \(3\times 3\) & \(16\times\mu\)c & \(16\times\mu\)c & True & RE & 2 \\
450 \(\times\) 57 \(\times\) (16 \(\times\mu\)c) & Mobile Block & \(3\times 3\) & \(72\times\mu\)c & \(24\times\mu\)c & False & RE & 2 \\
225 \(\times\) 20 \(\times\) (24 \(\times\mu\)c) & Mobile Block & \(5\times 5\) & \(96\times\mu\)c & \(40\times\mu\)c & True & HS & 2 \\
113 \(\times\) 15 \(\times\) (40 \(\times\mu\)c) & Mobile Block & \(5\times 5\) & \(240\times\mu\)c & \(80\times\mu\)c & True & HS & 2 \\
57 \(\times\) 8 \(\times\) (80 \(\times\mu\)c) & Mobile Block & \(5\times 5\) & \(240\times\mu\)c & \(80\times\mu\)c & True & HS & 2 \\ \hline \hline \end{tabular}
\end{table}
Table 3: Specifications for the feature extraction subnetwork.  
a similarity score \(h_{i,\,j}\), representing the similarity between \(x_{i}\) and \(x_{j}\). The \(h_{i,\,j}\) is defined as follows:  
\[h_{i,j}=g_{\varphi}(concate(f_{\varphi}(x_{i}),f_{\varphi}(y_{i}))) \tag{4}\]  
Additionally, the lightweight few-shot network adopts the mean square error loss function \(J\), defined as follows:  
\[J=\sum_{j=1}^{Q}\sum_{i=1}^{K}\bigl{(}h_{i,j}-P\bigl{(}y_{i}==y_{j}\bigr{)} \bigr{)}^{2} \tag{5}\]  
where \(y_{i}\) and \(y_{j}\) represent labels of sample \(x_{i}\)and sample \(x_{j}\), respectively. \(P\left(y_{i}==y_{j}\right)\) indicates whether \(y_{i}\) and \(y_{j}\) are equal. If they are equal, \(P\left(y_{i}==y_{j}\right)=1\); otherwise, \(P\left(y_{i}==y_{j}\right)=0\). Moreover, we adopted the gradual warmup learning scheduler [6] to minimize the loss function \(J\).  
Based on the episode-based training strategy, in each training episode, we can randomly produce a training support set and a training query set to simulate the support set and testing set encountered in the test scenario. We repeated the above process until the model could learn a robust transfer knowledge from the labeled training set \(D\). We then applied the learned transfer knowledge to the new testing domain to address the domain shift problem.  
\begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**Input** & **Operator** & **Kernel Size** & **\#Out** & **SE** & **NL** & **S** \\ \hline \(57\times 8\times(160\times\text{fac})\) & Conv Block & \(1\times 1\) & 576 \(\times\)_fac_ & False & HS & 1 \\ \(57\times 8\times(576\times\text{fac})\) & Pooling Layer & \(3\times 3\) & - & False & - & 1 \\ \(57\times 8\times(576\times\text{fac})\) & Conv Layer & \(1\times 1\) & 128 \(\times\)_fac_ & False & HS & 1 \\ \hline \hline \end{tabular}
\end{table}
Table 4: Specifications for the similarity discrimination subnetwork.  
Figure 6: Structure of the similarity discrimination subnetwork.