Search code examples
pythontensorflowgoogle-colaboratory

What is the best way to replace tensorflows placeholder for version 2.5.0 in google colabs python?


I am working on a project and am trying to replace this block of code with something that works. I am using version 2.5.0 of tensorflow and am faced with the following error. AttributeError: module 'tensorflow' has no attribute 'placeholder'

for ui in range(num_unrollings):
    train_inputs.append(tf.placeholder(tf.float32, shape [batch_size,D],name='train_inputs_%d'%ui))
    train_outputs.append(tf.placeholder(tf.float32, shape=[batch_size,1], name = 'train_outputs_%d'%ui))

Solution

  • Try this

    tf.compat.v1.placeholder(dtype, shape=None, name=None)
    

    Official documentation.