當前位置: 首頁>>代碼示例>>Python>>正文


Python gflags.FLAGS屬性代碼示例

本文整理匯總了Python中gflags.FLAGS屬性的典型用法代碼示例。如果您正苦於以下問題:Python gflags.FLAGS屬性的具體用法?Python gflags.FLAGS怎麽用?Python gflags.FLAGS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在gflags的用法示例。


在下文中一共展示了gflags.FLAGS屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: build_cost

# 需要導入模塊: import gflags [as 別名]
# 或者: from gflags import FLAGS [as 別名]
def build_cost(logits, targets):
    """
    Build a classification cost function.
    """
    # Clip gradients coming from the cost function.
    logits = theano.gradient.grad_clip(
        logits, -1. * FLAGS.clipping_max_value, FLAGS.clipping_max_value)

    predicted_dist = T.nnet.softmax(logits)

    costs = T.nnet.categorical_crossentropy(predicted_dist, targets)
    cost = costs.mean()

    pred = T.argmax(logits, axis=1)
    acc = 1. - T.mean(T.cast(T.neq(pred, targets), theano.config.floatX))

    return cost, acc 
開發者ID:stanfordnlp,項目名稱:spinn,代碼行數:19,代碼來源:classifier.py

示例2: evaluate

# 需要導入模塊: import gflags [as 別名]
# 或者: from gflags import FLAGS [as 別名]
def evaluate(eval_fn, eval_set, logger, step, zero_fn):
    # Evaluate
    acc_accum = 0.0
    action_acc_accum = 0.0
    eval_batches = 0.0
    for (eval_X_batch, eval_transitions_batch, eval_y_batch, eval_num_transitions_batch) in eval_set[1]:
        acc_value, action_acc_value = eval_fn(
            eval_X_batch, eval_transitions_batch,
            eval_y_batch, eval_num_transitions_batch, 0.0,  # Eval mode: Don't apply dropout.
            int(FLAGS.allow_gt_transitions_in_eval),  # Allow GT transitions to be used according to flag.
            float(FLAGS.allow_gt_transitions_in_eval))  # If flag not set, used scheduled sampling
                                                        # p(ground truth) = 0.0,
                                                        # else SS p(ground truth) = 1.0
        acc_accum += acc_value
        action_acc_accum += action_acc_value
        eval_batches += 1.0

        # Zero out all auxiliary variables.
        zero_fn()
    logger.Log("Step: %i\tEval acc: %f\t %f\t%s" %
              (step, acc_accum / eval_batches, action_acc_accum / eval_batches, eval_set[0]))
    return acc_accum / eval_batches 
開發者ID:stanfordnlp,項目名稱:spinn,代碼行數:24,代碼來源:classifier.py

示例3: evaluate

# 需要導入模塊: import gflags [as 別名]
# 或者: from gflags import FLAGS [as 別名]
def evaluate(eval_fn, eval_set, logger, step):
    # Evaluate
    acc_accum = 0.0
    action_acc_accum = 0.0
    eval_batches = 0.0
    for (eval_X_batch, eval_transitions_batch, eval_y_batch, eval_num_transitions_batch) in eval_set[1]:
        acc_value, action_acc_value = eval_fn(
            eval_X_batch, eval_transitions_batch,
            eval_y_batch, eval_num_transitions_batch, 0.0,  # Eval mode: Don't apply dropout.
            int(FLAGS.allow_gt_transitions_in_eval),  # Allow GT transitions to be used according to flag.
            float(FLAGS.allow_gt_transitions_in_eval))  # If flag not set, used scheduled sampling
                                                        # p(ground truth) = 0.0,
                                                        # else SS p(ground truth) = 1.0
        acc_accum += acc_value
        action_acc_accum += action_acc_value
        eval_batches += 1.0
    logger.Log("Step: %i\tEval acc: %f\t %f\t%s" %
              (step, acc_accum / eval_batches, action_acc_accum / eval_batches, eval_set[0]))
    return acc_accum / eval_batches 
開發者ID:stanfordnlp,項目名稱:spinn,代碼行數:21,代碼來源:fat_classifier.py

示例4: ShowPlots

# 需要導入模塊: import gflags [as 別名]
# 或者: from gflags import FLAGS [as 別名]
def ShowPlots(subplot=False):
  for log_ind, path in enumerate(FLAGS.path.split(":")):
    log = Log(path)
    if subplot:
      plt.subplot(len(FLAGS.path.split(":")), 1, log_ind + 1)
    for index in FLAGS.index.split(","):
      index = int(index)
      for attr in ["pred_acc", "parse_acc", "total_cost", "xent_cost", "l2_cost", "action_cost"]:
        if getattr(FLAGS, attr):
          if "cost" in attr:
            assert index == 0, "costs only associated with training log"
          steps, val = zip(*[(l.step, getattr(l, attr)) for l in log.corpus[index] if l.step < FLAGS.iters])
          dct = {}
          for k, v in zip(steps, val):
            dct[k] = max(v, dct[k]) if k in dct else v
          steps, val = zip(*sorted(dct.iteritems()))
          plt.plot(steps, val, label="Log%d:%s-%d" % (log_ind, attr, index))
    
  plt.xlabel("No. of training iteration")
  plt.ylabel(FLAGS.ylabel)
  if FLAGS.legend:
    plt.legend()
  plt.show() 
