python - 检查 Tensor 是否为 Placeholder?

标签 python tensorflow tensor

占位符在 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/

相关文章:

python - Python 3.x 和 Python 2.7 中 dict.values() 和 dict.keys() 相等之间的行为不一致

python - tensorflow 二维直方图

python - .view() 在 PyTorch 中做了什么?

python - matmul 和通常的张量乘法有区别吗

python - 如何以数值稳定的方式计算梯度

pytorch - 我怎样才能制作 torch 张量?

python - 分词高棉语的可行解决方案?

python - 使用 subprocess 模块会释放 python GIL 吗?

python - Matplotlib-Imported PNG 不会在 3D 绘图中显示

machine-learning - tensorflow :sigmoid_cross_entropy_with_logits