This tutorial shows how to define and generate a keras model for use with TMVA.
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Activation
from tensorflow.keras.regularizers import l2
from tensorflow.keras.optimizers import SGD
from tensorflow.keras.utils import plot_model
num_input_nodes = 4
num_output_nodes = 2
num_hidden_layers = 1
nodes_hidden_layer = 64
l2_val = 1e-5
model = Sequential()
model.add(Dense(nodes_hidden_layer, activation='relu', kernel_regularizer=l2(l2_val), input_dim=num_input_nodes))
for k in range(num_hidden_layers-1):
model.add(Dense(nodes_hidden_layer, activation='relu', kernel_regularizer=l2(l2_val)))
model.add(Dense(num_output_nodes, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer=SGD(learning_rate=0.01), weighted_metrics=['accuracy',])
model.save('model.h5')
model.summary()
try:
plot_model(model, to_file='model.png', show_shapes=True)
except:
print('[INFO] Failed to make model plot')
- Date
- 2017
- Author
- TMVA Team
Definition in file GenerateModel.py.