当前位置: 首页>>代码示例>>Python>>正文


Python Session.run方法代码示例

本文整理汇总了Python中session.Session.run方法的典型用法代码示例。如果您正苦于以下问题:Python Session.run方法的具体用法?Python Session.run怎么用?Python Session.run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在session.Session的用法示例。


在下文中一共展示了Session.run方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import run [as 别名]
class Application:
    """
    Determines which sub-application to run:
    * Menu Screen
    * The Actual Game
    """
    def __init__(self):
        self.session = Session()

    def run(self):
        game_data = GameData("sample") # For now run the game on startup.
        self.session.run_game(game_data)
        self.session.run()
开发者ID:JDShu,项目名称:das-leben,代码行数:15,代码来源:application.py

示例2: test

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import run [as 别名]
  def test(self, params):
    print('\n%s: testing...' %datetime.now())
    sys.stdout.flush()

    session = Session(self._graph, self.results_dir, params['model_name'])
    if 'init_step' not in params or params['init_step'] is None:
      init_step = session.init_step
    else:
      init_step = params['init_step']

    if 'step_num' not in params or params['step_num'] is None:
      step_num = int(np.ceil(np.float(self.fold_size) / self._batch_size))
    else:
      step_num = params['step_num']

    results_file_name = Tester.RESULTS_FILE + '-' + str(init_step) + '-' + \
                        self.fold_name + '-' + str(step_num) + '.json'
    results_file = os.path.join(self.results_dir, results_file_name)
    if not params['load_results'] or not os.path.isfile(results_file):
      session.init(self._classifier, init_step, params['restoring_file'])
      session.start()
      if init_step == 0:
        print 'WARNING: testing an untrained model'
      total_step_num = step_num * params['epoch_num']
      test_num = total_step_num * self._batch_size
      print('%s: test_num=%d' % (datetime.now(), step_num * self._batch_size))
      print('%s: epoch_num=%d' % (datetime.now(), params['epoch_num']))

      results = {}
      results['losses'] = np.zeros(test_num, dtype=np.float32)
      results['probs'] = np.zeros((test_num, Reader.CLASSES_NUM), dtype=np.float32)
      results['labels'] = np.zeros(test_num, dtype=np.int64)

      start_time = time.time()
      for step in range(total_step_num):
        #print('%s: eval_iter=%d' %(datetime.now(), i))
        loss_batch, prob_batch, label_batch = session.run(
          [self._cross_entropy_losses, self._probs, self._input['labels']]
        )
        begin = step * self._batch_size
        results['losses'][begin:begin+self._batch_size] = loss_batch
        results['probs'][begin:begin+self._batch_size, :] = prob_batch
        results['labels'][begin:begin + self._batch_size] = label_batch
        if (step+1) % step_num == 0:
          print "Epoch num: %d" % ((step+1)/step_num)
        if session.should_stop():
          break

      duration = time.time() - start_time
      print('%s: duration = %.1f sec' %(datetime.now(), float(duration)))
      sys.stdout.flush()
      if self.writer is not None:
        summary_str = session.run(self._all_summaries)
        self.writer.write_summaries(summary_str, init_step)

      session.stop()
    else:
      print 'WARNING: using precomputed results'
      results = utils.load_from_file(results_file)

    results['loss'] = np.mean(results['losses']).item()
    results = self.get_all_stats(results)
    if self.writer is not None and not params['load_results']:
      self.writer.write_scalars({'losses/testing/cross_entropy_loss': results['loss'],
                                 'accuracy': results['accuracy']}, init_step)
    utils.dump_to_file(results, results_file)

    return init_step, results['loss']
开发者ID:sdemyanov,项目名称:tensorflow-worklab,代码行数:70,代码来源:tester.py

示例3: Session

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import run [as 别名]
# -*- coding: utf-8 -*-
"""main of ReckonPrimer
see http://wiki.laptop.org/go/Software_projects#ReconPrimer
(c) Walther Neuper 2009
"""
# WN090416 after successful run there is a strange error at the end ?!?


from session import Session

# initializations

_sess = Session("ox-user-name", 'xxx') # TODO.WN090311 name should come from Sugar
_sess.run()

# finalizations

开发者ID:mifix,项目名称:ReckonPrimer,代码行数:18,代码来源:ReckonPrimerActivity-NOGUI.py

示例4: run_session

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import run [as 别名]
 def run_session(self):
     session = Session("xo-user-name", self)
     session.run()
开发者ID:mifix,项目名称:ReckonPrimer,代码行数:5,代码来源:ReckonPrimerActivity.py


注:本文中的session.Session.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。