티스토리 뷰

 

https://www.researchgate.net/figure/General-configuration-of-a-convolutional-neural-network-CNN_fig5_338812110

 

https://encord.com/blog/convolutional-neural-networks-explained/

 

 

https://journalofbigdata.springeropen.com/articles/10.1186/s40537-021-00444-8

 

https://towardsdatascience.com/applied-deep-learning-part-4-convolutional-neural-networks-584bc134c1e2

 

https://learnopencv.com/understanding-convolutional-neural-networks-cnn/

 

[합성곱 계층과 MaxPoolin 계층을 이용하는 예시 코드]

import tensorflow as tf
from tensorflow.keras import datasets, layers, models

# 데이터 로드 및 전처리 (예: CIFAR-10)
(x_train, y_train), (x_test, y_test) = datasets.cifar10.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

# CNN 모델 정의
model = models.Sequential([
    layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)),
    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개의 클래스
])

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.summary()

 

[VGG16 모델을 이용한 예시 코드]

from tensorflow.keras.applications import VGG16

# VGG16 모델 정의 (이미지 크기 224x224, RGB 채널)
model = VGG16(weights='imagenet', input_shape=(224, 224, 3), include_top=True)

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
model.summary()

 

[ResNet 모델을 이용하는 예시 코드]

from tensorflow.keras.applications import ResNet50

# ResNet50 모델 정의 (이미지 크기 224x224, RGB 채널)
model = ResNet50(weights='imagenet', input_shape=(224, 224, 3), include_top=True)

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
model.summary()

 

[MobilNet 모델을 이용한 예시 코드]

from tensorflow.keras.applications import MobileNet

# MobileNet 모델 정의 (이미지 크기 224x224, RGB 채널)
model = MobileNet(weights='imagenet', input_shape=(224, 224, 3), include_top=True)

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
model.summary()

 

[U-Net 모델을 이용한 예시 코드]

from tensorflow.keras import layers, models

# U-Net 모델 정의
def unet(input_size=(128, 128, 1)):
    inputs = layers.Input(input_size)
    
    # 인코딩 부분 (다운샘플링)
    c1 = layers.Conv2D(64, (3, 3), activation='relu', padding='same')(inputs)
    p1 = layers.MaxPooling2D((2, 2))(c1)
    
    c2 = layers.Conv2D(128, (3, 3), activation='relu', padding='same')(p1)
    p2 = layers.MaxPooling2D((2, 2))(c2)
    
    # 디코딩 부분 (업샘플링)
    u1 = layers.UpSampling2D((2, 2))(p2)
    concat1 = layers.concatenate([u1, c2], axis=-1)
    c3 = layers.Conv2D(128, (3, 3), activation='relu', padding='same')(concat1)
    
    u2 = layers.UpSampling2D((2, 2))(c3)
    concat2 = layers.concatenate([u2, c1], axis=-1)
    c4 = layers.Conv2D(64, (3, 3), activation='relu', padding='same')(concat2)
    
    # 출력층
    outputs = layers.Conv2D(1, (1, 1), activation='sigmoid')(c4)
    
    model = models.Model(inputs=[inputs], outputs=[outputs])
    return model

model = unet()
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
model.summary()

 

 

 

 

 

 

 

 

반응형