Module for ownmlp for keras model
Classes
OwnMLP
OwnMLP(
hidden_layers,
activation="relu",
final_activation="linear",
do_summary=True,
)
Bases: ModelFactory
Modelfactory for a mlp
Initializes the OwnMLP model factory
Source code in niceml/dlframeworks/keras/models/mlp.py
| def __init__(
self,
hidden_layers: List[int],
activation: str = "relu",
final_activation: str = "linear",
do_summary: bool = True,
):
"""Initializes the OwnMLP model factory"""
self.hidden_layers = hidden_layers
self.activation = activation
self.do_summary = do_summary
self.final_activation = final_activation
|
Functions
create_model
create_model(data_description)
Creates the mlp model
Source code in niceml/dlframeworks/keras/models/mlp.py
| def create_model(self, data_description: DataDescription) -> Any:
"""Creates the mlp model"""
input_dd: InputVectorDataDescription = check_instance(
data_description, InputVectorDataDescription
)
output_dd: OutputVectorDataDescription = check_instance(
data_description, OutputVectorDataDescription
)
model = Sequential()
input_size = input_dd.get_input_size()
# first hidden layer
count = self.hidden_layers.pop(0)
model.add(
layers.Dense(count, activation=self.activation, input_shape=(input_size,))
)
for count in self.hidden_layers:
model.add(layers.Dense(count, activation=self.activation))
# Outputs from dense layer are projected onto output layer
target_size = output_dd.get_output_size()
model.add(layers.Dense(target_size, activation=self.final_activation))
if self.do_summary:
model.summary()
return model
|
Functions