신경망 구조 탐색(Neural Architecture Search, NAS)은 주어진 태스크에 최적화된 신경망 구조를 자동으로 탐색하는 기법이다. 수동 설계의 한계를 극복하고 EfficientNet, NASNet 등 고성능 모델을 발견하는 데 활용됐다.
핵심 구성 요소
NAS = 탐색 공간(Search Space)
+ 탐색 전략(Search Strategy)
+ 성능 평가(Performance Estimation)
탐색 공간
python
# 셀 기반 탐색 공간 예시
OPERATIONS = [
'conv_3x3', 'conv_5x5', 'depthwise_conv_3x3',
'max_pool_3x3', 'avg_pool_3x3', 'skip_connect', 'zero'
]
# 각 셀은 N개 노드로 구성, 각 노드는 이전 노드 2개 + 연산 선택
def sample_cell(n_nodes=4, n_ops=len(OPERATIONS)):
import random
cell = []
for i in range(2, n_nodes + 2):
inp1 = random.randint(0, i - 1)
inp2 = random.randint(0, i - 1)
op1 = random.randint(0, n_ops - 1)
op2 = random.randint(0, n_ops - 1)
cell.append((inp1, op1, inp2, op2))
return cell
DARTS (Differentiable Architecture Search)
python
import torch
import torch.nn as nn
import torch.nn.functional as F
class MixedOp(nn.Module):
"""모든 연산의 가중합 → 그래디언트로 구조 학습"""
def __init__(self, channels, ops):
super().__init__()
self.ops = nn.ModuleList(ops)
self.arch_weights = nn.Parameter(torch.randn(len(ops)))
def forward(self, x):
weights = F.softmax(self.arch_weights, dim=0)
return sum(w * op(x) for w, op in zip(weights, self.ops))
# 학습 후 각 엣지에서 가장 높은 가중치의 연산 선택
def discretize(mixed_op):
weights = F.softmax(mixed_op.arch_weights, dim=0)
best_op = mixed_op.ops[weights.argmax()]
return best_op
NAS 방법론 비교
| 방법 | 탐색 전략 | GPU 비용 | 대표 모델 |
|---|
| RL 기반 | 강화학습 | ~800 GPU-days | NASNet |
| 진화 기반 | 유전 알고리즘 | ~3000 GPU-days | AmoebaNet |
| DARTS | 그래디언트 | ~4 GPU-days | DARTS |
| ProxylessNAS | 그래디언트 | ~8 GPU-days | ProxylessNAS |
| EfficientNAS | 복합 스케일링 | - | EfficientNet |
관련 개념