TensorFlow:没有可用的GPU设备支持的内核

时间:2018-07-17 17:17:15

标签: python tensorflow

下面的代码是我模型的一部分,正在尝试进行线性插值,类似于numpy.interp()。 在我的模型中,t的形状为(64,64)。 x的形状为(91,)。 y的形状为(91,)。

def tf_interp(b, x, y):
    xaxis_pad = tf.concat([[tf.minimum(b, tf.gather(x, 0))], x, [tf.maximum(b, tf.gather(x, height_sino - 1))]],
                          axis=0)
    yaxis_pad = tf.concat([[0.0], y, [0.0]], axis=0)

    cmp = tf.cast(b > xaxis_pad, dtype=tf.float32)
    diff = cmp[1:] - cmp[:-1]
    idx = tf.argmin(diff)

    # Interpolate
    alpha = (b - xaxis_pad[idx]) / (xaxis_pad[idx + 1] - xaxis_pad[idx])
    res = alpha * yaxis_pad[idx + 1] + (1 - alpha) * yaxis_pad[idx]

    #def f1(): return 0.0

    #def f2(): return alpha * yaxis_pad[idx + 1] + (1 - alpha) * yaxis_pad[idx]

    #with tf.device('/gpu:0'):
        #res = tf.cond(pred=tf.is_nan(res), true_fn=f1, false_fn=f2)

    return res


def tf_interpolation(t, x, y):
    t1 = tf.reshape(t, [-1, ])
    t_return = tf.map_fn(lambda b: tf_interp(b, x, y), t1, dtype=tf.float32, name='t_return')
    t_return = tf.reshape(t_return, [width, height])
    return t_return

当我尝试为模型定义Adam优化器时。发生以下错误:

Traceback (most recent call last):
  File "net_training_new.py", line 411, in <module>
    sess.run(tf.global_variables_initializer())
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 900, in run
    run_metadata_ptr)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1135, in _run
    feed_dict_tensor, options, run_metadata)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1316, in _do_run
    run_metadata)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1335, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation 'gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc': Could not satisfy explicit device specification '/device:GPU:0' because no supported kernel for GPU devices is available.
Colocation Debug Info:
Colocation group had the following types and devices: 
TensorArrayWriteV3: GPU CPU 
Add: GPU CPU 
Range: GPU CPU 
Const: GPU CPU 
Enter: GPU CPU 
StackPushV2: GPU CPU 
StackV2: GPU CPU 
TensorArrayV3: GPU CPU 
TensorArrayScatterV3: GPU CPU 
StackPopV2: CPU 
TensorArrayGatherV3: GPU CPU 
Identity: GPU CPU 
TensorArrayGradV3: GPU CPU 
Exit: GPU CPU 
TensorArrayReadV3: GPU CPU 
TensorArraySizeV3: GPU CPU 

