How to replace tf.placeholder in eager execution

For learning purposes:

I am using a tf1 code as a reference for developing a model. In the reference code, they used tf.placeholder to give input to the model and the code is

class model(object):
    def __init__(self, lstm_size, batch_len, output_nodes, keep_prob, learning_rate=0.001):
        self.inputs_ = tf.compat.v1.placeholder(tf.float32, shape=[batch_len, None, 512], name='lstm_inputs')
        self.targets_ = tf.compat.v1.placeholder(tf.int32, [batch_len], name='lstm_targets')

The execution mode of this model is Graph Execution(tf.Graph).

Since I want to convert and run the code in eager execution. But, the tf.placeholder will not work in eager execution. How can I replace the tf.placeholder without affecting the input name , dtype, and shape of the input value for sake of eager execution.!

Again I need it to convert for eager execution.

I will be thankful if anyone helps me out.

Please anyone reply for this

Have you tried to migrate the model to TF2 and then refine it?

1 Like

Yeah, I tried but tf.placeholder is not migrated to tf2 in which I want to run the code in eager execution. Since placeholder works only in graph execution where i don’t have GUI

You could replace it with Keras input.

See python - Replacing placeholder for tensorflow v2 - Stack Overflow

1 Like

Yeah got the output with this. I given the parameters wrongly :rofl: . Thanks a lot for helping me out…! :slightly_smiling_face: