Improve docs for multi_gpu_model.
@@ -58,8 +58,11 @@ def multi_gpu_model(model, gpus):
width = 224
num_classes = 1000
- # Instantiate the base model
- # (here, we do it on CPU, which is optional).
+ # Instantiate the base model (or "template" model).
+ # We recommend doing this with under a CPU device scope,
+ # so that the model's weights are hosted on CPU memory.
+ # Otherwise they may end up hosted on a GPU, which would
+ # complicate weight sharing.
with tf.device('/cpu:0'):
model = Xception(weights=None,
input_shape=(height, width, 3),
@@ -78,7 +81,16 @@ def multi_gpu_model(model, gpus):
# This `fit` call will be distributed on 8 GPUs.
# Since the batch size is 256, each GPU will process 32 samples.
parallel_model.fit(x, y, epochs=20, batch_size=256)
+
+ # Save model via the template model (which shares the same weights):
+ model.save('my_model.h5')
```
+
+ # On model saving
+
+ To save the multi-gpu model, use `.save(fname)` or `.save_weights(fname)`
+ with the template model (the argument you passed to `multi_gpu_model),
+ rather than the model returned by `multi_gpu_model`.
"""
if K.backend() != 'tensorflow':
raise ValueError('`multi_gpu_model` is only available '
