반응형
Keras로 작성된 VGG 종류에 따른 코드이다.
VGG11, VGG11-LRN, VGG13, VGG16, VGG16-conv1 모델들이다.
VGG11
def create_model(input_shape, label_class_cnt: int):
"""
:param input_shape: 입력 이미지 형태
:param label_class_cnt: 출력 class 수
:return: 생성된 모델
"""
# weight 초기화
He_normal = initializers.he_normal(seed=None)
model = Sequential()
model.add(Conv2D(64, kernel_size=(3, 3),activation='relu',padding='same', input_shape=input_shape, kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(128, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(256, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(Conv2D(256, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(512, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(Conv2D(512, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(512, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(Conv2D(512, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(4096,activation='sigmoid' , kernel_initializer=He_normal)) # activation='relu'
model.add(Dropout(0.5))
model.add(Dense(4096, activation='sigmoid', kernel_initializer=He_normal)) # activation='relu'
model.add(Dropout(0.5))
model.add(Dense(1000,activation='sigmoid', kernel_initializer=He_normal)) # activation='relu'
model.add(Dropout(0.5))
model.add(Dense(label_class_cnt, activation='sigmoid'))
return model
VGG11-LRN
def create_model(input_shape, label_class_cnt: int):
"""
:param input_shape: 입력 이미지 형태
:param label_class_cnt: 출력 class 수
:return: 생성된 모델
"""
# weight 초기화
He_normal = initializers.he_normal(seed=None)
model = Sequential()
model.add(Conv2D(64, kernel_size=(3, 3),activation='relu',padding='same', input_shape=input_shape, kernel_initializer=He_normal))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(128, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(256, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(Conv2D(256, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(512, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(Conv2D(512, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(512, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(Conv2D(512, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(4096, activation='sigmoid', kernel_initializer=He_normal)) # activation='relu'
model.add(Dropout(0.5))
model.add(Dense(4096, activation='sigmoid', kernel_initializer=He_normal)) # activation='relu'
model.add(Dropout(0.5))
model.add(Dense(1000, activation='sigmoid', kernel_initializer=He_normal)) # activation='relu'
model.add(Dropout(0.5))
model.add(Dense(label_class_cnt, activation='sigmoid'))
return model
VGG13
def create_model(input_shape, label_class_cnt: int):
"""
:param input_shape: 입력 이미지 형태
:param label_class_cnt: 출력 class 수
:return: 생성된 모델
"""
# weight 초기화
He_normal = initializers.he_normal(seed=None)
model = Sequential()
model.add(Conv2D(64, kernel_size=(3, 3),activation='relu',padding='same', input_shape=input_shape, kernel_initializer=He_normal))
model.add(Conv2D(64, kernel_size=(3, 3),activation='relu',padding='same', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(128, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(Conv2D(128, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(256, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(Conv2D(256, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(512, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(Conv2D(512, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(512, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(Conv2D(512, (3, 3), activation='relu',padding='same', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(4096, activation='sigmoid', kernel_initializer=He_normal)) # activation='relu'
model.add(Dropout(0.5))
model.add(Dense(4096,activation='sigmoid', kernel_initializer=He_normal)) # activation='relu',
model.add(Dropout(0.5))
model.add(Dense(1000,activation='sigmoid' , kernel_initializer=He_normal)) # activation='relu'
model.add(Dropout(0.5))
model.add(Dense(label_class_cnt, activation='sigmoid'))
return model
VGG16
def create_model(input_shape, label_class_cnt: int):
"""
:param input_shape: 입력 이미지 형태
:param label_class_cnt: 출력 class 수
:return: 생성된 모델
"""
# weight 초기화
He_normal = initializers.he_normal(seed=None)
model = Sequential()
model.add(Conv2D(64, kernel_size=(3, 3), activation='relu', input_shape=input_shape, kernel_initializer=He_normal))
model.add(Conv2D(64, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Conv2D(128, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(Conv2D(128, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Conv2D(256, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(Conv2D(256, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(Conv2D(256, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Conv2D(512, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(Conv2D(512, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(Conv2D(512, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Conv2D(512, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(Conv2D(512, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(Conv2D(512, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Flatten())
model.add(Dense(4096, activation='relu', kernel_initializer=He_normal))
model.add(Dropout(0.5))
model.add(Dense(4096, activation='relu', kernel_initializer=He_normal))
model.add(Dropout(0.5))
model.add(Dense(1000, activation='relu', kernel_initializer=He_normal))
model.add(Dropout(0.5))
model.add(Dense(label_class_cnt, activation='softmax', kernel_initializer=He_normal))
return model
VGG16-conv1
def create_model(input_shape, label_class_cnt: int):
"""
:param input_shape: 입력 이미지 형태
:param label_class_cnt: 출력 class 수
:return: 생성된 모델
"""
# weight 초기화
He_normal = initializers.he_normal(seed=None)
model = Sequential()
model.add(Conv2D(64, kernel_size=(3, 3), activation='relu', input_shape=input_shape, kernel_initializer=He_normal))
model.add(Conv2D(64, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Conv2D(128, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(Conv2D(128, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Conv2D(256, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(Conv2D(256, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(Conv2D(256, kernel_size=(1, 1), activation='relu', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Conv2D(512, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(Conv2D(512, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(Conv2D(512, kernel_size=(1, 1), activation='relu', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Conv2D(512, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(Conv2D(512, kernel_size=(3, 3), activation='relu', kernel_initializer=He_normal))
model.add(Conv2D(512, kernel_size=(1, 1), activation='relu', kernel_initializer=He_normal))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(Flatten())
model.add(Dense(4096, activation='relu', kernel_initializer=He_normal))
model.add(Dropout(0.5))
model.add(Dense(4096, activation='relu', kernel_initializer=He_normal))
model.add(Dropout(0.5))
model.add(Dense(1000, activation='relu', kernel_initializer=He_normal))
model.add(Dropout(0.5))
model.add(Dense(label_class_cnt, activation='softmax', kernel_initializer=He_normal))
return model
반응형
'Deep Learning' 카테고리의 다른 글
CNN(Convolutional Neural Network) 합성곱 신경망 (0) | 2022.08.23 |
---|---|
RNN(Recurrent Neural Network) 순환 신경망 (0) | 2022.08.19 |
[Deep Learning] 앙상블 학습(Ensemble Learning) (0) | 2021.07.29 |
[Deep Learning] 배치 정규화(Batch Normalization) [작성중] (0) | 2021.07.29 |
[Deep Learning] 활성 함수(activation function) 정리 (0) | 2021.07.28 |
댓글