MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / main

Function main

tensorflow/contrib/eager/python/examples/gan/mnist.py:265–308  ·  view source on GitHub ↗
(_)

Source from the content-addressed store, hash-verified

263
264
265def main(_):
266 (device, data_format) = ('/gpu:0', 'channels_first')
267 if FLAGS.no_gpu or tf.contrib.eager.num_gpus() <= 0:
268 (device, data_format) = ('/cpu:0', 'channels_last')
269 print('Using device %s, and data format %s.' % (device, data_format))
270
271 # Load the datasets
272 data = input_data.read_data_sets(FLAGS.data_dir)
273 dataset = (
274 tf.data.Dataset.from_tensor_slices(data.train.images).shuffle(60000)
275 .batch(FLAGS.batch_size))
276
277 # Create the models and optimizers.
278 model_objects = {
279 'generator': Generator(data_format),
280 'discriminator': Discriminator(data_format),
281 'generator_optimizer': tf.compat.v1.train.AdamOptimizer(FLAGS.lr),
282 'discriminator_optimizer': tf.compat.v1.train.AdamOptimizer(FLAGS.lr),
283 'step_counter': tf.train.get_or_create_global_step(),
284 }
285
286 # Prepare summary writer and checkpoint info
287 summary_writer = tf.contrib.summary.create_summary_file_writer(
288 FLAGS.output_dir, flush_millis=1000)
289 checkpoint_prefix = os.path.join(FLAGS.checkpoint_dir, 'ckpt')
290 latest_cpkt = tf.train.latest_checkpoint(FLAGS.checkpoint_dir)
291 if latest_cpkt:
292 print('Using latest checkpoint at ' + latest_cpkt)
293 checkpoint = tf.train.Checkpoint(**model_objects)
294 # Restore variables on creation if a checkpoint exists.
295 checkpoint.restore(latest_cpkt)
296
297 with tf.device(device):
298 for _ in range(100):
299 start = time.time()
300 with summary_writer.as_default():
301 train_one_epoch(dataset=dataset, log_interval=FLAGS.log_interval,
302 noise_dim=FLAGS.noise, **model_objects)
303 end = time.time()
304 checkpoint.save(checkpoint_prefix)
305 print('\nTrain time for epoch #%d (step %d): %f' %
306 (checkpoint.save_counter.numpy(),
307 checkpoint.step_counter.numpy(),
308 end - start))
309
310
311if __name__ == '__main__':

Callers

nothing calls this directly

Calls 15

restoreMethod · 0.95
saveMethod · 0.95
DiscriminatorClass · 0.85
AdamOptimizerMethod · 0.80
latest_checkpointMethod · 0.80
timeMethod · 0.80
GeneratorClass · 0.70
train_one_epochFunction · 0.70
rangeFunction · 0.50
num_gpusMethod · 0.45
batchMethod · 0.45
shuffleMethod · 0.45

Tested by

no test coverage detected