開發者ID:stanfordnlp,項目名稱:spinn,代碼行數:25,代碼來源:analyze_log.py

示例5: getExcludeFilename

# 需要導入模塊: import gflags [as 別名]
# 或者: from gflags import FLAGS [as 別名]
def getExcludeFilename(prefix=None, infile=None, log_file=None, job=None):
    try:
        if not prefix:
            prefix = 'exclude'
        if not infile:
            infile = FLAGS.infile
        if not log_file:
            log_file = FLAGS.log_file
        if not job:
            job = FLAGS.job
        # the exclude file is stored as ./log/$prefix-$job_name-$in_filename
        inname = os.path.basename(infile)
        log_dir = os.path.dirname(log_file)
        exclude_filename = os.path.join(log_dir, '%s-%s-%s' % (prefix, job, inname))
    except Exception as e:
        exclude_filename = None
    return exclude_filename 
開發者ID:osssanitizer,項目名稱:osspolice,代碼行數:19,代碼來源:job_util.py

示例6: __init__

# 需要導入模塊: import gflags [as 別名]
# 或者: from gflags import FLAGS [as 別名]
def __init__(self, external_file=None):
    """Initialize the error fixer.

    Args:
      external_file: If included, all output will be directed to this file
          instead of overwriting the files the errors are found in.
    """
    errorhandler.ErrorHandler.__init__(self)

    self._file_name = None
    self._file_token = None
    self._external_file = external_file

    try:
      self._fix_error_codes = set([errors.ByName(error.upper()) for error in
                                   FLAGS.fix_error_codes])
    except KeyError as ke:
      raise ValueError('Unknown error code ' + ke.args[0]) 
開發者ID:google,項目名稱:closure-linter,代碼行數:20,代碼來源:error_fixer.py

示例7: _GetRecursiveFiles

# 需要導入模塊: import gflags [as 別名]
# 或者: from gflags import FLAGS [as 別名]
def _GetRecursiveFiles(suffixes):
  """Returns files to be checked specified by the --recurse flag.

  Args:
    suffixes: Expected suffixes for the file type being checked.

  Returns:
    A list of files to be checked.
  """
  lint_files = []
  # Perform any request recursion
  if FLAGS.recurse:
    for start in FLAGS.recurse:
      for root, subdirs, files in os.walk(start):
        for f in files:
          if MatchesSuffixes(f, suffixes):
            lint_files.append(os.path.join(root, f))
  return lint_files 
開發者ID:google,項目名稱:closure-linter,代碼行數:20,代碼來源:simplefileflags.py

示例8: GetAllSpecifiedFiles

# 需要導入模塊: import gflags [as 別名]
# 或者: from gflags import FLAGS [as 別名]
def GetAllSpecifiedFiles(argv, suffixes):
  """Returns all files specified by the user on the commandline.

  Args:
    argv: Sequence of command line arguments. The second and following arguments
      are assumed to be files that should be linted.
    suffixes: Expected suffixes for the file type

  Returns:
    A list of all files specified directly or indirectly (via flags) on the
    command line by the user.
  """
  files = _GetUserSpecifiedFiles(argv, suffixes)

  if FLAGS.recurse:
    files += _GetRecursiveFiles(suffixes)

  return FilterFiles(files) 
開發者ID:google,項目名稱:closure-linter,代碼行數:20,代碼來源:simplefileflags.py

示例9: MakeErrorRecord

# 需要導入模塊: import gflags [as 別名]
# 或者: from gflags import FLAGS [as 別名]
def MakeErrorRecord(path, error):
  """Make an error record with correctly formatted error string.

  Errors are not able to be serialized (pickled) over processes because of
  their pointers to the complex token/context graph.  We use an intermediary
  serializable class to pass back just the relevant information.

  Args:
    path: Path of file the error was found in.
    error: An error.Error instance.

  Returns:
    _ErrorRecord instance.
  """
  new_error = error.code in errors.NEW_ERRORS

  if FLAGS.unix_mode:
    error_string = erroroutput.GetUnixErrorOutput(
        path, error, new_error=new_error)
  else:
    error_string = erroroutput.GetErrorOutput(error, new_error=new_error)

  return ErrorRecord(path, error_string, new_error) 
開發者ID:google,項目名稱:closure-linter,代碼行數:25,代碼來源:errorrecord.py

示例10: ShouldCheck

# 需要導入模塊: import gflags [as 別名]
# 或者: from gflags import FLAGS [as 別名]
def ShouldCheck(rule):
  """Returns whether the optional rule should be checked.

  Computes different flags (strict, jslint_error, jslint_noerror) to find out if
  this specific rule should be checked.

  Args:
    rule: Name of the rule (see Rule).

  Returns:
    True if the rule should be checked according to the flags, otherwise False.
  """
  if 'no_' + rule in FLAGS.jslint_error:
    return False
  if rule in FLAGS.jslint_error or Rule.ALL in FLAGS.jslint_error:
    return True
  # Checks strict rules.
  return FLAGS.strict and rule in Rule.CLOSURE_RULES 
