Python data_utils.LM1BDataset() Examples
The following are 24
code examples of data_utils.LM1BDataset().
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
data_utils
, or try the search function
.
Example #1
Source File: lm_1b_eval.py From object_detection_kitti with Apache License 2.0 | 5 votes |
def _EvalModel(dataset): """Evaluate model perplexity using provided dataset. Args: dataset: LM1BDataset object. """ sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt) current_step = t['global_step'].eval(session=sess) sys.stderr.write('Loaded step %d.\n' % current_step) data_gen = dataset.get_batch(BATCH_SIZE, NUM_TIMESTEPS, forever=False) sum_num = 0.0 sum_den = 0.0 perplexity = 0.0 for i, (inputs, char_inputs, _, targets, weights) in enumerate(data_gen): input_dict = {t['inputs_in']: inputs, t['targets_in']: targets, t['target_weights_in']: weights} if 'char_inputs_in' in t: input_dict[t['char_inputs_in']] = char_inputs log_perp = sess.run(t['log_perplexity_out'], feed_dict=input_dict) if np.isnan(log_perp): sys.stderr.error('log_perplexity is Nan.\n') else: sum_num += log_perp * weights.mean() sum_den += weights.mean() if sum_den > 0: perplexity = np.exp(sum_num / sum_den) sys.stderr.write('Eval Step: %d, Average Perplexity: %f.\n' % (i, perplexity)) if i > FLAGS.max_eval_steps: break
Example #2
Source File: lm_1b_eval.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def main(unused_argv): vocab = data_utils.CharsVocabulary(FLAGS.vocab_file, MAX_WORD_LEN) if FLAGS.mode == 'eval': dataset = data_utils.LM1BDataset(FLAGS.input_data, vocab) _EvalModel(dataset) elif FLAGS.mode == 'sample': _SampleModel(FLAGS.prefix, vocab) elif FLAGS.mode == 'dump_emb': _DumpEmb(vocab) elif FLAGS.mode == 'dump_lstm_emb': _DumpSentenceEmbedding(FLAGS.sentence, vocab) else: raise Exception('Mode not supported.')
Example #3
Source File: lm_1b_eval.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def _EvalModel(dataset): """Evaluate model perplexity using provided dataset. Args: dataset: LM1BDataset object. """ sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt) current_step = t['global_step'].eval(session=sess) sys.stderr.write('Loaded step %d.\n' % current_step) data_gen = dataset.get_batch(BATCH_SIZE, NUM_TIMESTEPS, forever=False) sum_num = 0.0 sum_den = 0.0 perplexity = 0.0 for i, (inputs, char_inputs, _, targets, weights) in enumerate(data_gen): input_dict = {t['inputs_in']: inputs, t['targets_in']: targets, t['target_weights_in']: weights} if 'char_inputs_in' in t: input_dict[t['char_inputs_in']] = char_inputs log_perp = sess.run(t['log_perplexity_out'], feed_dict=input_dict) if np.isnan(log_perp): sys.stderr.error('log_perplexity is Nan.\n') else: sum_num += log_perp * weights.mean() sum_den += weights.mean() if sum_den > 0: perplexity = np.exp(sum_num / sum_den) sys.stderr.write('Eval Step: %d, Average Perplexity: %f.\n' % (i, perplexity)) if i > FLAGS.max_eval_steps: break
Example #4
Source File: lm_1b_eval.py From models with Apache License 2.0 | 5 votes |
def main(unused_argv): vocab = data_utils.CharsVocabulary(FLAGS.vocab_file, MAX_WORD_LEN) if FLAGS.mode == 'eval': dataset = data_utils.LM1BDataset(FLAGS.input_data, vocab) _EvalModel(dataset) elif FLAGS.mode == 'sample': _SampleModel(FLAGS.prefix, vocab) elif FLAGS.mode == 'dump_emb': _DumpEmb(vocab) elif FLAGS.mode == 'dump_lstm_emb': _DumpSentenceEmbedding(FLAGS.sentence, vocab) else: raise Exception('Mode not supported.')
Example #5
Source File: lm_1b_eval.py From models with Apache License 2.0 | 5 votes |
def _EvalModel(dataset): """Evaluate model perplexity using provided dataset. Args: dataset: LM1BDataset object. """ sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt) current_step = t['global_step'].eval(session=sess) sys.stderr.write('Loaded step %d.\n' % current_step) data_gen = dataset.get_batch(BATCH_SIZE, NUM_TIMESTEPS, forever=False) sum_num = 0.0 sum_den = 0.0 perplexity = 0.0 for i, (inputs, char_inputs, _, targets, weights) in enumerate(data_gen): input_dict = {t['inputs_in']: inputs, t['targets_in']: targets, t['target_weights_in']: weights} if 'char_inputs_in' in t: input_dict[t['char_inputs_in']] = char_inputs log_perp = sess.run(t['log_perplexity_out'], feed_dict=input_dict) if np.isnan(log_perp): sys.stderr.error('log_perplexity is Nan.\n') else: sum_num += log_perp * weights.mean() sum_den += weights.mean() if sum_den > 0: perplexity = np.exp(sum_num / sum_den) sys.stderr.write('Eval Step: %d, Average Perplexity: %f.\n' % (i, perplexity)) if i > FLAGS.max_eval_steps: break
Example #6
Source File: lm_1b_eval.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def main(unused_argv): vocab = data_utils.CharsVocabulary(FLAGS.vocab_file, MAX_WORD_LEN) if FLAGS.mode == 'eval': dataset = data_utils.LM1BDataset(FLAGS.input_data, vocab) _EvalModel(dataset) elif FLAGS.mode == 'sample': _SampleModel(FLAGS.prefix, vocab) elif FLAGS.mode == 'dump_emb': _DumpEmb(vocab) elif FLAGS.mode == 'dump_lstm_emb': _DumpSentenceEmbedding(FLAGS.sentence, vocab) else: raise Exception('Mode not supported.')
Example #7
Source File: lm_1b_eval.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def _EvalModel(dataset): """Evaluate model perplexity using provided dataset. Args: dataset: LM1BDataset object. """ sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt) current_step = t['global_step'].eval(session=sess) sys.stderr.write('Loaded step %d.\n' % current_step) data_gen = dataset.get_batch(BATCH_SIZE, NUM_TIMESTEPS, forever=False) sum_num = 0.0 sum_den = 0.0 perplexity = 0.0 for i, (inputs, char_inputs, _, targets, weights) in enumerate(data_gen): input_dict = {t['inputs_in']: inputs, t['targets_in']: targets, t['target_weights_in']: weights} if 'char_inputs_in' in t: input_dict[t['char_inputs_in']] = char_inputs log_perp = sess.run(t['log_perplexity_out'], feed_dict=input_dict) if np.isnan(log_perp): sys.stderr.error('log_perplexity is Nan.\n') else: sum_num += log_perp * weights.mean() sum_den += weights.mean() if sum_den > 0: perplexity = np.exp(sum_num / sum_den) sys.stderr.write('Eval Step: %d, Average Perplexity: %f.\n' % (i, perplexity)) if i > FLAGS.max_eval_steps: break
Example #8
Source File: lm_1b_eval.py From HumanRecognition with MIT License | 5 votes |
def main(unused_argv): vocab = data_utils.CharsVocabulary(FLAGS.vocab_file, MAX_WORD_LEN) if FLAGS.mode == 'eval': dataset = data_utils.LM1BDataset(FLAGS.input_data, vocab) _EvalModel(dataset) elif FLAGS.mode == 'sample': _SampleModel(FLAGS.prefix, vocab) elif FLAGS.mode == 'dump_emb': _DumpEmb(vocab) elif FLAGS.mode == 'dump_lstm_emb': _DumpSentenceEmbedding(FLAGS.sentence, vocab) else: raise Exception('Mode not supported.')
Example #9
Source File: lm_1b_eval.py From HumanRecognition with MIT License | 5 votes |
def _EvalModel(dataset): """Evaluate model perplexity using provided dataset. Args: dataset: LM1BDataset object. """ sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt) current_step = t['global_step'].eval(session=sess) sys.stderr.write('Loaded step %d.\n' % current_step) data_gen = dataset.get_batch(BATCH_SIZE, NUM_TIMESTEPS, forever=False) sum_num = 0.0 sum_den = 0.0 perplexity = 0.0 for i, (inputs, char_inputs, _, targets, weights) in enumerate(data_gen): input_dict = {t['inputs_in']: inputs, t['targets_in']: targets, t['target_weights_in']: weights} if 'char_inputs_in' in t: input_dict[t['char_inputs_in']] = char_inputs log_perp = sess.run(t['log_perplexity_out'], feed_dict=input_dict) if np.isnan(log_perp): sys.stderr.error('log_perplexity is Nan.\n') else: sum_num += log_perp * weights.mean() sum_den += weights.mean() if sum_den > 0: perplexity = np.exp(sum_num / sum_den) sys.stderr.write('Eval Step: %d, Average Perplexity: %f.\n' % (i, perplexity)) if i > FLAGS.max_eval_steps: break
Example #10
Source File: lm_1b_eval.py From object_detection_with_tensorflow with MIT License | 5 votes |
def main(unused_argv): vocab = data_utils.CharsVocabulary(FLAGS.vocab_file, MAX_WORD_LEN) if FLAGS.mode == 'eval': dataset = data_utils.LM1BDataset(FLAGS.input_data, vocab) _EvalModel(dataset) elif FLAGS.mode == 'sample': _SampleModel(FLAGS.prefix, vocab) elif FLAGS.mode == 'dump_emb': _DumpEmb(vocab) elif FLAGS.mode == 'dump_lstm_emb': _DumpSentenceEmbedding(FLAGS.sentence, vocab) else: raise Exception('Mode not supported.')
Example #11
Source File: lm_1b_eval.py From object_detection_with_tensorflow with MIT License | 5 votes |
def _EvalModel(dataset): """Evaluate model perplexity using provided dataset. Args: dataset: LM1BDataset object. """ sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt) current_step = t['global_step'].eval(session=sess) sys.stderr.write('Loaded step %d.\n' % current_step) data_gen = dataset.get_batch(BATCH_SIZE, NUM_TIMESTEPS, forever=False) sum_num = 0.0 sum_den = 0.0 perplexity = 0.0 for i, (inputs, char_inputs, _, targets, weights) in enumerate(data_gen): input_dict = {t['inputs_in']: inputs, t['targets_in']: targets, t['target_weights_in']: weights} if 'char_inputs_in' in t: input_dict[t['char_inputs_in']] = char_inputs log_perp = sess.run(t['log_perplexity_out'], feed_dict=input_dict) if np.isnan(log_perp): sys.stderr.error('log_perplexity is Nan.\n') else: sum_num += log_perp * weights.mean() sum_den += weights.mean() if sum_den > 0: perplexity = np.exp(sum_num / sum_den) sys.stderr.write('Eval Step: %d, Average Perplexity: %f.\n' % (i, perplexity)) if i > FLAGS.max_eval_steps: break
Example #12
Source File: lm_1b_eval.py From object_detection_kitti with Apache License 2.0 | 5 votes |
def main(unused_argv): vocab = data_utils.CharsVocabulary(FLAGS.vocab_file, MAX_WORD_LEN) if FLAGS.mode == 'eval': dataset = data_utils.LM1BDataset(FLAGS.input_data, vocab) _EvalModel(dataset) elif FLAGS.mode == 'sample': _SampleModel(FLAGS.prefix, vocab) elif FLAGS.mode == 'dump_emb': _DumpEmb(vocab) elif FLAGS.mode == 'dump_lstm_emb': _DumpSentenceEmbedding(FLAGS.sentence, vocab) else: raise Exception('Mode not supported.')
Example #13
Source File: lm_1b_eval.py From DOTA_models with Apache License 2.0 | 5 votes |
def _EvalModel(dataset): """Evaluate model perplexity using provided dataset. Args: dataset: LM1BDataset object. """ sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt) current_step = t['global_step'].eval(session=sess) sys.stderr.write('Loaded step %d.\n' % current_step) data_gen = dataset.get_batch(BATCH_SIZE, NUM_TIMESTEPS, forever=False) sum_num = 0.0 sum_den = 0.0 perplexity = 0.0 for i, (inputs, char_inputs, _, targets, weights) in enumerate(data_gen): input_dict = {t['inputs_in']: inputs, t['targets_in']: targets, t['target_weights_in']: weights} if 'char_inputs_in' in t: input_dict[t['char_inputs_in']] = char_inputs log_perp = sess.run(t['log_perplexity_out'], feed_dict=input_dict) if np.isnan(log_perp): sys.stderr.error('log_perplexity is Nan.\n') else: sum_num += log_perp * weights.mean() sum_den += weights.mean() if sum_den > 0: perplexity = np.exp(sum_num / sum_den) sys.stderr.write('Eval Step: %d, Average Perplexity: %f.\n' % (i, perplexity)) if i > FLAGS.max_eval_steps: break
Example #14
Source File: lm_1b_eval.py From hands-detection with MIT License | 5 votes |
def main(unused_argv): vocab = data_utils.CharsVocabulary(FLAGS.vocab_file, MAX_WORD_LEN) if FLAGS.mode == 'eval': dataset = data_utils.LM1BDataset(FLAGS.input_data, vocab) _EvalModel(dataset) elif FLAGS.mode == 'sample': _SampleModel(FLAGS.prefix, vocab) elif FLAGS.mode == 'dump_emb': _DumpEmb(vocab) elif FLAGS.mode == 'dump_lstm_emb': _DumpSentenceEmbedding(FLAGS.sentence, vocab) else: raise Exception('Mode not supported.')
Example #15
Source File: lm_1b_eval.py From hands-detection with MIT License | 5 votes |
def _EvalModel(dataset): """Evaluate model perplexity using provided dataset. Args: dataset: LM1BDataset object. """ sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt) current_step = t['global_step'].eval(session=sess) sys.stderr.write('Loaded step %d.\n' % current_step) data_gen = dataset.get_batch(BATCH_SIZE, NUM_TIMESTEPS, forever=False) sum_num = 0.0 sum_den = 0.0 perplexity = 0.0 for i, (inputs, char_inputs, _, targets, weights) in enumerate(data_gen): input_dict = {t['inputs_in']: inputs, t['targets_in']: targets, t['target_weights_in']: weights} if 'char_inputs_in' in t: input_dict[t['char_inputs_in']] = char_inputs log_perp = sess.run(t['log_perplexity_out'], feed_dict=input_dict) if np.isnan(log_perp): sys.stderr.error('log_perplexity is Nan.\n') else: sum_num += log_perp * weights.mean() sum_den += weights.mean() if sum_den > 0: perplexity = np.exp(sum_num / sum_den) sys.stderr.write('Eval Step: %d, Average Perplexity: %f.\n' % (i, perplexity)) if i > FLAGS.max_eval_steps: break
Example #16
Source File: lm_1b_eval.py From ECO-pytorch with BSD 2-Clause "Simplified" License | 5 votes |
def main(unused_argv): vocab = data_utils.CharsVocabulary(FLAGS.vocab_file, MAX_WORD_LEN) if FLAGS.mode == 'eval': dataset = data_utils.LM1BDataset(FLAGS.input_data, vocab) _EvalModel(dataset) elif FLAGS.mode == 'sample': _SampleModel(FLAGS.prefix, vocab) elif FLAGS.mode == 'dump_emb': _DumpEmb(vocab) elif FLAGS.mode == 'dump_lstm_emb': _DumpSentenceEmbedding(FLAGS.sentence, vocab) else: raise Exception('Mode not supported.')
Example #17
Source File: lm_1b_eval.py From ECO-pytorch with BSD 2-Clause "Simplified" License | 5 votes |
def _EvalModel(dataset): """Evaluate model perplexity using provided dataset. Args: dataset: LM1BDataset object. """ sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt) current_step = t['global_step'].eval(session=sess) sys.stderr.write('Loaded step %d.\n' % current_step) data_gen = dataset.get_batch(BATCH_SIZE, NUM_TIMESTEPS, forever=False) sum_num = 0.0 sum_den = 0.0 perplexity = 0.0 for i, (inputs, char_inputs, _, targets, weights) in enumerate(data_gen): input_dict = {t['inputs_in']: inputs, t['targets_in']: targets, t['target_weights_in']: weights} if 'char_inputs_in' in t: input_dict[t['char_inputs_in']] = char_inputs log_perp = sess.run(t['log_perplexity_out'], feed_dict=input_dict) if np.isnan(log_perp): sys.stderr.error('log_perplexity is Nan.\n') else: sum_num += log_perp * weights.mean() sum_den += weights.mean() if sum_den > 0: perplexity = np.exp(sum_num / sum_den) sys.stderr.write('Eval Step: %d, Average Perplexity: %f.\n' % (i, perplexity)) if i > FLAGS.max_eval_steps: break
Example #18
Source File: lm_1b_eval.py From Action_Recognition_Zoo with MIT License | 5 votes |
def main(unused_argv): vocab = data_utils.CharsVocabulary(FLAGS.vocab_file, MAX_WORD_LEN) if FLAGS.mode == 'eval': dataset = data_utils.LM1BDataset(FLAGS.input_data, vocab) _EvalModel(dataset) elif FLAGS.mode == 'sample': _SampleModel(FLAGS.prefix, vocab) elif FLAGS.mode == 'dump_emb': _DumpEmb(vocab) elif FLAGS.mode == 'dump_lstm_emb': _DumpSentenceEmbedding(FLAGS.sentence, vocab) else: raise Exception('Mode not supported.')
Example #19
Source File: lm_1b_eval.py From Action_Recognition_Zoo with MIT License | 5 votes |
def _EvalModel(dataset): """Evaluate model perplexity using provided dataset. Args: dataset: LM1BDataset object. """ sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt) current_step = t['global_step'].eval(session=sess) sys.stderr.write('Loaded step %d.\n' % current_step) data_gen = dataset.get_batch(BATCH_SIZE, NUM_TIMESTEPS, forever=False) sum_num = 0.0 sum_den = 0.0 perplexity = 0.0 for i, (inputs, char_inputs, _, targets, weights) in enumerate(data_gen): input_dict = {t['inputs_in']: inputs, t['targets_in']: targets, t['target_weights_in']: weights} if 'char_inputs_in' in t: input_dict[t['char_inputs_in']] = char_inputs log_perp = sess.run(t['log_perplexity_out'], feed_dict=input_dict) if np.isnan(log_perp): sys.stderr.error('log_perplexity is Nan.\n') else: sum_num += log_perp * weights.mean() sum_den += weights.mean() if sum_den > 0: perplexity = np.exp(sum_num / sum_den) sys.stderr.write('Eval Step: %d, Average Perplexity: %f.\n' % (i, perplexity)) if i > FLAGS.max_eval_steps: break
Example #20
Source File: lm_1b_eval.py From Gun-Detector with Apache License 2.0 | 5 votes |
def main(unused_argv): vocab = data_utils.CharsVocabulary(FLAGS.vocab_file, MAX_WORD_LEN) if FLAGS.mode == 'eval': dataset = data_utils.LM1BDataset(FLAGS.input_data, vocab) _EvalModel(dataset) elif FLAGS.mode == 'sample': _SampleModel(FLAGS.prefix, vocab) elif FLAGS.mode == 'dump_emb': _DumpEmb(vocab) elif FLAGS.mode == 'dump_lstm_emb': _DumpSentenceEmbedding(FLAGS.sentence, vocab) else: raise Exception('Mode not supported.')
Example #21
Source File: lm_1b_eval.py From Gun-Detector with Apache License 2.0 | 5 votes |
def _EvalModel(dataset): """Evaluate model perplexity using provided dataset. Args: dataset: LM1BDataset object. """ sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt) current_step = t['global_step'].eval(session=sess) sys.stderr.write('Loaded step %d.\n' % current_step) data_gen = dataset.get_batch(BATCH_SIZE, NUM_TIMESTEPS, forever=False) sum_num = 0.0 sum_den = 0.0 perplexity = 0.0 for i, (inputs, char_inputs, _, targets, weights) in enumerate(data_gen): input_dict = {t['inputs_in']: inputs, t['targets_in']: targets, t['target_weights_in']: weights} if 'char_inputs_in' in t: input_dict[t['char_inputs_in']] = char_inputs log_perp = sess.run(t['log_perplexity_out'], feed_dict=input_dict) if np.isnan(log_perp): sys.stderr.error('log_perplexity is Nan.\n') else: sum_num += log_perp * weights.mean() sum_den += weights.mean() if sum_den > 0: perplexity = np.exp(sum_num / sum_den) sys.stderr.write('Eval Step: %d, Average Perplexity: %f.\n' % (i, perplexity)) if i > FLAGS.max_eval_steps: break
Example #22
Source File: lm_1b_eval.py From yolo_v2 with Apache License 2.0 | 5 votes |
def main(unused_argv): vocab = data_utils.CharsVocabulary(FLAGS.vocab_file, MAX_WORD_LEN) if FLAGS.mode == 'eval': dataset = data_utils.LM1BDataset(FLAGS.input_data, vocab) _EvalModel(dataset) elif FLAGS.mode == 'sample': _SampleModel(FLAGS.prefix, vocab) elif FLAGS.mode == 'dump_emb': _DumpEmb(vocab) elif FLAGS.mode == 'dump_lstm_emb': _DumpSentenceEmbedding(FLAGS.sentence, vocab) else: raise Exception('Mode not supported.')
Example #23
Source File: lm_1b_eval.py From yolo_v2 with Apache License 2.0 | 5 votes |
def _EvalModel(dataset): """Evaluate model perplexity using provided dataset. Args: dataset: LM1BDataset object. """ sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt) current_step = t['global_step'].eval(session=sess) sys.stderr.write('Loaded step %d.\n' % current_step) data_gen = dataset.get_batch(BATCH_SIZE, NUM_TIMESTEPS, forever=False) sum_num = 0.0 sum_den = 0.0 perplexity = 0.0 for i, (inputs, char_inputs, _, targets, weights) in enumerate(data_gen): input_dict = {t['inputs_in']: inputs, t['targets_in']: targets, t['target_weights_in']: weights} if 'char_inputs_in' in t: input_dict[t['char_inputs_in']] = char_inputs log_perp = sess.run(t['log_perplexity_out'], feed_dict=input_dict) if np.isnan(log_perp): sys.stderr.error('log_perplexity is Nan.\n') else: sum_num += log_perp * weights.mean() sum_den += weights.mean() if sum_den > 0: perplexity = np.exp(sum_num / sum_den) sys.stderr.write('Eval Step: %d, Average Perplexity: %f.\n' % (i, perplexity)) if i > FLAGS.max_eval_steps: break
Example #24
Source File: lm_1b_eval.py From DOTA_models with Apache License 2.0 | 5 votes |
def main(unused_argv): vocab = data_utils.CharsVocabulary(FLAGS.vocab_file, MAX_WORD_LEN) if FLAGS.mode == 'eval': dataset = data_utils.LM1BDataset(FLAGS.input_data, vocab) _EvalModel(dataset) elif FLAGS.mode == 'sample': _SampleModel(FLAGS.prefix, vocab) elif FLAGS.mode == 'dump_emb': _DumpEmb(vocab) elif FLAGS.mode == 'dump_lstm_emb': _DumpSentenceEmbedding(FLAGS.sentence, vocab) else: raise Exception('Mode not supported.')