CNNInterface
- class ketos.neural_networks.cnn.CNNInterface(convolutional_layers=[{'activation': 'relu', 'batch_normalization': True, 'filter_shape': (8, 8), 'max_pool': {'pool_size': (3, 3), 'strides': (2, 2)}, 'n_filters': 32, 'padding': 'valid', 'strides': 4}, {'activation': 'relu', 'batch_normalization': True, 'filter_shape': (3, 3), 'max_pool': {'pool_size': (3, 3), 'strides': (2, 2)}, 'n_filters': 64, 'padding': 'valid', 'strides': 1}], dense_layers=[{'activation': 'relu', 'batch_normalization': True, 'dropout': 0.5, 'n_hidden': 512}, {'activation': 'relu', 'batch_normalization': True, 'dropout': 0.5, 'n_hidden': 128}], n_classes=2, optimizer=Adam ketos recipe, loss_function=BinaryCrossentropy ketos recipe, metrics=[BinaryAccuracy ketos recipe])[source]
Creates a CNN model with the standardized Ketos interface.
- Args:
- convolutional_layers: list
A list of dictionaries containing the detailed specification for the convolutional layers. Each layer is specified as a dictionary with the following format:
>>> {'n_filters':96, "filter_shape":(11,11), 'strides':4, 'padding':'valid', activation':'relu', 'max_pool': {'pool_size':(3,3) , 'strides':(2,2)}, 'batch_normalization':True}
- dense_layers: list
A list of dictionaries containing the detailed specification for the fully connected layers. Each layer is specified as a dictionary with the following format:
>>> {'n_hidden':4096, 'activation':'relu', 'batch_normalization':True, 'dropout':0.5}
- n_classes:int
The number of classes the network will be used to classify. The output will be this number of values representing the scores for each class. Scores sum to 1.0.
- optimizer: ketos.neural_networks.RecipeCompat object
A recipe compatible optimizer (i.e.: wrapped by the ketos.neural_networksRecipeCompat class)
- loss_function: ketos.neural_networks.RecipeCompat object
A recipe compatible loss_function (i.e.: wrapped by the ketos.neural_networksRecipeCompat class)
- metrics: list of ketos.neural_networks.RecipeCompat objects
A list of recipe compatible metrics (i.e.: wrapped by the ketos.neural_networksRecipeCompat class). These metrics will be computed on each batch during training.
Examples:
>>> # Most users will create a model based on a Ketos recipe >>> # The one below, specifies a CNN with 3 convolutional layers and 2 dense layers >>> >>> recipe = {'conv_set':[[64, False], [128, True], [256, True]], ... 'dense_set': [512, ], ... 'n_classes':2, ... 'optimizer': {'recipe_name':'Adam', 'parameters': {'learning_rate':0.005}}, ... 'loss_function': {'recipe_name':'FScoreLoss', 'parameters':{}}, ... 'metrics': [{'recipe_name':'CategoricalAccuracy', 'parameters':{}}] ... } >>> # To create the CNN, simply use the 'build_from_recipe' method: >>> cnn = CNNInterface._build_from_recipe(recipe, recipe_compat=False)
Methods
Attributes
checkpoint_dir
early_stopping_monitor
Sets an early stopping monitor.
log_dir
test_generator
train_generator
val_generator
valid_losses
valid_metrics
valid_optimizers