def main(argv): """Implement a simple demo for computing error CDFs.""" # Input/output flags. gflags.DEFINE_string('input_file', None, 'Full path to wing HDF5 log file.') gflags.MarkFlagAsRequired('input_file') gflags.DEFINE_string('output_file', None, 'Full path to output MAT file.') gflags.MarkFlagAsRequired('output_file') # Segment processing flags. gflags.DEFINE_integer('increment', 100, 'Integer number of messages between segments.') gflags.DEFINE_integer('seg_length', 1000, 'Integer number of messages in each segment.') # Evaluate segments over a specific time interval. gflags.DEFINE_float('start_time', -float('inf'), 'Start time to evaluate segment errors.') gflags.DEFINE_float('end_time', float('inf'), 'End time to evaluate segment errors.') # Override default parameters. gflags.DEFINE_list('params', [], 'A comma-separated list of param=value tokens, where ' 'each param describes the dot path to a parameter in ' 'EstimatorParams.') gflags.RegisterValidator('params', lambda l: all(len(s.split('=')) == 2 for s in l), message='Invalid key=value parameter syntax.') # Scenarios to process. gflags.DEFINE_bool('scenario_pure_inertial', False, 'Process pure inertial scenario.') gflags.DEFINE_bool('scenario_gps_dropout', False, 'Process GPS dropout scenario.') # Common faults to introduce. gflags.DEFINE_bool('fault_weather', False, 'Fault weather subsystems to avoid an assert when ' 'reprocessing historical data.') gflags.DEFINE_bool('fault_glas', False, 'Fault GLAS subsystems.') # Specify flight for special handling. gflags.DEFINE_string('flight', None, 'Fix known issues associated with the given flight.') try: argv = gflags.FLAGS(argv) except gflags.FlagsError, e: print '{}\nUsage: {} ARGS\n{}'.format(e, sys.argv[0], gflags.FLAGS) sys.exit(1)
def flags(): # Debug settings gflags.DEFINE_string("branch", None, "") gflags.DEFINE_string("sha", None, "") gflags.DEFINE_boolean("debug", False, "") # Performance settings gflags.DEFINE_boolean("cuda", False, "") # Display settings gflags.DEFINE_string("env", "main", "") gflags.DEFINE_string("experiment_name", None, "") # Data settings gflags.DEFINE_string("descr_train", "./utils/descriptions.csv", "") gflags.DEFINE_string("descr_dev", "./utils/descriptions.csv", "") gflags.DEFINE_string("train_data", "./utils/imgs/train", "") gflags.DEFINE_string("dev_data", "./utils/imgs/dev", "") gflags.DEFINE_integer("word_embedding_dim", 100, "") gflags.DEFINE_string("word_embedding_path", "~/data/glove/glove.6B.100d.txt", "") # Optimization settings gflags.DEFINE_enum("optim_type", "RMSprop", ["Adam", "SGD", "RMSprop"], "") gflags.DEFINE_integer("batch_size", 32, "Minibatch size for train set.") gflags.DEFINE_integer("batch_size_dev", 50, "Minibatch size for dev set.") gflags.DEFINE_float("learning_rate", 1e-4, "Used in optimizer.") gflags.DEFINE_integer("max_epoch", 500, "")
def args(): default_experiment_name = "exp-{}".format(int(time.time())) gflags.DEFINE_enum("preset", None, ["demo"], "Easily set configuration.") gflags.DEFINE_string("data_path", os.path.expanduser("~/data/multinli_0.9/multinli_0.9_dev_matched.jsonl"), "Path to NLI data.") gflags.DEFINE_string("eval_data_path", os.path.expanduser("~/data/multinli_0.9/multinli_0.9_dev_matched.jsonl"), "Path to NLI data.") gflags.DEFINE_string("embedding_path", os.path.expanduser("~/data/glove.840B.300d.txt"), "Path to GloVe vectors.") gflags.DEFINE_integer("batch_size", 100, "Batch size.") gflags.DEFINE_integer("input_dim", 300, "Word embedding dimension.") gflags.DEFINE_integer("hidden_dim", 300, "Hidden representation dimension.") gflags.DEFINE_string("save_path", ".", "Path to logs and checkpoints.") gflags.DEFINE_string("load_path", None, "Path to load checkpoint.") gflags.DEFINE_string("log_path", None, "Path to log.") gflags.DEFINE_string("experiment_name", default_experiment_name, "Experiment name.") gflags.DEFINE_float("l2", None, "Use l2 regularization.") gflags.DEFINE_boolean("extract", False, "Use pretrained model to calculate query and target vectors for input data.") gflags.DEFINE_integer("seed", 11, "Random seed.") FLAGS(sys.argv) presets() if not FLAGS.load_path: FLAGS.load_path = FLAGS.save_path # this way we use logs/ckpt for an experiment_name if it exists. if not FLAGS.log_path: FLAGS.log_path = os.path.join('.', FLAGS.experiment_name + '.log') logger = MainLogger().init(path=FLAGS.log_path) logger.Log(json.dumps(FLAGS.FlagValuesDict(), indent=4, sort_keys=True))
def get_flags(): # Debug settings. gflags.DEFINE_string("data_dir", "cmu", "dir containing train.txt, test.txt, valid.txt") gflags.DEFINE_string("log_path", "logs", "") gflags.DEFINE_string("data_type", "discriminator", "figure out how to use this") gflags.DEFINE_enum("model_type", "LSTM", ["LSTM", "BiLSTM", "DEEP"], "options: LSTM, BiLSTM, DEEP, ...") gflags.DEFINE_string("ckpt_path", "checkpoints", "") gflags.DEFINE_boolean("gpu", False, "set to false on local") gflags.DEFINE_string("experiment_name", "", "") gflags.DEFINE_boolean("evaluate_only", False, "") #sizes gflags.DEFINE_integer("embedding_size", 29, "hardcoded for simplicity") gflags.DEFINE_integer("reduction_size", 40, "hardcoded for simplicity") gflags.DEFINE_integer("crop_pad_length", 30, "") #chunks gflags.DEFINE_integer("stages_per_epoch", 40, "how many eval/stats steps per epoch?") gflags.DEFINE_integer("prints_per_stage", 1, "how often to print stats to stdout during epoch") gflags.DEFINE_integer("convergence_threshold", 50, "how many eval steps before early stop") gflags.DEFINE_integer( "max_epochs", 100, "number of epochs before stop, essentially unreachable") gflags.DEFINE_integer("batch_size", 64, "") #tunable parameters gflags.DEFINE_integer("hidden_size", 1024, "") gflags.DEFINE_integer("num_layers", 1, "") gflags.DEFINE_float("learning_rate", .002, "")
def _set_flags(): gflags.DEFINE_boolean("predict_hyp", False, "train to predict hypotheses") gflags.DEFINE_boolean("infer_hyp", False, "use hypotheses at test time") gflags.DEFINE_boolean("infer_by_likelihood", False, "use likelihood (rather than accuracy) to rank hypotheses") gflags.DEFINE_boolean("use_true_hyp", False, "predict using ground-truth description") gflags.DEFINE_integer("n_sample_hyps", 5, "number of hypotheses to sample") gflags.DEFINE_float("learning_rate", 0.001, "learning rate") gflags.DEFINE_string("restore", None, "model to restore") gflags.DEFINE_boolean("use_true_eval", False, "score with true evaluation function") gflags.DEFINE_boolean("use_task_hyp", False, "task as hypothesis")
def _set_flags(): gflags.DEFINE_boolean("predict_hyp", False, "train to predict hypotheses") gflags.DEFINE_boolean("infer_hyp", False, "use hypotheses at test time") gflags.DEFINE_string("restore", None, "model to restore") gflags.DEFINE_float("concept_prior", None, "place a normal prior on concept representations") gflags.DEFINE_integer( "adapt_reprs", 100, "number of representations to sample when doing adaptation") gflags.DEFINE_integer( "adapt_samples", 1000, "number of episodes to spend evaluating sampled representations")
def __init__(self, name, flag_values): super(SetTargetPoolBackup, self).__init__(name, flag_values) flags.DEFINE_float( 'failover_ratio', None, '--failover_ratio and --backup_pool must either be ' 'both set or not set. If not set, existing failover ' 'ratio will be removed from the target pool, which will ' 'disable the fallback behavior of the primary target ' 'pool. If set, the failover ratio of the primary target ' 'pool will be replaced by this value.', flag_values=flag_values) flags.DEFINE_string( 'backup_pool', None, '--backup_pool and --failover_ratio must either be ' 'both set or not set. If not set, existing backup ' 'pool will be removed from the target pool, which will ' 'disable the fallback behavior of the primary target ' 'pool. If set, the backup pool of the primary target ' 'pool will be replaced by this value.', flag_values=flag_values)
def load_defaults(): ### Experiment Parameters gflags.DEFINE_integer( 'num_experiments', 1, 'the number of times to train the model (with different initialization)' ) gflags.DEFINE_integer( 'seed', 1, 'a random seed used in all randomized model initialization') ### Data Parameters gflags.DEFINE_string('train_data', 'data/NTC_1.5/processed/train.utf8', 'the path to the train data file') gflags.DEFINE_string('test_data', 'data/NTC_1.5/processed/test.utf8', 'the path to the test data file') gflags.DEFINE_string('dev_data', 'data/NTC_1.5/processed/dev.utf8', 'the path to the dev data file') gflags.DEFINE_integer( 'max_train_instances', 100000, 'max number of instances to read for each train/test/dev set') ### Model Parameters ## Representation gflags.DEFINE_boolean( 'use_context', True, 'construct the representation from LSTM context embeddings') gflags.DEFINE_boolean( 'use_sp', True, 'construct the representation directly from pred/arg embeddings') gflags.DEFINE_integer('context_dims', 20, 'output dimension for LSTM context embeddings') gflags.DEFINE_integer( 'sp_dims', 8, 'dimensionality of arg embedding for selectional preference') gflags.DEFINE_integer('num_context_layers', 2, 'number of layers in the context LSTM') gflags.DEFINE_float( 'context_dropout', 0.0, 'amount of dropout on each LSTM layer in the context representation')
"""Provide row of input image.""") gflags.DEFINE_integer('input_col', 448, """Provide col of input image.""") gflags.DEFINE_integer('output_row', 14, """Provide row of output shape.""") gflags.DEFINE_integer('output_col', 14, """Provide col of output shape.""") gflags.DEFINE_integer('num_class', 20, """Number of class of dataset.""") gflags.DEFINE_string('eval_dir', 'result', """Directory where to write result files..""") gflags.DEFINE_string('checkpoint_path', 'backup/model.ckpt-50000', """Model file after training.""") gflags.DEFINE_string('gpu_list', '1', """GPU list, such as '0, 1, ....'.""") gflags.DEFINE_float('gpu_usage', 0.8, """Per process gpu memory fraction.""") CLASSES = [] COLORS = [(0, 255, 0), (0, 0, 255), (241, 90, 36), (235, 0, 139), (0, 159, 255), (223, 255, 0), (237, 34, 42), (180, 58, 228), (247, 147, 30), (2, 254, 207)] COUNT = -1 def save_result(im_id, im_sz, boxes_list, eval_dir): global COUNT COUNT += 1
def get_flags(): gflags.DEFINE_enum("model_type", "transup", ["transup", "bprmf", "fm", "transe", "transh", "transr", "transd", "cfkg", "cke", "cofm", "jtransup"], "") gflags.DEFINE_enum("dataset", "ml1m", ['kktix', "ml1m", "dbbook2014", "amazon-book", "last-fm", "yelp2018"], "including ratings.csv, r2kg.tsv and a kg dictionary containing kg_hop[0-9].dat") gflags.DEFINE_bool( "filter_wrong_corrupted", True, "If set to True, filter test samples from train and validations.") gflags.DEFINE_bool("share_embeddings", False, "") gflags.DEFINE_bool("use_st_gumbel", False, "") gflags.DEFINE_integer("max_queue", 10, ".") gflags.DEFINE_integer("num_processes", 40, ".") gflags.DEFINE_float("learning_rate", 0.001, "Used in optimizer.") gflags.DEFINE_float("norm_lambda", 1.0, "decay of joint model.") gflags.DEFINE_float("kg_lambda", 1.0, "decay of kg model.") gflags.DEFINE_integer( "early_stopping_steps_to_wait", 70000, "How many times will lr decrease? If set to 0, it remains constant.") gflags.DEFINE_bool( "L1_flag", False, "If set to True, use L1 distance as dissimilarity; else, use L2.") gflags.DEFINE_bool( "is_report", False, "If set to True, use L1 distance as dissimilarity; else, use L2.") gflags.DEFINE_float("l2_lambda", 1e-5, "") gflags.DEFINE_integer("embedding_size", 64, ".") gflags.DEFINE_integer("negtive_samples", 1, ".") gflags.DEFINE_integer("batch_size", 512, "Minibatch size.") gflags.DEFINE_enum("optimizer_type", "Adagrad", ["Adam", "SGD", "Adagrad", "Rmsprop"], "") gflags.DEFINE_float("learning_rate_decay_when_no_progress", 0.5, "Used in optimizer. Decay the LR by this much every epoch steps if a new best has not been set in the last epoch.") gflags.DEFINE_integer( "eval_interval_steps", 14000, "Evaluate at this interval in each epoch.") gflags.DEFINE_integer( "training_steps", 1400000, "Stop training after this point.") gflags.DEFINE_float("clipping_max_value", 5.0, "") gflags.DEFINE_float("margin", 1.0, "Used in margin loss.") gflags.DEFINE_float("momentum", 0.9, "The momentum of the optimizer.") gflags.DEFINE_integer("seed", 0, "Fix the random seed. Except for 0, which means no setting of random seed.") gflags.DEFINE_integer("topn", 10, "") gflags.DEFINE_integer("num_preferences", 4, "") gflags.DEFINE_float("joint_ratio", 0.5, "(0 - 1). The train ratio of recommendation, kg is 1 - joint_ratio.") gflags.DEFINE_string("experiment_name", None, "") gflags.DEFINE_string("data_path", None, "") gflags.DEFINE_string("rec_test_files", None, "multiple filenames separated by ':'.") gflags.DEFINE_string("kg_test_files", None, "multiple filenames separated by ':'.") gflags.DEFINE_string("log_path", None, "") gflags.DEFINE_enum("log_level", "debug", ["debug", "info"], "") gflags.DEFINE_string( "ckpt_path", None, "Where to save/load checkpoints. If not set, the same as log_path") gflags.DEFINE_string( "load_ckpt_file", None, "Where to load pretrained checkpoints under log path. multiple filenames separated by ':'.") gflags.DEFINE_boolean( "has_visualization", True, "if set True, use visdom for visualization.") gflags.DEFINE_integer("visualization_port", 8097, "") # todo: only eval when no train.dat when load data gflags.DEFINE_boolean( "eval_only_mode", False, "If set, a checkpoint is loaded and a forward pass is done to get the predicted candidates." "Requirements: Must specify load_experiment_name.") gflags.DEFINE_string("load_experiment_name", None, "")
# Random seed gflags.DEFINE_bool('random_seed', True, 'Random seed') # Input gflags.DEFINE_integer('num_img', 45, 'Target Gesture Length') gflags.DEFINE_integer('img_width', 100, 'Target Image Width') gflags.DEFINE_integer('img_height', 100, 'Target Image Height') gflags.DEFINE_string('img_mode', "grayscale", 'Load mode for images, either ' 'rgb or grayscale') # Training parameters gflags.DEFINE_integer('batch_size', 64, 'Batch size in training and evaluation') gflags.DEFINE_integer('epochs', 15, 'Number of epochs for training') gflags.DEFINE_integer('initial_epoch', 0, 'Initial epoch to start training') gflags.DEFINE_float('initial_lr', 1e-4, 'Initial learning rate for adam') # Files gflags.DEFINE_string('experiment_rootdir', "./models/test_5", 'Folder ' ' containing all the logs, model weights and results') gflags.DEFINE_string('data_path', "./ProcessedData", 'Folder containing the whole dataset') gflags.DEFINE_string('video_dir', "../video_1", 'Folder containing' ' only one experiment to be processed') gflags.DEFINE_string('exp_name', "exp_1", 'Name of the experiment' ' to be processed') # Model gflags.DEFINE_bool('restore_model', True, 'Whether to restore a trained' ' model for training') gflags.DEFINE_string('weights_fname', './models/test_3/weights_050.h5',
import gflags import logging import numpy as np from needle.agents import BasicAgent, register_agent from needle.agents.TNPG.net import Net from needle.agents.TRPO.critic import Critic from needle.helper.conjugate_gradient import conjugate_gradient from needle.helper.OU_process import OUProcess from needle.helper.softmax_sampler import SoftmaxSampler from needle.helper.batcher import Batcher from needle.helper.utils import decay_cumsum, softmax gflags.DEFINE_float("GAE_lambda", 0.98, "GAE lambda") gflags.DEFINE_float("critic_eps", 0.01, "critic's trust region") gflags.DEFINE_float("line_search_decay", 0.7, "line search's decay factor") FLAGS = gflags.FLAGS @register_agent("TRPO") class Agent(SoftmaxSampler, Batcher, BasicAgent): def __init__(self, input_dim, output_dim): self.input_dim = input_dim self.output_dim = output_dim self.counter = 0 self.net = Net(input_dim, output_dim) self.net.build_infer() self.net.build_train() self.critic = Critic(input_dim)
def __init__(self, name, flag_values): super(AddTargetPool, self).__init__(name, flag_values) flags.DEFINE_string('description', '', 'An optional Target Pool description', flag_values=flag_values) flags.DEFINE_list( 'health_checks', [], 'Specifies a HttpHealthCheck resource to use to ' 'determine the health of VMs in this pool. ' 'If no health check is specified, traffic will be ' 'sent to all instances in this target pool as if the ' 'instances were healthy, but the health status of this ' 'pool will appear as unhealthy as a warning that this ' 'target pool does not have a health check.', flag_values=flag_values) flags.DEFINE_list( 'instances', [], '[Required] Specifies a list of instances that will ' 'receive traffic directed to this target pool. Each ' 'entry must be specified by the instance name ' '(e.g., \'--instances=myinstance\') or a relative or ' 'fully-qualified path to the instance (e.g., ' '\'--instances=<zone>/instances/myotherinstance\'). To ' 'specify multiple instances, provide them as ' 'comma-separated entries. All instances in one target ' 'pool must belong to the same region as the target pool. ' 'Instances do not need to exist at the time the target ' 'pool is created and can be created afterwards.', flag_values=flag_values) gcutil_flags.DEFINE_case_insensitive_enum( 'session_affinity', self.DEFAULT_SESSION_AFFINITY, ['NONE', 'CLIENT_IP', 'CLIENT_IP_PROTO'], 'Specifies the session affinity option for the ' 'connection. Options include:' '\n NONE: connections from the same client IP ' 'may go to any VM in the target pool ' '\n CLIENT_IP: connections from the same client IP ' 'will go to the same VM in the target pool; ' '\n CLIENT_IP_PROTO: connections from the same ' 'client IP with the same IP protocol will go to the ' 'same VM in the targetpool. ', flag_values=flag_values) flags.DEFINE_float( 'failover_ratio', None, 'If set, --backup_pool must also be set to point to an ' 'existing target pool in the same region. They together ' 'define the fallback behavior of the target pool ' '(primary pool) to be created by this command: if the ' 'ratio of the healthy VMs in the primary pool is at ' 'or below this number, traffic arriving at the ' 'load-balanced IP will be directed to the backup pool. ' 'If not set, the traaffic will be directed the VMs in ' 'this pool in the "force" mode, where traffic will be ' 'spread to the healthy VMs with the best effort, or ' 'to all VMs when no VM is healthy.', flag_values=flag_values) flags.DEFINE_string( 'backup_pool', None, 'Together with --failover_ratio, this flag defines ' 'the fallback behavior of the target pool ' '(primary pool) to be created by this command: if the ' 'ratio of the healthy VMs in the primary pool is at ' 'or below --failover_ratio, traffic arriving at the ' 'load-balanced IP will be directed to the backup ' 'pool. ', flag_values=flag_values)
import gflags FLAGS = gflags.FLAGS # Dataset selection parameters gflags.DEFINE_string('trajectory_name', 'bentDice', 'The name of the trajectory to use from the dataset') gflags.DEFINE_string('yaw_type', 'yawForward', 'The yaw type to use from the dataset') gflags.DEFINE_float('max_speed', 2.0, 'The maximum speed of the drone in the dataset')
import gflags FLAGS = gflags.FLAGS # Random seed gflags.DEFINE_bool('random_seed', True, 'Random seed') # Input gflags.DEFINE_integer('target_level', -14, 'Target Level dB') gflags.DEFINE_float('target_nu', 0.1995262315, 'Target Level nu') gflags.DEFINE_integer('sr', 44100, 'Sample Rate') gflags.DEFINE_integer('img_width', 862, 'Target Image Width') gflags.DEFINE_integer('img_height', 96, 'Target Image Height') gflags.DEFINE_string('img_mode', "rgb", 'Load mode for images, either rgb or grayscale') gflags.DEFINE_string('h_grid', 50, 'Horizontal size of the grid classifiers') gflags.DEFINE_string('v_grid', 25, 'Vertical size of the grid classifiers') # Training parameters gflags.DEFINE_integer('batch_size', 128, 'Batch size in training and evaluation') gflags.DEFINE_integer('epochs', 100, 'Number of epochs for training') gflags.DEFINE_integer('verbose', 1, 'Type of verbose for training') gflags.DEFINE_integer('initial_epoch', 0, 'Initial epoch to start training') gflags.DEFINE_float('initial_lr', 1e-3, 'Initial learning rate for adam') gflags.DEFINE_string('f_output', 'softmax', 'Output function') # Testing parameters gflags.DEFINE_float('IOU', 0.5, 'Threshold for the IoU') gflags.DEFINE_float('NMS', 0.3, 'Threshold for the NMS') gflags.DEFINE_float(
'url to which output is posted. The url must include param name, ' 'value for which is populated with task_id from puller while posting ' 'the data. Format of output url is absolute url which handles the' 'post request from task queue puller.' '(Eg: "http://taskpuller.appspot.com/taskdata?name=").' 'The Param value is always the task_id. The handler for this post' 'should be able to associate the task with its id and take' 'appropriate action. Use the appengine_access_token.py tool to' 'generate the token and store it in a file before you start.') flags.DEFINE_string( 'appengine_access_token_file', None, 'File containing an Appengine Access token, if any. If present this' 'token is added to the output_url request, so that the output_url can' 'be an authenticated end-point. Use the appengine_access_token.py tool' 'to generate the token and store it in a file before you start.') flags.DEFINE_float('task_timeout_secs', '3600', 'timeout to kill the task') class ClientTaskInitError(Exception): """Raised when initialization of client task fails.""" def __init__(self, task_id, error_str): Exception.__init__(self) self.task_id = task_id self.error_str = error_str def __str__(self): return ('Error initializing task "%s". Error details "%s". ' % (self.task_id, self.error_str)) class ClientTask(object):
FLAGS = flags.FLAGS flags.DEFINE_string("train", "data/joint/shuffle.train.txt", "training data") flags.DEFINE_string("dev", "data/joint/shuffle.dev.txt", "development data") flags.DEFINE_string("save", None, "model saving path") flags.DEFINE_integer("epoch", 30, "number of training epochs") flags.DEFINE_integer("batch", 1, "Minibatch size") flags.DEFINE_bool("extlabelfeatures", True, "extend label features to include two children of s0") # arguments for span-based parser flags.DEFINE_integer("dynet_mem", 10000, "Memory allocation for Dynet. (DEFAULT=10000)") flags.DEFINE_float("dynet_l2", 0, "L2 regularization parmeter. (DEFAULT=0)") flags.DEFINE_integer("dynet_seed", 123, "Seed for PNG (0: generate)") flags.DEFINE_integer("word_dims", 50, "Embedding dimensions for word forms. (DEFAULT=50)") flags.DEFINE_integer("tag_dims", 20, "Embedding dimensions of POS tags. (DEFAULT=2-)") flags.DEFINE_integer("lstm_units", 200, "Number of LSTM units in each layer/direction. " "(DEFAULT=200)") flags.DEFINE_integer("hidden_units", 200, "Number of hidden units for each FC ReLU layer. " "(DEFAULT=200)") flags.DEFINE_float("droprate", 0.5, "Drouput probability. (DEFAULT=0.5)") flags.DEFINE_float("unk_param", 0.8375, "Parameter z for random UNKing. (DEFAULT=0.8375)") flags.DEFINE_float("alpha", 1.0,
import codecs import sys import re import gflags FLAGS = gflags.FLAGS gflags.DEFINE_string("dictfile", None, "dict file with frequencies and reverse-sorted") gflags.DEFINE_integer("topn", None, "Top N frequency tokens u want to filter the data with") gflags.DEFINE_float("unkratio", 0.2, "unk token ratio limit for each sentence to filter") gflags.MarkFlagAsRequired('dictfile') gflags.MarkFlagAsRequired('topn') try: FLAGS(sys.argv) except gflags.FlagsError as e: print "\n%s" % e print FLAGS.GetHelp(include_special_flags=False) sys.exit(1) dictname = FLAGS.dictfile topn = FLAGS.topn unkratio = FLAGS.unkratio dic = {} count = 0 with codecs.open(dictname) as f: for line in f:
import os import glob import sys import gflags from rmp_nav.simulation import agent_factory from rmp_nav.common.utils import get_model_dir, get_gibson_asset_dir, get_config_dir, get_data_dir from topological_nav.controller import inference from topological_nav.controller.dataset import DatasetSourceTargetPairMultiframeDst from topological_nav.tools.eval_controller_common import EvaluatorMultiframeDst gflags.DEFINE_string('env', 'space8', '') gflags.DEFINE_integer('start_idx', 0, '') gflags.DEFINE_integer('n_traj', 200, '') gflags.DEFINE_boolean('visualize', True, '') gflags.DEFINE_boolean('save_screenshot', False, '') gflags.DEFINE_float('zoom', 1.0, '') FLAGS = gflags.FLAGS FLAGS(sys.argv) weights_file = os.path.join( get_model_dir(), 'topological_nav/controller/multiframe_dst/gtwp-normwp-farwp-jitter-weightedloss-checkwp-nf6-interval3-dmax3-z0228-model.8' ) _env_dict = {} def register(f): _env_dict[f.__name__] = f return f
def get_flags(): # Debug settings. gflags.DEFINE_bool( "debug", False, "Set to True to disable debug_mode and type_checking.") gflags.DEFINE_bool( "show_progress_bar", True, "Turn this off when running experiments on HPC.") gflags.DEFINE_string("git_branch_name", "", "Set automatically.") gflags.DEFINE_string("slurm_job_id", "", "Set automatically.") gflags.DEFINE_integer( "deque_length", 100, "Max trailing examples to use when computing average training statistics.") gflags.DEFINE_string("git_sha", "", "Set automatically.") gflags.DEFINE_string("experiment_name", "", "") gflags.DEFINE_string("load_experiment_name", None, "") # Data types. gflags.DEFINE_enum("data_type", "bl", ["bl", "sst", "sst-binary", "nli", "arithmetic", "listops", "sign", "eq", "relational"], "Which data handler and classifier to use.") # Choose Genre. # 'fiction', 'government', 'slate', 'telephone', 'travel' # 'facetoface', 'letters', 'nineeleven', 'oup', 'verbatim' gflags.DEFINE_string("train_genre", None, "Filter MultiNLI data by genre.") gflags.DEFINE_string("eval_genre", None, "Filter MultiNLI data by genre.") # Where to store checkpoints gflags.DEFINE_string( "log_path", "./logs", "A directory in which to write logs.") gflags.DEFINE_string( "load_log_path", None, "A directory from which to read logs.") gflags.DEFINE_boolean( "write_proto_to_log", False, "Write logs in a protocol buffer format.") gflags.DEFINE_string( "ckpt_path", None, "Where to save/load checkpoints. Can be either " "a filename or a directory. In the latter case, the experiment name serves as the " "base for the filename.") gflags.DEFINE_integer( "ckpt_step", 1000, "Steps to run before considering saving checkpoint.") gflags.DEFINE_boolean( "load_best", False, "If True, attempt to load 'best' checkpoint.") # Data settings. gflags.DEFINE_string("training_data_path", None, "") gflags.DEFINE_string( "eval_data_path", None, "Can contain multiple file paths, separated " "using ':' tokens. The first file should be the dev set, and is used for determining " "when to save the early stopping 'best' checkpoints.") gflags.DEFINE_integer("seq_length", 200, "") gflags.DEFINE_boolean( "allow_cropping", False, "Trim overly long training examples to fit. If not set, skip them.") gflags.DEFINE_integer("eval_seq_length", None, "") gflags.DEFINE_boolean( "allow_eval_cropping", False, "Trim overly long evaluation examples to fit. If not set, crash on overly long examples.") gflags.DEFINE_boolean( "smart_batching", True, "Organize batches using sequence length.") gflags.DEFINE_boolean("use_peano", True, "A mind-blowing sorting key.") gflags.DEFINE_integer( "eval_data_limit", None, "Truncate evaluation set to this many batches. -1 indicates no truncation.") gflags.DEFINE_boolean( "bucket_eval", True, "Bucket evaluation data for speed improvement.") gflags.DEFINE_boolean("shuffle_eval", False, "Shuffle evaluation data.") gflags.DEFINE_integer( "shuffle_eval_seed", 123, "Seed shuffling of eval data.") gflags.DEFINE_string("embedding_data_path", None, "If set, load GloVe-formatted embeddings from here.") gflags.DEFINE_boolean("fine_tune_loaded_embeddings", False, "If set, backpropagate into embeddings even when initializing from pretrained.") # Model architecture settings. gflags.DEFINE_enum( "model_type", "RNN", [ "CBOW", "RNN", "SPINN", "RLSPINN", "ChoiPyramid", "Maillard", "LMS"], "") gflags.DEFINE_integer("gpu", -1, "") gflags.DEFINE_integer("model_dim", 8, "") gflags.DEFINE_integer("word_embedding_dim", 8, "") gflags.DEFINE_boolean("lowercase", False, "When True, ignore case.") gflags.DEFINE_boolean("use_internal_parser", False, "Use predicted parse.") gflags.DEFINE_boolean( "validate_transitions", True, "Constrain predicted transitions to ones that give a valid parse tree.") gflags.DEFINE_float( "embedding_keep_rate", 1.0, "Used for dropout on transformed embeddings and in the encoder RNN.") gflags.DEFINE_boolean("use_difference_feature", True, "") gflags.DEFINE_boolean("use_product_feature", True, "") # SPINN tracking LSTM settings. gflags.DEFINE_integer( "tracking_lstm_hidden_dim", None, "Set to none to avoid using tracker.") gflags.DEFINE_boolean( "tracking_ln", False, "When True, layer normalization is used in tracking.") gflags.DEFINE_float( "transition_weight", None, "Set to none to avoid predicting transitions.") gflags.DEFINE_boolean("lateral_tracking", True, "Use previous tracker state as input for new state.") gflags.DEFINE_boolean( "use_tracking_in_composition", True, "Use tracking lstm output as input for the reduce function.") gflags.DEFINE_boolean( "composition_ln", True, "When True, layer normalization is used in TreeLSTM composition.") gflags.DEFINE_boolean("predict_use_cell", True, "Use cell output as feature for transition net.") # SPINN composition function settings. gflags.DEFINE_enum( "reduce", "treelstm", [ "treelstm", "treegru", "tanh", "lms"], "Specify composition function.") # ChoiPyramid/ST-Gumbel model settings gflags.DEFINE_boolean( "pyramid_trainable_temperature", None, "If set, add a scalar trained temperature parameter.") gflags.DEFINE_float("pyramid_temperature_decay_per_10k_steps", 0.5, "What it says on the box. Does not impact SparseAdam (for word embedding fine-tuning).") gflags.DEFINE_float( "pyramid_temperature_cycle_length", 0.0, "For wake-sleep-style experiments. 0.0 disables this feature.") # Embedding preprocessing settings. gflags.DEFINE_enum("encode", "projection", ["pass", "projection", "gru", "attn"], "Encode embeddings with sequential context.") gflags.DEFINE_boolean("encode_reverse", False, "Encode in reverse order.") gflags.DEFINE_boolean( "encode_bidirectional", False, "Encode in both directions.") gflags.DEFINE_integer( "encode_num_layers", 1, "RNN layers in encoding net.") # RL settings. gflags.DEFINE_float( "rl_mu", 0.1, "Use in exponential moving average baseline.") gflags.DEFINE_enum("rl_baseline", "ema", ["ema", "pass", "greedy", "value"], "Different configurations to approximate reward function.") gflags.DEFINE_enum("rl_reward", "standard", ["standard", "xent"], "Different reward functions to use.") gflags.DEFINE_float("rl_weight", 1.0, "Hyperparam for REINFORCE loss.") gflags.DEFINE_boolean("rl_whiten", False, "Reduce variance in advantage.") gflags.DEFINE_boolean( "rl_valid", True, "Only consider non-validated actions.") gflags.DEFINE_float( "rl_epsilon", 1.0, "Percent of sampled actions during train time.") gflags.DEFINE_float( "rl_epsilon_decay", 50000, "Step constant in epsilon delay equation.") gflags.DEFINE_float( "rl_confidence_interval", 1000, "Penalize probabilities of transitions.") gflags.DEFINE_float( "rl_confidence_penalty", None, "Penalize probabilities of transitions.") gflags.DEFINE_boolean( "rl_catalan", False, "Sample over a uniform distribution of binary trees.") gflags.DEFINE_boolean( "rl_catalan_backprop", False, "Sample over a uniform distribution of binary trees.") gflags.DEFINE_boolean( "rl_wake_sleep", False, "Inverse relationship between temperature and rl_weight.") gflags.DEFINE_boolean( "rl_transition_acc_as_reward", False, "Use the transition accuracy as the reward. For debugging only.") # MLP settings. gflags.DEFINE_integer( "mlp_dim", 256, "Dimension of intermediate MLP layers.") gflags.DEFINE_integer("num_mlp_layers", 1, "Number of MLP layers.") gflags.DEFINE_boolean( "mlp_ln", True, "When True, layer normalization is used between MLP layers.") gflags.DEFINE_float("semantic_classifier_keep_rate", 0.9, "Used for dropout in the semantic task classifier.") # Optimization settings. gflags.DEFINE_enum("optimizer_type", "SGD", ["Adam", "SGD"], "") gflags.DEFINE_integer( "training_steps", 1000000, "Stop training after this point.") gflags.DEFINE_integer("batch_size", 32, "Minibatch size.") gflags.DEFINE_float("learning_rate", 0.5, "Used in optimizer.") # https://twitter.com/karpathy/status/801621764144971776 gflags.DEFINE_float("learning_rate_decay_when_no_progress", 0.5, "Used in optimizer. Decay the LR by this much every epoch steps if a new best has not been set in the last epoch.") gflags.DEFINE_float("clipping_max_value", 5.0, "") gflags.DEFINE_float("l2_lambda", 1e-5, "") # Display settings. gflags.DEFINE_integer( "statistics_interval_steps", 100, "Log training set performance statistics at this interval.") gflags.DEFINE_integer( "eval_interval_steps", 100, "Evaluate at this interval.") gflags.DEFINE_integer( "sample_interval_steps", None, "Sample transitions at this interval.") gflags.DEFINE_integer("ckpt_interval_steps", 5000, "Update the checkpoint on disk at this interval.") gflags.DEFINE_boolean( "ckpt_on_best_dev_error", True, "If error on the first eval set (the dev set) is " "at most 0.99 of error at the previous checkpoint, save a special 'best' checkpoint.") gflags.DEFINE_integer( "early_stopping_steps_to_wait", 50000, "If development set error doesn't improve significantly in this many steps, cease training.") gflags.DEFINE_boolean("evalb", False, "Print transition statistics.") gflags.DEFINE_integer("num_samples", 0, "Print sampled transitions.") # Evaluation settings gflags.DEFINE_boolean( "expanded_eval_only_mode", False, "If set, a checkpoint is loaded and a forward pass is done to get the predicted " "transitions. The inferred parses are written to the supplied file(s) along with example-" "by-example accuracy information. Requirements: Must specify checkpoint path.") # TODO: Rename. gflags.DEFINE_boolean( "expanded_eval_only_mode_use_best_checkpoint", True, "When in expanded_eval_only_mode, load the ckpt_best checkpoint.") gflags.DEFINE_boolean("write_eval_report", False, "") gflags.DEFINE_boolean( "eval_report_use_preds", True, "If False, use the given transitions in the report, " "otherwise use predicted transitions. Note that when predicting transitions but not using them, the " "reported predictions will look very odd / not valid.") # TODO: Remove. # Maillard Pyramid gflags.DEFINE_boolean( "cosine", False, "If true, use cosine similarity instead of dot product in measuring score for compositions.") gflags.DEFINE_enum( "parent_selection", "gumbel", ["gumbel", "st-gumbel", "softmax"], "Which function to use to select or calculate the parent.") gflags.DEFINE_boolean( "right_branching", False, "Force right-branching composition.") gflags.DEFINE_boolean( "debug_branching", False, "use alternative style of right-branching composition.") gflags.DEFINE_boolean( "uniform_branching", False, "Uniform distribution instead of gumble softmax weighting during chart parsing.") gflags.DEFINE_boolean( "random_branching", False, "Random weighting instead of gumble softmax weighting during chart parsing.") gflags.DEFINE_boolean( "st_gumbel", False, "ST-gumble softmax weighting during chart parsing.")
flags.DEFINE_boolean("naiveavg", False, "naive sum for averaging (slow!)") flags.DEFINE_string ("train", None, "training corpus") flags.DEFINE_string ("dev", None, "dev corpus") flags.DEFINE_string ("out", None, "output file (for weights)") flags.DEFINE_boolean ("finaldump", False, "dump best weights at the end instead of at each new high") flags.DEFINE_integer ("multi", 20, "multiprocessing: # of CPUs, -1 to use all CPUs") ##flags.DEFINE_boolean("singletrain", False, "use single thread for training") ##flags.DEFINE_boolean("singledev", False, "use single thread for eval_on_dev") ##flags.DEFINE_boolean("single", True, "--singletrain --singledev") flags.DEFINE_string("update", "max", "update method: early, noearly, hybrid, late, max") flags.DEFINE_boolean("shuffle", False, "shuffle training data before each iteration") flags.DEFINE_float("learning_rate", 1.0, "learning rate") flags.DEFINE_boolean("allmodels", False, "dumpto separate model files at each best-so-far iteration") #from mydouble import counts import gc import os class Perceptron(object): def __init__(self, decoder): Perceptron.learning_rate = FLAGS.learning_rate Perceptron.singletrain = FLAGS.multi == 1 Perceptron.singledev = FLAGS.multi == 1
gflags.DEFINE_integer("update_iterations", None, "Number of iterations to output logging information.") gflags.DEFINE_integer("iter_per_epoch", None, "Number of iterations per epoch. Leave empty.") gflags.DEFINE_integer("save_iterations", None, ("Number of iterations to save the network (expensive " "to do this).")) gflags.DEFINE_integer("total_epochs", 500, "Total number of epochs.") gflags.DEFINE_boolean("reweight", True, "Try re-weighting.") gflags.DEFINE_string("frames", "-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10", "Frames to process.") # gflags.DEFINE_float( # "hantman_weight_decay", 0.0001, "Weight decay value.") gflags.DEFINE_float("learning_rate", 0.001, "Learning rate.") gflags.DEFINE_integer("hantman_mini_batch", 256, "Mini batch size for training.") # needed to limit how much to process during eval. important for speed purposes. gflags.DEFINE_integer("seq_len", 1500, "Sequence length.") gflags.MarkFlagAsRequired("out_dir") gflags.MarkFlagAsRequired("train_file") gflags.MarkFlagAsRequired("test_file") # gflags.DEFINE_boolean("help", False, "Help") gflags.ADOPT_module_key_flags(arg_parsing) gflags.ADOPT_module_key_flags(flags.cuda_flags) g_label_names = ["lift", "hand", "grab", "supinate", "mouth", "chew"]
import sys from collections import deque import os if __name__ == '__main__': Flags = gflags.FLAGS gflags.DEFINE_bool("cuda", True, "use cuda") gflags.DEFINE_string("train_path", "/home/data/pin/data/omniglot/images_background", "training folder") gflags.DEFINE_string("test_path", "/home/data/pin/data/omniglot/images_evaluation", 'path of testing folder') gflags.DEFINE_integer("way", 20, "how much way one-shot learning") gflags.DEFINE_string("times", 400, "number of samples to test accuracy") gflags.DEFINE_integer("workers", 4, "number of dataLoader workers") gflags.DEFINE_integer("batch_size", 128, "number of batch size") gflags.DEFINE_float("lr", 0.00006, "learning rate") gflags.DEFINE_integer("show_every", 10, "show result after each show_every iter.") gflags.DEFINE_integer("save_every", 100, "save model after each save_every iter.") gflags.DEFINE_integer("test_every", 100, "test model after each test_every iter.") gflags.DEFINE_integer("max_iter", 50000, "number of iterations before stopping") gflags.DEFINE_string("model_path", "/home/data/pin/model/siamese", "path to store model") gflags.DEFINE_string("gpu_ids", "0,1,2,3", "gpu ids used to train") Flags(sys.argv) data_transforms = transforms.Compose([ transforms.RandomAffine(15), transforms.ToTensor() ])
# See the License for the specific language governing permissions and # limitations under the License. """A Cisco XR device . This module implements the base device interface of base_device.py for CiscoXR devices. """ import gflags import paramiko_device import push_exceptions as exceptions FLAGS = gflags.FLAGS gflags.DEFINE_float('ciscoxr_timeout_response', None, 'CiscoXR device response timeout in seconds.') gflags.DEFINE_float('ciscoxr_timeout_connect', None, 'CiscoXR device connect timeout in seconds.') gflags.DEFINE_float('ciscoxr_timeout_idle', None, 'CiscoXR device idle timeout in seconds.') gflags.DEFINE_float('ciscoxr_timeout_disconnect', None, 'CiscoXR device disconnect timeout in seconds.') gflags.DEFINE_float('ciscoxr_timeout_act_user', None, 'CiscoXR device user activation timeout in seconds.') # pylint: disable=arguments-differ # 38:CiscoXrDevice._Cmd: Arguments number differs from overridden method. class CiscoXrDevice(paramiko_device.ParamikoDevice): """A base device model suitable for CiscoXR devices.
import cv2 import cv_bridge import gflags import glog import rosbag import yaml # Requried flags. gflags.DEFINE_string('input_bag', None, 'Input bag path.') # Optional flags. gflags.DEFINE_string('output_path', './', 'Output path.') gflags.DEFINE_string('weather', 'CLEAR', 'Options: CLEAR, SUNNY, RAINY.') gflags.DEFINE_string('scene', 'CITY', 'Options: CITY, HIGHWAY.') gflags.DEFINE_string('time_interval', 'DAYTIME', 'Options: DAYTIME, NIGHT.') gflags.DEFINE_float('extract_rate', 3, 'Rate to extract image, in seconds.') # Stable flags which rarely change. # gflags.DEFINE_string('topic', '/apollo/sensor/camera/obstacle/front_6mm','Source topic.') gflags.DEFINE_string('topic', '/apollo/sensor/camera/traffic/image_short', 'Source topic.') gflags.DEFINE_integer('sensor_id', 436, 'Source sensor ID.') gflags.DEFINE_string('capture_place', 'Multiple', 'E.g.: Multiple, Sunnyvale.') def extract_meta_info(bag): """Extract information from a bag file, return an info dict.""" # Extract from bag info. info_dict = yaml.load(bag._get_yaml_info()) meta_info = { 'car_id': 'MKZ056',
import gflags import imageio import numpy from PIL import Image from PIL.ImageDraw import Draw gflags.DEFINE_string('inp', None, 'Input screenshot image') gflags.DEFINE_string('out', None, 'Output antimated GIF') gflags.DEFINE_integer('h', 0, 'Window height') gflags.DEFINE_integer('maxspeed', 200, 'Max speed on scroll px/frame') gflags.DEFINE_list('stops', [], 'List of stops for scrolling') gflags.DEFINE_integer('zoom', 0, 'Number of steps on initial zoom in') gflags.DEFINE_float('zoom_frac', .3, 'Fraction of screenshot to see on zoomout') gflags.register_validator('inp', os.path.exists, 'Input screenshot required') gflags.register_validator('h', lambda v: v > 0, 'Window height required') F = gflags.FLAGS def add_frame(frames, frame, duration): frames.append((prettify(frame), duration)) def prettify(frame): off = 5 h, w = frame.shape[:2] pretty = Image.new('RGB', (w + off, h + off), '#ffffff')
import cPickle as pickle from iceberk import mpi, classifier, mathutil from iceberk.experimental.meu_logistic_loss import loss_meu_logistic import numpy as np import logging import os, sys from sklearn.cross_validation import StratifiedKFold import time import gflags ######## # Settings ######## FEATDIR = "/tscratch/tmp/jiayq/imagenet-sbow/" gflags.DEFINE_bool("load", False, "If set, load the data and then stop.") gflags.DEFINE_float("reg", 0.01, "The reg term") gflags.DEFINE_integer("minibatch", 100000, "The minibatch size") gflags.DEFINE_bool("svm", False, "If set, run SVM") gflags.DEFINE_bool("hier", False, "If set, use hierarchical loss") FLAGS = gflags.FLAGS FLAGS(sys.argv) ######## # Main script ######## if mpi.SIZE > 1: raise RuntimeError, "This script runs on single machines only." np.random.seed(42 + mpi.RANK) mpi.root_log_level(level=logging.DEBUG) logging.info("Loading data...")
import sys sys.path.insert(0, caffe_dir) import util import gflags import numpy as np import caffe if not gflags.FLAGS.has_key("model_dir"): gflags.DEFINE_string("model_dir", "@model_path", "set model dir") if not gflags.FLAGS.has_key("feature_layer_names"): gflags.DEFINE_string("feature_layer_names", "['@feature_layer_name']", "set feature layer names") if not gflags.FLAGS.has_key("device_id"): gflags.DEFINE_integer("device_id", 0, "set device id") if not gflags.FLAGS.has_key("ratio"): gflags.DEFINE_float("ratio", -1.0, "set image ratio") if not gflags.FLAGS.has_key("scale"): gflags.DEFINE_float("scale", 1.1, "set image scale") if not gflags.FLAGS.has_key("resize_height"): gflags.DEFINE_integer("resize_height", 256, "set image size") if not gflags.FLAGS.has_key("resize_width"): gflags.DEFINE_integer("resize_width", 256, "set image size") if not gflags.FLAGS.has_key("raw_scale"): gflags.DEFINE_float("raw_scale", 255.0, "set raw scale") if not gflags.FLAGS.has_key("input_scale"): gflags.DEFINE_float("input_scale", 1.0, "set input scale") if not gflags.FLAGS.has_key("gray"): gflags.DEFINE_boolean("gray", False, "set gray") if not gflags.FLAGS.has_key("oversample"): gflags.DEFINE_boolean("oversample", False, "set oversample")
#!/usr/bin/python import os import sys import gflags import pandas as pd import numpy as np from market import market from portfolio import portfolio from simulations_code import simulate gflags.DEFINE_multi_int('hour', 24, 'Hours in between market') gflags.DEFINE_float( 'min_percentage_change', 0.1, "Minimum variation in 'balance' needed to place an order." "1 is 100%") gflags.DEFINE_string('state_csv', None, "path to csv containing a 'state'") FLAGS = gflags.FLAGS gflags.RegisterValidator('min_percentage_change', lambda x: x >= 0, 'Should be positive or 0') #gflags.RegisterValidator('state_csv', os.path.isfile) if __name__ == "__main__": try: argv = FLAGS(sys.argv) except gflags.FlagsError as e: print "%s\nUsage: %s ARGS\n%s" % (e, sys.argv[0], FLAGS) sys.exit(1) print '*' * 80
# -*- coding:utf-8 -*- from collections import defaultdict import create_features as cf import predict_nn as nn import gflags import sys FLAGS = gflags.FLAGS gflags.DEFINE_boolean('use_average', False, 'Use averaged perceptoron.' ) gflags.DEFINE_float('use_margin', 0.0, 'Use margin perceptoron.' ) gflags.DEFINE_float('l1_value', 0.0, 'Use L1 regularization.') def get_label_and_sentence(line): parts = line.rstrip().split() label = parts.pop(0) sentence = " ".join(parts) return (label, sentence) def update_weights(w, phi, y): for name, value in phi.items(): w[name] += value * y def learning(weight): for line in iter(sys.stdin.readline, ""): label, sent = get_label_and_sentence(line) phi = cf.create_features(sent) pre_label = po.predict_one(weight, phi) if int(pre_label) != int(label): update_weights(weight, phi, int(label))