【发布时间】: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 > 0(例如1、2、3)会抛出同样的问题
Check failed 错误,而 0 是唯一没有错误的形状。
编辑 2。
在我将 gpu 从 TITAN Xp 更改为 GeForce GTX 后,错误日志显示
浮点异常(核心转储)
在相同的代码 (sess.run)。
【问题讨论】:
-
这个错误与CUDA无关,是Tensorflow内部的问题,我已经相应地编辑了问题
-
@talonmies 谢谢!现在我发现它与 cuda 无关。仍然遭受着 TensorFlow 的困扰。我还编辑了一些内容。
标签: python-3.x tensorflow deep-learning gpu