本文整理汇总了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
示例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
示例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
示例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()
示例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
示例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])
示例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
示例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)
示例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)
示例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
示例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))
示例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
示例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)
示例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)
示例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