import horovod.tensorflow as hvd hvd.init() from inception import get_inception_score set_seed(0) torch.manual_seed(0) np.random.seed(0) tf.set_random_seed(0) FLAGS = flags.FLAGS # Dataset Options flags.DEFINE_string( 'datasource', 'random', 'initialization for chains, either random or default (decorruption)') flags.DEFINE_string( 'dataset', 'mnist', 'dsprites, cifar10, imagenet (32x32) or imagenetfull (128x128)') flags.DEFINE_integer('batch_size', 256, 'Size of inputs') flags.DEFINE_integer('test_batch_size', 8, 'Size of test inputs') flags.DEFINE_bool('single', False, 'whether to debug by training on a single image') flags.DEFINE_integer( 'data_workers', 4, 'Number of different data workers to load data in parallel') # General Experiment Settings flags.DEFINE_string('logdir', 'cachedir', 'location where log of experiments will be stored')
import random import tensorflow as tf import logging import imageio from data_generator import DataGenerator from mil import MIL from evaluation.eval_reach import evaluate_vision_reach from evaluation.eval_push import evaluate_push from tensorflow.python.platform import flags FLAGS = flags.FLAGS LOGGER = logging.getLogger(__name__) ## Dataset/method options flags.DEFINE_string('experiment', 'sim_reach', 'sim_vision_reach or sim_push') flags.DEFINE_string( 'demo_file', None, 'path to the directory where demo files that containing robot states and actions are stored' ) flags.DEFINE_string('demo_gif_dir', None, 'path to the videos of demonstrations') flags.DEFINE_string( 'gif_prefix', 'object', 'prefix of the video directory for each task, e.g. object_0 for task 0') flags.DEFINE_integer( 'im_width', 100, 'width of the images in the demo videos, 125 for sim_push, and 80 for sim_vision_reach' ) flags.DEFINE_integer( 'im_height', 90,
flags.DEFINE_integer('ps_tasks', 0, 'The number of parameter servers. If the value is 0, then' ' the parameters are handled locally by the worker.') flags.DEFINE_integer('save_summaries_secs', 60, 'The frequency with which summaries are saved, in ' 'seconds.') flags.DEFINE_integer('save_interval_secs', 2, 'Frequency in seconds of saving the model.') flags.DEFINE_integer('max_number_of_steps', int(1000), 'The maximum number of gradient steps.') flags.DEFINE_string('checkpoint_inception', '', 'Checkpoint to recover inception weights from.') flags.DEFINE_float('clip_gradient_norm', 2.0, 'If greater than 0 then the gradients would be clipped by ' 'it.') flags.DEFINE_bool('sync_replicas', False, 'If True will synchronize replicas during training.') flags.DEFINE_integer('replicas_to_aggregate', 1, 'The number of gradients updates before updating params.') flags.DEFINE_integer('total_num_replicas', 1, 'Total number of worker replicas.') flags.DEFINE_integer('startup_delay_steps', 15,
from tensorflow import app from tensorflow.python.platform import flags import os import tesserocr import numpy as np from tesserocr import PyTessBaseAPI, RIL import shutil import tempfile from PIL import Image import math import tensorflow as tf import cv2 import vgsl_model flags.DEFINE_string('graph_def_file', None, 'Output eval graph definition file.') flags.DEFINE_string('train_dir', '/tmp/mdir', 'Directory where to find training checkpoints.') flags.DEFINE_string( 'model_str', '1,60,0,1[Ct5,5,16 Mp3,3 Lfys64 Lfx128 Lrx128 Lfx256]O1c225', 'Network description.') flags.DEFINE_string('image', None, 'Inference image path') flags.DEFINE_string('decoder', '../dataset_ctc/tha+eng/charset_size=225.txt', 'Charset decoder') FLAGS = flags.FLAGS # initialise params alphabet = '' RESIZE = 60
from tensorflow.python.tpu.ops import tpu_ops FLAGS = flags.FLAGS flags.DEFINE_boolean('use_tpu', True, 'Use TPU or GPU.') flags.DEFINE_float('lr', 0.003, 'Learning rate.') flags.DEFINE_float('lr_drop_steps', 20000, 'Learning rate drops for every `lr_drop_steps` steps.') flags.DEFINE_float('lr_drop_rate', 0.3, 'Learning rate drops by this amount.') flags.DEFINE_integer('num_train_iterations_per_loop', 500, 'Number of training iterations per loop.') flags.DEFINE_integer('num_eval_iterations_per_loop', 2, 'Number of eval iterations per loop.') flags.DEFINE_integer('num_training_loops', 1000, 'Number of training loops.') flags.DEFINE_string('mesh_shape', 'rows:4, columns:4, cores:2', 'mesh shape') flags.DEFINE_string('master', '', 'Can be a headless master.') flags.DEFINE_string('checkpoint_dir', '', 'Path to saved models.') flags.DEFINE_integer('save_checkpoints_steps', 500, 'Frequency for saving models.') flags.DEFINE_boolean('write_summary', True, 'Whether to write summary.') flags.DEFINE_string('summary_dir', '', 'Path to saved summaries.') flags.DEFINE_string('pred_output_dir', '', 'Path to saved pred results.') class _CapturedObject(object): """A placeholder to capture an object. This is useful when we need to capture a Python object in the Tensorflow
import os import tensorflow as tf from tensorflow.core.framework import graph_pb2 from tensorflow.core.protobuf import config_pb2 from tensorflow.core.protobuf import meta_graph_pb2 from tensorflow.python.platform import app from tensorflow.python.platform import flags from tensorflow.python.platform import tf_logging as logging from tensorflow.python.summary import event_file_inspector as efi logging.set_verbosity(logging.INFO) # Set threshold for what will be logged FLAGS = flags.FLAGS flags.DEFINE_string('event_file', '', 'The TensorFlow summary file to use as input.') def main(unused_argv=None): event_file = os.path.expanduser(FLAGS.event_file) if not event_file: msg = ('The path to an event_file must be specified. ' 'Run `inspect_summary.py --help` for usage instructions.') logging.error(msg) return -1 for event in tf.train.summary_iterator(event_file): # Yields a sequence of `tensorflow.core.util.event_pb2.Event` # https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/util/event.proto #print '>>', event
import time import datetime import os os.environ["CUDA_VISIBLE_DEVICES"] = '0' import numpy as np import tensorflow as tf from utils import * from model.rnn import BiRNN from tensorflow.python.platform import flags from tensorflow.python.platform import app flags.DEFINE_string('mode', 'train', 'set whether to train or test') flags.DEFINE_string('model', 'BiRNN', 'set the model to use, BiRNN, CNN') flags.DEFINE_string('rnncell', 'lstm', 'set the rnncell to use, rnn, gru, lstm...') flags.DEFINE_integer('num_layer', 3, 'set the layers for rnn') flags.DEFINE_boolean('layerNormalization', True, 'set whether to apply layer normalization to rnn cell') flags.DEFINE_integer('batch_size', 64, 'set the batch size') flags.DEFINE_integer('num_hidden', 512, 'set the hidden size of rnn cell') flags.DEFINE_integer('num_feature', 39, 'set the size of input feature') flags.DEFINE_integer('num_class', 462, 'set the speakrs') flags.DEFINE_integer('num_epoch', 200, 'set the number of epochs') flags.DEFINE_float('learning_rate', 0.0001, 'set the learning rate') flags.DEFINE_float('keep_prob', 0.8, 'set probability of dropout') flags.DEFINE_float(
from __future__ import unicode_literals import keras from keras import backend import tensorflow as tf from tensorflow.python.platform import app from tensorflow.python.platform import flags from cleverhans.utils_mnist import data_mnist from cleverhans.utils_tf import model_train, model_eval from cleverhans.utils import cnn_model FLAGS = flags.FLAGS flags.DEFINE_string('train_dir', '/tmp', 'Directory storing the saved model.') flags.DEFINE_string('filename', 'mnist.ckpt', 'Filename to save model under.') flags.DEFINE_integer('nb_epochs', 2, 'Number of epochs to train model') flags.DEFINE_integer('batch_size', 128, 'Size of training batches') flags.DEFINE_float('learning_rate', 0.1, 'Learning rate for training') def main(argv=None): keras.layers.core.K.set_learning_phase(0) # Set TF random seed to improve reproducibility tf.set_random_seed(1234) if not hasattr(backend, "tf"): raise RuntimeError("This tutorial requires keras to be configured" " to use the TensorFlow backend.")
from tensorflow.core.framework import types_pb2 from tensorflow.core.protobuf import config_pb2 from tensorflow.python.client import session from tensorflow.python.framework import dtypes from tensorflow.python.framework import ops from tensorflow.python.framework import random_seed from tensorflow.python.ops import array_ops from tensorflow.python.ops import variables from tensorflow.python.platform import flags from tensorflow.python.platform import test from tensorflow.python.platform import tf_logging as logging FLAGS = flags.FLAGS flags.DEFINE_string( 'test_device', None, 'Tensorflow device on which to place operators under test') flags.DEFINE_string('types', None, 'Types to test. Comma-separated list.') flags.DEFINE_string( 'disabled_manifest', None, 'Path to a file with a list of tests that should not run.') class XLATestCase(test.TestCase): """XLA test cases are parameterized test cases.""" def __init__(self, method_name='runTest'): super(XLATestCase, self).__init__(method_name) self.device = FLAGS.test_device self.has_custom_call = (self.device == 'XLA_CPU') self.all_tf_types = [ dtypes.as_dtype(types_pb2.DataType.Value(name))
import numpy as np import random import tensorflow as tf import logging import gym from data_generator import DataGenerator from mil import MIL from mtl import MTL from tensorflow.python.platform import flags import matplotlib.pyplot as plt FLAGS = flags.FLAGS LOGGER = logging.getLogger(__name__) ## Dataset/method options flags.DEFINE_string('experiment', 'target_vision_reach', 'target_vision_reach, action_vision_reach or sim_push') flags.DEFINE_string('demo_file', '/home/raviteja/code/python/VIL/data/vision_reach/color_data', 'path to the directory where demo files that containing robot states and actions are stored') flags.DEFINE_string('demo_gif_dir', '/home/raviteja/code/python/VIL/data/vision_reach/color_data/', 'path to the videos of demonstrations') flags.DEFINE_string('gif_prefix', 'color', 'prefix of the video directory for each task, e.g. object_0 for task 0') flags.DEFINE_integer('im_width', 128, 'width of the images in the demo videos 256 for vision_reach') flags.DEFINE_integer('im_height', 128, 'height of the images in the demo videos 256 for vision_reach') flags.DEFINE_integer('num_channels', 3, 'number of channels of the images in the demo videos') flags.DEFINE_integer('T', 24, 'time horizon of the demo videos 24 for reach') flags.DEFINE_bool('hsv', False, 'convert the image to HSV format') flags.DEFINE_bool('use_noisy_demos', False, 'use noisy demonstrations or not (for domain shift)') flags.DEFINE_string('noisy_demo_gif_dir', None, 'path to the videos of noisy demonstrations') flags.DEFINE_string('noisy_demo_file', None, 'path to the directory where noisy demo files that containing robot states and actions are stored') flags.DEFINE_bool('no_action', False, 'do not include actions in the demonstrations for inner update') flags.DEFINE_bool('no_state', False, 'do not include states in the demonstrations during training, use with two headed architecture') flags.DEFINE_bool('no_final_eept', False, 'do not include final ee pos in the demonstrations for inner update') flags.DEFINE_bool('zero_state', False, 'zero-out states (meta-learn state) in the demonstrations for inner update (used in the paper with video-only demos)')
import random import numpy as np import tensorflow as tf from maml import MAML tf.set_random_seed(1234) from data_generator import DataGenerator from tensorflow.python.platform import flags FLAGS = flags.FLAGS ## Dataset/method options flags.DEFINE_string('datasource', 'plainmulti', '2D or plainmulti or artmulti') flags.DEFINE_integer( 'test_dataset', -1, 'which data to be test, plainmulti: 0-3, artmulti: 0-11, -1: random select' ) flags.DEFINE_integer( 'num_classes', 5, 'number of classes used in classification (e.g. 5-way classification).') flags.DEFINE_integer('num_test_task', 1000, 'number of test tasks.') flags.DEFINE_integer('test_epoch', -1, 'test epoch, only work when test start') ## Training options flags.DEFINE_integer( 'metatrain_iterations', 15000, 'number of metatraining iterations.') # 15k for omniglot, 50k for sinusoid flags.DEFINE_integer('meta_batch_size', 25, 'number of tasks sampled per meta-update')
import tensorflow as tf import tensorflow.contrib.semisup as semisup import tensorflow.contrib.slim as slim from tensorflow.contrib.slim.python.slim.nets import inception_v3 from tensorflow.python.platform import app from tensorflow.python.platform import flags sys.path.insert( 0, '/usr/wiss/haeusser/libs/tfmodels/inception') #TODO(haeusser) use slim from inception.imagenet_data import ImagenetData from inception import image_processing FLAGS = flags.FLAGS flags.DEFINE_string('architecture', 'inception_model', 'Which dataset to work on.') flags.DEFINE_integer('eval_batch_size', 500, 'Batch size for eval loop.') flags.DEFINE_integer( 'new_size', 0, 'If > 0, resize image to this width/height.' 'Needs to match size used for training.') flags.DEFINE_integer('eval_interval_secs', 300, 'How many seconds between executions of the eval loop.') flags.DEFINE_string( 'logdir', '/tmp/semisup/imagenet', 'Where the checkpoints are stored ' 'and eval events will be written to.') flags.DEFINE_string('master', '', 'BNS name of the TensorFlow master to use.')
import tensorflow as tf from tensorflow.contrib import slim from tensorflow import app from tensorflow.python.platform import flags from PIL import Image import numpy as np import data_provider import common_flags FLAGS = flags.FLAGS common_flags.define() flags.DEFINE_string('input_image', 'input00.png', 'Image to eval.') def main(_): dataset = common_flags.create_dataset(split_name=FLAGS.split_name) model = common_flags.create_model(dataset.num_char_classes, dataset.max_sequence_length, dataset.num_of_views, dataset.null_code, charset=dataset.charset) data = data_provider.get_data( dataset, FLAGS.batch_size, augment=False, central_crop_size=common_flags.get_crop_size()) input_image = Image.open(FLAGS.input_image).convert("RGB").resize((data.images.shape[2] / dataset.num_of_views, data.images.shape[1])) input_array = np.array(input_image).astype(np.float32)
import sys from absl import app import tensorflow as tf from tensorflow.compiler.mlir.tfr.python import composite from tensorflow.compiler.mlir.tfr.python.op_reg_gen import gen_register_op from tensorflow.compiler.mlir.tfr.python.tfr_gen import tfr_gen_from_module from tensorflow.python.ops import gen_array_ops from tensorflow.python.platform import flags Composite = composite.Composite FLAGS = flags.FLAGS flags.DEFINE_string( 'output', None, 'Path to write the genereated register op file and MLIR file.') flags.DEFINE_bool('gen_register_op', True, 'Generate register op cc file or tfr mlir file.') @Composite('NewMirrorPad', inputs=['input_: T', 'paddings: Tpaddings'], attrs=['mode: {"REFLECT", "SYMMETRIC"}'], derived_attrs=['T: type', 'Tpaddings: {int32, int64} = DT_INT32'], outputs=['output: T']) def _composite_mirror_pad(input_, paddings, mode): shape = input_.shape.as_list() for i in range(len(shape)): rdims = tf.raw_ops.OneHot(indices=i,
# Calculate training errors if testing: eval_params = {'batch_size': batch_size} accuracy = model_eval(sess, x, y, preds_2, X_train, Y_train, args=eval_params) report.train_adv_train_clean_eval = accuracy accuracy = model_eval(sess, x, y, preds_2_adv, X_train, Y_train, args=eval_params) report.train_adv_train_adv_eval = accuracy ''' return report def main(argv=None): mnist_tutorial(nb_epochs=FLAGS.nb_epochs, batch_size=FLAGS.batch_size, learning_rate=FLAGS.learning_rate, train_dir=FLAGS.train_dir, filename=FLAGS.filename, load_model=FLAGS.load_model) if __name__ == '__main__': flags.DEFINE_integer('nb_epochs', 1, 'Number of epochs to train model') flags.DEFINE_integer('batch_size', 128, 'Size of training batches') flags.DEFINE_float('learning_rate', 0.001, 'Learning rate for training') flags.DEFINE_string('train_dir', '/tmp', 'Directory where to save model.') flags.DEFINE_string('filename', 'mnist.ckpt', 'Checkpoint filename.') flags.DEFINE_boolean('load_model', True, 'Load saved model or train.') tf.app.run()
if s >= completeness: p_completeness += 1 if combination == np.ones(t_t).astype('int').tolist(): sparse += 1 sparse_coverage = 1.0 * sparse / total dense_coverage = 1.0 * dense / (t_t * total) pt_completeness = 1.0 * p_completeness / total print([sparse_coverage, dense_coverage, pt_completeness]) return [sparse_coverage, dense_coverage, pt_completeness] def main(argv=None): ct(datasets=FLAGS.datasets, model_name=FLAGS.model, samples_path=FLAGS.samples, t=FLAGS.t, p=FLAGS.p) if __name__ == '__main__': flags.DEFINE_string('datasets', 'mnist', 'The target datasets.') flags.DEFINE_string('model', 'lenet5', 'The name of model') flags.DEFINE_string( 'samples', 'test', 'The path to load samples.') # '../mt_result/mnist_jsma/adv_jsma' flags.DEFINE_integer('t', 2, 't-way combination') flags.DEFINE_float('p', 0.5, 'p-completeness') tf.app.run()
from __future__ import division from __future__ import print_function import json import os from tensorflow.python.platform import app from tensorflow.python.platform import flags from tensorflow.python.platform import gfile from absl import logging import numpy as np from lib import dataset_utils from lib import paths flags.DEFINE_string("dataset_name", "default", "Name of source dataset.") flags.DEFINE_string( "n_labeled_list", "100,250,500,1000,2000,4000,8000", "Comma-separated list of label counts to create label maps for.") flags.DEFINE_integer("label_map_index", 0, "Identifier for this label map.") flags.DEFINE_integer("seed", 0, "Random seed for determinism.") flags.DEFINE_string( "fkeys_path", paths.LABEL_MAP_PATH, "Where to write read the fkeys and write the label_maps.", ) flags.DEFINE_string( "imagenet_path", paths.RAW_IMAGENET_PATH, "Where to read raw imagenet files.", )
import pickle import numpy as np from sklearn.decomposition import PCA from sklearn.svm import SVC from sklearn import metrics from tensorflow.python.platform import flags import pickle import data import saab import cv2 flags.DEFINE_string("output_path", None, "The output dir to save params") flags.DEFINE_string("use_classes", "0-9", "Supported format: 0,1,5-9") flags.DEFINE_string("kernel_sizes", "3,5", "Kernels size for each stage. Format: '3,3'") flags.DEFINE_string("num_kernels", "5,15", "Num of kernels for each stage. Format: '4,10'") flags.DEFINE_float("energy_percent", None, "Energy to be preserved in each stage") flags.DEFINE_integer("use_num_images",3000, "Num of images used for training") FLAGS = flags.FLAGS train_images, train_labels, test_images, test_labels, class_list = data.import_data(FLAGS.use_classes) fr=open('ffcnn_feature_1.pkl','rb') feature_1=pickle.load(fr) fr.close() fr=open('ffcnn_feature_2.pkl','rb') feature_2=pickle.load(fr) fr.close() fr=open('ffcnn_feature_3.pkl','rb') feature_3=pickle.load(fr)
def main(argv=None): mnist_tutorial_cw(viz_enabled=FLAGS.viz_enabled, nb_epochs=FLAGS.nb_epochs, batch_size=FLAGS.batch_size, source_samples=FLAGS.source_samples, learning_rate=FLAGS.learning_rate, attack_iterations=FLAGS.attack_iterations, model_path=FLAGS.model_path, targeted=FLAGS.targeted) if __name__ == '__main__': flags.DEFINE_boolean('viz_enabled', VIZ_ENABLED, 'Visualize adversarial ex.') flags.DEFINE_integer('nb_epochs', NB_EPOCHS, 'Number of epochs to train model') flags.DEFINE_integer('batch_size', BATCH_SIZE, 'Size of training batches') flags.DEFINE_integer('source_samples', SOURCE_SAMPLES, 'Number of test inputs to attack') flags.DEFINE_float('learning_rate', LEARNING_RATE, 'Learning rate for training') flags.DEFINE_string('model_path', MODEL_PATH, 'Path to save or load the model file') flags.DEFINE_integer('attack_iterations', ATTACK_ITERATIONS, 'Number of iterations to run attack; 1000 is good') flags.DEFINE_boolean('targeted', TARGETED, 'Run the tutorial in targeted mode?') tf.app.run()
from __future__ import absolute_import from __future__ import division from __future__ import print_function from tensorflow.core.protobuf import tensorflow_server_pb2 from tensorflow.python.platform import app from tensorflow.python.platform import flags from tensorflow.python.training import server_lib FLAGS = flags.FLAGS flags.DEFINE_string( "cluster_spec", "", """Cluster spec: SPEC. SPEC is <JOB>(,<JOB>)*," JOB is <NAME>|<HOST:PORT>(;<HOST:PORT>)*," NAME is a valid job name ([a-z][0-9a-z]*)," HOST is a hostname or IP address," PORT is a port number." E.g., local|localhost:2222;localhost:2223, ps|ps0:2222;ps1:2222""") flags.DEFINE_string("job_name", "", "Job name: e.g., local") flags.DEFINE_integer("task_id", 0, "Task index, e.g., 0") flags.DEFINE_boolean("verbose", False, "Verbose mode") def parse_cluster_spec(cluster_spec, cluster): """Parse content of cluster_spec string and inject info into cluster protobuf. Args: cluster_spec: cluster specification string, e.g., "local|localhost:2222;localhost:2223" cluster: cluster protobuf.
Make train_32x32.mat for next round of training: X: images selected from SVHN trainset -- corresponding to each pseudo-labels selected from the transferred SVHN. (32, 32, 3, <72257) y: pseudo-labels selected from the transferred SVHN (1, <72257) ''' FLAGS = flags.FLAGS # data_dirs (SVHN trainset images) = '/home/chen/Documents/cycleDA/Eval_code/data/svhn/' PSEUDO_LABEL_DIR = '/home/chen/Downloads/CycleDA_data/star_colorstat_recon30_ps/train_32x32.mat' OUTPUT_PRE = '/home/chen/Downloads/CycleDA_data/star_colorstat_recon30_ps/train/train' CHECK_PSEUDO_LABEL_ACC = True VIS = True START = 17965 END = 18005 flags.DEFINE_string('pseudo_label_dir', PSEUDO_LABEL_DIR, 'Directory of pseudo_labels') flags.DEFINE_string('vis_dir', OUTPUT_VIS, 'Directory of pseudo_labels') flags.DEFINE_string('output_path_prefix', OUTPUT_PRE, 'Name of output file') flags.DEFINE_string('image_set', 'train', 'The corresponding set of pseudo_labels') flags.DEFINE_integer('start_idx', 1, 'The starting index of generated image, usually 0 or 1') flags.DEFINE_bool('check_acc', CHECK_PSEUDO_LABEL_ACC, '(# of correct pseudo-labels) / (# of total pseudo-labels)') flags.DEFINE_integer('visualize', VIS, 'visualize') def generate_mat(image_set, start_idx, pseudo_label_dir, output_path_prefix, check_acc, visualize): images, gt_labels = svhn_tools.get_data(image_set) print(pseudo_label_dir) pseudo_mat = sio.loadmat(pseudo_label_dir) labels = pseudo_mat['Pseudo'].astype(np.uint8) mask = np.squeeze(pseudo_mat['Mask']).astype(np.uint8)
from __future__ import print_function import numpy as np from google.protobuf import text_format from tensorflow.contrib.proto.python.kernel_tests import test_case from tensorflow.contrib.proto.python.kernel_tests import test_example_pb2 from tensorflow.contrib.proto.python.ops import decode_proto_op from tensorflow.python.framework import dtypes from tensorflow.python.platform import flags from tensorflow.python.platform import test FLAGS = flags.FLAGS flags.DEFINE_string('message_text_file', None, 'A file containing a text serialized TestCase protobuf.') class DecodeProtoOpTest(test_case.ProtoOpTestCase): def _compareValues(self, fd, vs, evs): """Compare lists/arrays of field values.""" if len(vs) != len(evs): self.fail('Field %s decoded %d outputs, expected %d' % (fd.name, len(vs), len(evs))) for i, ev in enumerate(evs): # Special case fuzzy match for float32. TensorFlow seems to mess with # MAX_FLT slightly and the test doesn't work otherwise. # TODO(nix): ask on TF list about why MAX_FLT doesn't pass through. if fd.cpp_type == fd.CPPTYPE_FLOAT: # Numpy isclose() is better than assertIsClose() which uses an absolute
# Calculating train error if testing: eval_par = {'batch_size': batch_size} acc = model_eval(sess, x, y, preds_adv, x_train, y_train, args=eval_par) report.train_clean_train_adv_eval = acc return report def main(argv=None): cifar_tutorial(nb_epochs=FLAGS.nb_epochs, batch_size=FLAGS.batch_size, learning_rate=FLAGS.learning_rate, train_dir=FLAGS.train_dir, filename=FLAGS.filename, load_model=FLAGS.load_model, method=FLAGS.method) if __name__ == '__main__': flags.DEFINE_integer('nb_epochs', 40, 'Number of epochs to train model') flags.DEFINE_integer('batch_size', 128, 'Size of training batches') flags.DEFINE_float('learning_rate', 0.001, 'Learning rate for training') flags.DEFINE_string('train_dir', 'cifar_ff_model', 'Directory where to save model.') flags.DEFINE_string('filename', 'FF_init_model.ckpt', 'Checkpoint filename.') flags.DEFINE_boolean('load_model', True, 'Load saved model or train.') flags.DEFINE_string('method', 'FGSM', 'Adversarial attack method') tf.app.run()
from six.moves import cPickle from functools import wraps import random import numpy as np import tensorflow as tf from tensorflow.python.ops import ctc_ops as ctc from speechvalley.utils import load_batched_data, describe, output_to_sequence, list_dirs, logging, count_params, get_num_classes, check_path_exists, dotdict, activation_functions_dict, optimizer_functions_dict from speechvalley.models import DBiRNN from tensorflow.python.platform import flags from tensorflow.python.platform import app flags.DEFINE_string('task', 'libri', 'set task name of this program') flags.DEFINE_string('train_dataset', 'train-clean-100', 'set the training dataset') flags.DEFINE_string('dev_dataset', 'dev-clean', 'set the development dataset') flags.DEFINE_string('test_dataset', 'test-clean', 'set the test dataset') flags.DEFINE_string('mode', 'test', 'set whether to train, dev or test') flags.DEFINE_boolean('keep', True, 'set whether to restore a model, when test mode, keep should be set to True') flags.DEFINE_string('level', 'cha', 'set the task level, phn, cha, or seq2seq, seq2seq will be supported soon') flags.DEFINE_string('model', 'DBiRNN', 'set the model to use, DBiRNN, BiRNN, ResNet..') flags.DEFINE_string('rnncell', 'lstm', 'set the rnncell to use, rnn, gru, lstm...') flags.DEFINE_integer('num_layer', 2, 'set the layers for rnn') flags.DEFINE_string('activation', 'tanh', 'set the activation to use, sigmoid, tanh, relu, elu...') flags.DEFINE_string('optimizer', 'adam', 'set the optimizer to use, sgd, adam...') flags.DEFINE_boolean('layerNormalization', False, 'set whether to apply layer normalization to rnn cell')
------------------------------------------------- Change Activity: 2018/12/28: ------------------------------------------------- """ import os import tensorflow as tf from tensorflow.python.platform import flags from model import rnn_model from poems import process_poems, generate_batch data_path = 'F:\project\Chatbot_CN\Chatbot_Data\Text_generator\poem\poems.txt' flags.DEFINE_integer('batch_size', 64, 'batch size.') # 每次取64首进行训练 flags.DEFINE_float('learning_rate', 0.01, 'learning rate.') flags.DEFINE_string('model_dir', os.path.abspath('./model'), 'model save path.') flags.DEFINE_string('file_path', os.path.abspath(data_path), 'file name of poems.') flags.DEFINE_string('model_prefix', 'poems', 'model save prefix.') flags.DEFINE_integer('epochs', 50, 'train how many epochs.') # FLAGS = tf.app.flags.FLAGS FLAGS = flags.FLAGS def run_training(): if not os.path.exists(FLAGS.model_dir): os.makedirs(FLAGS.model_dir) poems_vector, word_to_int, vocabularies = process_poems(FLAGS.file_path) batches_inputs, batches_outputs = generate_batch(FLAGS.batch_size,
from utils_vpred.skip_example import skip_example from datetime import datetime # How often to record tensorboard summaries. SUMMARY_INTERVAL = 40 # How often to run a batch through the validation model. VAL_INTERVAL = 200 # How often to save a model checkpoint SAVE_INTERVAL = 2000 if __name__ == '__main__': FLAGS = flags.FLAGS flags.DEFINE_string('hyper', '', 'hyperparameters configuration file') flags.DEFINE_string( 'visualize', '', 'model within hyperparameter folder from which to create gifs') flags.DEFINE_integer('device', 0, 'the value for CUDA_VISIBLE_DEVICES variable') flags.DEFINE_string('pretrained', '', 'model weights from which to resume training') ## Helper functions def peak_signal_to_noise_ratio(true, pred): """Image quality metric based on maximal signal power vs. power of the noise. Args: true: the ground truth image.
import flownet import flownet_tools import architectures import bilateral_solver as bs import computeColor import writeFlowFile from skimage.io import imread dir_path = dirname(os.path.realpath(__file__)) # Basic model parameters as external flags. FLAGS = flags.FLAGS flags.DEFINE_string('dataset', '/kitti_2012', 'Data Set in use') flags.DEFINE_string('grid_params', { 'sigma_luma': 8, 'sigma_chroma': 8, 'sigma_spatial': 8 }, 'grid_params') flags.DEFINE_string('bs_params', { 'lam': 80, 'A_diag_min': 1e-5, 'cg_tol': 1e-5, 'cg_maxiter': 25 }, 'bs_params') flags.DEFINE_integer('batchsize', 20, 'Batch size for eval loop.')
from tensorflow.python.platform import app from tensorflow.python.platform import flags from cfgs import config_cmp from cfgs import config_vision_baseline import datasets.nav_env as nav_env import src.file_utils as fu import src.utils as utils import tfcode.cmp as cmp from tfcode import tf_utils from tfcode import vision_baseline_lstm #Tri from copy import deepcopy FLAGS = flags.FLAGS flags.DEFINE_string('master', '', 'The address of the tensorflow master') flags.DEFINE_integer( 'ps_tasks', 0, 'The number of parameter servers. If the ' 'value is 0, then the parameters are handled locally by ' 'the worker.') flags.DEFINE_integer( 'task', 0, 'The Task ID. This value is used when training ' 'with multiple workers to identify each worker.') flags.DEFINE_integer('num_workers', 1, '') flags.DEFINE_string('config_name', '', '') flags.DEFINE_string('logdir', '', '') flags.DEFINE_integer('solver_seed', 0, '')
flags.DEFINE_integer('sup_batch_size', 100, 'Number of unlabeled samples per batch.') flags.DEFINE_integer('eval_interval', 500, 'Number of steps between evaluations.') flags.DEFINE_float('learning_rate', 1e-1, 'Initial learning rate.') flags.DEFINE_float('decay_factor', 0.1, 'Learning rate decay factor.') flags.DEFINE_float('decay_steps', 30000, 'Learning rate decay interval in steps.') flags.DEFINE_integer('max_steps', 80000, 'Number of training steps.') flags.DEFINE_string('logdir', '/tmp/semisup_mnist', 'Training log path.') flags.DEFINE_string('subset', 'train', 'Training or test.') from tools import cifar as cifar_tools #from conviz import conviz from data_layer import data_layer #from models import resnet_mkb_old as resnet_mkb from models import resnet_mkb as resnet_mkb from models import resnet as resnet NUM_LABELS = cifar_tools.NUM_LABELS IMAGE_SHAPE = cifar_tools.IMAGE_SHAPE def valid_and_test(model, images, labels): (pred_0, pred_1) = model.classify(images)
Note that better sinusoid results can be achieved by using a larger network. """ import csv import numpy as np import pickle import random import tensorflow as tf from data_generator import DataGenerator from maml import MAML from tensorflow.python.platform import flags FLAGS = flags.FLAGS ## Dataset/method options flags.DEFINE_string('datasource', 'sinusoid', 'sinusoid or omniglot or miniimagenet') flags.DEFINE_integer( 'num_classes', 5, 'number of classes used in classification (e.g. 5-way classification).') # oracle means task id is input (only suitable for sinusoid) flags.DEFINE_string('baseline', None, 'oracle, or None') ## Training options flags.DEFINE_integer('pretrain_iterations', 0, 'number of pre-training iterations.') flags.DEFINE_integer( 'metatrain_iterations', 15000, 'number of metatraining iterations.') # 15k for omniglot, 50k for sinusoid flags.DEFINE_integer('meta_batch_size', 25, 'number of tasks sampled per meta-update') flags.DEFINE_float('meta_lr', 0.001, 'the base learning rate of the generator')