코드 6-2 LeNet-5 클래스 생성
num_classes = 2
class LeNet(Sequential):
def __init__(self, input_shape, nb_classes):
super().__init__()
self.add(Conv2D(6, kernel_size=(5,5), strides=(1,1), activation='relu',
input_shape=input_shape, padding="same")) ------ ①
self.add(AveragePooling2D(pool_size=(2,2), strides=(2,2), padding='valid')) ------ ②
self.add(Conv2D(16, kernel_size=(5,5), strides=(1,1), activation='relu',
padding='valid'))
self.add(AveragePooling2D(pool_size=(2,2), strides=(2,2), padding='valid'))
self.add(Flatten())
self.add(Dense(120, activation='relu'))
self.add(Dense(84, activation='relu'))
self.add(Dense(nb_classes, activation='softmax'))
self.compile(optimizer='adam',
loss=categorical_crossentropy,
metrics=['accuracy'])