Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 57f839b

Browse files
sguadamartinwicke
authored andcommitted
Make the split of batch outside GPUs (tensorflow#51)
Tentative fix for issue tensorflow#47
1 parent c348081 commit 57f839b

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

inception/inception/inception_train.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,28 +220,23 @@ def train(dataset):
220220
# Number of classes in the Dataset label set plus 1.
221221
# Label 0 is reserved for an (unused) background class.
222222
num_classes = dataset.num_classes() + 1
223+
224+
# Split the batch of images and labels for towers.
225+
images_splits = tf.split(0, FLAGS.num_gpus, images)
226+
labels_splits = tf.split(0, FLAGS.num_gpus, labels)
223227

224228
# Calculate the gradients for each model tower.
225229
tower_grads = []
226230
for i in xrange(FLAGS.num_gpus):
227231
with tf.device('/gpu:%d' % i):
228232
with tf.name_scope('%s_%d' % (inception.TOWER_NAME, i)) as scope:
229-
# Split the batch of images and labels.
230-
batch_start = split_batch_size * i
231-
images_batch = tf.slice(images,
232-
begin=[batch_start, 0, 0, 0],
233-
size=[split_batch_size, -1, -1, -1])
234-
labels_batch = tf.slice(labels,
235-
begin=[batch_start],
236-
size=[split_batch_size])
237-
238-
239233
# Force all Variables to reside on the CPU.
240234
with slim.arg_scope([slim.variables.variable], device='/cpu:0'):
241235
# Calculate the loss for one tower of the ImageNet model. This
242236
# function constructs the entire ImageNet model but shares the
243237
# variables across all towers.
244-
loss = _tower_loss(images_batch, labels_batch, num_classes, scope)
238+
loss = _tower_loss(images_splits[i], labels_splits[i], num_classes,
239+
scope)
245240

246241
# Reuse variables for the next tower.
247242
tf.get_variable_scope().reuse_variables()

0 commit comments

Comments
 (0)