def cnn_validate_base_model_creation(self, feature_model_name,
                                         module_path):
        #Arrange
        base_model = BaseModel(feature_model_name, input_shape)

        #Act & Assert
        with mock_patch(module_path) as base_mock:
            base_model._prepare_model = MagicMock()
            base_model.cnn(dimensions)
            base_mock.assert_called_once()
Example #2
0
def cnn(base_model_name, input_shape, learning_rate, feature_dims):
    """It creates a convolutional network model using the input as a base model.

    Arguments:
        base_model_name {string} -- A string containing the name of a base model.
        input_shape {(int, int, int))} -- A tuple to indicate the shape of inputs.
        learning_rate {float} -- A float value to control speed of learning.
        feature_dims {int} -- An integer indicating the dimensions of the feature vector.

    Returns:
        {A Model object} -- A keras model.
    """
    #Base model
    base_model = BaseModel(base_model_name, input_shape)

    #Model
    model = base_model.cnn(feature_dims)

    #Create an optimizer object
    adam_optimizer = Adam(lr = learning_rate)

    #Compile the model
    model.compile(loss = 'categorical_crossentropy', optimizer = adam_optimizer, metrics = ['categorical_accuracy'])
    model.summary()

    return model
    def test_cnn_model(self):
        #Arrange
        base_model = BaseModel('inceptionv3', input_shape)

        #Act
        model = base_model.cnn(dimensions)

        #Assert
        self.assertIsNotNone(model)
        self.assertTrue(model.layers[-1].name.startswith(
            LayerSpecification.layer_prefixes[LayerType.Dense][1]))
        self.assertTrue(model.layers[-2].name.startswith(
            LayerSpecification.layer_prefixes[LayerType.Dropout][1]))