def main(args=None): methods = map(eval, ("KillWorkers", "RestartWorkers", "PingWorkers")) profile = None try: opts, args = util.GetOptions("p:v", args=args) for opt, arg in opts: if opt == '-p': profile = arg elif opt == '-v': import logging logging.getLogger().setLevel(logging.INFO) if len(args) < 1: raise util.UsageException method = eval(args[0]) client = Client(profile=profile) # dview = client.direct_view() method(client, *args[1:]) except util.UsageException, e: method_info = [ " %s -- %s" % (m.func_name, m.__doc__.splitlines()[0]) for m in methods ] util.Usage( "[options] CMD [ARGS]\n" " -p PROF Set the IPython profile\n" " -v Be verbose with logging\n" "CMDs include:\n" + "\n".join(method_info), e)
def main(): default_model = "viz2" try: opts, args = util.GetOptions("c:m:v") model_name = default_model pool = None pool = pools.MulticorePool() for opt, arg in opts: if opt == '-c': # Use a cluster of worker nodes from glimpse.pools.cluster import ClusterConfig, ClusterPool config = ClusterConfig(arg) pool = ClusterPool(config) elif opt == '-m': # Set the model class arg = arg.lower() if arg == "default": model_name = default_model else: model_name = arg elif opt == '-v': logging.getLogger().setLevel(logging.INFO) models = __import__("glimpse.models.%s" % model_name, globals(), locals(), ['cmds'], 0) try: model = getattr(models, 'cmds') except AttributeError: raise util.UsageException("Unknown model (-m): %s" % model_name) except util.UsageException, e: util.Usage("[options]\n" " -c FILE Use a cluster to evaluate images, configured in FILE.\n" " -m MOD Use model named MOD\n" " -v Enable verbose logging", e )
def main(): try: model_class = glab.GetModelClass() ofile = None params = None cli_opts, cli_args = util.GetOptions('i:m:o:') for opt, arg in cli_opts: if opt == '-i': params = util.Load(arg) elif opt == '-m': model_class = glab.CLIGetModel(arg) elif opt == '-o': ofile = arg except util.UsageException, e: util.Usage( "[options]\n" " -i FILE Read params from FILE\n" " -m MODEL Use model class MODEL\n" " -o FILE Write params to FILE", e)
def main(): try: opts = dict() opts['verbose'] = 0 opts['corpus_subdirs'] = [] cli_opts, _ = util.GetOptions('bc:C:el:m:n:o:p:P:r:st:vx', ['balance', 'corpus=', 'corpus-subdir=', 'cluster-config=', 'compute-features', 'edit-options', 'layer=', 'model=', 'num-prototypes=', 'options=', 'prototype-algorithm=', 'prototypes=', 'results=', 'svm', 'svm-decision-values', 'svm-predicted-labels', 'pool-type=', 'verbose', 'cross-validate']) for opt, arg in cli_opts: if opt in ('-b', '--balance'): opts['balance'] = True elif opt in ('-c', '--corpus'): opts['corpus'] = arg elif opt in ('-C', '--corpus-subdir'): opts['corpus_subdirs'].append(arg) elif opt in ('--cluster-config'): # Use a cluster of worker nodes opts['cluster_config'] = arg elif opt in ('--compute-features'): opts['compute_features'] = True elif opt in ('-e', '--edit-options'): opts['edit_params'] = True elif opt in ('-l', '--layer'): opts['layer'] = arg elif opt in ('-m', '--model'): opts['model_name'] = arg elif opt in ('-n', '--num-prototypes'): opts['num_prototypes'] = int(arg) elif opt in ('-o', '--options'): opts['params'] = util.Load(arg) elif opt in ('-p', '--prototype-algorithm'): opts['prototype_algorithm'] = arg.lower() elif opt in ('-P', '--prototypes'): opts['prototypes'] = util.Load(arg) elif opt in ('-r', '--results'): opts['result_path'] = arg elif opt in ('-s', '--svm'): opts['use_svm'] = True elif opt == '--svm-decision-values': opts['svm_decision_values'] = True opts['verbose'] = max(1, opts['verbose']) opts['svm'] = True elif opt == '--svm-predicted-labels': opts['svm_predicted_labels'] = True opts['verbose'] = max(1, opts['verbose']) opts['svm'] = True elif opt in ('-t', '--pool-type'): opts['pool_type'] = arg.lower() elif opt in ('-v', '--verbose'): opts['verbose'] += 1 elif opt in ('-x', '--cross-validate'): opts['cross_validate'] = True CommandLineInterface(**opts) except util.UsageException, ex: util.Usage("[options]\n" " -b, --balance Choose equal number of images per " "class\n" " -c, --corpus=DIR Use corpus directory DIR\n" " -C, --corpus-subdir=DIR Specify subdirectories (using -C" " repeatedly)\n" " instead of single corpus directory" " (with -c)\n" " --cluster-config=FILE Read cluster configuration from " "FILE\n" " --compute-features Compute feature vectors (implied " "by -s)\n" " -e, --edit-options Edit model options with a GUI\n" " -l, --layer=LAYR Compute feature vectors from LAYR " "activity\n" " -m, --model=MODL Use model named MODL\n" " -n, --num-prototypes=NUM Generate NUM S2 prototypes\n" " -o, --options=FILE Read model options from FILE\n" " -p, --prototype-algorithm=ALG Generate S2 prototypes according " "to algorithm\n" " ALG (one of 'imprint', 'uniform', " "'shuffle',\n" " 'histogram', or 'normal')\n" " -P, --prototypes=FILE Read S2 prototypes from FILE " "(overrides -p)\n" " -r, --results=FILE Store results to FILE\n" " -s, --svm Train and test an SVM classifier\n" " --svm-decision-values Print the pre-thresholded SVM " "decision values\n" " for each test image (implies -vs)\n" " --svm-predicted-labels Print the predicted labels for each " "test image\n" " (implies -vs)\n" " -t, --pool-type=TYPE Set the worker pool type (one of " "'multicore',\n" " 'singlecore', or 'cluster')\n" " -v, --verbose Enable verbose logging\n" " -x, --cross-validate Compute test accuracy via cross-" "validation\n" " instead of fixed training/testing " "split", ex )
config_files.append(arg) elif opt == '-v': import logging logging.getLogger().setLevel(logging.INFO) if len(args) < 1: raise util.UsageException if len(config_files) == 0: raise util.UsageException( "Must specify a socket configuration file.") method = eval(args[0]) config = ConfigParser.SafeConfigParser() if len(config.read(*config_files)) == 0: util.UsageException("Failed to read cluster config file.") method(config, *args[1:]) except pool.ConfigException, e: sys.exit("Configuration error: %s" % e) except util.UsageException, e: method_info = [ " %s -- %s" % (m.func_name, m.__doc__.splitlines()[0]) for m in methods ] util.Usage( "[options] CMD [ARGS]\n" " -c FILE Read socket configuration from FILE\n" " -v Be verbose with logging\n" "CMDs include:\n" + "\n".join(method_info), e) if __name__ == "__main__": main()