gpt4 book ai didi

python - Tensorflow 无法分配设备进行操作

转载 作者:太空宇宙 更新时间:2023-11-03 11:13:57 25 4
gpt4 key购买 nike

我正在尝试运行 NVidia's face generating demo在我的电脑上。我使用的是 Windows 10。我已经下载了源代码,并尝试按照页面下方的步骤进行操作。我已经为我的 GTX1060 安装了最新的 NVidia 驱动程序,它应该是支持 cuda 功能的设备。我已经安装了 Cuda 工具包,以及 TensorFlow 需要的 cuDNN SDK。

但是,当运行 import_example.py 脚本时,出现以下错误。谁能告诉我我做错了什么?

   2019-03-19 20:16:26.112574: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
WARNING:tensorflow:From C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
Traceback (most recent call last):
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 1334, in _do_call
return fn(*args)
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 1319, in _run_fn
options, feed_dict, fetch_list, target_list, run_metadata)
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 1407, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation G_paper_1/Run/G_paper_1/latents_in: {{node G_paper_1/Run/G_paper_1/latents_in}}was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0 ]. Make sure the device specification refers to a valid device. The requested device appears to be a GPU, but CUDA is not enabled.
[[{{node G_paper_1/Run/G_paper_1/latents_in}}]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File ".\import_example.py", line 21, in <module>
images = Gs.run(latents, labels)
File "C:\Users\me\Desktop\progressive_growing_of_gans-master\tfutil.py", line 668, in run
mb_out = tf.get_default_session().run(out_expr, dict(zip(self.input_templates, mb_in)))
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 929, in run
run_metadata_ptr)
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 1152, in _run
feed_dict_tensor, options, run_metadata)
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 1328, in _do_run
run_metadata)
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 1348, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation G_paper_1/Run/G_paper_1/latents_in: node G_paper_1/Run/G_paper_1/latents_in (defined at C:\Users\me\Desktop\progressive_growing_of_gans-master\tfutil.py:508) was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0 ]. Make sure the device specification refers to a valid device. The requested device appears to be a GPU, but CUDA is not enabled.
[[node G_paper_1/Run/G_paper_1/latents_in (defined at C:\Users\me\Desktop\progressive_growing_of_gans-master\tfutil.py:508) ]]

Caused by op 'G_paper_1/Run/G_paper_1/latents_in', defined at:
File ".\import_example.py", line 21, in <module>
images = Gs.run(latents, labels)
File "C:\Users\me\Desktop\progressive_growing_of_gans-master\tfutil.py", line 645, in run
out_expr = self.get_output_for(*in_split[gpu], return_as_list=True, **dynamic_kwargs)
File "C:\Users\me\Desktop\progressive_growing_of_gans-master\tfutil.py", line 508, in get_output_for
named_inputs = [tf.identity(expr, name=name) for expr, name in zip(in_expr, self.input_names)]
File "C:\Users\me\Desktop\progressive_growing_of_gans-master\tfutil.py", line 508, in <listcomp>
named_inputs = [tf.identity(expr, name=name) for expr, name in zip(in_expr, self.input_names)]
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\util\dispatch.py", line 180, in wrapper
return target(*args, **kwargs)
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\ops\array_ops.py", line 81, in identity
ret = gen_array_ops.identity(input, name=name)
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 4537, in identity
"Identity", input=input, name=name)
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 788, in _apply_op_helper
op_def=op_def)
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\util\deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\ops.py", line 3300, in create_op
op_def=op_def)
File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\ops.py", line 1801, in __init__
self._traceback = tf_stack.extract_stack()

InvalidArgumentError (see above for traceback): Cannot assign a device for operation G_paper_1/Run/G_paper_1/latents_in: node G_paper_1/Run/G_paper_1/latents_in (defined at C:\Users\me\Desktop\progressive_growing_of_gans-master\tfutil.py:508) was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0 ]. Make sure the device specification refers to a valid device. The requested device appears to be a GPU, but CUDA is not enabled.
[[node G_paper_1/Run/G_paper_1/latents_in (defined at C:\Users\me\Desktop\progressive_growing_of_gans-master\tfutil.py:508) ]]

最佳答案

Cannot assign a device for operation G_paper_1/Run/G_paper_1/latents_in: {{node G_paper_1/Run/G_paper_1/latents_in}}was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0 ]

你有没有安装tensorflow或者tensorflow-gpu?如果您想使用 GPU,则后者是您想要的。


也可能是版本兼容性问题。首先,检查你的 nvidia 驱动程序是否安装了:nvidia-smi,你应该得到如下内容:

Mon Apr 1 12:30:02 2019       
+------------------------------------------------------+
| NVIDIA-SMI 3.295.41 Driver Version: 295.41 |
|-------------------------------+----------------------+----------------------+
| Nb. Name | Bus Id Disp. | Volatile ECC SB / DB |
| Fan Temp Power Usage /Cap | Memory Usage | GPU Util. Compute M. |
|===============================+======================+======================|
| 0. GeForce GTX 580 | 0000:25:00.0 N/A | N/A N/A |
| 54% 70 C N/A N/A / N/A | 25% 383MB / 1535MB | N/A Default |
|-------------------------------+----------------------+----------------------|
| Compute processes: GPU Memory |
| GPU PID Process name Usage |
|=============================================================================|
| 0. Not Supported |
+-----------------------------------------------------------------------------+

之后,使用 nvcc --version 检查您的 cuda 版本。示例:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Mon_Apr__1_12:34:01_CDT_2016
Cuda compilation tools, release 8.0, V8.0.44

最后,检查您是否安装了 python/tensorflow/cuda 的兼容版本。为此,使用这个 table作为引用似乎对大多数人都有效。


安装完驱动不要忘记重启!

关于python - Tensorflow 无法分配设备进行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55248631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com