본문 바로가기
프로그래밍/AI 머신러닝,LLM

심층신경망, cnn, rnn

by -현's- 2025. 4. 20.
반응형

●심층 신경망(Deep Neural Network, DNN)

인공신경망의 층을 추가하여 만든 모델입니다.

층이 많아질수록 더 복잡한 패턴을 학습할 수 있습니다.

ex)

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

# 신경망 모델 생성
model = keras.Sequential([
    layers.Dense(64, activation='relu', input_shape=(10,)),  # 첫 번째 은닉층 (64개 뉴런)
    layers.Dense(32, activation='relu'),  # 두 번째 은닉층 (32개 뉴런)
    layers.Dense(1, activation='sigmoid')  # 출력층 (이진 분류를 위한 sigmoid 활성화 함수)
])

# 모델 요약
model.summary()

 

 

●합성곱 신경망 (CNN, Convolutional Neural Network)

이미지나 영상 데이터를 다룰 때 주로 사용하는 딥러닝 모델입니다.

일반적인 신경망(MLP, 다층 퍼셉트론)과 달리, CNN은 이미지의 공간적 구조를 유지하면서 특징을 추출하는 데 강합니다.

주로 이미지분류, 객체탐지, 영상분석, 자율주행 등에 사용됩니다.

ex)

import tensorflow as tf
from tensorflow.keras import layers, models
from tensorflow.keras.datasets import mnist
import matplotlib.pyplot as plt

# 1. MNIST 데이터셋 로드
(x_train, y_train), (x_test, y_test) = mnist.load_data()

# 2. 데이터 전처리
x_train = x_train.reshape((x_train.shape[0], 28, 28, 1)) / 255.0
x_test = x_test.reshape((x_test.shape[0], 28, 28, 1)) / 255.0

# 3. CNN 모델 생성
model = models.Sequential([
    layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),
    layers.MaxPooling2D((2, 2)),
    layers.Conv2D(64, (3, 3), activation='relu'),
    layers.MaxPooling2D((2, 2)),
    layers.Conv2D(64, (3, 3), activation='relu'),
    layers.Flatten(),
    layers.Dense(64, activation='relu'),
    layers.Dense(10, activation='softmax')  # 10개의 숫자 클래스
])

# 4. 모델 컴파일 및 훈련
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5, batch_size=64, validation_data=(x_test, y_test))

# 5. 모델 평가
test_loss, test_acc = model.evaluate(x_test, y_test)
print(f"테스트 정확도: {test_acc:.4f}")

반응형

●순환 신경망 (RNN, Recurrent Neural Network)

연속된 데이터(시계열 데이터, 텍스트, 음성 등)를 처리하는 데 특화된 신경망입니다.

기존의 신경망과 달리 이전의 정보를 기억하고 다음 계산에 활용할 수 있는 구조를 가지고 있습니다.

RNN의 가장 큰 특징은 "순환 구조" 입니다. 일반적인 신경망(MLP, CNN)은 입력을 한 번만 처리하지만, RNN은 이전 상태(hidden state) 를 기억하여 다음 단계의 입력으로 활용합니다.

기울기 소실 문제를 해결하기 위해 LSTM, GRU 같은 모델이 등장했습니다.

RNN은 주로 자연어처리, 음성인식, 시계열예측, 음악생성, 자동자막 생성등에 사용됩니다.

반응형

'프로그래밍 > AI 머신러닝,LLM' 카테고리의 다른 글

RAG(Retrieval-Augmented Generation)  (0) 2025.04.26
LLM 기초  (0) 2025.04.23
딥러닝, 신경망, 활성화 함수  (0) 2025.04.16
결정트리,군집화,차원축소  (0) 2025.04.12
파이썬 numpy, pandas  (0) 2025.04.07

댓글