【问题标题】:Tensorflow Check failed: work_element_count > 0TensorFlow 检查失败:work_element_count > 0
【发布时间】:2019-01-13 05:17:49
【问题描述】:

有人知道如何处理 Tensorflow 'work_element_count' 错误吗?

F ./tensorflow/core/util/cuda_launch_config.h:127] 检查失败:work_element_count > 0 (0 vs. 0) 中止(核心转储)

这是我的部分源代码:

class DiscriminatorModel:
    def __init__(self, session, some_parameters):
        self.sess = session
        self.parameters = some_parameters

    def build_feed_dict(self, input_frames, gt_output_frames, generator):
        feed_dict = {}
        batch_size = np.shape(gt_output_frames)[0]
        print(batch_size) # 1

        print(np.shape(generator.input_frames_train))   # (?,7,32,32,32,1)
        print(np.shape(input_frames))                   # (1,7,32,32,32,1)
        print(np.shape(generator.gt_frames_train))      # (?,7,32,32,32,1)
        print(np.shape(gt_output_frames))               # (1,7,32,32,32,1)

        g_feed_dict={generator.input_frames_train:input_frames,
                     generator.gt_frames_train:gt_output_frames}

        def getshape(d):
            if isinstance(d, dict):
                return {k:getshape(d[k]) for k in d}
            else:
                return None
        print("g_feed_dict shape :", getshape(g_feed_dict),"\n")
        # {<tf.Tensor 'generator/data/Placeholder:0' shape=(?, 32, 32, 32, 1) dtype=float32>: None, <tf.Tensor 'generator/data/Placeholder_1:0' shape=(?, 32, 32, 32, 1) dtype=float32>: None}

        print(sys.getsizeof(generator.scale_preds_train))    # 96
        print(sys.getsizeof(g_feed_dict))                    # 288


        # error occurs here.
        g_scale_preds = self.sess.run(generator.scale_preds_train, feed_dict=g_feed_dict)
        # F ./tensorflow/core/util/cuda_launch_config.h:127] Check failed: work_element_count > 0 (0 vs. 0)
        # Aborted (core dumped)

    def train_step(self, batch, generator):
        print(np.shape(batch))    # [1, 7, 32, 32, 32, 2]
        input_frames = batch[:, :, :, :, :, :-1]
        gt_output_frames = batch[:, :, :, :, :, -1:]

        feed_dict = self.build_feed_dict(input_frames, gt_output_frames, generator)

class GeneratorModel:
    def __init__(self, session, some_parameters):
        self.sess = session
        self.parameters = some_parameters

        self.input_frames_train = tf.placeholder(
            tf.float32, shape=[None, 7, 32, 32, 32, 1])
        self.gt_frames_train = tf.placeholder(
            tf.float32, shape=[None, 7, 32, 32, 32, 1])

        self.input_frames_test = tf.placeholder(
            tf.float32, shape=[None, 7, 32, 32, 32, 1])
        self.gt_frames_test = tf.placeholder(
            tf.float32, shape=[None, 7, 32, 32, 32, 1])

        self.scale_preds_train = []
        for p in range(4):
            # scale size, 4 --> 8 --> 16 --> 32
            sc = 4*(2**p)
            # this passes tf.Tensor array of shape (1,7,sc,sc,sc,1)
            train_preds = calculate(self.width_train,
                                    self.height_train,
                                    self.depth_train,
                                    ...)
            self.scale_preds_train.append(train_preds

        # [ <..Tensor shape=(1,7,4,4,4,1) ....>,
        #   <..Tensor shape=(1,7,8,8,8,1) ....>,
        #   <..Tensor shape=(1,7,16,16,16,1)..>,
        #   <..Tensor shape=(1,7,32,32,32,1)..> ]
        print(self.scale_preds_train)

sess = tf.Session()
d_model = DiscriminatorModel(sess, some_parameters)
g_model = GeneratorModel(sess, some_parameters)
sess.run(tf.global_variables_initializer())

# this returns numpy array of shape [1,7,32,32,32,2]
batch = get_batch()

# trouble here.
d_model.train_step(batch, g_model)

我看到了一些关于以下方面的建议:

  • 使用 CUDA 9.0 / cuDNN 7.0 / tensorflow-gpu 1.7.0(-->我已经在使用这些了)
  • 检查批次的大小是否大于 0(--> 似乎是。)
  • 不要使用比批次中的样本数量更多的 gpus(--> 我不使用)

我在其中 5 个中使用单个 11GB gpu,指定为

~$ CUDA_VISIBLE_DEVICES=2 python3 foo.py

并且批量大小为 1。 谁能告诉我遗漏的地方或我做错了什么?

编辑 1。

我发现了一个解决此错误的案例。如果我对输入进行一些修改,例如

# ... previous code does not change
print(sys.getsizeof(g_feed_dict))                    # 288
temp_index = 0
temp_input = [generator.scale_preds_train[temp_index],
              generator.scale_preds_train[temp_index],
              generator.scale_preds_train[temp_index],
              generator.scale_preds_train[temp_index]]
# this <temp_input> does not raise error here.
# however temp_index > 0 don't work.
g_scale_preds = self.sess.run(temp_input, feed_dict=g_feed_dict)

这使得输入传递给sess.run,其形状类似于

[(1,7,4,4,4,1), (1,7,4,4,4,1), (1,7,4,4,4,1), (1,7,4,4,4,1)]

这应该是(最初)缩放形状的列表,例如 [(1,7,4,4,4,1), (1,7,8,8,8,1), (1,7,16, 16,16,1), (1,7,32,32,32,1)]。 此外,字典feed_dict 中的数组具有形状 (1,7,32,32,32,1).

似乎错误来自 tensorflow-gpu 试图到达错误的数组索引(实际上未分配内存),因此“工作元素计数为 0”(但我还不确定)。

我不明白为什么temp_index &gt; 0(例如123)会抛出同样的问题 Check failed 错误,而 0 是唯一没有错误的形状。

编辑 2。

在我将 gpu 从 TITAN Xp 更改为 GeForce GTX 后,错误日志显示

浮点异常(核心转储)

在相同的代码 (sess.run)。

【问题讨论】:

  • 这个错误与CUDA无关,是Tensorflow内部的问题,我已经相应地编辑了问题
  • @talonmies 谢谢!现在我发现它与 cuda 无关。仍然遭受着 TensorFlow 的困扰。我还编辑了一些内容。

标签: python-3.x tensorflow deep-learning gpu


【解决方案1】:

在我的例子中,其中一个卷积层有 0 个输出特征图,这导致了这个问题。

【讨论】:

    【解决方案2】:

    现在我已经解决了..

    正如 GTX 错误日志告诉我的那样,有些东西变成了零,实际上是一个分母(因此与上面的所有代码都无关)。上次调试时的规格如下:

    CUDA 8.0 / TensorFlow 1.8.0

    当然是 GeForce GTX。我认为日志显示不同(并且稍微更详细)是因为版本而不是实际的 GPU,即使不同的版本本身并没有真正解决。

    【讨论】:

    • 并且肯定与以前的版本(cuda 9.0 / tf 1.8)配合得很好。我认为这些版本在这种情况下无关紧要,除了显示不同的日志。
    【解决方案3】:

    我在 Colab 上训练模型时遇到了同样的问题。问题是“num_classes”,在配置文件中它设置为 2,而我的模型有 36 个类。

    您应该考虑注意配置文件中的 num_classes。

    【讨论】:

      猜你喜欢
      • 2022-09-28
      • 1970-01-01
      • 2021-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-28
      相关资源
      最近更新 更多