在 google colabs python 中替换 2.5.0 版 tensorflows 占位符的最佳方法是什么?

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

我正在做一个项目,并试图用有效的代码替换这段代码。我正在使用 2.5.0 版的 tensorflow 并遇到以下错误。 AttributeError: 模块 'tensorflow' 没有属性 '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))

试试这个

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

官方documentation.