def build_model(self): conv_base = MobileNet( include_top=False, weights='imagenet', input_shape=config.input_shape ) conv_base.trainable = False print(conv_base.summary()) inputs = Input(shape=config.input_shape) x = conv_base(inputs) x = Flatten()(x) x = Dense(units=128, activation=mobilenet['activation'])(x) x = Dropout(rate=0.5)(x) outputs = Dense(units=config.num_classes, activation=mobilenet['outact'])(x) self.model = Model(inputs=inputs, outputs=outputs)
input_shape=(32, 32, 3)) # print(model.weights) # ============== 전처리 =================== x_train = preprocess_input(x_train) x_test = preprocess_input(x_test) x_train = x_train.astype('float32') / 255. # 전처리 x_test = x_test.astype('float32') / 255. # 전처리 #다중분류 y원핫코딩 y_train = to_categorical(y_train) #(50000, 10) y_test = to_categorical(y_test) #(10000, 10) # ============== 모델링 ===================== MobileNetV2.trainable = False # 훈련을 안시키겠다, 저장된 가중치 사용 MobileNetV2.summary() # 즉, 16개의 레이어지만 연산되는 것은 13개 이고 그래서 len=26개 print(len(MobileNetV2.weights)) # 26 print(len(MobileNetV2.trainable_weights)) # 0 model = Sequential() model.add(MobileNetV2) # 3차원 -> layer 26개 model.add(Flatten()) model.add(Dense(10)) model.add(Dense(5)) model.add(Dense(10, activation='softmax')) model.summary() #3. 컴파일, 훈련 model.compile(loss='categorical_crossentropy', optimizer='adam',