Colocation members and user-requested devices:
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Const (Const) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc (StackV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2/Enter (Enter) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter (Enter) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/Const (Const) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/f_acc (StackV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/StackPopV2/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Const_1 (Const) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc_1 (StackV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2_1/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter_1 (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Const (Const) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc (StackV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2 (StackPopV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter_1 (Enter) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/StackPopV2 (StackPopV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2_1 (StackPopV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2 (StackPopV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3 (TensorArrayGradV3) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/gradient_flow (Identity) 
  generator_model/backprojected/while/t_return/TensorArrayStack/range/delta (Const) 
  generator_model/backprojected/while/t_return/TensorArrayStack/range/start (Const) 
  generator_model/backprojected/while/t_return/TensorArray_1 (TensorArrayV3) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPushV2 (StackPushV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPushV2 (StackPushV2) 
  generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3/Enter (Enter) /device:GPU:0
  generator_model/backprojected/while/t_return/while/Exit_1 (Exit) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPushV2_1 (StackPushV2) 
  generator_model/backprojected/while/t_return/TensorArrayStack/TensorArraySizeV3 (TensorArraySizeV3) 
  generator_model/backprojected/while/t_return/TensorArrayStack/range (Range) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/StackPushV2 (StackPushV2) 
  generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3 (TensorArrayGatherV3) 
  generator_model/backprojected/while/t_return/while/add_7 (Add) /device:GPU:0
  generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3 (TensorArrayWriteV3) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3 (TensorArrayScatterV3) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3 (TensorArrayGradV3) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/gradient_flow (Identity) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayReadV3 (TensorArrayReadV3) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/tuple/control_dependency (Identity) 
  gradients_1/generator_model/backprojected/while/t_return/while/add_7_grad/tuple/control_dependency_1 (Identity) 
  gradients_1/generator_model/backprojected/while/t_return/while/add_7_grad/tuple/control_dependency (Identity) 

Registered kernels:
  device='GPU'
  device='CPU'

     [[Node: gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc = StackV2[_class=["loc:@generator_model/backprojected/while/t_return/TensorArray_1", "loc:@generator_model/backprojected/while/t_return/while/add_7"], elem_type=DT_RESOURCE, stack_name="", _device="/device:GPU:0"](gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Const)]]

Caused by op 'gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc', defined at:
  File "net_training_new.py", line 397, in <module>
    g_trainer = tf.train.AdamOptimizer(learning_rate=lr).minimize(g_loss, var_list=gen_variables)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/training/optimizer.py", line 414, in minimize
    grad_loss=grad_loss)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/training/optimizer.py", line 526, in compute_gradients
    colocate_gradients_with_ops=colocate_gradients_with_ops)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 494, in gradients
    gate_gradients, aggregation_method, stop_gradients)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 636, in _GradientsHelper
    lambda: grad_fn(op, *out_grads))
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 385, in _MaybeCompile
    return grad_fn()  # Exit early
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 636, in <lambda>
    lambda: grad_fn(op, *out_grads))
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/tensor_array_grad.py", line 130, in _TensorArrayWriteGrad
    .grad(source=grad_source, flow=flow))
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/tensor_array_ops.py", line 849, in grad
    return self._implementation.grad(source, flow=flow, name=name)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/tensor_array_ops.py", line 241, in grad
    handle=self._handle, source=source, flow_in=flow, name=name)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 6229, in tensor_array_grad_v3
    name=name)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
    op_def=op_def)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1760, in __init__
    self._control_flow_post_processing()
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1771, in _control_flow_post_processing
    self._control_flow_context.AddOp(self)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2445, in AddOp
    self._AddOpInternal(op)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2466, in _AddOpInternal
    real_x = self.AddValue(x)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2398, in AddValue
    real_val = grad_ctxt.grad_state.GetRealValue(val)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1155, in GetRealValue
    history_value = cur_grad_state.AddForwardAccumulator(cur_value)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1022, in AddForwardAccumulator
    max_size=max_size, elem_type=value.dtype.base_dtype, name="f_acc")
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 5033, in stack_v2
    stack_name=stack_name, name=name)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
    op_def=op_def)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1718, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

...which was originally created as op 'generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3', defined at:
  File "net_training_new.py", line 365, in <module>
    Gz = generator(LD_placeholder)
  File "net_training_new.py", line 212, in generator
    backprojected = tf.map_fn(lambda s: tf_interpolation(t, x, s[:, i]), radon_filtered, name='backprojected')
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 423, in map_fn
    swap_memory=swap_memory)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 3224, in while_loop
    result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2956, in BuildLoop
    pred, body, original_loop_vars, loop_vars, shape_invariants)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2893, in _BuildLoop
    body_result = body(*packed_vars_for_body)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 413, in compute
    packed_fn_values = fn(packed_values)
  File "net_training_new.py", line 212, in <lambda>
    backprojected = tf.map_fn(lambda s: tf_interpolation(t, x, s[:, i]), radon_filtered, name='backprojected')
  File "net_training_new.py", line 79, in tf_interpolation
    t_return = tf.map_fn(lambda b: tf_interp(b, x, y), t1, dtype=tf.float32, name='t_return')
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 423, in map_fn
    swap_memory=swap_memory)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 3224, in while_loop
    result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2956, in BuildLoop
    pred, body, original_loop_vars, loop_vars, shape_invariants)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2893, in _BuildLoop
    body_result = body(*packed_vars_for_body)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 416, in compute
    tas = [ta.write(i, value) for (ta, value) in zip(tas, flat_fn_values)]
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 416, in <listcomp>
    tas = [ta.write(i, value) for (ta, value) in zip(tas, flat_fn_values)]
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/util/tf_should_use.py", line 118, in wrapped
    return _add_should_use_warning(fn(*args, **kwargs))
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/tensor_array_ops.py", line 879, in write
    return self._implementation.write(index, value, name=name)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/util/tf_should_use.py", line 118, in wrapped
    return _add_should_use_warning(fn(*args, **kwargs))
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/tensor_array_ops.py", line 278, in write
    name=name)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 7344, in tensor_array_write_v3
    flow_in=flow_in, name=name)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
    op_def=op_def)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1718, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc': Could not satisfy explicit device specification '/device:GPU:0' because no supported kernel for GPU devices is available.
