简体   繁体   中英

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.

You can use tf.keras.Input() in the place of tf.compat.v1.placeholder() to run the code in eager execution mode.

Also, please check this migration guide to convert TensorFlow 1.x code to TensorFlow 2.x .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM