Python tensorflow.contrib.slim.get_or_create_global_step() Examples
The following are 30
code examples of tensorflow.contrib.slim.get_or_create_global_step().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.contrib.slim
, or try the search function
.
Example #1
Source File: eval.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def main(_): if not tf.gfile.Exists(FLAGS.eval_log_dir): tf.gfile.MakeDirs(FLAGS.eval_log_dir) dataset = common_flags.create_dataset(split_name=FLAGS.split_name) model = common_flags.create_model(dataset.num_char_classes, dataset.max_sequence_length, dataset.num_of_views, dataset.null_code) data = data_provider.get_data( dataset, FLAGS.batch_size, augment=False, central_crop_size=common_flags.get_crop_size()) endpoints = model.create_base(data.images, labels_one_hot=None) model.create_loss(data, endpoints) eval_ops = model.create_summaries( data, endpoints, dataset.charset, is_training=False) slim.get_or_create_global_step() session_config = tf.ConfigProto(device_count={"GPU": 0}) slim.evaluation.evaluation_loop( master=FLAGS.master, checkpoint_dir=FLAGS.train_log_dir, logdir=FLAGS.eval_log_dir, eval_op=eval_ops, num_evals=FLAGS.num_batches, eval_interval_secs=FLAGS.eval_interval_secs, max_number_of_evaluations=FLAGS.number_of_steps, session_config=session_config)
Example #2
Source File: eval.py From hands-detection with MIT License | 5 votes |
def main(_): if not tf.gfile.Exists(FLAGS.eval_log_dir): tf.gfile.MakeDirs(FLAGS.eval_log_dir) dataset = common_flags.create_dataset(split_name=FLAGS.split_name) model = common_flags.create_model(dataset.num_char_classes, dataset.max_sequence_length, dataset.num_of_views, dataset.null_code) data = data_provider.get_data( dataset, FLAGS.batch_size, augment=False, central_crop_size=common_flags.get_crop_size()) endpoints = model.create_base(data.images, labels_one_hot=None) model.create_loss(data, endpoints) eval_ops = model.create_summaries( data, endpoints, dataset.charset, is_training=False) slim.get_or_create_global_step() session_config = tf.ConfigProto(device_count={"GPU": 0}) slim.evaluation.evaluation_loop( master=FLAGS.master, checkpoint_dir=FLAGS.train_log_dir, logdir=FLAGS.eval_log_dir, eval_op=eval_ops, num_evals=FLAGS.num_batches, eval_interval_secs=FLAGS.eval_interval_secs, max_number_of_evaluations=FLAGS.number_of_steps, session_config=session_config)
Example #3
Source File: eval.py From DOTA_models with Apache License 2.0 | 5 votes |
def main(_): if not tf.gfile.Exists(FLAGS.eval_log_dir): tf.gfile.MakeDirs(FLAGS.eval_log_dir) dataset = common_flags.create_dataset(split_name=FLAGS.split_name) model = common_flags.create_model(dataset.num_char_classes, dataset.max_sequence_length, dataset.num_of_views, dataset.null_code) data = data_provider.get_data( dataset, FLAGS.batch_size, augment=False, central_crop_size=common_flags.get_crop_size()) endpoints = model.create_base(data.images, labels_one_hot=None) model.create_loss(data, endpoints) eval_ops = model.create_summaries( data, endpoints, dataset.charset, is_training=False) slim.get_or_create_global_step() session_config = tf.ConfigProto(device_count={"GPU": 0}) slim.evaluation.evaluation_loop( master=FLAGS.master, checkpoint_dir=FLAGS.train_log_dir, logdir=FLAGS.eval_log_dir, eval_op=eval_ops, num_evals=FLAGS.num_batches, eval_interval_secs=FLAGS.eval_interval_secs, max_number_of_evaluations=FLAGS.number_of_steps, session_config=session_config)
Example #4
Source File: eval.py From object_detection_kitti with Apache License 2.0 | 5 votes |
def main(_): if not tf.gfile.Exists(FLAGS.eval_log_dir): tf.gfile.MakeDirs(FLAGS.eval_log_dir) dataset = common_flags.create_dataset(split_name=FLAGS.split_name) model = common_flags.create_model(dataset.num_char_classes, dataset.max_sequence_length, dataset.num_of_views, dataset.null_code) data = data_provider.get_data( dataset, FLAGS.batch_size, augment=False, central_crop_size=common_flags.get_crop_size()) endpoints = model.create_base(data.images, labels_one_hot=None) model.create_loss(data, endpoints) eval_ops = model.create_summaries( data, endpoints, dataset.charset, is_training=False) slim.get_or_create_global_step() session_config = tf.ConfigProto(device_count={"GPU": 0}) slim.evaluation.evaluation_loop( master=FLAGS.master, checkpoint_dir=FLAGS.train_log_dir, logdir=FLAGS.eval_log_dir, eval_op=eval_ops, num_evals=FLAGS.num_batches, eval_interval_secs=FLAGS.eval_interval_secs, max_number_of_evaluations=FLAGS.number_of_steps, session_config=session_config)
Example #5
Source File: tf_utils.py From object_detection_kitti with Apache License 2.0 | 5 votes |
def setup_training(loss_op, initial_learning_rate, steps_per_decay, learning_rate_decay, momentum, max_steps, sync=False, adjust_lr_sync=True, num_workers=1, replica_id=0, vars_to_optimize=None, clip_gradient_norm=0, typ=None, momentum2=0.999, adam_eps=1e-8): if sync and adjust_lr_sync: initial_learning_rate = initial_learning_rate * num_workers max_steps = np.int(max_steps / num_workers) steps_per_decay = np.int(steps_per_decay / num_workers) global_step_op = slim.get_or_create_global_step() lr_op = tf.train.exponential_decay(initial_learning_rate, global_step_op, steps_per_decay, learning_rate_decay, staircase=True) if typ == 'sgd': optimizer = tf.train.MomentumOptimizer(lr_op, momentum) elif typ == 'adam': optimizer = tf.train.AdamOptimizer(learning_rate=lr_op, beta1=momentum, beta2=momentum2, epsilon=adam_eps) if sync: sync_optimizer = tf.train.SyncReplicasOptimizer(optimizer, replicas_to_aggregate=num_workers, replica_id=replica_id, total_num_replicas=num_workers) train_op = slim.learning.create_train_op(loss_op, sync_optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) else: sync_optimizer = None train_op = slim.learning.create_train_op(loss_op, optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) should_stop_op = tf.greater_equal(global_step_op, max_steps) return lr_op, global_step_op, train_op, should_stop_op, optimizer, sync_optimizer
Example #6
Source File: base_estimator.py From object_detection_with_tensorflow with MIT License | 5 votes |
def _setup_np_inference(self, np_images, checkpoint_path): """Sets up and restores inference graph, creates and caches a Session.""" tf.logging.info('Restoring model weights.') # Define inference over an image placeholder. _, height, width, _ = np.shape(np_images) image_placeholder = tf.placeholder( tf.float32, shape=(None, height, width, 3)) # Preprocess batch. preprocessed = self.preprocess_data(image_placeholder, is_training=False) # Unscale and jpeg encode preprocessed images for display purposes. im_strings = preprocessing.unscale_jpeg_encode(preprocessed) # Do forward pass to get embeddings. embeddings = self.forward(preprocessed, is_training=False) # Create a saver to restore model variables. tf.train.get_or_create_global_step() saver = tf.train.Saver(tf.all_variables()) self._image_placeholder = image_placeholder self._batch_encoded = embeddings self._np_inf_tensor_dict = { 'embeddings': embeddings, 'raw_image_strings': im_strings, } # Create a session and restore model variables. self._sess = tf.Session() saver.restore(self._sess, checkpoint_path)
Example #7
Source File: eval.py From object_detection_with_tensorflow with MIT License | 5 votes |
def main(_): if not tf.gfile.Exists(FLAGS.eval_log_dir): tf.gfile.MakeDirs(FLAGS.eval_log_dir) dataset = common_flags.create_dataset(split_name=FLAGS.split_name) model = common_flags.create_model(dataset.num_char_classes, dataset.max_sequence_length, dataset.num_of_views, dataset.null_code) data = data_provider.get_data( dataset, FLAGS.batch_size, augment=False, central_crop_size=common_flags.get_crop_size()) endpoints = model.create_base(data.images, labels_one_hot=None) model.create_loss(data, endpoints) eval_ops = model.create_summaries( data, endpoints, dataset.charset, is_training=False) slim.get_or_create_global_step() session_config = tf.ConfigProto(device_count={"GPU": 0}) slim.evaluation.evaluation_loop( master=FLAGS.master, checkpoint_dir=FLAGS.train_log_dir, logdir=FLAGS.eval_log_dir, eval_op=eval_ops, num_evals=FLAGS.num_batches, eval_interval_secs=FLAGS.eval_interval_secs, max_number_of_evaluations=FLAGS.number_of_steps, session_config=session_config)
Example #8
Source File: tf_utils.py From object_detection_with_tensorflow with MIT License | 5 votes |
def setup_training(loss_op, initial_learning_rate, steps_per_decay, learning_rate_decay, momentum, max_steps, sync=False, adjust_lr_sync=True, num_workers=1, replica_id=0, vars_to_optimize=None, clip_gradient_norm=0, typ=None, momentum2=0.999, adam_eps=1e-8): if sync and adjust_lr_sync: initial_learning_rate = initial_learning_rate * num_workers max_steps = np.int(max_steps / num_workers) steps_per_decay = np.int(steps_per_decay / num_workers) global_step_op = slim.get_or_create_global_step() lr_op = tf.train.exponential_decay(initial_learning_rate, global_step_op, steps_per_decay, learning_rate_decay, staircase=True) if typ == 'sgd': optimizer = tf.train.MomentumOptimizer(lr_op, momentum) elif typ == 'adam': optimizer = tf.train.AdamOptimizer(learning_rate=lr_op, beta1=momentum, beta2=momentum2, epsilon=adam_eps) if sync: sync_optimizer = tf.train.SyncReplicasOptimizer(optimizer, replicas_to_aggregate=num_workers, replica_id=replica_id, total_num_replicas=num_workers) train_op = slim.learning.create_train_op(loss_op, sync_optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) else: sync_optimizer = None train_op = slim.learning.create_train_op(loss_op, optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) should_stop_op = tf.greater_equal(global_step_op, max_steps) return lr_op, global_step_op, train_op, should_stop_op, optimizer, sync_optimizer
Example #9
Source File: base_estimator.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def _setup_np_inference(self, np_images, checkpoint_path): """Sets up and restores inference graph, creates and caches a Session.""" tf.logging.info('Restoring model weights.') # Define inference over an image placeholder. _, height, width, _ = np.shape(np_images) image_placeholder = tf.placeholder( tf.float32, shape=(None, height, width, 3)) # Preprocess batch. preprocessed = self.preprocess_data(image_placeholder, is_training=False) # Unscale and jpeg encode preprocessed images for display purposes. im_strings = preprocessing.unscale_jpeg_encode(preprocessed) # Do forward pass to get embeddings. embeddings = self.forward(preprocessed, is_training=False) # Create a saver to restore model variables. tf.train.get_or_create_global_step() saver = tf.train.Saver(tf.all_variables()) self._image_placeholder = image_placeholder self._batch_encoded = embeddings self._np_inf_tensor_dict = { 'embeddings': embeddings, 'raw_image_strings': im_strings, } # Create a session and restore model variables. self._sess = tf.Session() saver.restore(self._sess, checkpoint_path)
Example #10
Source File: tf_utils.py From hands-detection with MIT License | 5 votes |
def setup_training(loss_op, initial_learning_rate, steps_per_decay, learning_rate_decay, momentum, max_steps, sync=False, adjust_lr_sync=True, num_workers=1, replica_id=0, vars_to_optimize=None, clip_gradient_norm=0, typ=None, momentum2=0.999, adam_eps=1e-8): if sync and adjust_lr_sync: initial_learning_rate = initial_learning_rate * num_workers max_steps = np.int(max_steps / num_workers) steps_per_decay = np.int(steps_per_decay / num_workers) global_step_op = slim.get_or_create_global_step() lr_op = tf.train.exponential_decay(initial_learning_rate, global_step_op, steps_per_decay, learning_rate_decay, staircase=True) if typ == 'sgd': optimizer = tf.train.MomentumOptimizer(lr_op, momentum) elif typ == 'adam': optimizer = tf.train.AdamOptimizer(learning_rate=lr_op, beta1=momentum, beta2=momentum2, epsilon=adam_eps) if sync: sync_optimizer = tf.train.SyncReplicasOptimizer(optimizer, replicas_to_aggregate=num_workers, replica_id=replica_id, total_num_replicas=num_workers) train_op = slim.learning.create_train_op(loss_op, sync_optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) else: sync_optimizer = None train_op = slim.learning.create_train_op(loss_op, optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) should_stop_op = tf.greater_equal(global_step_op, max_steps) return lr_op, global_step_op, train_op, should_stop_op, optimizer, sync_optimizer
Example #11
Source File: tf_utils.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def setup_training(loss_op, initial_learning_rate, steps_per_decay, learning_rate_decay, momentum, max_steps, sync=False, adjust_lr_sync=True, num_workers=1, replica_id=0, vars_to_optimize=None, clip_gradient_norm=0, typ=None, momentum2=0.999, adam_eps=1e-8): if sync and adjust_lr_sync: initial_learning_rate = initial_learning_rate * num_workers max_steps = np.int(max_steps / num_workers) steps_per_decay = np.int(steps_per_decay / num_workers) global_step_op = slim.get_or_create_global_step() lr_op = tf.train.exponential_decay(initial_learning_rate, global_step_op, steps_per_decay, learning_rate_decay, staircase=True) if typ == 'sgd': optimizer = tf.train.MomentumOptimizer(lr_op, momentum) elif typ == 'adam': optimizer = tf.train.AdamOptimizer(learning_rate=lr_op, beta1=momentum, beta2=momentum2, epsilon=adam_eps) if sync: sync_optimizer = tf.train.SyncReplicasOptimizer(optimizer, replicas_to_aggregate=num_workers, replica_id=replica_id, total_num_replicas=num_workers) train_op = slim.learning.create_train_op(loss_op, sync_optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) else: sync_optimizer = None train_op = slim.learning.create_train_op(loss_op, optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) should_stop_op = tf.greater_equal(global_step_op, max_steps) return lr_op, global_step_op, train_op, should_stop_op, optimizer, sync_optimizer
Example #12
Source File: base_estimator.py From models with Apache License 2.0 | 5 votes |
def _setup_np_inference(self, np_images, checkpoint_path): """Sets up and restores inference graph, creates and caches a Session.""" tf.logging.info('Restoring model weights.') # Define inference over an image placeholder. _, height, width, _ = np.shape(np_images) image_placeholder = tf.placeholder( tf.float32, shape=(None, height, width, 3)) # Preprocess batch. preprocessed = self.preprocess_data(image_placeholder, is_training=False) # Unscale and jpeg encode preprocessed images for display purposes. im_strings = preprocessing.unscale_jpeg_encode(preprocessed) # Do forward pass to get embeddings. embeddings = self.forward(preprocessed, is_training=False) # Create a saver to restore model variables. tf.train.get_or_create_global_step() saver = tf.train.Saver(tf.all_variables()) self._image_placeholder = image_placeholder self._batch_encoded = embeddings self._np_inf_tensor_dict = { 'embeddings': embeddings, 'raw_image_strings': im_strings, } # Create a session and restore model variables. self._sess = tf.Session() saver.restore(self._sess, checkpoint_path)
Example #13
Source File: eval.py From models with Apache License 2.0 | 5 votes |
def main(_): if not tf.gfile.Exists(FLAGS.eval_log_dir): tf.gfile.MakeDirs(FLAGS.eval_log_dir) dataset = common_flags.create_dataset(split_name=FLAGS.split_name) model = common_flags.create_model(dataset.num_char_classes, dataset.max_sequence_length, dataset.num_of_views, dataset.null_code) data = data_provider.get_data( dataset, FLAGS.batch_size, augment=False, central_crop_size=common_flags.get_crop_size()) endpoints = model.create_base(data.images, labels_one_hot=None) model.create_loss(data, endpoints) eval_ops = model.create_summaries( data, endpoints, dataset.charset, is_training=False) slim.get_or_create_global_step() session_config = tf.ConfigProto(device_count={"GPU": 0}) slim.evaluation.evaluation_loop( master=FLAGS.master, checkpoint_dir=FLAGS.train_log_dir, logdir=FLAGS.eval_log_dir, eval_op=eval_ops, num_evals=FLAGS.num_batches, eval_interval_secs=FLAGS.eval_interval_secs, max_number_of_evaluations=FLAGS.number_of_steps, session_config=session_config)
Example #14
Source File: tf_utils.py From models with Apache License 2.0 | 5 votes |
def setup_training(loss_op, initial_learning_rate, steps_per_decay, learning_rate_decay, momentum, max_steps, sync=False, adjust_lr_sync=True, num_workers=1, replica_id=0, vars_to_optimize=None, clip_gradient_norm=0, typ=None, momentum2=0.999, adam_eps=1e-8): if sync and adjust_lr_sync: initial_learning_rate = initial_learning_rate * num_workers max_steps = np.int(max_steps / num_workers) steps_per_decay = np.int(steps_per_decay / num_workers) global_step_op = slim.get_or_create_global_step() lr_op = tf.train.exponential_decay(initial_learning_rate, global_step_op, steps_per_decay, learning_rate_decay, staircase=True) if typ == 'sgd': optimizer = tf.train.MomentumOptimizer(lr_op, momentum) elif typ == 'adam': optimizer = tf.train.AdamOptimizer(learning_rate=lr_op, beta1=momentum, beta2=momentum2, epsilon=adam_eps) if sync: sync_optimizer = tf.train.SyncReplicasOptimizer(optimizer, replicas_to_aggregate=num_workers, replica_id=replica_id, total_num_replicas=num_workers) train_op = slim.learning.create_train_op(loss_op, sync_optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) else: sync_optimizer = None train_op = slim.learning.create_train_op(loss_op, optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) should_stop_op = tf.greater_equal(global_step_op, max_steps) return lr_op, global_step_op, train_op, should_stop_op, optimizer, sync_optimizer
Example #15
Source File: base_estimator.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def _setup_np_inference(self, np_images, checkpoint_path): """Sets up and restores inference graph, creates and caches a Session.""" tf.logging.info('Restoring model weights.') # Define inference over an image placeholder. _, height, width, _ = np.shape(np_images) image_placeholder = tf.placeholder( tf.float32, shape=(None, height, width, 3)) # Preprocess batch. preprocessed = self.preprocess_data(image_placeholder, is_training=False) # Unscale and jpeg encode preprocessed images for display purposes. im_strings = preprocessing.unscale_jpeg_encode(preprocessed) # Do forward pass to get embeddings. embeddings = self.forward(preprocessed, is_training=False) # Create a saver to restore model variables. tf.train.get_or_create_global_step() saver = tf.train.Saver(tf.all_variables()) self._image_placeholder = image_placeholder self._batch_encoded = embeddings self._np_inf_tensor_dict = { 'embeddings': embeddings, 'raw_image_strings': im_strings, } # Create a session and restore model variables. self._sess = tf.Session() saver.restore(self._sess, checkpoint_path)
Example #16
Source File: eval.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def main(_): if not tf.gfile.Exists(FLAGS.eval_log_dir): tf.gfile.MakeDirs(FLAGS.eval_log_dir) dataset = common_flags.create_dataset(split_name=FLAGS.split_name) model = common_flags.create_model(dataset.num_char_classes, dataset.max_sequence_length, dataset.num_of_views, dataset.null_code) data = data_provider.get_data( dataset, FLAGS.batch_size, augment=False, central_crop_size=common_flags.get_crop_size()) endpoints = model.create_base(data.images, labels_one_hot=None) model.create_loss(data, endpoints) eval_ops = model.create_summaries( data, endpoints, dataset.charset, is_training=False) slim.get_or_create_global_step() session_config = tf.ConfigProto(device_count={"GPU": 0}) slim.evaluation.evaluation_loop( master=FLAGS.master, checkpoint_dir=FLAGS.train_log_dir, logdir=FLAGS.eval_log_dir, eval_op=eval_ops, num_evals=FLAGS.num_batches, eval_interval_secs=FLAGS.eval_interval_secs, max_number_of_evaluations=FLAGS.number_of_steps, session_config=session_config)
Example #17
Source File: tf_utils.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def setup_training(loss_op, initial_learning_rate, steps_per_decay, learning_rate_decay, momentum, max_steps, sync=False, adjust_lr_sync=True, num_workers=1, replica_id=0, vars_to_optimize=None, clip_gradient_norm=0, typ=None, momentum2=0.999, adam_eps=1e-8): if sync and adjust_lr_sync: initial_learning_rate = initial_learning_rate * num_workers max_steps = np.int(max_steps / num_workers) steps_per_decay = np.int(steps_per_decay / num_workers) global_step_op = slim.get_or_create_global_step() lr_op = tf.train.exponential_decay(initial_learning_rate, global_step_op, steps_per_decay, learning_rate_decay, staircase=True) if typ == 'sgd': optimizer = tf.train.MomentumOptimizer(lr_op, momentum) elif typ == 'adam': optimizer = tf.train.AdamOptimizer(learning_rate=lr_op, beta1=momentum, beta2=momentum2, epsilon=adam_eps) if sync: sync_optimizer = tf.train.SyncReplicasOptimizer(optimizer, replicas_to_aggregate=num_workers, replica_id=replica_id, total_num_replicas=num_workers) train_op = slim.learning.create_train_op(loss_op, sync_optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) else: sync_optimizer = None train_op = slim.learning.create_train_op(loss_op, optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) should_stop_op = tf.greater_equal(global_step_op, max_steps) return lr_op, global_step_op, train_op, should_stop_op, optimizer, sync_optimizer
Example #18
Source File: tf_utils.py From DOTA_models with Apache License 2.0 | 5 votes |
def setup_training(loss_op, initial_learning_rate, steps_per_decay, learning_rate_decay, momentum, max_steps, sync=False, adjust_lr_sync=True, num_workers=1, replica_id=0, vars_to_optimize=None, clip_gradient_norm=0, typ=None, momentum2=0.999, adam_eps=1e-8): if sync and adjust_lr_sync: initial_learning_rate = initial_learning_rate * num_workers max_steps = np.int(max_steps / num_workers) steps_per_decay = np.int(steps_per_decay / num_workers) global_step_op = slim.get_or_create_global_step() lr_op = tf.train.exponential_decay(initial_learning_rate, global_step_op, steps_per_decay, learning_rate_decay, staircase=True) if typ == 'sgd': optimizer = tf.train.MomentumOptimizer(lr_op, momentum) elif typ == 'adam': optimizer = tf.train.AdamOptimizer(learning_rate=lr_op, beta1=momentum, beta2=momentum2, epsilon=adam_eps) if sync: sync_optimizer = tf.train.SyncReplicasOptimizer(optimizer, replicas_to_aggregate=num_workers, replica_id=replica_id, total_num_replicas=num_workers) train_op = slim.learning.create_train_op(loss_op, sync_optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) else: sync_optimizer = None train_op = slim.learning.create_train_op(loss_op, optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) should_stop_op = tf.greater_equal(global_step_op, max_steps) return lr_op, global_step_op, train_op, should_stop_op, optimizer, sync_optimizer
Example #19
Source File: eval.py From Gun-Detector with Apache License 2.0 | 5 votes |
def main(_): if not tf.gfile.Exists(FLAGS.eval_log_dir): tf.gfile.MakeDirs(FLAGS.eval_log_dir) dataset = common_flags.create_dataset(split_name=FLAGS.split_name) model = common_flags.create_model(dataset.num_char_classes, dataset.max_sequence_length, dataset.num_of_views, dataset.null_code) data = data_provider.get_data( dataset, FLAGS.batch_size, augment=False, central_crop_size=common_flags.get_crop_size()) endpoints = model.create_base(data.images, labels_one_hot=None) model.create_loss(data, endpoints) eval_ops = model.create_summaries( data, endpoints, dataset.charset, is_training=False) slim.get_or_create_global_step() session_config = tf.ConfigProto(device_count={"GPU": 0}) slim.evaluation.evaluation_loop( master=FLAGS.master, checkpoint_dir=FLAGS.train_log_dir, logdir=FLAGS.eval_log_dir, eval_op=eval_ops, num_evals=FLAGS.num_batches, eval_interval_secs=FLAGS.eval_interval_secs, max_number_of_evaluations=FLAGS.number_of_steps, session_config=session_config)
Example #20
Source File: base_estimator.py From Gun-Detector with Apache License 2.0 | 5 votes |
def _setup_np_inference(self, np_images, checkpoint_path): """Sets up and restores inference graph, creates and caches a Session.""" tf.logging.info('Restoring model weights.') # Define inference over an image placeholder. _, height, width, _ = np.shape(np_images) image_placeholder = tf.placeholder( tf.float32, shape=(None, height, width, 3)) # Preprocess batch. preprocessed = self.preprocess_data(image_placeholder, is_training=False) # Unscale and jpeg encode preprocessed images for display purposes. im_strings = preprocessing.unscale_jpeg_encode(preprocessed) # Do forward pass to get embeddings. embeddings = self.forward(preprocessed, is_training=False) # Create a saver to restore model variables. tf.train.get_or_create_global_step() saver = tf.train.Saver(tf.all_variables()) self._image_placeholder = image_placeholder self._batch_encoded = embeddings self._np_inf_tensor_dict = { 'embeddings': embeddings, 'raw_image_strings': im_strings, } # Create a session and restore model variables. self._sess = tf.Session() saver.restore(self._sess, checkpoint_path)
Example #21
Source File: tf_utils.py From yolo_v2 with Apache License 2.0 | 5 votes |
def setup_training(loss_op, initial_learning_rate, steps_per_decay, learning_rate_decay, momentum, max_steps, sync=False, adjust_lr_sync=True, num_workers=1, replica_id=0, vars_to_optimize=None, clip_gradient_norm=0, typ=None, momentum2=0.999, adam_eps=1e-8): if sync and adjust_lr_sync: initial_learning_rate = initial_learning_rate * num_workers max_steps = np.int(max_steps / num_workers) steps_per_decay = np.int(steps_per_decay / num_workers) global_step_op = slim.get_or_create_global_step() lr_op = tf.train.exponential_decay(initial_learning_rate, global_step_op, steps_per_decay, learning_rate_decay, staircase=True) if typ == 'sgd': optimizer = tf.train.MomentumOptimizer(lr_op, momentum) elif typ == 'adam': optimizer = tf.train.AdamOptimizer(learning_rate=lr_op, beta1=momentum, beta2=momentum2, epsilon=adam_eps) if sync: sync_optimizer = tf.train.SyncReplicasOptimizer(optimizer, replicas_to_aggregate=num_workers, replica_id=replica_id, total_num_replicas=num_workers) train_op = slim.learning.create_train_op(loss_op, sync_optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) else: sync_optimizer = None train_op = slim.learning.create_train_op(loss_op, optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) should_stop_op = tf.greater_equal(global_step_op, max_steps) return lr_op, global_step_op, train_op, should_stop_op, optimizer, sync_optimizer
Example #22
Source File: eval.py From yolo_v2 with Apache License 2.0 | 5 votes |
def main(_): if not tf.gfile.Exists(FLAGS.eval_log_dir): tf.gfile.MakeDirs(FLAGS.eval_log_dir) dataset = common_flags.create_dataset(split_name=FLAGS.split_name) model = common_flags.create_model(dataset.num_char_classes, dataset.max_sequence_length, dataset.num_of_views, dataset.null_code) data = data_provider.get_data( dataset, FLAGS.batch_size, augment=False, central_crop_size=common_flags.get_crop_size()) endpoints = model.create_base(data.images, labels_one_hot=None) model.create_loss(data, endpoints) eval_ops = model.create_summaries( data, endpoints, dataset.charset, is_training=False) slim.get_or_create_global_step() session_config = tf.ConfigProto(device_count={"GPU": 0}) slim.evaluation.evaluation_loop( master=FLAGS.master, checkpoint_dir=FLAGS.train_log_dir, logdir=FLAGS.eval_log_dir, eval_op=eval_ops, num_evals=FLAGS.num_batches, eval_interval_secs=FLAGS.eval_interval_secs, max_number_of_evaluations=FLAGS.number_of_steps, session_config=session_config)
Example #23
Source File: base_estimator.py From yolo_v2 with Apache License 2.0 | 5 votes |
def _setup_np_inference(self, np_images, checkpoint_path): """Sets up and restores inference graph, creates and caches a Session.""" tf.logging.info('Restoring model weights.') # Define inference over an image placeholder. _, height, width, _ = np.shape(np_images) image_placeholder = tf.placeholder( tf.float32, shape=(None, height, width, 3)) # Preprocess batch. preprocessed = self.preprocess_data(image_placeholder, is_training=False) # Unscale and jpeg encode preprocessed images for display purposes. im_strings = preprocessing.unscale_jpeg_encode(preprocessed) # Do forward pass to get embeddings. embeddings = self.forward(preprocessed, is_training=False) # Create a saver to restore model variables. tf.train.get_or_create_global_step() saver = tf.train.Saver(tf.all_variables()) self._image_placeholder = image_placeholder self._batch_encoded = embeddings self._np_inf_tensor_dict = { 'embeddings': embeddings, 'raw_image_strings': im_strings, } # Create a session and restore model variables. self._sess = tf.Session() saver.restore(self._sess, checkpoint_path)
Example #24
Source File: tf_utils.py From Gun-Detector with Apache License 2.0 | 5 votes |
def setup_training(loss_op, initial_learning_rate, steps_per_decay, learning_rate_decay, momentum, max_steps, sync=False, adjust_lr_sync=True, num_workers=1, replica_id=0, vars_to_optimize=None, clip_gradient_norm=0, typ=None, momentum2=0.999, adam_eps=1e-8): if sync and adjust_lr_sync: initial_learning_rate = initial_learning_rate * num_workers max_steps = np.int(max_steps / num_workers) steps_per_decay = np.int(steps_per_decay / num_workers) global_step_op = slim.get_or_create_global_step() lr_op = tf.train.exponential_decay(initial_learning_rate, global_step_op, steps_per_decay, learning_rate_decay, staircase=True) if typ == 'sgd': optimizer = tf.train.MomentumOptimizer(lr_op, momentum) elif typ == 'adam': optimizer = tf.train.AdamOptimizer(learning_rate=lr_op, beta1=momentum, beta2=momentum2, epsilon=adam_eps) if sync: sync_optimizer = tf.train.SyncReplicasOptimizer(optimizer, replicas_to_aggregate=num_workers, replica_id=replica_id, total_num_replicas=num_workers) train_op = slim.learning.create_train_op(loss_op, sync_optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) else: sync_optimizer = None train_op = slim.learning.create_train_op(loss_op, optimizer, variables_to_train=vars_to_optimize, clip_gradient_norm=clip_gradient_norm) should_stop_op = tf.greater_equal(global_step_op, max_steps) return lr_op, global_step_op, train_op, should_stop_op, optimizer, sync_optimizer
Example #25
Source File: base_estimator.py From g-tensorflow-models with Apache License 2.0 | 4 votes |
def get_train_op(self, loss): """Creates a training op. Args: loss: A float32 `Tensor` representing the total training loss. Returns: train_op: A slim.learning.create_train_op train_op. Raises: ValueError: If specified optimizer isn't supported. """ # Get variables to train (defined in subclass). assert self.variables_to_train # Define a learning rate schedule. decay_steps = self._config.learning.decay_steps decay_factor = self._config.learning.decay_factor learning_rate = float(self._config.learning.learning_rate) # Define a learning rate schedule. global_step = slim.get_or_create_global_step() learning_rate = tf.train.exponential_decay( learning_rate, global_step, decay_steps, decay_factor, staircase=True) # Create an optimizer. opt_type = self._config.learning.optimizer if opt_type == 'adam': opt = tf.train.AdamOptimizer(learning_rate) elif opt_type == 'momentum': opt = tf.train.MomentumOptimizer(learning_rate, 0.9) elif opt_type == 'rmsprop': opt = tf.train.RMSPropOptimizer(learning_rate, momentum=0.9, epsilon=1.0, decay=0.9) else: raise ValueError('Unsupported optimizer %s' % opt_type) if self._config.use_tpu: opt = tpu_optimizer.CrossShardOptimizer(opt) # Create a training op. # train_op = opt.minimize(loss, var_list=self.variables_to_train) # Create a training op. train_op = slim.learning.create_train_op( loss, optimizer=opt, variables_to_train=self.variables_to_train, update_ops=tf.get_collection(tf.GraphKeys.UPDATE_OPS)) return train_op
Example #26
Source File: build_whole_network.py From R2CNN_Faster-RCNN_Tensorflow with MIT License | 4 votes |
def get_restorer(self): checkpoint_path = tf.train.latest_checkpoint(os.path.join(cfgs.TRAINED_CKPT, cfgs.VERSION)) if checkpoint_path != None: if cfgs.RESTORE_FROM_RPN: print('___restore from rpn___') model_variables = slim.get_model_variables() restore_variables = [var for var in model_variables if not var.name.startswith('FastRCNN_Head')] + \ [slim.get_or_create_global_step()] for var in restore_variables: print(var.name) restorer = tf.train.Saver(restore_variables) else: restorer = tf.train.Saver() print("model restore from :", checkpoint_path) else: checkpoint_path = cfgs.PRETRAINED_CKPT print("model restore from pretrained mode, path is :", checkpoint_path) model_variables = slim.get_model_variables() # print(model_variables) def name_in_ckpt_rpn(var): return var.op.name def name_in_ckpt_fastrcnn_head(var): ''' Fast-RCNN/resnet_v1_50/block4 -->resnet_v1_50/block4 :param var: :return: ''' return '/'.join(var.op.name.split('/')[1:]) nameInCkpt_Var_dict = {} for var in model_variables: if var.name.startswith('Fast-RCNN/'+self.base_network_name+'/block4'): var_name_in_ckpt = name_in_ckpt_fastrcnn_head(var) nameInCkpt_Var_dict[var_name_in_ckpt] = var else: if var.name.startswith(self.base_network_name): var_name_in_ckpt = name_in_ckpt_rpn(var) nameInCkpt_Var_dict[var_name_in_ckpt] = var else: continue restore_variables = nameInCkpt_Var_dict for key, item in restore_variables.items(): print("var_in_graph: ", item.name) print("var_in_ckpt: ", key) print(20*"---") restorer = tf.train.Saver(restore_variables) print(20 * "****") print("restore from pretrained_weighs in IMAGE_NET") return restorer, checkpoint_path
Example #27
Source File: build_whole_network.py From R2CNN-Plus-Plus_Tensorflow with MIT License | 4 votes |
def get_restorer(self): checkpoint_path = tf.train.latest_checkpoint(os.path.join(cfgs.TRAINED_CKPT, cfgs.VERSION)) if checkpoint_path != None: if cfgs.RESTORE_FROM_RPN: print('___restore from rpn___') model_variables = slim.get_model_variables() restore_variables = [var for var in model_variables if not var.name.startswith('FastRCNN_Head')] + \ [slim.get_or_create_global_step()] for var in restore_variables: print(var.name) restorer = tf.train.Saver(restore_variables) else: restorer = tf.train.Saver() print("model restore from :", checkpoint_path) else: checkpoint_path = cfgs.PRETRAINED_CKPT print("model restore from pretrained mode, path is :", checkpoint_path) model_variables = slim.get_model_variables() # print(model_variables) def name_in_ckpt_rpn(var): return var.op.name def name_in_ckpt_fastrcnn_head(var): ''' Fast-RCNN/resnet_v1_50/block4 -->resnet_v1_50/block4 :param var: :return: ''' return '/'.join(var.op.name.split('/')[1:]) nameInCkpt_Var_dict = {} for var in model_variables: if var.name.startswith('Fast-RCNN/'+self.base_network_name+'/block4'): var_name_in_ckpt = name_in_ckpt_fastrcnn_head(var) nameInCkpt_Var_dict[var_name_in_ckpt] = var else: if var.name.startswith(self.base_network_name): var_name_in_ckpt = name_in_ckpt_rpn(var) nameInCkpt_Var_dict[var_name_in_ckpt] = var else: continue restore_variables = nameInCkpt_Var_dict for key, item in restore_variables.items(): print("var_in_graph: ", item.name) print("var_in_ckpt: ", key) print(20*"---") restorer = tf.train.Saver(restore_variables) print(20 * "****") print("restore from pretrained_weighs in IMAGE_NET") return restorer, checkpoint_path
Example #28
Source File: base_estimator.py From multilabel-image-classification-tensorflow with MIT License | 4 votes |
def get_train_op(self, loss): """Creates a training op. Args: loss: A float32 `Tensor` representing the total training loss. Returns: train_op: A slim.learning.create_train_op train_op. Raises: ValueError: If specified optimizer isn't supported. """ # Get variables to train (defined in subclass). assert self.variables_to_train # Define a learning rate schedule. decay_steps = self._config.learning.decay_steps decay_factor = self._config.learning.decay_factor learning_rate = float(self._config.learning.learning_rate) # Define a learning rate schedule. global_step = slim.get_or_create_global_step() learning_rate = tf.train.exponential_decay( learning_rate, global_step, decay_steps, decay_factor, staircase=True) # Create an optimizer. opt_type = self._config.learning.optimizer if opt_type == 'adam': opt = tf.train.AdamOptimizer(learning_rate) elif opt_type == 'momentum': opt = tf.train.MomentumOptimizer(learning_rate, 0.9) elif opt_type == 'rmsprop': opt = tf.train.RMSPropOptimizer(learning_rate, momentum=0.9, epsilon=1.0, decay=0.9) else: raise ValueError('Unsupported optimizer %s' % opt_type) if self._config.use_tpu: opt = tpu_optimizer.CrossShardOptimizer(opt) # Create a training op. # train_op = opt.minimize(loss, var_list=self.variables_to_train) # Create a training op. train_op = slim.learning.create_train_op( loss, optimizer=opt, variables_to_train=self.variables_to_train, update_ops=tf.get_collection(tf.GraphKeys.UPDATE_OPS)) return train_op
Example #29
Source File: build_whole_network_refine_retinanet.py From R3Det_Tensorflow with MIT License | 4 votes |
def get_restorer(self): checkpoint_path = tf.train.latest_checkpoint(os.path.join(cfgs.TRAINED_CKPT, cfgs.VERSION)) if checkpoint_path != None: if cfgs.RESTORE_FROM_RPN: print('___restore from rpn___') model_variables = slim.get_model_variables() restore_variables = [var for var in model_variables if not var.name.startswith('FastRCNN_Head')] + \ [slim.get_or_create_global_step()] for var in restore_variables: print(var.name) restorer = tf.train.Saver(restore_variables) else: restorer = tf.train.Saver() print("model restore from :", checkpoint_path) else: checkpoint_path = cfgs.PRETRAINED_CKPT print("model restore from pretrained mode, path is :", checkpoint_path) model_variables = slim.get_model_variables() # for var in model_variables: # print(var.name) # print(20*"__++__++__") def name_in_ckpt_rpn(var): return var.op.name def name_in_ckpt_fastrcnn_head(var): ''' Fast-RCNN/resnet_v1_50/block4 -->resnet_v1_50/block4 Fast-RCNN/MobilenetV2/** -- > MobilenetV2 ** :param var: :return: ''' return '/'.join(var.op.name.split('/')[1:]) nameInCkpt_Var_dict = {} for var in model_variables: if var.name.startswith('Fast-RCNN/'+self.base_network_name): # +'/block4' var_name_in_ckpt = name_in_ckpt_fastrcnn_head(var) nameInCkpt_Var_dict[var_name_in_ckpt] = var else: if var.name.startswith(self.base_network_name): var_name_in_ckpt = name_in_ckpt_rpn(var) nameInCkpt_Var_dict[var_name_in_ckpt] = var else: continue restore_variables = nameInCkpt_Var_dict for key, item in restore_variables.items(): print("var_in_graph: ", item.name) print("var_in_ckpt: ", key) print(20*"___") restorer = tf.train.Saver(restore_variables) print(20 * "****") print("restore from pretrained_weighs in IMAGE_NET") return restorer, checkpoint_path
Example #30
Source File: build_whole_network_r3det_plusplus.py From R3Det_Tensorflow with MIT License | 4 votes |
def get_restorer(self): checkpoint_path = tf.train.latest_checkpoint(os.path.join(cfgs.TRAINED_CKPT, cfgs.VERSION)) if checkpoint_path != None: if cfgs.RESTORE_FROM_RPN: print('___restore from rpn___') model_variables = slim.get_model_variables() restore_variables = [var for var in model_variables if not var.name.startswith('FastRCNN_Head')] + \ [slim.get_or_create_global_step()] for var in restore_variables: print(var.name) restorer = tf.train.Saver(restore_variables) else: restorer = tf.train.Saver() print("model restore from :", checkpoint_path) else: checkpoint_path = cfgs.PRETRAINED_CKPT print("model restore from pretrained mode, path is :", checkpoint_path) model_variables = slim.get_model_variables() # for var in model_variables: # print(var.name) # print(20*"__++__++__") def name_in_ckpt_rpn(var): return var.op.name def name_in_ckpt_fastrcnn_head(var): ''' Fast-RCNN/resnet_v1_50/block4 -->resnet_v1_50/block4 Fast-RCNN/MobilenetV2/** -- > MobilenetV2 ** :param var: :return: ''' return '/'.join(var.op.name.split('/')[1:]) nameInCkpt_Var_dict = {} for var in model_variables: if var.name.startswith('Fast-RCNN/'+self.base_network_name): # +'/block4' var_name_in_ckpt = name_in_ckpt_fastrcnn_head(var) nameInCkpt_Var_dict[var_name_in_ckpt] = var else: if var.name.startswith(self.base_network_name): var_name_in_ckpt = name_in_ckpt_rpn(var) nameInCkpt_Var_dict[var_name_in_ckpt] = var else: continue restore_variables = nameInCkpt_Var_dict for key, item in restore_variables.items(): print("var_in_graph: ", item.name) print("var_in_ckpt: ", key) print(20*"___") restorer = tf.train.Saver(restore_variables) print(20 * "****") print("restore from pretrained_weighs in IMAGE_NET") return restorer, checkpoint_path