使用TensorFlow时运行代码段时出现属性错误

时间:2019-03-01 06:58:19

标签: python python-3.x python-2.7 tensorflow

DeepMind开源IMPALA的实现:https://github.com/deepmind/scalable_agent

对于并行性,它们包装了一种基于类的机制,该文件为:https://github.com/deepmind/scalable_agent/blob/master/py_process.py

文件开头有一个代码段:

  class Zeros(object):
    def __init__(self, dim0):
      self._dim0 = dim0
    def compute(self, dim1):
      return np.zeros([self._dim0, dim1], dtype=np.int32)
    @staticmethod
    def _tensor_specs(method_name, kwargs, constructor_kwargs):
      dim0 = constructor_kwargs['dim0']
      dim1 = kwargs['dim1']
      if method_name == 'compute':
        return tf.contrib.framework.TensorSpec([dim0, dim1], tf.int32)
  with tf.Graph().as_default():
    p = py_process.PyProcess(Zeros, 1)
    result = p.proxy.compute(2)
    with tf.train.SingularMonitoredSession(
        hooks=[py_process.PyProcessHook()]) as session:
      print(session.run(result))  # Prints [[0, 0]].

但是,当我尝试运行它时,出现以下错误:

2019-03-01 17:37:16.260732: W tensorflow/core/framework/op_kernel.cc:1389] Unknown: AttributeError: 'Zeros' object has no attribute 'b'compute''
Traceback (most recent call last):

  File "/home/yuming/tensorflow/lib/python3.6/site-packages/tensorflow/python/ops/script_ops.py", line 207, in __call__
    ret = func(*args)

  File "/data/yuming/eeg-dpg/py_process.py", line 89, in py_call
    raise result

AttributeError: 'Zeros' object has no attribute 'b'compute''

我只是想知道有人对此有想法吗?

我在Red Hat 7.5上使用TensorFlow 1.13.1,Python 3.6.3运行代码段。

我怀疑编码之间可能存在不匹配,但不确定。

感谢您的帮助。

0 个答案:

没有答案