# Lint as: python3 """ResNet-50 with rank-1 distributions on ImageNet.""" import os import time from absl import app from absl import flags from absl import logging import edward2 as ed from baselines.imagenet import utils # local file import from experimental.rank1_bnns import imagenet_model # local file import import tensorflow.compat.v2 as tf flags.DEFINE_integer('kl_annealing_epochs', 90, 'Number of epochs over which to anneal the KL term to 1.') flags.DEFINE_string('alpha_initializer', 'trainable_normal', 'Initializer name for the alpha parameters.') flags.DEFINE_string('gamma_initializer', 'trainable_normal', 'Initializer name for the gamma parameters.') flags.DEFINE_string('alpha_regularizer', 'normal_kl_divergence', 'Regularizer name for the alpha parameters.') flags.DEFINE_string('gamma_regularizer', 'normal_kl_divergence', 'Regularizer name for the gamma parameters.') flags.DEFINE_boolean('use_additive_perturbation', False, 'Use additive perturbations instead of multiplicative.') # General model flags flags.DEFINE_integer('ensemble_size', 4, 'Size of ensemble.') flags.DEFINE_integer('per_core_batch_size', 128, 'Batch size per TPU core/GPU.') flags.DEFINE_float('random_sign_init', 0.75,
'inference is run in single inference mode, it is assumed ' 'that files in the same directory belong in the same ' 'sequence, and sorting them alphabetically establishes the ' 'right temporal order.') flags.DEFINE_string('model_ckpt', None, 'Model checkpoint to evaluate.') flags.DEFINE_string( 'input_dir', None, 'Directory containing image files to ' 'evaluate. This crawls recursively for images in the ' 'directory, mirroring relative subdirectory structures ' 'into the output directory.') flags.DEFINE_string( 'input_list_file', None, 'Text file containing paths to ' 'image files to process. Paths should be relative with ' 'respect to the list file location. Relative path ' 'structures will be mirrored in the output directory.') flags.DEFINE_integer('batch_size', 1, 'The size of a sample batch') flags.DEFINE_integer('img_height', 128, 'Input frame height.') flags.DEFINE_integer('img_width', 416, 'Input frame width.') flags.DEFINE_integer('seq_length', 3, 'Number of frames in sequence.') flags.DEFINE_enum( 'architecture', nets.RESNET, nets.ARCHITECTURES, 'Defines the architecture to use for the depth prediction ' 'network. Defaults to ResNet-based encoder and accompanying ' 'decoder.') flags.DEFINE_boolean( 'imagenet_norm', True, 'Whether to normalize the input ' 'images channel-wise so that they match the distribution ' 'most ImageNet-models were trained on.') flags.DEFINE_bool( 'use_skip', True, 'Whether to use skip connections in the ' 'encoder-decoder architecture.')
import tensorflow.compat.v1 as tf from genomics_ood.images_ood import pixel_cnn from genomics_ood.images_ood import utils tf.compat.v1.disable_v2_behavior() flags.DEFINE_string('data_dir', '/tmp/image_data', 'Directory to data np arrays.') flags.DEFINE_string('out_dir', '/tmp/pixelcnn', 'Directory to write results and logs.') flags.DEFINE_boolean('save_im', False, 'If True, save image to npy.') flags.DEFINE_string('exp', 'fashion', 'cifar or fashion') # general hyper-parameters flags.DEFINE_integer('batch_size', 32, 'Batch size for training.') flags.DEFINE_integer('total_steps', 10, 'Max steps for training') flags.DEFINE_integer('random_seed', 1234, 'Fixed random seed to use.') flags.DEFINE_integer('eval_every', 10, 'Interval to evaluate model.') flags.DEFINE_float('learning_rate', 0.0001, 'Initial learning rate.') flags.DEFINE_float('learning_rate_decay', 0.999995, 'LR decay every step.') flags.DEFINE_integer('num_logistic_mix', 1, 'Number of components in decoder mixture distribution.') flags.DEFINE_integer('num_hierarchies', 1, 'Number of hierarchies in ' 'Pixel CNN.') flags.DEFINE_integer( 'num_resnet', 5, 'Number of convoluational layers ' 'before depth changes in Pixel CNN.') flags.DEFINE_integer('num_filters', 32, 'Number of pixel cnn filters')
from utils import tokenization FLAGS = flags.FLAGS flags.DEFINE_string("task_name", "IMDB", "The name of the task to train.") flags.DEFINE_string("raw_data_dir", None, "Data directory of the raw data") flags.DEFINE_string("output_base_dir", None, "Data directory of the processed data") flags.DEFINE_string("aug_ops", "bt-0.9", "augmentation method") flags.DEFINE_integer( "aug_copy_num", -1, help="We generate multiple augmented examples for one" "unlabeled example, aug_copy_num is the index of the generated augmented" "example") flags.DEFINE_integer( "max_seq_length", 512, help="The maximum total sequence length after WordPiece tokenization. " "Sequences longer than this will be truncated, and sequences shorter " "than this will be padded.") flags.DEFINE_integer("sup_size", -1, "size of the labeled set") flags.DEFINE_bool( "trunc_keep_right", True,
import urllib from queue import Queue from tqdm import tqdm from absl import app, flags, logging from absl.flags import FLAGS import threading """ Example usage: python download_images.py --image_dir data/lcwaikiki_images --meta_path data/meta/lcwaikiki.csv --label_path data/labels/lcwaikiki.csv python download_images.py --image_dir data/boyner_images --meta_path data/meta/boyner.csv --label_path data/labels/boyner.csv """ flags.DEFINE_string('image_dir', None, 'download directory') flags.DEFINE_string('meta_path', None, 'input meta file path') flags.DEFINE_string('label_path', None, 'output labels file path') flags.DEFINE_integer('workers', 8, 'number of worker threads') flags.mark_flag_as_required('image_dir') flags.mark_flag_as_required('label_path') flags.mark_flag_as_required('meta_path') def fetch_url(inp_queue, out_queue, stop_event): while not inp_queue.empty(): url, attrs = inp_queue.get() try: raw_img = urllib.request.urlopen(url).read() output = (raw_img, attrs) out_queue.put(output) except Exception as e: logging.info("Exception occured %s" % str(e))
' on CPU/GPU') flags.DEFINE_bool('use_tpu', True, 'Use TPUs rather than CPUs/GPUs') flags.DEFINE_bool('use_fake_data', False, 'Use fake input.') flags.DEFINE_bool( 'use_xla', False, 'Use XLA even if use_tpu is false. If use_tpu is true, we always use XLA, ' 'and this flag has no effect.') flags.DEFINE_string('model_dir', None, 'Location of model_dir') flags.DEFINE_string( 'backbone_ckpt', '', 'Location of the ResNet50 checkpoint to use for model ' 'initialization.') flags.DEFINE_string('hparams', '', 'Comma separated k=v pairs of hyperparameters.') flags.DEFINE_integer('num_cores', default=8, help='Number of TPU cores for training') flags.DEFINE_bool('use_spatial_partition', False, 'Use spatial partition.') flags.DEFINE_integer('num_cores_per_replica', default=8, help='Number of TPU cores per' 'replica when using spatial partition.') flags.DEFINE_multi_integer( 'input_partition_dims', [1, 4, 2, 1], 'A list that describes the partition dims for all the tensors.') flags.DEFINE_integer('train_batch_size', 64, 'training batch size') flags.DEFINE_integer('eval_batch_size', 1, 'evaluation batch size') flags.DEFINE_integer('eval_samples', 5000, 'The number of samples for ' 'evaluation.') flags.DEFINE_integer('iterations_per_loop', 100, 'Number of iterations per TPU training loop')
from absl import app from absl import flags from absl import logging import tensorflow as tf from tensorflow_federated.python.research.adaptive_lr_decay import adaptive_fed_avg from tensorflow_federated.python.research.adaptive_lr_decay import decay_iterative_process_builder from tensorflow_federated.python.research.utils import training_loop from tensorflow_federated.python.research.utils import training_utils from tensorflow_federated.python.research.utils import utils_impl from tensorflow_federated.python.research.utils.datasets import cifar100_dataset from tensorflow_federated.python.research.utils.models import resnet_models with utils_impl.record_hparam_flags(): # Experiment hyperparameters flags.DEFINE_integer('client_epochs_per_round', 1, 'Number of epochs in the client to take per round.') flags.DEFINE_integer('client_batch_size', 32, 'Batch size on the clients.') flags.DEFINE_integer('clients_per_round', 2, 'How many clients to sample per round.') flags.DEFINE_integer( 'max_batches_per_client', -1, 'Maximum number of batches to process at ' 'each client in a given round. If set to -1, we take the full dataset.' ) flags.DEFINE_enum( 'client_weight', 'uniform', ['num_samples', 'uniform'], 'Weighting scheme for the client model deltas. Currently, this can ' 'either weight according to the number of samples on a client ' '(num_samples) or uniformly (uniform).') flags.DEFINE_integer( 'client_datasets_random_seed', 1, 'The random seed '
import sys import time from absl import flags import numpy as np FLAGS = flags.FLAGS flags.DEFINE_string('f', '', 'kernel') flags.DEFINE_enum("agent_race", 'random', sc2_env.Race._member_names_, "Agent's race.") flags.DEFINE_bool("visualize", False, "Whether to visualize.") #flags.DEFINE_string("map", "CollectMineralShards", "Name of a map to use.") # flags.DEFINE_string("map", "DefeatRoaches", "Name of a map to use.") flags.DEFINE_string("map", "DefeatZerglingsAndBanelings", "Name of a map to use.") flags.DEFINE_integer("screen_resolution", 64, "Resolution for screen feature layers.") flags.DEFINE_integer("minimap_resolution", 64, "Resolution for minimap feature layers.") flags.DEFINE_integer("max_episodes", 20, "Max episodes.") flags.DEFINE_integer("step_mul", 1, "Game steps per agent step.") FUNCTIONS = actions.FUNCTIONS _BANELING = units.Zerg.Baneling _ZERGLING = units.Zerg.Zergling _PLAYER_RELATIVE = features.SCREEN_FEATURES.player_relative.index _PLAYER_FRIENDLY = 1 _PLAYER_NEUTRAL = 3 # beacon/minerals _PLAYER_HOSTILE = 4
flags.DEFINE_string( "init_checkpoint", None, "Initial checkpoint (usually from a pre-trained BERT model).") # if you download cased checkpoint you should use "False",if uncased you should use # "True" # if we used in bio-medical field,don't do lower case would be better! flags.DEFINE_bool( "do_lower_case", True, "Whether to lower case the input text. Should be True for uncased " "models and False for cased models.") flags.DEFINE_integer( "max_seq_length", 512, "The maximum total input sequence length after WordPiece tokenization. " "Sequences longer than this will be truncated, and sequences shorter " "than this will be padded.") flags.DEFINE_bool("do_train", False, "Whether to run training.") flags.DEFINE_bool("do_eval", False, "Whether to run eval on the dev set.") flags.DEFINE_bool( "do_predict", False, "Whether to run the model in inference mode on the test set.") flags.DEFINE_integer("train_batch_size", 32, "Total batch size for training.") flags.DEFINE_integer("eval_batch_size", 8, "Total batch size for eval.")
flags.DEFINE_string("dataset", "cifar10_keras", "Dataset name") flags.DEFINE_string("sampling_method", "marginEDL", ("Name of sampling method to use, can be any defined in " "AL_MAPPING in sampling_methods.constants")) flags.DEFINE_float( "warmstart_size", 2000, # CIFAR-10: 1./24 MNIST: 100# medical: 64 # !!!Data Split Umstellen ("Can be float or integer. Float indicates percentage of training data " "to use in the initial warmstart model")) flags.DEFINE_float( "batch_size", 2000, # CIAFAR-10: 1./24 MNIST: 100 # audi: 64 !!!Data Split Umstellen ("Can be float or integer. Float indicates batch size as a percentage " "of training data size.")) flags.DEFINE_integer("trials", 5, "Number of curves to create using different seeds") flags.DEFINE_integer("seed", 1, "Seed to use for rng and random state") flags.DEFINE_string("confusions", "0.", "Percentage of labels to randomize") flags.DEFINE_string("active_sampling_percentage", "1.0", "Mixture weights on active sampling.") flags.DEFINE_string("score_method", "ResNet_DEAL", "Method to use to calculate accuracy.") flags.DEFINE_string("select_method", "ResNet_DEAL", "Method to use for selecting points.") flags.DEFINE_string("normalize_data", "False", "Whether to normalize the data.") flags.DEFINE_string("standardize_data", "False", "Whether to standardize the data.") flags.DEFINE_string("save_dir", "/tmp/toy_experiments", "Where to save outputs") flags.DEFINE_string(
from absl import app, flags from dual_net import DualNetwork from gtp_cmd_handlers import (KgsCmdHandler, GoGuiCmdHandler, MiniguiCmdHandler, RegressionsCmdHandler) import gtp_engine from strategies import MCTSPlayer, CGOSPlayer flags.DEFINE_bool('cgos_mode', False, 'Whether to use CGOS settings.') flags.DEFINE_bool('kgs_mode', False, 'Whether to use KGS courtesy-pass.') flags.DEFINE_string('load_file', None, 'Path to model save files.') # this should be called "verbosity" but flag name conflicts with absl.logging. flags.DEFINE_integer('verbose', 1, 'How much debug info to print.') # See mcts.py, strategies.py for other configurations around gameplay FLAGS = flags.FLAGS def make_gtp_instance(load_file, cgos_mode=False, kgs_mode=False, verbosity=1, num_readouts=None): '''Takes a path to model files and set up a GTP engine instance.''' n = DualNetwork(load_file) if cgos_mode: player = CGOSPlayer(network=n,
from language.capwap.datasets import vqa_dataset from language.capwap.models import supervised_model from language.capwap.utils import experiment_utils from language.capwap.utils import io_utils from language.capwap.utils import text_utils import tensorflow.compat.v1 as tf DATA_DIR = os.getenv("QA2CAPTION_DATA", "data") flags.DEFINE_string("checkpoint", None, "Model checkpoint.") flags.DEFINE_string("input_pattern", None, "Path to eval data.") flags.DEFINE_string("output_file", None, "Path to write to.") flags.DEFINE_integer("decode_length", 30, "Max decoding length.") flags.DEFINE_integer("beam_size", 3, "Beam search width.") flags.DEFINE_float("beam_length_penalty", 0.6, "Beam search length penalty.") flags.DEFINE_string("vocab_path", os.path.join(DATA_DIR, "uncased_vocab.txt"), "Path to BERT vocab file.") FLAGS = flags.FLAGS def main(argv): if len(argv) > 1: raise app.UsageError("Too many command-line arguments.")
import os os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID' os.environ['CUDA_VISIBLE_DEVICES'] = "2" import tensorflow as tf # tf.enable_eager_execution() from absl import flags from model import create_model_fn, create_train_and_eval_specs from inputs import create_prediction_input_fn, create_input_fn flags.DEFINE_string('model_dir', None, 'Path to output model directory') flags.DEFINE_integer('num_train_steps', 200000, 'Number of train steps') flags.DEFINE_string('train_file_pattern', None, 'Pattern of tfrecord file for training') flags.DEFINE_string('eval_file_pattern', None, 'Pattern of tfrecord file for evaluation') flags.DEFINE_integer('image_size', 224, 'Input image shape') flags.DEFINE_integer('num_classes', 1, 'Number of total classes') flags.DEFINE_integer('batch_size', 2, 'Number of batch size for training') flags.DEFINE_string('finetune_ckpt', None, 'Path to finetune checkpoint file') flags.DEFINE_string( 'label_map_path', None, 'Path to label map file in tensorflow object detection api format') FLAGS = flags.FLAGS def main(unused_argv): flags.mark_flag_as_required('model_dir')
from __future__ import division from __future__ import print_function import os from absl import app from absl import flags from absl import logging import edward2 as ed import deterministic_model # local file import import utils # local file import import numpy as np import tensorflow.compat.v2 as tf flags.DEFINE_integer('per_core_batch_size', 512, 'Batch size per TPU core/GPU.') flags.DEFINE_integer('seed', 0, 'Random seed.') flags.DEFINE_string('data_dir', None, 'Path to training and testing data.') flags.mark_flag_as_required('data_dir') flags.DEFINE_string('checkpoint_dir', None, 'The directory where the model weights are stored.') flags.mark_flag_as_required('checkpoint_dir') flags.DEFINE_string('output_dir', '/tmp/imagenet', 'The directory where to save predictions.') flags.DEFINE_string('alexnet_errors_path', None, 'Path to AlexNet corruption errors file.') flags.DEFINE_integer('num_bins', 15, 'Number of bins for ECE computation.') # Accelerator flags. flags.DEFINE_bool('use_gpu', True, 'Whether to run on GPU or otherwise TPU.') flags.DEFINE_integer('num_cores', 1, 'Number of TPU cores or number of GPUs.')
from absl import flags # PID controller parameters. flags.DEFINE_float('pid_p', 0.25, 'PID p parameter') flags.DEFINE_float('pid_i', 0.20, 'PID i parameter') flags.DEFINE_float('pid_d', 0.0, 'PID d parameter') # Agent stopping configs. flags.DEFINE_bool('stop_for_traffic_lights', True, 'True to enable traffic light stopping') flags.DEFINE_bool('stop_for_people', True, 'True to enable person stopping') flags.DEFINE_bool('stop_for_vehicles', True, 'True to enable vehicle stopping') # Agent stopping parameters. flags.DEFINE_integer('traffic_light_min_dist_thres', 5, 'Min distance threshold traffic light') flags.DEFINE_integer('traffic_light_max_dist_thres', 20, 'Max distance threshold traffic light') flags.DEFINE_float('traffic_light_angle_thres', 0.5, 'Traffic light angle threshold') flags.DEFINE_integer('vehicle_distance_thres', 15, 'Vehicle distance threshold') flags.DEFINE_float('vehicle_angle_thres', 0.4, 'Vehicle angle threshold') flags.DEFINE_float('person_angle_hit_thres', 0.15, 'Person hit zone angle threshold') flags.DEFINE_integer('person_distance_emergency_thres', 12, 'Person emergency zone distance threshold') flags.DEFINE_float('person_angle_emergency_thres', 0.5, 'Person emergency zone angle threshold') flags.DEFINE_integer('person_distance_hit_thres', 35, 'Person hit zone distance threshold') # Steering control parameters flags.DEFINE_float('default_throttle', 0.0, 'Default throttle')
flags.DEFINE_string( 'conv_type', '3d', '3d, 2plus1d, or 3d_2plus1d. 3d configures the network ' 'to use the default 3D convolution. 2plus1d uses (2+1)D convolution ' 'with Conv2D operations and 2D reshaping (e.g., a 5x3x3 kernel becomes ' '3x3 followed by 5x1 conv). 3d_2plus1d uses (2+1)D convolution with ' 'Conv3D and no 2D reshaping (e.g., a 5x3x3 kernel becomes 1x3x3 ' 'followed by 5x1x1 conv).') flags.DEFINE_string('activation', 'swish', 'The main activation to use across layers.') flags.DEFINE_string( 'gating_activation', 'sigmoid', 'The gating activation to use in squeeze-excitation layers.') flags.DEFINE_bool( 'use_positional_encoding', False, 'Whether to use positional encoding (only applied when causal=True).') flags.DEFINE_integer('num_classes', 600, 'The number of classes for prediction.') flags.DEFINE_integer( 'batch_size', None, 'The batch size of the input. Set to None for dynamic input.') flags.DEFINE_integer( 'num_frames', None, 'The number of frames of the input. Set to None for dynamic input.') flags.DEFINE_integer( 'image_size', None, 'The resolution of the input. Set to None for dynamic input.') flags.DEFINE_string( 'checkpoint_path', '', 'Checkpoint path to load. Leave blank for default initialization.') FLAGS = flags.FLAGS
import numpy as np import tensorflow as tf from yolov3_tf2.models import ( YoloV3, YoloV3Tiny ) from yolov3_tf2.dataset import transform_images, load_tfrecord_dataset from yolov3_tf2.utils import draw_outputs import os, glob #import os #os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" #os.environ["CUDA_VISIBLE_DEVICES"] = "0" flags.DEFINE_string('classes', './data/particle.names', 'path to classes file') flags.DEFINE_string('weights', './checkpoints/yolov3.tf', 'path to weights file') flags.DEFINE_integer('size', 416, 'resize images to') flags.DEFINE_string('tfrecord', None, 'path to tfrecord') flags.DEFINE_integer('num_classes', 1, 'number of classes in the model') flags.DEFINE_integer('batch_size', 12, 'number of batch size for detection') def DeleteCache(): for filePath in glob.glob("benchmark/ground-truth/*.txt"): os.remove(filePath) for filePath in glob.glob("benchmark/detection-results/*.txt"): os.remove(filePath) def detect_tfrecord_batch(record_path, weights = './checkpoints/yolov3.tf', classes = './data/particle.names', num_classes = 1, size = 416, batch_size = 1): DeleteCache() physical_devices = tf.config.experimental.list_physical_devices('GPU') for physical_device in physical_devices:
from absl import app, flags, logging from absl.flags import FLAGS import code as yt import os import sys import time from subprocess import Popen flags.DEFINE_string('url', '', 'video url') flags.DEFINE_string('format', 'mp4', '(mp3, mp4)') flags.DEFINE_string('output', 'Media', 'Folder to save into') flags.DEFINE_string('filename', None, 'Output filename') flags.DEFINE_string('quality', 'best', 'Output quality') flags.DEFINE_integer('start', -1, 'start of file in seconds') flags.DEFINE_integer('end', -1, 'end of file in seconds') def main(_argv): # FLAGS.url = "https://www.youtube.com/watch?v=JByDbPn6A1o" path, file_length = yt.download(FLAGS.url, FLAGS.format, FLAGS.quality, FLAGS.output, FLAGS.filename) if FLAGS.format == "mp3": new_file_name = f"{path[:-3]}{FLAGS.format}" ffmpeg_process = Popen(["ffmpeg", "-i", path, new_file_name]) ffmpeg_process.wait() os.remove(path) path = new_file_name if FLAGS.start != -1 or FLAGS.end != -1:
flags.DEFINE_string("dir", "/h/wangale/project/few-shot-sketch", "Project directory") flags.DEFINE_string("data_dir", "/h/wangale/data", "Data directory") flags.DEFINE_string("id", None, "training_id") flags.DEFINE_string("logfile", "", "Logfile name") flags.DEFINE_boolean("test", False, "Perform testing") flags.DEFINE_string("dataset", None, "Dataset used") flags.DEFINE_string("dataset_cfgset", None, "Configuration set for the dataset") flags.DEFINE_string("dataset_cfgs", "", "Custom configuration for the dataset configs") flags.DEFINE_integer("random_seed", 1, "Random seed") flags.mark_flags_as_required(["id", "dataset", "dataset_cfgset"]) def prepare(): dataset_config: HParams = configs.get_config(FLAGS.dataset_cfgset)().parse( FLAGS.dataset_cfgs) log_hparams(dataset_config) logging.info("Getting and preparing dataset: %s", FLAGS.dataset) dataset = datasets.get_dataset(FLAGS.dataset)(FLAGS.data_dir, dataset_config) dataset.prepare(FLAGS)
from pathlib import Path import os import numpy as np import seaborn as sns import matplotlib.pyplot as plt from absl import flags, app from tensorboard.backend.event_processing.event_accumulator import EventAccumulator FLAGS = flags.FLAGS flags.DEFINE_spaceseplist( 'logdirs', [], 'Space separated list of directories to plot results from.') flags.DEFINE_string('output_file_name', 'out.pdf', 'Output file to generate plot.') flags.DEFINE_integer('seeds', 5, 'Number of seeds per run') def main(_): sns.color_palette() fig = plt.figure(figsize=(8, 4)) ax = fig.gca() print(FLAGS.logdirs) for logdir in FLAGS.logdirs: print(logdir) samples = [] rewards = [] for seed in range(FLAGS.seeds): logdir_ = Path(logdir) / f'seed{seed}' logdir_ = logdir_ / 'val' event_acc = EventAccumulator(str(logdir_)) event_acc.Reload() _, step_nums, vals = zip(*event_acc.Scalars('val-mean_reward'))
from absl import app from absl import flags from absl import logging import interval_bound_propagation as ibp import tensorflow as tf import numpy as np FLAGS = flags.FLAGS flags.DEFINE_string('dataset', 'fmnist', 'Dataset (either "mnist" or "cifar10")') flags.DEFINE_string('output_dir', './model_robust', 'Output directory.') #flags.DEFINE_integer('width_num', 4, 'Width Number for CNN') # Options. flags.DEFINE_integer('steps', 80001, 'Number of steps in total.') flags.DEFINE_integer('test_every_n', 5000, 'Number of steps between testing iterations.') flags.DEFINE_integer('warmup_steps', 8000, 'Number of warm-up steps.') flags.DEFINE_integer('rampup_steps', 30000, 'Number of ramp-up steps.') flags.DEFINE_integer('batch_size', 100, 'Batch size.') flags.DEFINE_float('epsilon', 0.1, 'Target epsilon.') flags.DEFINE_string( 'learning_rate', '1e-4,1e-5@50000,1e-6@65000', 'Learning rate schedule of the form: ' 'initial_learning_rate[,learning:steps]*. E.g., "1e-3" or ' '"1e-3,1e-4@15000,1e-5@25000".') flags.DEFINE_float('nominal_xent_init', 1., 'Initial weight for the nominal cross-entropy.') flags.DEFINE_float('nominal_xent_final', .5, 'Final weight for the nominal cross-entropy.')
import tensorflow as tf import tensorflow_federated as tff from tensorflow_federated.python.research.differential_privacy import dp_utils from tensorflow_federated.python.research.optimization.shared import keras_metrics from tensorflow_federated.python.research.optimization.shared import optimizer_utils from tensorflow_federated.python.research.utils import training_loop from tensorflow_federated.python.research.utils import training_utils from tensorflow_federated.python.research.utils import utils_impl from tensorflow_federated.python.research.utils.datasets import stackoverflow_dataset from tensorflow_federated.python.research.utils.models import stackoverflow_models with utils_impl.record_new_flags() as hparam_flags: # Training hyperparameters flags.DEFINE_integer('clients_per_round', 10, 'How many clients to sample per round.') flags.DEFINE_integer('client_epochs_per_round', 1, 'Number of epochs in the client to take per round.') flags.DEFINE_integer('client_batch_size', 8, 'Batch size used on the client.') flags.DEFINE_integer('sequence_length', 20, 'Max sequence length to use.') flags.DEFINE_integer('max_elements_per_user', 1000, 'Max number of training ' 'sentences to use per user.') flags.DEFINE_integer('num_validation_examples', 10000, 'Number of examples ' 'to use from test set for per-round validation.') flags.DEFINE_boolean('uniform_weighting', False, 'Whether to weigh clients uniformly. If false, clients ' 'are weighted by the number of tokens.') # Optimizer configuration (this defines one or more flags per optimizer). utils_impl.define_optimizer_flags('server') utils_impl.define_optimizer_flags('client')
from tensorflow_probability import distributions as tfd from robust_loss import adaptive # Celeb-A images are cropped to the center-most (160, 160) pixel image, and # then downsampled by 2.5x to be (64, 64) IMAGE_PRECROP_SIZE = 160 IMAGE_SIZE = 64 VIZ_GRID_SIZE = 8 VIZ_MAX_N_SAMPLES = 3 VIZ_MAX_N_INPUTS = 16 flags.DEFINE_float("learning_rate", default=0.001, help="Initial learning rate.") flags.DEFINE_integer("max_steps", default=50000, help="Number of training steps to run.") flags.DEFINE_float( "decay_start", default=0.8, help="The fraction (in [0, 1]) of training at which point the learning " "rate should start getting annealed to 0") flags.DEFINE_integer("latent_size", default=16, help="Number of dimensions in the latent code (z).") flags.DEFINE_integer("base_depth", default=32, help="Base depth for layers.") flags.DEFINE_integer("batch_size", default=32, help="Batch size.") flags.DEFINE_integer( "n_samples", default=1, help="Number of samples to use in encoding. For accurate importance "
import pybullet as p from pyquaternion import Quaternion #import sensor_msgs.msg from sensor_msgs.msg import Joy import threading flags.DEFINE_string('assets_root', '.', '') flags.DEFINE_string('data_dir', '.', '') flags.DEFINE_bool('disp', False, '') flags.DEFINE_bool('shared_memory', False, '') flags.DEFINE_string('task', 'towers-of-hanoi', '') flags.DEFINE_string('mode', 'train', '') flags.DEFINE_integer('n', 1000, '') assets_root = "/home/yan/git/ravens/ravens/environments/assets/" task_name = "place-red-in-green" mode = "train" FLAGS = flags.FLAGS class ViveRobotBridge: def __init__(self): self.offset = [0, 0, 0] self.offset_flag = 0 self.grasp = 0 self.trigger_pressed_event = 0 self.trigger_released_event = 0 self.trigger_current_status = 0
from tensorflow.keras.layers import ( Add, Concatenate, Conv2D, Input, Lambda, LeakyReLU, UpSampling2D, ZeroPadding2D, BatchNormalization, ) from tensorflow.keras.regularizers import l2 from tensorflow.keras.losses import (binary_crossentropy, sparse_categorical_crossentropy) flags.DEFINE_integer('yolo_max_boxes', 100, 'maximum number of boxes per image') flags.DEFINE_float('yolo_iou_threshold', 0.5, 'iou threshold') flags.DEFINE_float('yolo_score_threshold', 0.5, 'score threshold') yolo_anchors = np.array([(10, 13), (16, 30), (33, 23), (30, 61), (62, 45), (59, 119), (116, 90), (156, 198), (373, 326)], np.float32) / 416 yolo_anchor_masks = np.array([[6, 7, 8], [3, 4, 5], [0, 1, 2]]) def darknet_conv(x, filters, size, strides=1, batch_norm=True): if strides == 1: padding = 'same' else: x = ZeroPadding2D(((1, 0), (1, 0)))(x) # top left half-padding padding = 'valid'
# Import BERT model libraries. from official.bert import bert_models from official.bert import common_flags from official.bert import input_pipeline from official.bert import model_saving_utils from official.bert import model_training_utils from official.bert import modeling from official.bert import optimization from official.utils.misc import tpu_lib flags.DEFINE_string('input_files', None, 'File path to retrieve training data for pre-training.') # Model training specific flags. flags.DEFINE_integer( 'max_seq_length', 128, 'The maximum total input sequence length after WordPiece tokenization. ' 'Sequences longer than this will be truncated, and sequences shorter ' 'than this will be padded.') flags.DEFINE_integer('max_predictions_per_seq', 20, 'Maximum predictions per sequence_output.') flags.DEFINE_integer('train_batch_size', 32, 'Total batch size for training.') flags.DEFINE_integer('num_steps_per_epoch', 1000, 'Total number of training steps to run per epoch.') flags.DEFINE_float('warmup_steps', 10000, 'Warmup steps for Adam weight decay optimizer.') common_flags.define_common_bert_flags() FLAGS = flags.FLAGS
from utils import utils_impl from utils.models import emnist_models from tensorboard.plugins.hparams import api as hp with utils_impl.record_new_flags() as hparam_flags: # Metadata flags.DEFINE_string( 'exp_name', 'emnist', 'Unique name for the experiment, suitable for use ' 'in filenames.') # Training hyperparameters flags.DEFINE_boolean( 'digit_only_emnist', True, 'Whether to train on the digits only (10 classes) data ' 'or the full data (62 classes).') flags.DEFINE_integer('total_rounds', 500, 'Number of total training rounds.') flags.DEFINE_integer('rounds_per_eval', 1, 'How often to evaluate') flags.DEFINE_integer( 'rounds_per_checkpoint', 25, 'How often to emit a state checkpoint. Higher numbers ' 'mean more lost work in case of failure, lower numbers ' 'mean more overhead per round.') flags.DEFINE_integer('train_clients_per_round', 2, 'How many clients to sample per round.') flags.DEFINE_integer('client_epochs_per_round', 1, 'Number of epochs in the client to take per round.') flags.DEFINE_integer('batch_size', 20, 'Batch size used on the client.') # Client optimizer configuration (it defines one or more flags per optimizer). utils_impl.define_optimizer_flags('client')
Run a q-learning agent on a task. """ from absl import app from absl import flags import tensorflow.compat.v1 as tf from option_keyboard import configs from option_keyboard import dqn_agent from option_keyboard import environment_wrappers from option_keyboard import experiment from option_keyboard import scavenger FLAGS = flags.FLAGS flags.DEFINE_integer("num_episodes", 10000, "Number of training episodes.") flags.DEFINE_list("test_w", [], "The w to test.") def main(argv): del argv # Create the task environment. test_w = [float(x) for x in FLAGS.test_w] env_config = configs.get_fig5_task_config(test_w) env = scavenger.Scavenger(**env_config) env = environment_wrappers.EnvironmentWithLogging(env) # Create the flat agent. agent = dqn_agent.Agent( obs_spec=env.observation_spec(),
from absl import flags flags.DEFINE_float('step_size_hybrid_astar', 3.0, 'Sampling distance [m]') flags.DEFINE_integer('max_iterations_hybrid_astar', 2000, 'Maximum number of iterations') flags.DEFINE_float('completion_threshold', 1.0, 'Threshold to end position [m]') flags.DEFINE_float('angle_completion_threshold', 100.0, ' Threshold to end yaw [rad]') flags.DEFINE_float('rad_step', 0.5, 'Turning sampling discretization [rad]') flags.DEFINE_float('rad_upper_range', 4.0, 'Maximum turning angle to the right [rad]') flags.DEFINE_float('rad_lower_range', 4.0, 'Maximum turning angle to the left [rad]') flags.DEFINE_float('obstacle_clearance_hybrid_astar', 1.0, 'Obstacle clearance threshold [m]') flags.DEFINE_float('lane_width_hybrid_astar', 6, 'Road width') flags.DEFINE_float('radius', 6.0, 'Minimum turning radius of the car [m]') flags.DEFINE_float('car_length', 4.8, 'Length of car [m]') flags.DEFINE_float('car_width', 1.8, 'Width of car [m]')
' stored.')) flags.DEFINE_string( 'model_name', default='mnasnet-a1', help=( 'The model name to select models among existing MnasNet configurations.' )) flags.DEFINE_string('mode', default='train_and_eval', help='One of {"train_and_eval", "train", "eval", "pred"}.') flags.DEFINE_integer( 'train_steps', default=437898, help=('The number of steps to use for training. Default is 437898 steps' ' which is approximately 350 epochs at batch size 1024. This flag' ' should be adjusted according to the --train_batch_size flag.')) flags.DEFINE_integer('input_image_size', default=224, help='Input image size.') flags.DEFINE_integer('train_batch_size', default=1024, help='Batch size for training.') flags.DEFINE_integer('eval_batch_size', default=1024, help='Batch size for evaluation.') flags.DEFINE_integer('num_train_images', default=1281167,