예제 #1
0
    def _create(self):
        base_model = KerasResNet50(include_top=False,
                                   input_tensor=self.get_input_tensor())
        self.make_net_layers_non_trainable(base_model)

        x = base_model.output
        x = Dropout(self.dropout)(x)
        x = Flatten()(x)
        # we could achieve almost the same accuracy without this layer, buy this one helps later
        # for novelty detection part and brings much more useful features.
        #x = Dense(self.noveltyDetectionLayerSize, activation='elu', name=self.noveltyDetectionLayerName)(x)
        #x = Dropout(0.5)(x)
        if self.run_config.main.classification_type == _config.CLASSIFICATION_TYPE.CLASSIFICATION:
            predictions = Dense(self.run_config.data.nb_classes,
                                activation='softmax',
                                name='predictions')(x)
        elif self.run_config.main.classification_type == _config.CLASSIFICATION_TYPE.REGRESSION:
            predictions = Dense(1, activation='linear', name='regression')(x)
        elif self.run_config.main.classification_type == _config.CLASSIFICATION_TYPE.MULTIPLE_REGRESSION:
            predictions = Dense(self.run_config.data.nb_classes,
                                activation='linear',
                                name='multiple_regression')(x)
        else:
            raise ValueError("Error, unknown classification_type: <%s>" %
                             self.run_config.main.classification_type)

        self.model = Model(input=base_model.input, output=predictions)
예제 #2
0
    def _create(self):
        base_model = KerasResNet50(include_top=False, input_tensor=self.get_input_tensor())#create base_model
        self.make_net_layers_non_trainable(base_model)#make net layers non trainable

        x = base_model.output
        x = Flatten()(x)
        x = Dropout(0.5)(x)
        # we could achieve almost the same accuracy without this layer, buy this one helps later
        # for novelty detection part and brings much more useful features.
        x = Dense(self.noveltyDetectionLayerSize, activation='elu', name=self.noveltyDetectionLayerName)(x)
        x = Dropout(0.5)(x)
        predictions = Dense(len(config.classes), activation='softmax', name='predictions')(x)

        self.model = Model(input=base_model.input, output=predictions)
예제 #3
0
    def _create(self):
        base_model = KerasResNet50(include_top=False,
                                   input_tensor=self.get_input_tensor())
        self.make_net_layers_non_trainable(base_model)

        x = base_model.output
        x = Flatten()(x)
        x = Dropout(0.5)(x)
        x = Dense(128, activation='elu',
                  name=self.noveltyDetectionLayerName)(x)
        x = Dense(128, activation='elu',
                  name=self.noveltyDetectionLayerName1)(x)
        x = Dropout(0.5)(x)
        predictions = Dense(len(config.classes),
                            activation='softmax',
                            name='predictions')(x)

        self.model = Model(input=base_model.input, output=predictions)
        self.model.summary()
예제 #4
0
    def define(self, optimizer=Adam(lr=config.configured_learning_rate)):

        self.optimizer = optimizer

        keras_model = KerasResNet50(weights=None,
                                    include_top=True,
                                    input_tensor=self.get_input_tensor(),
                                    input_shape=self.get_input_shape(),
                                    classes=len(config.configured_classes))

        self.make_net_layers_non_trainable(keras_model)

        #use standard model or fine turn model
        if config.use_fineturn_model:
            self.model = self.fineturn(self, keras_model)
        else:
            self.model = Model(
                input=keras_model.input,
                output=keras_model.output)  #this means NO CHANGE