Skip to content

Instantly share code, notes, and snippets.

@philipperemy
Created April 29, 2020 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipperemy/26b275be2b4d66dd6661f0caa3fae82f to your computer and use it in GitHub Desktop.
Save philipperemy/26b275be2b4d66dd6661f0caa3fae82f to your computer and use it in GitHub Desktop.
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.applications import Xception
import numpy as np
num_samples = 1000
height = 224
width = 224
num_classes = 1000
strategy = tf.distribute.MirroredStrategy()
with strategy.scope():
parallel_model = Xception(weights=None,
input_shape=(height, width, 3),
classes=num_classes)
parallel_model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
# Generate dummy data.
x = np.random.random((num_samples, height, width, 3))
y = np.random.random((num_samples, num_classes))
parallel_model.summary()
# 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=16) #batch_sized changed to 16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment