我在“ keras.models.Sequential”模型上实现了“ keras.utils.training_utils.multi_gpu_model”功能。但这没有用。奇怪的是Xception模型(keras.applications.Xception)正常工作。错误消息如下。
File "cifar10_test.py", line 18, in <module>
multi_model = multi_gpu_model(model, gpus=3)
File "/.../my-env1/lib/python3.5/site-packages/keras/utils/training_utils.py", line 155, in multi_gpu_model
for i in range(len(model.outputs)):
TypeError: object of type 'NoneType' has no len()
这是我的代码。
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Convolution2D, BatchNormalization
from keras.layers import Dense, Dropout, Flatten
from keras.utils.training_utils import multi_gpu_model
import numpy as np
from keras.datasets import cifar10
import tensorflow as tf
def cnn_model1():
model = Sequential()
model.add(Dense(10, activation='softmax'))
return model
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
model = cnn_model1()
multi_model = multi_gpu_model(model, gpus=3)
multi_model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
multi_model.fit(x_train, y_train, validation_data=(x_test, y_test), nb_epoch=3, batch_size=32, verbose=1)
仅供参考,我正在使用tensorflow-gpu-1.9.0,Keras-2.2.0,python-3.5.2和4 Quadro M6000 24GB GPU。
有人可以给我建议吗?