Python beam_search.BeamSearch() Examples
The following are 13
code examples of beam_search.BeamSearch().
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
beam_search
, or try the search function
.
Example #1
Source File: seq2seq_attention_decode.py From DOTA_models with Apache License 2.0 | 5 votes |
def _Decode(self, saver, sess): """Restore a checkpoint and decode it. Args: saver: Tensorflow checkpoint saver. sess: Tensorflow session. Returns: If success, returns true, otherwise, false. """ ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to decode yet at %s', FLAGS.log_root) return False tf.logging.info('checkpoint path %s', ckpt_state.model_checkpoint_path) ckpt_path = os.path.join( FLAGS.log_root, os.path.basename(ckpt_state.model_checkpoint_path)) tf.logging.info('renamed checkpoint path %s', ckpt_path) saver.restore(sess, ckpt_path) self._decode_io.ResetFiles() for _ in xrange(FLAGS.decode_batches_per_ckpt): (article_batch, _, _, article_lens, _, _, origin_articles, origin_abstracts) = self._batch_reader.NextBatch() for i in xrange(self._hps.batch_size): bs = beam_search.BeamSearch( self._model, self._hps.batch_size, self._vocab.WordToId(data.SENTENCE_START), self._vocab.WordToId(data.SENTENCE_END), self._hps.dec_timesteps) article_batch_cp = article_batch.copy() article_batch_cp[:] = article_batch[i:i+1] article_lens_cp = article_lens.copy() article_lens_cp[:] = article_lens[i:i+1] best_beam = bs.BeamSearch(sess, article_batch_cp, article_lens_cp)[0] decode_output = [int(t) for t in best_beam.tokens[1:]] self._DecodeBatch( origin_articles[i], origin_abstracts[i], decode_output) return True
Example #2
Source File: seq2seq_attention_decode.py From yolo_v2 with Apache License 2.0 | 5 votes |
def _Decode(self, saver, sess): """Restore a checkpoint and decode it. Args: saver: Tensorflow checkpoint saver. sess: Tensorflow session. Returns: If success, returns true, otherwise, false. """ ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to decode yet at %s', FLAGS.log_root) return False tf.logging.info('checkpoint path %s', ckpt_state.model_checkpoint_path) ckpt_path = os.path.join( FLAGS.log_root, os.path.basename(ckpt_state.model_checkpoint_path)) tf.logging.info('renamed checkpoint path %s', ckpt_path) saver.restore(sess, ckpt_path) self._decode_io.ResetFiles() for _ in xrange(FLAGS.decode_batches_per_ckpt): (article_batch, _, _, article_lens, _, _, origin_articles, origin_abstracts) = self._batch_reader.NextBatch() for i in xrange(self._hps.batch_size): bs = beam_search.BeamSearch( self._model, self._hps.batch_size, self._vocab.WordToId(data.SENTENCE_START), self._vocab.WordToId(data.SENTENCE_END), self._hps.dec_timesteps) article_batch_cp = article_batch.copy() article_batch_cp[:] = article_batch[i:i+1] article_lens_cp = article_lens.copy() article_lens_cp[:] = article_lens[i:i+1] best_beam = bs.BeamSearch(sess, article_batch_cp, article_lens_cp)[0] decode_output = [int(t) for t in best_beam.tokens[1:]] self._DecodeBatch( origin_articles[i], origin_abstracts[i], decode_output) return True
Example #3
Source File: seq2seq_attention_decode.py From Gun-Detector with Apache License 2.0 | 5 votes |
def _Decode(self, saver, sess): """Restore a checkpoint and decode it. Args: saver: Tensorflow checkpoint saver. sess: Tensorflow session. Returns: If success, returns true, otherwise, false. """ ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to decode yet at %s', FLAGS.log_root) return False tf.logging.info('checkpoint path %s', ckpt_state.model_checkpoint_path) ckpt_path = os.path.join( FLAGS.log_root, os.path.basename(ckpt_state.model_checkpoint_path)) tf.logging.info('renamed checkpoint path %s', ckpt_path) saver.restore(sess, ckpt_path) self._decode_io.ResetFiles() for _ in xrange(FLAGS.decode_batches_per_ckpt): (article_batch, _, _, article_lens, _, _, origin_articles, origin_abstracts) = self._batch_reader.NextBatch() for i in xrange(self._hps.batch_size): bs = beam_search.BeamSearch( self._model, self._hps.batch_size, self._vocab.WordToId(data.SENTENCE_START), self._vocab.WordToId(data.SENTENCE_END), self._hps.dec_timesteps) article_batch_cp = article_batch.copy() article_batch_cp[:] = article_batch[i:i+1] article_lens_cp = article_lens.copy() article_lens_cp[:] = article_lens[i:i+1] best_beam = bs.BeamSearch(sess, article_batch_cp, article_lens_cp)[0] decode_output = [int(t) for t in best_beam.tokens[1:]] self._DecodeBatch( origin_articles[i], origin_abstracts[i], decode_output) return True
Example #4
Source File: pred.py From transformer-pointer-generator with MIT License | 5 votes |
def _init_graph(self): """ init graph """ self.ys = (self.input_y, None, None) self.xs = (self.input_x, None) self.memory = self.model.encode(self.xs, False)[0] self.logits = self.model.decode(self.xs, self.ys, self.memory, False)[0] ckpt = self.tf.train.get_checkpoint_state(self.model_dir).all_model_checkpoint_paths[-1] graph = self.logits.graph sess_config = self.tf.ConfigProto(allow_soft_placement=True) sess_config.gpu_options.allow_growth = True saver = self.tf.train.Saver() self.sess = self.tf.Session(config=sess_config, graph=graph) self.sess.run(self.tf.global_variables_initializer()) self.tf.reset_default_graph() saver.restore(self.sess, ckpt) self.bs = BeamSearch(self.model, self.hp.beam_size, list(self.idx2token.keys())[2], list(self.idx2token.keys())[3], self.idx2token, self.hp.maxlen2, self.input_x, self.input_y, self.logits)
Example #5
Source File: seq2seq_attention_decode.py From Action_Recognition_Zoo with MIT License | 5 votes |
def _Decode(self, saver, sess): """Restore a checkpoint and decode it. Args: saver: Tensorflow checkpoint saver. sess: Tensorflow session. Returns: If success, returns true, otherwise, false. """ ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to decode yet at %s', FLAGS.log_root) return False tf.logging.info('checkpoint path %s', ckpt_state.model_checkpoint_path) ckpt_path = os.path.join( FLAGS.log_root, os.path.basename(ckpt_state.model_checkpoint_path)) tf.logging.info('renamed checkpoint path %s', ckpt_path) saver.restore(sess, ckpt_path) self._decode_io.ResetFiles() for _ in xrange(FLAGS.decode_batches_per_ckpt): (article_batch, _, _, article_lens, _, _, origin_articles, origin_abstracts) = self._batch_reader.NextBatch() for i in xrange(self._hps.batch_size): bs = beam_search.BeamSearch( self._model, self._hps.batch_size, self._vocab.WordToId(data.SENTENCE_START), self._vocab.WordToId(data.SENTENCE_END), self._hps.dec_timesteps) article_batch_cp = article_batch.copy() article_batch_cp[:] = article_batch[i:i+1] article_lens_cp = article_lens.copy() article_lens_cp[:] = article_lens[i:i+1] best_beam = bs.BeamSearch(sess, article_batch_cp, article_lens_cp)[0] decode_output = [int(t) for t in best_beam.tokens[1:]] self._DecodeBatch( origin_articles[i], origin_abstracts[i], decode_output) return True
Example #6
Source File: seq2seq_attention_decode.py From ECO-pytorch with BSD 2-Clause "Simplified" License | 5 votes |
def _Decode(self, saver, sess): """Restore a checkpoint and decode it. Args: saver: Tensorflow checkpoint saver. sess: Tensorflow session. Returns: If success, returns true, otherwise, false. """ ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to decode yet at %s', FLAGS.log_root) return False tf.logging.info('checkpoint path %s', ckpt_state.model_checkpoint_path) ckpt_path = os.path.join( FLAGS.log_root, os.path.basename(ckpt_state.model_checkpoint_path)) tf.logging.info('renamed checkpoint path %s', ckpt_path) saver.restore(sess, ckpt_path) self._decode_io.ResetFiles() for _ in xrange(FLAGS.decode_batches_per_ckpt): (article_batch, _, _, article_lens, _, _, origin_articles, origin_abstracts) = self._batch_reader.NextBatch() for i in xrange(self._hps.batch_size): bs = beam_search.BeamSearch( self._model, self._hps.batch_size, self._vocab.WordToId(data.SENTENCE_START), self._vocab.WordToId(data.SENTENCE_END), self._hps.dec_timesteps) article_batch_cp = article_batch.copy() article_batch_cp[:] = article_batch[i:i+1] article_lens_cp = article_lens.copy() article_lens_cp[:] = article_lens[i:i+1] best_beam = bs.BeamSearch(sess, article_batch_cp, article_lens_cp)[0] decode_output = [int(t) for t in best_beam.tokens[1:]] self._DecodeBatch( origin_articles[i], origin_abstracts[i], decode_output) return True
Example #7
Source File: seq2seq_attention_decode.py From hands-detection with MIT License | 5 votes |
def _Decode(self, saver, sess): """Restore a checkpoint and decode it. Args: saver: Tensorflow checkpoint saver. sess: Tensorflow session. Returns: If success, returns true, otherwise, false. """ ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to decode yet at %s', FLAGS.log_root) return False tf.logging.info('checkpoint path %s', ckpt_state.model_checkpoint_path) ckpt_path = os.path.join( FLAGS.log_root, os.path.basename(ckpt_state.model_checkpoint_path)) tf.logging.info('renamed checkpoint path %s', ckpt_path) saver.restore(sess, ckpt_path) self._decode_io.ResetFiles() for _ in xrange(FLAGS.decode_batches_per_ckpt): (article_batch, _, _, article_lens, _, _, origin_articles, origin_abstracts) = self._batch_reader.NextBatch() for i in xrange(self._hps.batch_size): bs = beam_search.BeamSearch( self._model, self._hps.batch_size, self._vocab.WordToId(data.SENTENCE_START), self._vocab.WordToId(data.SENTENCE_END), self._hps.dec_timesteps) article_batch_cp = article_batch.copy() article_batch_cp[:] = article_batch[i:i+1] article_lens_cp = article_lens.copy() article_lens_cp[:] = article_lens[i:i+1] best_beam = bs.BeamSearch(sess, article_batch_cp, article_lens_cp)[0] decode_output = [int(t) for t in best_beam.tokens[1:]] self._DecodeBatch( origin_articles[i], origin_abstracts[i], decode_output) return True
Example #8
Source File: seq2seq_attention_decode.py From object_detection_kitti with Apache License 2.0 | 5 votes |
def _Decode(self, saver, sess): """Restore a checkpoint and decode it. Args: saver: Tensorflow checkpoint saver. sess: Tensorflow session. Returns: If success, returns true, otherwise, false. """ ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to decode yet at %s', FLAGS.log_root) return False tf.logging.info('checkpoint path %s', ckpt_state.model_checkpoint_path) ckpt_path = os.path.join( FLAGS.log_root, os.path.basename(ckpt_state.model_checkpoint_path)) tf.logging.info('renamed checkpoint path %s', ckpt_path) saver.restore(sess, ckpt_path) self._decode_io.ResetFiles() for _ in xrange(FLAGS.decode_batches_per_ckpt): (article_batch, _, _, article_lens, _, _, origin_articles, origin_abstracts) = self._batch_reader.NextBatch() for i in xrange(self._hps.batch_size): bs = beam_search.BeamSearch( self._model, self._hps.batch_size, self._vocab.WordToId(data.SENTENCE_START), self._vocab.WordToId(data.SENTENCE_END), self._hps.dec_timesteps) article_batch_cp = article_batch.copy() article_batch_cp[:] = article_batch[i:i+1] article_lens_cp = article_lens.copy() article_lens_cp[:] = article_lens[i:i+1] best_beam = bs.BeamSearch(sess, article_batch_cp, article_lens_cp)[0] decode_output = [int(t) for t in best_beam.tokens[1:]] self._DecodeBatch( origin_articles[i], origin_abstracts[i], decode_output) return True
Example #9
Source File: seq2seq_attention_decode.py From object_detection_with_tensorflow with MIT License | 5 votes |
def _Decode(self, saver, sess): """Restore a checkpoint and decode it. Args: saver: Tensorflow checkpoint saver. sess: Tensorflow session. Returns: If success, returns true, otherwise, false. """ ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to decode yet at %s', FLAGS.log_root) return False tf.logging.info('checkpoint path %s', ckpt_state.model_checkpoint_path) ckpt_path = os.path.join( FLAGS.log_root, os.path.basename(ckpt_state.model_checkpoint_path)) tf.logging.info('renamed checkpoint path %s', ckpt_path) saver.restore(sess, ckpt_path) self._decode_io.ResetFiles() for _ in xrange(FLAGS.decode_batches_per_ckpt): (article_batch, _, _, article_lens, _, _, origin_articles, origin_abstracts) = self._batch_reader.NextBatch() for i in xrange(self._hps.batch_size): bs = beam_search.BeamSearch( self._model, self._hps.batch_size, self._vocab.WordToId(data.SENTENCE_START), self._vocab.WordToId(data.SENTENCE_END), self._hps.dec_timesteps) article_batch_cp = article_batch.copy() article_batch_cp[:] = article_batch[i:i+1] article_lens_cp = article_lens.copy() article_lens_cp[:] = article_lens[i:i+1] best_beam = bs.BeamSearch(sess, article_batch_cp, article_lens_cp)[0] decode_output = [int(t) for t in best_beam.tokens[1:]] self._DecodeBatch( origin_articles[i], origin_abstracts[i], decode_output) return True
Example #10
Source File: seq2seq_attention_decode.py From HumanRecognition with MIT License | 5 votes |
def _Decode(self, saver, sess): """Restore a checkpoint and decode it. Args: saver: Tensorflow checkpoint saver. sess: Tensorflow session. Returns: If success, returns true, otherwise, false. """ ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to decode yet at %s', FLAGS.log_root) return False tf.logging.info('checkpoint path %s', ckpt_state.model_checkpoint_path) ckpt_path = os.path.join( FLAGS.log_root, os.path.basename(ckpt_state.model_checkpoint_path)) tf.logging.info('renamed checkpoint path %s', ckpt_path) saver.restore(sess, ckpt_path) self._decode_io.ResetFiles() for _ in xrange(FLAGS.decode_batches_per_ckpt): (article_batch, _, _, article_lens, _, _, origin_articles, origin_abstracts) = self._batch_reader.NextBatch() for i in xrange(self._hps.batch_size): bs = beam_search.BeamSearch( self._model, self._hps.batch_size, self._vocab.WordToId(data.SENTENCE_START), self._vocab.WordToId(data.SENTENCE_END), self._hps.dec_timesteps) article_batch_cp = article_batch.copy() article_batch_cp[:] = article_batch[i:i+1] article_lens_cp = article_lens.copy() article_lens_cp[:] = article_lens[i:i+1] best_beam = bs.BeamSearch(sess, article_batch_cp, article_lens_cp)[0] decode_output = [int(t) for t in best_beam.tokens[1:]] self._DecodeBatch( origin_articles[i], origin_abstracts[i], decode_output) return True
Example #11
Source File: seq2seq_attention_decode.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def _Decode(self, saver, sess): """Restore a checkpoint and decode it. Args: saver: Tensorflow checkpoint saver. sess: Tensorflow session. Returns: If success, returns true, otherwise, false. """ ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to decode yet at %s', FLAGS.log_root) return False tf.logging.info('checkpoint path %s', ckpt_state.model_checkpoint_path) ckpt_path = os.path.join( FLAGS.log_root, os.path.basename(ckpt_state.model_checkpoint_path)) tf.logging.info('renamed checkpoint path %s', ckpt_path) saver.restore(sess, ckpt_path) self._decode_io.ResetFiles() for _ in xrange(FLAGS.decode_batches_per_ckpt): (article_batch, _, _, article_lens, _, _, origin_articles, origin_abstracts) = self._batch_reader.NextBatch() for i in xrange(self._hps.batch_size): bs = beam_search.BeamSearch( self._model, self._hps.batch_size, self._vocab.WordToId(data.SENTENCE_START), self._vocab.WordToId(data.SENTENCE_END), self._hps.dec_timesteps) article_batch_cp = article_batch.copy() article_batch_cp[:] = article_batch[i:i+1] article_lens_cp = article_lens.copy() article_lens_cp[:] = article_lens[i:i+1] best_beam = bs.BeamSearch(sess, article_batch_cp, article_lens_cp)[0] decode_output = [int(t) for t in best_beam.tokens[1:]] self._DecodeBatch( origin_articles[i], origin_abstracts[i], decode_output) return True
Example #12
Source File: seq2seq_attention_decode.py From models with Apache License 2.0 | 5 votes |
def _Decode(self, saver, sess): """Restore a checkpoint and decode it. Args: saver: Tensorflow checkpoint saver. sess: Tensorflow session. Returns: If success, returns true, otherwise, false. """ ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to decode yet at %s', FLAGS.log_root) return False tf.logging.info('checkpoint path %s', ckpt_state.model_checkpoint_path) ckpt_path = os.path.join( FLAGS.log_root, os.path.basename(ckpt_state.model_checkpoint_path)) tf.logging.info('renamed checkpoint path %s', ckpt_path) saver.restore(sess, ckpt_path) self._decode_io.ResetFiles() for _ in xrange(FLAGS.decode_batches_per_ckpt): (article_batch, _, _, article_lens, _, _, origin_articles, origin_abstracts) = self._batch_reader.NextBatch() for i in xrange(self._hps.batch_size): bs = beam_search.BeamSearch( self._model, self._hps.batch_size, self._vocab.WordToId(data.SENTENCE_START), self._vocab.WordToId(data.SENTENCE_END), self._hps.dec_timesteps) article_batch_cp = article_batch.copy() article_batch_cp[:] = article_batch[i:i+1] article_lens_cp = article_lens.copy() article_lens_cp[:] = article_lens[i:i+1] best_beam = bs.BeamSearch(sess, article_batch_cp, article_lens_cp)[0] decode_output = [int(t) for t in best_beam.tokens[1:]] self._DecodeBatch( origin_articles[i], origin_abstracts[i], decode_output) return True
Example #13
Source File: seq2seq_attention_decode.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def _Decode(self, saver, sess): """Restore a checkpoint and decode it. Args: saver: Tensorflow checkpoint saver. sess: Tensorflow session. Returns: If success, returns true, otherwise, false. """ ckpt_state = tf.train.get_checkpoint_state(FLAGS.log_root) if not (ckpt_state and ckpt_state.model_checkpoint_path): tf.logging.info('No model to decode yet at %s', FLAGS.log_root) return False tf.logging.info('checkpoint path %s', ckpt_state.model_checkpoint_path) ckpt_path = os.path.join( FLAGS.log_root, os.path.basename(ckpt_state.model_checkpoint_path)) tf.logging.info('renamed checkpoint path %s', ckpt_path) saver.restore(sess, ckpt_path) self._decode_io.ResetFiles() for _ in xrange(FLAGS.decode_batches_per_ckpt): (article_batch, _, _, article_lens, _, _, origin_articles, origin_abstracts) = self._batch_reader.NextBatch() for i in xrange(self._hps.batch_size): bs = beam_search.BeamSearch( self._model, self._hps.batch_size, self._vocab.WordToId(data.SENTENCE_START), self._vocab.WordToId(data.SENTENCE_END), self._hps.dec_timesteps) article_batch_cp = article_batch.copy() article_batch_cp[:] = article_batch[i:i+1] article_lens_cp = article_lens.copy() article_lens_cp[:] = article_lens[i:i+1] best_beam = bs.BeamSearch(sess, article_batch_cp, article_lens_cp)[0] decode_output = [int(t) for t in best_beam.tokens[1:]] self._DecodeBatch( origin_articles[i], origin_abstracts[i], decode_output) return True