def testEagerMemory(self): training_util.get_or_create_global_step() logdir = self.get_temp_dir() with summary_ops.create_file_writer( logdir, max_queue=0, name='t0').as_default(), summary_ops.always_record_summaries(): summary_ops.generic('tensor', 1, '') summary_ops.scalar('scalar', 2.0) summary_ops.histogram('histogram', [1.0]) summary_ops.image('image', [[[[1.0]]]]) summary_ops.audio('audio', [[1.0]], 1.0, 1)
def testEagerMemory(self): training_util.get_or_create_global_step() logdir = self.get_temp_dir() with summary_ops.create_file_writer( logdir, max_queue=0, name='t0').as_default(), summary_ops.always_record_summaries(): summary_ops.generic('tensor', 1, '') summary_ops.scalar('scalar', 2.0) summary_ops.histogram('histogram', [1.0]) summary_ops.image('image', [[[[1.0]]]]) summary_ops.audio('audio', [[1.0]], 1.0, 1)
def testSummaryOps(self): training_util.get_or_create_global_step() logdir = tempfile.mkdtemp() with summary_ops.create_file_writer( logdir, max_queue=0, name='t0').as_default(), summary_ops.always_record_summaries(): summary_ops.generic('tensor', 1, '') summary_ops.scalar('scalar', 2.0) summary_ops.histogram('histogram', [1.0]) summary_ops.image('image', [[[[1.0]]]]) summary_ops.audio('audio', [[1.0]], 1.0, 1) # The working condition of the ops is tested in the C++ test so we just # test here that we're calling them correctly. self.assertTrue(gfile.Exists(logdir))
def testSummaryOps(self): training_util.get_or_create_global_step() logdir = tempfile.mkdtemp() with summary_ops.create_file_writer( logdir, max_queue=0, name='t0').as_default(), summary_ops.always_record_summaries(): summary_ops.generic('tensor', 1, '') summary_ops.scalar('scalar', 2.0) summary_ops.histogram('histogram', [1.0]) summary_ops.image('image', [[[[1.0]]]]) summary_ops.audio('audio', [[1.0]], 1.0, 1) # The working condition of the ops is tested in the C++ test so we just # test here that we're calling them correctly. self.assertTrue(gfile.Exists(logdir))
def testSummaryOps(self): logdir = self.get_temp_dir() writer = summary_ops.create_file_writer(logdir, max_queue=0) with writer.as_default(), summary_ops.always_record_summaries(): summary_ops.generic('tensor', 1, step=1) summary_ops.scalar('scalar', 2.0, step=1) summary_ops.histogram('histogram', [1.0], step=1) summary_ops.image('image', [[[[1.0]]]], step=1) summary_ops.audio('audio', [[1.0]], 1.0, 1, step=1) with self.cached_session() as sess: sess.run(summary_ops.summary_writer_initializer_op()) sess.run(summary_ops.all_summary_ops()) # The working condition of the ops is tested in the C++ test so we just # test here that we're calling them correctly. self.assertTrue(gfile.Exists(logdir))
def testSummaryOps(self): logdir = self.get_temp_dir() writer = summary_ops.create_file_writer(logdir, max_queue=0) with writer.as_default(), summary_ops.always_record_summaries(): summary_ops.generic('tensor', 1, step=1) summary_ops.scalar('scalar', 2.0, step=1) summary_ops.histogram('histogram', [1.0], step=1) summary_ops.image('image', [[[[1.0]]]], step=1) summary_ops.audio('audio', [[1.0]], 1.0, 1, step=1) with self.cached_session() as sess: sess.run(summary_ops.summary_writer_initializer_op()) sess.run(summary_ops.all_summary_ops()) # The working condition of the ops is tested in the C++ test so we just # test here that we're calling them correctly. self.assertTrue(gfile.Exists(logdir))
def main(): batch_size = 16 dataset = get_dataset(batch_size, x_train, y_train, distorted_image_fn, shuffle=True, repeat=True) model = ClassificationNet(st_out_dim=IMG_SHAPE, num_class=NUM_CLASS) optimizer = tf.train.AdamOptimizer(learning_rate=0.001) global_step = tf.train.get_or_create_global_step() for i, (image, rotated_image, angle, label) in enumerate(dataset, start=1): global_step.assign_add(1) with summary.record_summaries_every_n_global_steps(10): loss, prediction, transformed, theta = model.train( optimizer, rotated_image, label) acc = model.accuracy(prediction, label) # test if i % 500 == 0: total_acc = 0 dataset_test = get_dataset( 1000, x_test, y_test, distorted_image_test_fn).make_one_shot_iterator() split = 10000 // 1000 for _ in range(split): image_test, rotated_image_test, angle_test, label_test = dataset_test.get_next( ) logits_test, transformed_test, theta_test = model( rotated_image_test) prediction_test = tf.nn.softmax(logits_test) acc_test = model.accuracy(prediction_test, label_test).numpy() total_acc += acc_test print(total_acc / split) summary.scalar('accuracy/test', total_acc / split) if i % 10 == 0: print("step: {}, loss: {}, accuracy: {}".format( int(global_step), float(loss), float(acc))) summary.scalar('loss', loss) summary.scalar('accuracy/training', acc) # summary images origin_images = image_utils.image_gallery(image.numpy(), columns=4, expand_dim=True) rotated_images = image_utils.image_gallery( rotated_image.numpy(), columns=4, expand_dim=True) transformed_images = image_utils.image_gallery( transformed.numpy(), columns=4, expand_dim=True) summary.image('image/original', origin_images) summary.image('image/rotated', rotated_images) summary.image('image/transformed', transformed_images)