Colocation Debug Info:
Colocation group had the following types and devices: 
TensorArrayWriteV3: GPU CPU 
Add: GPU CPU 
Range: GPU CPU 
Const: GPU CPU 
Enter: GPU CPU 
StackPushV2: GPU CPU 
StackV2: GPU CPU 
TensorArrayV3: GPU CPU 
TensorArrayScatterV3: GPU CPU 
StackPopV2: CPU 
TensorArrayGatherV3: GPU CPU 
Identity: GPU CPU 
TensorArrayGradV3: GPU CPU 
Exit: GPU CPU 
TensorArrayReadV3: GPU CPU 
TensorArraySizeV3: GPU CPU 

Colocation members and user-requested devices:
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Const (Const) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc (StackV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2/Enter (Enter) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter (Enter) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/Const (Const) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/f_acc (StackV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/StackPopV2/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Const_1 (Const) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc_1 (StackV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2_1/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter_1 (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Const (Const) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc (StackV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2 (StackPopV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter_1 (Enter) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/StackPopV2 (StackPopV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2_1 (StackPopV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2 (StackPopV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3 (TensorArrayGradV3) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/gradient_flow (Identity) 
  generator_model/backprojected/while/t_return/TensorArrayStack/range/delta (Const) 
  generator_model/backprojected/while/t_return/TensorArrayStack/range/start (Const) 
  generator_model/backprojected/while/t_return/TensorArray_1 (TensorArrayV3) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPushV2 (StackPushV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPushV2 (StackPushV2) 
  generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3/Enter (Enter) /device:GPU:0
  generator_model/backprojected/while/t_return/while/Exit_1 (Exit) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPushV2_1 (StackPushV2) 
  generator_model/backprojected/while/t_return/TensorArrayStack/TensorArraySizeV3 (TensorArraySizeV3) 
  generator_model/backprojected/while/t_return/TensorArrayStack/range (Range) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/StackPushV2 (StackPushV2) 
  generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3 (TensorArrayGatherV3) 
  generator_model/backprojected/while/t_return/while/add_7 (Add) /device:GPU:0
  generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3 (TensorArrayWriteV3) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3 (TensorArrayScatterV3) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3 (TensorArrayGradV3) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/gradient_flow (Identity) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayReadV3 (TensorArrayReadV3) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/tuple/control_dependency (Identity) 
  gradients_1/generator_model/backprojected/while/t_return/while/add_7_grad/tuple/control_dependency_1 (Identity) 
  gradients_1/generator_model/backprojected/while/t_return/while/add_7_grad/tuple/control_dependency (Identity) 

Registered kernels:
  device='GPU'
  device='CPU'

     [[Node: gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc = StackV2[_class=["loc:@generator_model/backprojected/while/t_return/TensorArray_1", "loc:@generator_model/backprojected/while/t_return/while/add_7"], elem_type=DT_RESOURCE, stack_name="", _device="/device:GPU:0"](gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Const)]]

它说问题出在这行上

t_return = tf.map_fn(lambda b: tf_interp(b, x, y), t1, dtype=tf.float32, name='t_return') 

TensorFlow无法为该操作分配设备,因为没有可用的GPU设备支持的内核。

我可以完美地在CPU上运行它。 为什么我不能在GPU上运行此行?

1 个答案:

答案 0 :(得分:6)

尝试一下,看看是否可行:

with tf.device('/device:GPU:2'):
    t1 = tf.reshape(t, [-1, ])
    t_return = tf.map_fn(lambda b: tf_interp(b, x, y), t1, dtype=tf.float32, name='t_return')
    t_return = tf.reshape(t_return, [width, height])
    return t_return

此外,尝试使用这段代码来初始化会话对象。

with tf.Session(config=tf.ConfigProto(allow_soft_placement=True, \
                  log_device_placement=True)) as sess:
    sess.run(tf.global_variables_initializer())
    ...
  

如果您指定的设备不​​存在,您将得到   InvalidArgumentError:

> InvalidArgumentError: Invalid argument: Cannot assign a device to node
> 'b': Could not satisfy explicit device specification '/device:GPU:2'  
> [[Node: b = Const[dtype=DT_FLOAT, value=Tensor<type: float shape:
> [3,2]    values: 1 2 3...>, _device="/device:GPU:2"]()]]
  

如果您希望TensorFlow 自动选择现有的和   受支持的设备以运行该操作(如果指定了该设备)   不存在,您可以在allow_soft_placement中将True设置为{   创建会话时配置选项。