StyleGAN图像生成不起作用,TensorFlow没有看到GPU

时间:2019-12-05 16:30:34

标签: python tensorflow machine-learning gpu

重新安装Ubuntu 18.04之后,我无法再使用StyleGAN代理生成映像。我收到的错误消息是InvalidArgumentError: Cannot assign a device for operation Gs_1/_Run/Gs/latents_in: {{node Gs_1/_Run/Gs/latents_in}}was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0, /job:localhost/replica:0/task:0/device:XLA_GPU:0 ]. Make sure the device specification refers to a valid device.

我有CUDA 10.1,我的驱动程序版本是418.87。用于conda环境的yml文件可用here。我使用pip安装了tensorflow-gpu == 1.14。

Here yopu可以找到我用来生成图像的jupyter笔记本。

如果我按照建议使用命令检查可用资源

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

我得到了答案

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 7185754797200004029
, name: "/device:XLA_GPU:0"
device_type: "XLA_GPU"
memory_limit: 17179869184
locality {
}
incarnation: 18095173531080603805
physical_device_desc: "device: XLA_GPU device"
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 10470458648887235209
physical_device_desc: "device: XLA_CPU device"
]

任何有关解决此问题的建议都非常欢迎!

1 个答案:

答案 0 :(得分:0)

可能是因为当图形单元的名称实际上为GPU:0时,TensorFlow正在寻找XLA_GPU:0来分配用于操作的设备。

您可以尝试在打开会话时使用软放置,以便TensorFlow在运行时使用任何现有的GPU(或任何其他受支持的设备(如果不可用)):

#  using allow_soft_placement=True
se = tf.Session(config=tf.ConfigProto(allow_soft_placement=True))