開發者ID:google,項目名稱:closure-linter,代碼行數:20,代碼來源:error_check.py

示例11: process_flags

# 需要導入模塊: import gflags [as 別名]
# 或者: from gflags import FLAGS [as 別名]
def process_flags(flags=[]):
    """Uses the command-line flags to set the logging level.

    Args:
    argv: List of command line arguments passed to the python script.
    """

    # Let the gflags module process the command-line arguments.
    try:
        FLAGS(flags)
    except gflags.FlagsError as e:
        print('%s\nUsage: %s ARGS\n%s' % (e, str(flags), FLAGS))
        sys.exit(1)

    # Set the logging according to the command-line flag.
    logging.getLogger().setLevel(getattr(logging, FLAGS.logging_level)) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:18,代碼來源:auth.py

示例12: map

# 需要導入模塊: import gflags [as 別名]
# 或者: from gflags import FLAGS [as 別名]
def map(self, key, value):
        if type(value) is not str:
            value = str(value)
        files = [value]
        image_lib = FLAGS.image_lib.lower()
        if image_lib == 'pil':
            resize_crop = PILResizeCrop()
        else:
            resize_crop = OpenCVResizeCrop()
        for i, line in enumerate(files):
            try:
                line = line.replace(FLAGS.input_folder, '').strip()
                line = line.split()
                image_file_name = line[0]
                input_file = os.path.join(FLAGS.input_folder, image_file_name)
                output_file = os.path.join(FLAGS.output_folder, image_file_name)
                output_dir = output_file[:output_file.rfind('/')]
                if not os.path.exists(output_dir):
                    os.makedirs(output_dir)
                feat = resize_crop.resize_and_crop_image(input_file, output_file,
                                                              FLAGS.output_side_length)
            except Exception, e:
                # we ignore the exception (maybe the image is corrupted?)
                print line, Exception, e 
開發者ID:msracver,項目名稱:Deep-Exemplar-based-Colorization,代碼行數:26,代碼來源:resize_and_crop_images.py

示例13: test_defeat_zerglings

# 需要導入模塊: import gflags [as 別名]
# 或者: from gflags import FLAGS [as 別名]
def test_defeat_zerglings(self):
    FLAGS(sys.argv)

    with sc2_env.SC2Env(
        "DefeatZerglingsAndBanelings",
        step_mul=self.step_mul,
        visualize=True,
        game_steps_per_episode=self.steps * self.step_mul) as env:
      obs = env.step(actions=[sc2_actions.FunctionCall(_NO_OP, [])])
      player_relative = obs[0].observation["screen"][_PLAYER_RELATIVE]

      # Break Point!!
      print(player_relative)

      agent = random_agent.RandomAgent()
      run_loop.run_loop([agent], env, self.steps)

    self.assertEqual(agent.steps, self.steps) 
開發者ID:llSourcell,項目名稱:A-Guide-to-DeepMinds-StarCraft-AI-Environment,代碼行數:20,代碼來源:scripted_test.py

示例14: testRmDirs

# 需要導入模塊: import gflags [as 別名]
# 或者: from gflags import FLAGS [as 別名]
def testRmDirs(self):
    test_sandbox = os.path.join(FLAGS.test_tmpdir, 'test-rm-dirs')
    test_dir = os.path.join(test_sandbox, 'test', 'dir')

    os.makedirs(test_sandbox)
    with open(os.path.join(test_sandbox, 'file'), 'w'):
      pass
    os.makedirs(test_dir)
    with open(os.path.join(test_dir, 'file'), 'w'):
      pass

    file_util.RmDirs(test_dir)

    self.assertFalse(os.path.exists(os.path.join(test_sandbox, 'test')))
    self.assertTrue(os.path.exists(os.path.join(test_sandbox, 'file')))

    shutil.rmtree(test_sandbox) 
開發者ID:google,項目名稱:google-apputils,代碼行數:19,代碼來源:file_util_test.py

示例15: Run

# 需要導入模塊: import gflags [as 別名]
# 或者: from gflags import FLAGS [as 別名]
def Run(self, unused_argv):
    """Output 'Command1' and flag info.

    Args:
      unused_argv: Remaining arguments after parsing flags and command

    Returns:
      Value of flag fail1
    """
    print 'Command1'
    if FLAGS.hint:
      print "Hint1:'%s'" % FLAGS.hint
    print "Foo1:'%s'" % FLAGS.foo
    print "Bar1:'%s'" % FLAGS.bar
    if FLAGS.allhelp:
      print "AllHelp:'%s'" % self._all_commands_help
    return FLAGS.fail1 * 1 
開發者ID:google,項目名稱:google-apputils,代碼行數:19,代碼來源:appcommands_example.py


注:本文中的gflags.FLAGS屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。