Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OOM on GPU with Tensorboard enabled #4797 (problem2) #4834

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions keras/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,19 +545,29 @@ def _set_model(self, model):

def on_epoch_end(self, epoch, logs={}):
import tensorflow as tf
from keras.engine.training import slice_X

if self.model.validation_data and self.histogram_freq:
if epoch % self.histogram_freq == 0:
# TODO: implement batched calls to sess.run
# (current call will likely go OOM on GPU)
if self.model.uses_learning_phase:
cut_v_data = len(self.model.inputs)
val_data = self.model.validation_data[:cut_v_data] + [0]
tensors = self.model.inputs + [K.learning_phase()]
else:
val_data = self.model.validation_data
tensors = self.model.inputs
feed_dict = dict(zip(tensors, val_data))
# Sample one batch of validation data to avoid OOM on GPU
if 'batch_size' in self.params:
index_array = np.arange(len(val_data[0]))
batch_ids = np.random.choice(index_array, self.params['batch_size'])
if self.model.uses_learning_phase:
ins_batch = slice_X(val_data[:-1], batch_ids) + [val_data[-1]]
else:
ins_batch = slice_X(val_data, batch_ids)
else:
# Generators yield one batch at a time and don't provide batch_size
ins_batch = val_data
feed_dict = dict(zip(tensors, ins_batch))
result = self.sess.run([self.merged], feed_dict=feed_dict)
summary_str = result[0]
self.writer.add_summary(summary_str, epoch)
Expand Down