检查 Tensor 是否为 Placeholder?

Check if Tensor is Placeholder?

占位符在 TensorFlow 中被识别为张量。

isinstance(tf.placeholder("float", []), tf.Tensor) returns True

有没有办法专门检查张量是否是占位符?类似于:

isinstance(tf.placeholder("float", []), tf.Placeholder)

不幸的是,对于我正在构建的 API,tf.Placeholder 不是 TensorFlow 中的实际实例类型。

你可以用op.type查看:

assert tf.placeholder("float", []).op.type == 'Placeholder'