神經(jīng)網(wǎng)絡(luò)架構(gòu)搜索——可微分搜索(SGAS)

SGAS原理及源碼解析

KAUST&Intel發(fā)表在CVPR 2020上的NAS工作,針對現(xiàn)有DARTS框架在搜索階段具有高驗證集準(zhǔn)確率的架構(gòu)可能在評估階段表現(xiàn)不好的問題,提出了分解神經(jīng)網(wǎng)絡(luò)架構(gòu)搜索過程為一系列子問題,SGAS使用貪婪策略選擇并剪枝候選操作的技術(shù),在搜索CNN和GCN網(wǎng)絡(luò)架構(gòu)均達到了SOTA。

動機

NAS技術(shù)都有一個通?。?strong>在搜索過程中驗證精度較高,但是在實際測試精度卻沒有那么高。傳統(tǒng)的基于梯度搜索的DARTS技術(shù),是根據(jù)block構(gòu)建更大的超網(wǎng),由于搜索的過程中驗證不充分,最終eval和test精度會出現(xiàn)鴻溝。從下圖的Kendall系數(shù)來看,DARTS搜出的網(wǎng)絡(luò)精度排名和實際訓(xùn)練完成的精度排名偏差還是比較大。

"Accuracy GAP"

方法

整體思路

本文使用與DARTS相同的搜索空間,SGAS搜索過程簡單易懂,如下圖所示。類似DARTS搜索過程為每條邊指定參數(shù)α,超網(wǎng)訓(xùn)練時通過文中判定規(guī)則逐漸確定每條邊的具體操作,搜索結(jié)束后即可得到最終模型。

SGAS架構(gòu)示意圖
算法偽代碼

為了保證在貪心搜索的過程中能盡量保證搜索的全局最優(yōu)性,進而引入了三個指標(biāo)兩個評估準(zhǔn)則。

三個指標(biāo)

邊的重要性

非零操作參數(shù)對應(yīng)的softmax值求和,作為邊的重要性衡量指標(biāo)。
S_{E I}^{(i, j)}=\sum_{o \in \mathcal{O}, o \neq z e r o} \frac{\exp \left(\alpha_{o}^{(i, j)}\right)}{\sum_{o^{\prime} \in \mathcal{O}} \exp \left(\alpha_{o^{\prime}}^{(i, j)}\right)}

alphas = []
for i in range(4):
    for n in range(2 + i):
        alphas.append(Variable(1e-3 * torch.randn(8)))
# alphas經(jīng)過訓(xùn)練后
mat = F.softmax(torch.stack(alphas, dim=0), dim=-1).detach() # mat為14*8維度的二維列表,softmax歸一化。 
EI = torch.sum(mat[:, 1:], dim=-1) # EI為14個數(shù)的一維列表,去掉none后的7個ops對應(yīng)alpha值相加
選擇的準(zhǔn)確性

計算操作分布的標(biāo)準(zhǔn)化熵,熵越小確定性越高;熵越高確定性越小。
\begin{array}{c} p_{o}^{(i, j)}=\frac{\exp \left(\alpha_{o}^{(i, j)}\right)}{S_{E I}^{(i, j)} \sum_{o^{\prime} \in \mathcal{O}} \exp \left(\alpha_{o^{\prime}}^{(i, j)}\right)}, o \in \mathcal{O}, o \neq z e r o \\ S_{S C}^{(i, j)}=1-\frac{-\sum_{o \in \mathcal{O}, o \neq z e r o} p_{o}^{(i, j)} \log \left(p_{o}^{(i, j)}\right)}{\log (|\mathcal{O}|-1)} \end{array}

import torch.distributions.categorical as cate
probs = mat[:, 1:] / EI[:, None]
entropy = cate.Categorical(probs=probs).entropy() / math.log(probs.size()[1])
SC = 1-entropy
選擇的穩(wěn)定性

將歷史信息納入操作分布評估,使用直方圖交叉核計算平均選擇穩(wěn)定性。直方圖交叉核的原理詳見(https://blog.csdn.net/hong__fang/article/details/50550656)。
S_{S S}^{(i, j)}=\frac{1}{K} \sum_{t=T-K}^{T-1} \sum_{o_{t} \in \mathcal{O}, o_{t} \neq z e r o} \min \left(p_{o_{t}}^{(i, j)}, p_{o_{T}}^{(i, j)}\right)

def histogram_intersection(a, b):
  c = np.minimum(a.cpu().numpy(),b.cpu().numpy())
  c = torch.from_numpy(c).cuda()
  sums = c.sum(dim=1)
  return sums

def histogram_average(history, probs):
  histogram_inter = torch.zeros(probs.shape[0], dtype=torch.float).cuda()
  if not history:
    return histogram_inter
  for hist in history:
    histogram_inter += utils.histogram_intersection(hist, probs)
  histogram_inter /= len(history)
  return histogram_inter

probs_history = []

probs_history.append(probs)
if (len(probs_history) > args.history_size):
  probs_history.pop(0)
  
histogram_inter = histogram_average(probs_history, probs)

SS = histogram_inter

兩種評估準(zhǔn)則

評估準(zhǔn)則1:

選擇具有高邊緣重要性和高選擇確定性的操作
S_{1}^{(i, j)}=\text { normalize }\left(S_{E I}^{(i, j)}\right) * \text { normalize }\left(S_{S C}^{(i, j)}\right)

def normalize(v):
  min_v = torch.min(v)
  range_v = torch.max(v) - min_v
  if range_v > 0:
    normalized_v = (v - min_v) / range_v
  else:
    normalized_v = torch.zeros(v.size()).cuda()

  return normalized_v

score = utils.normalize(EI) * utils.normalize(SC)
評估準(zhǔn)則2:

在評估準(zhǔn)則1的基礎(chǔ)上,加入考慮選擇穩(wěn)定性
S_{2}^{(i, j)}=S_{1}^{(i, j)} * \text { normalize }\left(S_{S S}^{(i, j)}\right)

score = utils.normalize(EI) * utils.normalize(SC) * utils.normalize(SS)

實驗結(jié)果

CIFAR-10(CNN)

CIFAR-10(CNN)

ImageNet(CNN)

ImageNet(CNN)

ModelNet40(GCN)

ModelNet40(GCN)

PPI(GCN)

PPI(GCN)

參考

[1] Li, Guohao et al. ,SGAS: Sequential Greedy Architecture Search

[2] https://zhuanlan.zhihu.com/p/134294068

[3] 直方圖交叉核 https://blog.csdn.net/hong__fang/article/details/50550656

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容