16ROOT.gROOT.SetBatch(
True)
23from tensorflow.keras.layers
import Activation, Dense, Input, Softmax
24from tensorflow.keras.models
import Model
26input=Input(shape=(4,),batch_size=2)
28x=Activation(
'relu')(x)
29x=Dense(16,activation=
'relu')(x)
30x=Dense(8,activation=
'relu')(x)
33model=Model(inputs=input,outputs=output)
35randomGenerator=np.random.RandomState(0)
36x_train=randomGenerator.rand(4,4)
37y_train=randomGenerator.rand(4,2)
39model.compile(loss=
'mse', optimizer=
'adam')
40model.fit(x_train, y_train, epochs=3, batch_size=2)
41model.save(
'KerasModel.keras')
52model = ROOT.TMVA.Experimental.SOFIE.PyKeras.Parse(
"KerasModel.keras")
56model.OutputGenerated()
58print(
"\n**************************************************")
59print(
" Generated code")
60print(
"**************************************************\n")
62print(
"**************************************************\n\n\n")
65ROOT.gInterpreter.Declare(
'#include "KerasModel.hxx"')
73session = ROOT.TMVA_SOFIE_KerasModel.Session()
76x = np.array([[0.1, 0.2, 0.3, 0.4],[0.5, 0.6, 0.7, 0.8]], dtype=np.float32)
81print(
"Inference output:", y)