【发布时间】:2018-05-06 11:37:11
【问题描述】:
在我的代码中,我想检查返回的对象类型是否为EagerTensor:
import tensorflow as tf
import inspect
if __name__ == '__main__':
tf.enable_eager_execution()
iterator = tf.data.Dataset.from_tensor_slices([[1, 2], [3, 4]]).__iter__()
elem = iterator.next()
print(type(elem))
print(inspect.getmodule(elem))
assert type(elem) == tf.python.framework.ops.EagerTensor
但结果是:
<class 'EagerTensor'>
<module 'tensorflow.python.framework.ops' from '/home/antek/anaconda3/envs/mnist_identification/lib/python3.6/site-packages/tensorflow/python/framework/ops.py'>
Traceback (most recent call last):
File "/home/antek/.PyCharm2018.1/config/scratches/scratch_4.py", line 11, in <module>
assert type(elem) == tf.python.framework.ops.EagerTensor
AttributeError: module 'tensorflow' has no attribute 'python'
这里:AttributeError: module 'tensorflow' has no attribute 'python' 我发现 tensorflow 故意删除了它对 python 模块的引用。那么如何检查我的对象是否是 EagerTensor 实例?
【问题讨论】:
标签: tensorflow