def create_model(self): print("Creating model") base_model = KerasInceptionV3(weights='imagenet', include_top=False, input_tensor=self.get_input_tensor()) # print("base_model.layers:", len(base_model.layers)) # self.make_net_layers_non_trainable(base_model) x = base_model.output x = GlobalAveragePooling2D()(x) feature = Dense(config.noveltyDetectionLayerSize, activation='elu', name=config.noveltyDetectionLayerName)(x) # x = Dropout(0.6)(feature) predictions = Dense(len(Inference.classes), activation='softmax', name='predictions')(feature) if config.isCenterLoss: print(config.isCenterLoss) input_target = Input(shape=(None,)) centers = Embedding(len(Inference.classes), 4096)(input_target) print('center:', centers) center_loss = Lambda(lambda x: K.sum(K.square(x[0] - x[1][:, 0]), 1, keepdims=True), name='center_loss')( [feature, centers]) model = Model(inputs=[base_model.input, input_target], outputs=[predictions, center_loss]) elif config.isTripletLoss: model = Model(input=base_model.input, output=[predictions, feature]) else: print(base_model.input) model = Model(input=base_model.input, output=predictions) Inference.loaded_model = model
def _create(self): base_model = KerasInceptionV3(weights='imagenet', include_top=False, input_tensor=self.get_input_tensor()) self.make_net_layers_non_trainable(base_model) x = base_model.output x = GlobalAveragePooling2D()(x) x = Dense(1024, activation='elu', name=self.noveltyDetectionLayerName)(x) predictions = Dense(len(config.classes), activation='softmax')(x) self.model = Model(input=base_model.input, output=predictions)
def define(self, optimizer=Adam(lr=config.configured_learning_rate)): self.optimizer = optimizer keras_model = KerasInceptionV3(weights=None, include_top=False, input_tensor=self.get_input_tensor()) self.make_net_layers_non_trainable(keras_model) #use standard model or fine turn model self.fineturn(keras_model)