畢設進了圖網絡的坑,感覺有點難,一點點慢慢學吧,本文方法是《Rethinking Table Recognition using Graph Neural Networks》中關系建模環節中的主要方法。
## 概述
本文是對經典的PointNet進行改進,主要目標是設計一個可以直接使用點雲作為輸入的CNN架構,可適用於分類、分割等任務。主要的創新點是提出了一個新的可微網絡模塊EdgeConv(邊卷積操作)來提取局部鄰域信息。
其整體的網絡結構如下所示,值得注意的有:
- 整體的網絡結構與PointNet的結構類似,最重要的區別就是使用EdgeConv代替MLP;
- 對於每個EdgeConv模塊,我們即考慮全局特征,又考慮局部特征,
(圖2左)聚合函數
(圖2右);
- EdgeConv模塊中KNN圖的K值是一個超參,分類網絡中K=20,而在分割網絡中K=30;在做表格識別任務時,k=10;
- 在分割網絡中,將global descripter和每層的local descripter進行連接后對每個點輸出一個預測分數;
- 每層后的mlp全連接 都是為了計算邊特征(edge features),實現動態的圖卷積。
## Edge Convolution
- 假設一個F維點$\mathbf{X}=\left\{\mathbf{x}_{1}, \ldots, \mathbf{x}_{n}\right\} \subseteq \mathbb{R}^{F}$, 最簡單的$\mathrm{F}=3$(即x y z位置信息),另外還可能引入每個點顏色、法線等信息。
- 給定一個有向圖 $\mathcal{G}=(\mathcal{V}, \mathcal{E})$ ,用來表示點雲結構信息,其中頂點為$\mathcal{V}=\{1, \ldots, n\}$,邊為 $\mathcal{E} \subseteq \mathcal{V} \times \mathcal{V}$,邊特征函數$e_{i j}=h_{\Theta}\left(x_{i}, x_{j}\right)$,其中 $h$是 $\mathbb{R}^{F} \times \mathbb{R}^{F} \rightarrow \mathbb{R}^{F^{\prime}}$的映射(從結點信息獲取邊特征信息)
- 圖2左 就描述了一個點$x_{i}$和其鄰近點$x_{j}$ 的邊特征$e_{i j}$求解過程,$h$使用三層全連接,用tf.layers.dense實現。(注:Dense and fully connected are two names for the same thing.)
- 圖2右 描述的是結點參數更新的過程(結點聚合函數),定義為$\square$,其定義是:$\mathbf{x}_{i}^{\prime}=\square_{j:(i, j) \in \mathcal{E}} h_{\Theta}\left(\mathbf{x}_{i}, \mathbf{x}_{j}\right)$,根據不同的需求,h和□有四種不同的選擇
- 認為$x_{i}$的特征是周圍所有點的加權求和,這一點類似於圖像的卷積操作,其中每個卷積核為${\theta}_{m}$,他的維度與x的維度相同,$\Theta=\left(\theta_{1}, \ldots, \theta_{M}\right)$表示所有卷積核的集合。其公式如下:$x_{i m}^{\prime}=\sum_{i=(j, j) \in \mathcal{E}} \boldsymbol{\theta}_{m} \cdot \mathbf{x}_{j}$
- 若只考慮全局特征,即PointNet的使用方法,公式如下:$h_{\Theta}\left(\mathbf{x}_{i}, \mathbf{x}_{j}\right)=h_{\Theta}\left(\mathbf{x}_{i}\right)$
- 若只考慮局部特征,即輸入的僅為點和周圍點的差,則公式如下:$h_{\Theta}\left(\mathbf{x}_{i}, \mathbf{x}_{j}\right)=h_{\Theta}\left(\mathbf{x}_{j}-\mathbf{x}_{i}\right)$
- 同時關注全局特征和局部特征,這也是本文中的主要形式:$h_{\Theta}\left(\mathbf{x}_{i}, \mathbf{x}_{j}\right)=\bar{h}_{\Theta}\left(\mathbf{x}_{i}, \mathbf{x}_{j}-\mathbf{x}_{i}\right)$
- 在本文中,h函數使用$e_{i j m}^{\prime}=\operatorname{ReLU}\left(\boldsymbol{\theta}_{m} \cdot\left(\mathbf{x}_{j}-\mathbf{x}_{i}\right)+\boldsymbol{\phi}_{m} \cdot \mathbf{x}_{i}\right)$,關系聚合函數選用 max
## 在表格識別任務中實現的代碼
在我的畢設,即表格識別任務中,主要借用edge conv的思想,和分割部分的網絡結構。
其流程目的是將結點的特征進行提取,即輸入為(25,900,133)(batch_size, node_num, feature_num),輸出為經DGCNN處理后的結點信息,size為(25,900,128),整體流程如下:
1 def edge_conv_layer(vertices_in, num_neighbors=30, 2 mpl_layers=[64, 64, 64], 3 aggregation_function=tf.reduce_max, 4 share_keyword=None, # TBI, 5 edge_activation=None 6 ): 7 trans_space = vertices_in # (25,900,64) 8 indexing, _ = indexing_tensor(trans_space, num_neighbors) # (25,900,10,2) 9 # change indexing to be not self-referential 10 neighbour_space = tf.gather_nd(vertices_in, indexing) # (25, 900, 10, 64) 11 12 expanded_trans_space = tf.expand_dims(trans_space, axis=2) 13 expanded_trans_space = tf.tile(expanded_trans_space, [1, 1, num_neighbors, 1]) # (25, 900 , 10(null), 64) 14 15 diff = expanded_trans_space - neighbour_space # (25, 900, 10, 64) 16 edge = tf.concat([expanded_trans_space, diff], axis=-1) # (25, 900, 10, 128) 17 18 for f in mpl_layers: 19 edge = tf.layers.dense(edge, f, activation=tf.nn.relu) # 三層全連接 (25,900,10,64) 20 if edge_activation is not None: 21 edge = edge_activation(edge) 22 23 vertex_out = aggregation_function(edge, axis=2) # (25,900,64) 24 # print("vertex_out:", vertex_out.shape) 25 return vertex_out