占位符在 TensorFlow 中被识别为张量。
isinstance(tf.placeholder("float", []), tf.Tensor)
返回 True
有没有办法专门检查张量是否是占位符?像这样的东西:
isinstance(tf.placeholder("float", []), tf.Placeholder)
不幸的是,对于我正在构建的 API,tf.Placeholder
不是 TensorFlow 中的实际实例类型。
最佳答案
你可以用op.type
来检查它:
assert tf.placeholder("float", []).op.type == 'Placeholder'
关于python - 检查 Tensor 是否为 Placeholder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52471675/