我使用具有tensorflow和多个gpu配置的python 3,我尝试使用下面的例子插入多个gpu模型,我创建了一个模型,它很好,编译、运行和训练,但是当我尝试在模型编译之前添加这个模型:
from tensorflow.python.keras.utils import multi_gpu_model
model = multi_gpu_model(model, gpus=2, cpu_merge=False)我知道这个错误
TypeError: int()参数必须是字符串或数字,而不是'TensorShape‘
注意,我使用的是tf和急切的eval。
我发现这指的是使用keras.utils.multi_gpu_model而不是tf.python.keras.utils.multi_gpu_model,但是当我这样做时,我得到了以下错误:
我在这里错过了什么?
第217行,在multi_gpu_model with tf.device(x.device)中: AttributeError:'DeferredTensor‘对象没有属性’DeferredTensor‘
模型的代码是
model = Sequential()
model.add(Flatten(input_shape=(128, 128, 3)))
model.add(Dense(100, activation="sigmoid"))
model.add(Dense(100, activation="sigmoid"))更新:这可能是gpu的id问题吗?当我试图创建一个multi_gpu_model而不指定gpus时,gpus使用以下代码进行计数:
model = multi_gpu_model(model)我得到以下错误:
ValueError:要用
gpus=3调用multi_gpu_model,我们希望有以下设备可用:'/cpu:0‘、'/gpu:0’、'/gpu:1‘、'/gpu:2’。然而,这台机器只有:'/cpu:0','/xla_cpu:0','/xla_gpu:0','/gpu:0','/gpu:1‘。试着降低gpus
我只有两个GPU,它们连接到pci端口# 1和2(我不能改变这一点,我在板上没有连接到端口0所需的适当空间),当指定两个GPU时,tf会尝试获得GPU 0和GPU 1,这有什么意义吗?我可以另加说明吗?
谢谢
发布于 2019-07-01 01:43:49
我遇到了同样的错误,我通过将os.environ[CUDA_VISIBLE_DEVICES]='1, 3'更改为os.environ[CUDA_VISIBLE_DEVICES]="1, 3"来解决它--如果您已经这样做了,您可能需要检查这个非常简单的代码:不要忘记将gpu设备更改为您的。
from keras.utils import multi_gpu_model
from keras import Input, Model
from keras.layers import Conv2D
import os
#if you have gpu 1,3 avaliable
os.environ["CUDA_VISIBLE_DEVICES"]="1,3"
x = Input((64,64,3))
out = Conv2D(64,(3,3),padding='same')(x)
model = Model(x,out)
#model = deeplabv3_nopadding.Deeplabv3()
model = multi_gpu_model(model,gpus=2)将产生以下结果:
使用TensorFlow后端。2019-07-01 09:40:25.971722: I tensorflow/core/platform/cpu_feature_guard.cc:141]您的CPU支持以下指令: SSE4.1 SSE4.2、SSE4.2 AVX AVX2 AVX2 2019-07-01 :40:26.277398:我找到了具有属性的设备0:名称:泰坦Xp专业:6小调:1 memoryClockRate(GHz):1.582 pciBusID: 0000:03:00.0 totalMemory: 11.90GiB freeMemory: 11.74GiB 2019-07-01 :40:40:26.586391:我找到了具有属性的设备1:名称:泰坦Xp专业:6小修:1 memoryClockRate(GHz):1.582 pciBusID: 0000:83:00.0 totalMemory: 11.74GiB 2019-07-01 09:40:26.586477: I tensorflow/core/runtime_GHz/gpu/gpu/gpu_device.cc:1511[添加可见gpu设备: 0,1 2019-07-01 09:40:27.377910: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982]设备互连StreamExecutor与强度1边缘矩阵: 2019-07-01 :40:27.377970:I tensorflow/core/common_runtime/gpu/gpu_device.cc:988] 0 1 2019-07-01 :40:27.377977:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0:N N 2019-07-01 09:40:27.377981: i tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 1: n N 2019-07-01 09:40:27.378592: i tensorflow/core/common_runtime/gpu/gpu_device.cc:1115]创建了TensorFlow设备(/job:localhost/TensorFlow:0/TensorFlow:0/ device :0具有11355 MB内存) ->物理GPU (设备: 0,名称: TITAN Xp,pci总线id: 0000:03:00.0,计算能力: 6.1) 2019-07-01 :40:27.382844:i tensorflow/core/common_runtime/gpu/gpu_device.cc:1115]创建了TensorFlow设备(/job:localhost/TensorFlow:0/TensorFlow:0/ device : GPU :1 with 11355 MB内存) ->物理GPU(设备: 1,名称: TITAN Xp,pci总线id: 0000:83:00.0,计算能力: 6.1)
https://stackoverflow.com/questions/54440168
复制相似问题