lundi 21 septembre 2020

How to generate a random vector for every batch in Tensorflow keras?

In the code here below the vector rand is initialized when I call the first time the function create_model().

def create_model(num_columns):
    inp_layer = tfl.Input((num_columns,))
    rand = tf.random.uniform((1,num_columns), minval = 0, maxval = 2, dtype = tf.int32), tf.float32))
    inp_rand = tfl.Multiply()([inp_layer, rand])
    dense = tfl.Dense(256, activation = 'relu')(inp_rand)
    dense = tfl.Dense(128, activation = 'relu')(dense)
    dense = tfl.Dense(64, activation = 'sigmoid')(dense)
    model = tf.keras.Model(inputs = inp_layer, outputs = dense)
    model.compile(optimizer = 'adam', loss = 'binary_crossentropy')

model = create_model(num_columns)
model.fit()

I would like it to be regenerated with new random values every time I call the function model.fit(), or even better, at any batch during the execution of model.fit().

Would you know how I can do this?




Aucun commentaire:

Enregistrer un commentaire