신경망과 레이어

PyTorch로 배우는 딥러닝 입문

Jasmin Ludolf

Senior Data Science Content Developer, DataCamp

신경망 레이어

입력, 은닉층, 출력이 있는 신경망 다이어그램

PyTorch로 배우는 딥러닝 입문

신경망 레이어

입력, 은닉층, 출력이 있는 신경망 다이어그램

PyTorch로 배우는 딥러닝 입문

신경망 레이어

입력, 은닉층, 출력이 있는 신경망 다이어그램

PyTorch로 배우는 딥러닝 입문

신경망 레이어

입력, 은닉층, 출력이 있는 신경망 다이어그램

PyTorch로 배우는 딥러닝 입문

첫 번째 신경망

입력과 출력만 있는 기본 신경망 다이어그램

  • 완전연결 신경망
  • 선형 모델과 동등
PyTorch로 배우는 딥러닝 입문

신경망 설계

신경망 입력을 나타내는 세 개의 노드

# Importing as nn to avoid writing torch.nn
import torch.nn as nn


# Create input_tensor with three features input_tensor = torch.tensor( [[0.3471, 0.4547, -0.2356]])
  • 입력 뉴런 = 특성
  • 출력 뉴런 = 클래스
PyTorch로 배우는 딥러닝 입문

신경망 설계

선형 레이어를 향하는 화살표가 있는 세 입력 노드

# Importing as nn to avoid writing torch.nn
import torch.nn as nn


# Create input_tensor with three features input_tensor = torch.tensor( [[0.3471, 0.4547, -0.2356]])
# Define our linear layer linear_layer = nn.Linear(
in_features=3,
out_features=2
)
PyTorch로 배우는 딥러닝 입문

신경망 설계

입력과 출력만 있는 기본 신경망 다이어그램

# Importing as nn to avoid writing torch.nn
import torch.nn as nn


# Create input_tensor with three features input_tensor = torch.tensor( [[0.3471, 0.4547, -0.2356]])
# Define our linear layer linear_layer = nn.Linear( in_features=3, out_features=2 )
# Pass input through linear layer output = linear_layer(input_tensor) print(output)
PyTorch로 배우는 딥러닝 입문

신경망 설계

입력과 출력만 있는 기본 신경망 다이어그램

$$ $$ $$

# Pass input through linear layer
output = linear_layer(input_tensor)
print(output)
tensor([[-0.2415, -0.1604]], 
    grad_fn=<AddmmBackward0>)
PyTorch로 배우는 딥러닝 입문

가중치와 바이어스

output = linear_layer(input_tensor)

선형 연산 표현

PyTorch로 배우는 딥러닝 입문

가중치와 바이어스

  • .weight
    print(linear_layer.weight)
    
Parameter containing:
tensor([[-0.4799,  0.4996,  0.1123],
        [-0.0365, -0.1855,  0.0432]], 
        requires_grad=True)

$$

  • 서로 다른 특성의 중요도를 반영
  • .bias
    print(linear_layer.bias)
    
Parameter containing:
tensor([0.0310, 0.1537], requires_grad=True)

$$

$$

  • 뉴런의 기준 출력 제공
PyTorch로 배우는 딥러닝 입문

완전연결 신경망 살펴보기

입력과 출력만 있는 기본 신경망 다이어그램

PyTorch로 배우는 딥러닝 입문

완전연결 신경망 살펴보기

입력과 출력만 있는 기본 신경망 다이어그램

PyTorch로 배우는 딥러닝 입문

완전연결 신경망 살펴보기

입력과 출력만 있는 기본 신경망 다이어그램

  • 습도 특성의 가중치가 더 큼
  • 바이어스는 기준 정보를 반영
PyTorch로 배우는 딥러닝 입문

연습해 봅시다!

PyTorch로 배우는 딥러닝 입문

Preparing Video For Download...