Say you have e.g. a boolean tf.placeholder
, and you want to feed it when you call Model.fit
. How would you do it? Below is some runnable dummy code that illustrates the problem.
import tensorflow as tf
from tensorflow.keras.layers import Dense, Input, Flatten
from tensorflow.keras.models import Model
# A boolean value that should have some effect of something
do_stuff = tf.placeholder(tf.bool)
# If do_stuff is true, return tf.ones else tf.zeros, and a 1 or 0 label
if_dostuff = lambda: [tf.ones((5, 5)), tf.constant(1)]
if_not_dostuff = lambda: [tf.zeros((5, 5)), tf.constant(0)]
X, Y_true = tf.cond(do_stuff, if_dostuff, if_not_dostuff)
# Make some dummy labels
# Do some random model operation
X_input = Input(shape=(5, 5))
layer_mod = Flatten()(X_input)
layer_mod = Dense(1)(layer_mod)
out_model = Model(inputs=[X_input], outputs=[layer_mod])
# Compile model
out_model.compile(
optimizer=tf.keras.optimizers.Adam(),
loss=tf.keras.metrics.binary_crossentropy
)
### Other ops with other models and summaries etc. ###
out_model.fit(...) # What do I do at this point?
Keep in mind that the boolean is just to keep things simple. In reality I have strings that are iterator handles that needs to be fed (based on what dataset I want to train).
How can I do keras' amazing model.fit
interface with this sort of layout?
An alternative would be what I ask in this question