def __init__(self): try: flags.DEFINE_string('classes', './data/coco.names', 'path to classes file') flags.DEFINE_string('weights', './checkpoints/yolov3.tf', 'path to weights file') flags.DEFINE_boolean('tiny', False, 'yolov3 or yolov3-tiny') flags.DEFINE_integer('size', 416, 'resize images to') flags.DEFINE_string('image', './data/girl.png', 'path to input image') flags.DEFINE_string('tfrecord', None, 'tfrecord instead of image') flags.DEFINE_string('output', './output.jpg', 'path to output image') flags.DEFINE_integer('num_classes', 80, 'number of classes in the model') except NameError: print("再代入禁止") self.yolo = YoloV3(classes=flags.FLAGS.num_classes) self.yolo.load_weights(flags.FLAGS.weights).expect_partial() #logging.info('weights loaded') self.class_names = [ c.strip() for c in open(flags.FLAGS.classes).readlines() ]
FLAGS = flags.FLAGS ## Dataset/method options flags.DEFINE_string('datasource', 'sinusoid', 'sinusoid or omniglot or miniimagenet or dclaw') flags.DEFINE_string('expt_number', '0', '1 or 2 etc') flags.DEFINE_string( 'expt_name', 'intershuffle', 'non_exclusive or intrashuffle or intershuffle or sin_noise') flags.DEFINE_string( 'dclaw_pn', '1', '1 or 2 or 3; dataset permutation number for dclaw. Does differnt train/val/test splits' ) 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') flags.DEFINE_integer( 'update_batch_size', 5,
# limitations under the License. from tensorflow.compiler import vitis_vai from dataset import get_images_infor_from_file, ImagenetSequence from tensorflow.compat.v1 import flags import tensorflow as tf import numpy as np import threading import time keras = tf.keras # Get frozen ConcreteFunction flags.DEFINE_string('input_graph', '', 'TensorFlow \'h5\' file to load.') flags.DEFINE_string('eval_image_path', '/scratch/data/Imagenet/val_dataset', 'The directory where put the eval images') flags.DEFINE_integer('nthreads', 8, 'thread number') flags.DEFINE_integer('batch_iter', 2000, 'eval iterations') flags.DEFINE_string('mode', 'perf', 'normal or perf mode') FLAGS = flags.FLAGS filePath = "./words.txt" def run_func(): r = model(x[0])[0] fp = open(filePath, "r") data1 = fp.readlines() fp.close() result = tf.math.top_k(r, 5) for k in range(5): cnt = 0 for line in data1:
FLAGS = flags.FLAGS tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) normalizer = preprocessing.MaxAbsScaler() audio_dir = os.path.join(os.getcwd(), 'music-data') SONG_FN = 'dubstep.p' #filenames = glob.glob(audio_dir + '/fma_small/' + '/*[0-9]/*') with open(SONG_FN, 'rb') as f: filenames = pickle.load(f) flags.DEFINE_integer('batch', 32, 'Batch size') flags.DEFINE_integer('epochs', 10, 'Number of iterations to train on the entire dataset') flags.DEFINE_integer('latent', 100, 'Dimensionality of the latent space') flags.DEFINE_string('model_path', '.', 'Path to model checkpoint') flags.DEFINE_string('output_dir', '.', 'Path to model checkpoints and logs') flags.DEFINE_string('dtype', 'float32', 'Floating point data type of tensorflow graph') flags.DEFINE_boolean('train', False, 'Train the music GAN') flags.DEFINE_integer('seed', -1, 'Random seed for data shuffling and latent vector generator') flags.DEFINE_boolean('logging', False, 'Whether or not to log and checkpoint the training model') flags.DEFINE_integer('sampling_rate', 14400, 'Sampling rate of loaded music files') flags.DEFINE_float('g_lr', 1e-4, 'Learning rate of the generator') flags.DEFINE_float('d_lr', 1e-6, 'Learning rate of the discriminator') flags.DEFINE_float('dropout', 0.1, 'Dropout rate of the discriminator') flags.DEFINE_integer('g_attn', 2, 'Number of multi-head attention layers in the generator') flags.DEFINE_integer('d_attn', 4, 'Number of multi-head attention layers in the disciminator') flags.DEFINE_float('noise', 0.05, 'Level of noise added to discriminator input data')
def define(): """Define common flags.""" # yapf: disable # common_flags.define() may be called multiple times in unit tests. global _common_flags_defined if _common_flags_defined: return _common_flags_defined = True flags.DEFINE_integer('batch_size', 32, 'Batch size.') flags.DEFINE_integer('crop_width', None, 'Width of the central crop for images.') flags.DEFINE_integer('crop_height', None, 'Height of the central crop for images.') flags.DEFINE_string('train_log_dir', '/tmp/attention_ocr/train', 'Directory where to write event logs.') flags.DEFINE_string('dataset_name', 'fsns', 'Name of the dataset. Supported: fsns') flags.DEFINE_string('split_name', 'train', 'Dataset split name to run evaluation for: test,train.') flags.DEFINE_string('dataset_dir', None, 'Dataset root folder.') flags.DEFINE_string('checkpoint', '', 'Path for checkpoint to restore weights from.') flags.DEFINE_string('master', '', 'BNS name of the TensorFlow master to use.') # Model hyper parameters flags.DEFINE_float('learning_rate', 0.004, 'learning rate') flags.DEFINE_string('optimizer', 'momentum', 'the optimizer to use') flags.DEFINE_float('momentum', 0.9, 'momentum value for the momentum optimizer if used') flags.DEFINE_bool('use_augment_input', True, 'If True will use image augmentation') # Method hyper parameters # conv_tower_fn flags.DEFINE_string('final_endpoint', 'Mixed_5d', 'Endpoint to cut inception tower') # sequence_logit_fn flags.DEFINE_bool('use_attention', True, 'If True will use the attention mechanism') flags.DEFINE_bool('use_autoregression', True, 'If True will use autoregression (a feedback link)') flags.DEFINE_integer('num_lstm_units', 256, 'number of LSTM units for sequence LSTM') flags.DEFINE_float('weight_decay', 0.00004, 'weight decay for char prediction FC layers') flags.DEFINE_float('lstm_state_clip_value', 10.0, 'cell state is clipped by this value prior to the cell' ' output activation') # 'sequence_loss_fn' flags.DEFINE_float('label_smoothing', 0.1, 'weight for label smoothing') flags.DEFINE_bool('ignore_nulls', True, 'ignore null characters for computing the loss') flags.DEFINE_bool('average_across_timesteps', False, 'divide the returned cost by the total label weight')
import os import tensorflow as tf from tensorflow import app from tensorflow.contrib import slim from tensorflow.compat.v1 import flags import common_flags import model_export_lib FLAGS = flags.FLAGS common_flags.define() flags.DEFINE_string('export_dir', None, 'Directory to export model files to.') flags.DEFINE_integer( 'image_width', None, 'Image width used during training (or crop width if used)' ' If not set, the dataset default is used instead.') flags.DEFINE_integer( 'image_height', None, 'Image height used during training(or crop height if used)' ' If not set, the dataset default is used instead.') flags.DEFINE_string('work_dir', '/tmp', 'A directory to store temporary files.') flags.DEFINE_integer('version_number', 1, 'Version number of the model') flags.DEFINE_bool( 'export_for_serving', True, 'Whether the exported model accepts serialized tf.Example ' 'protos as input') def get_checkpoint_path():
flags.DEFINE_string('model', './train_dir/resnet50_model_195.h5', 'TensorFlow \'GraphDef\' file to load.') flags.DEFINE_bool('eval_tfrecords', True, 'If True then use tf_records data .') flags.DEFINE_string('data_dir', '/data3/datasets/Kaggle/fruits-360/tf_records', 'The directory where put the eval images') flags.DEFINE_bool('eval_images', False, 'If True then use tf_records data .') flags.DEFINE_string('eval_image_path', '/data3/datasets/Kaggle/fruits-360/val_for_tf2', 'The directory where put the eval images') flags.DEFINE_string('eval_image_list', '/data3/datasets/Kaggle/fruits-360/val_labels.txt', 'file has validation images list') flags.DEFINE_string('save_path', "train_dir", 'The directory where save model') flags.DEFINE_string('filename', "resnet50_model_{epoch}.h5", 'The name of sved model') flags.DEFINE_integer('label_offset', 1, 'label offset') flags.DEFINE_string('gpus', '0', 'The gpus used for running evaluation.') flags.DEFINE_bool('eval_only', False, 'If True then do not train model, only eval model.') flags.DEFINE_bool( 'save_whole_model', False, 'as applications h5 file just include weights if true save whole model to h5 file.' ) flags.DEFINE_bool('use_synth_data', False, 'If True then use synth data other than imagenet.') flags.DEFINE_bool( 'save_best_only', False, 'If True then only save a model if `val_loss` has improved..') flags.DEFINE_integer('train_step', None, 'Train step number') flags.DEFINE_integer('batch_size', 32, 'Train batch size') flags.DEFINE_integer('epochs', 200, 'Train epochs')
import numpy as np import random import tensorflow as tf from load_data import DataGenerator from tensorflow.compat.v1 import flags from tensorflow.keras import layers from matplotlib import pyplot as plt FLAGS = flags.FLAGS flags.DEFINE_integer( 'num_classes', 2, 'number of classes used in classification (e.g. 5-way classification).') flags.DEFINE_integer( 'num_samples', 1, 'number of examples used for inner gradient update (K for K-shot learning).' ) flags.DEFINE_integer('meta_batch_size', 128, 'Number of N-way classification tasks per batch') def loss_function(preds, labels): """ Computes MANN loss Args: preds: [B, K+1, N, N] network output labels: [B, K+1, N, N] labels Returns: scalar cross-entropy loss
import logging import tensorflow as tf from tensorflow.contrib import slim from tensorflow import app from tensorflow.compat.v1 import flags from tensorflow.contrib.tfprof import model_analyzer import data_provider import common_flags FLAGS = flags.FLAGS common_flags.define() # yapf: disable flags.DEFINE_integer('task', 0, 'The Task ID. This value is used when training with ' 'multiple workers to identify each worker.') 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', 600, 'Frequency in seconds of saving the model.') flags.DEFINE_integer('max_number_of_steps', int(1e10), 'The maximum number of gradient steps.')
from tensorflow.keras.layers import Input, Dense from tensorflow.keras.models import Model from tensorflow.keras.callbacks import ModelCheckpoint from tensorflow.compat.v1 import flags from tensorflow.keras import optimizers import sys, os import config as conf #set up and parse custom flags flags.DEFINE_integer('model_version', conf.version, "Width of the image") flags.DEFINE_boolean('rebuild', False, "Drop the checkpoint weights and rebuild model from scratch") flags.DEFINE_string('lib_folder', conf.lib_folder, "Local library folder") FLAGS = flags.FLAGS #mount the library folder sys.path.append(os.path.abspath(FLAGS.lib_folder)) from data import MNISTProcessor import visualizer as v #load data data_processor = MNISTProcessor(conf.data_path, conf.train_labels, conf.train_images, '', '') x_data_train, y_data_train = data_processor.load_train(normalize=True).get_training_data() #initialize the network input_layer = Input(shape=(784,), name='input') network = Dense(152, activation='tanh', name='dense_1')(input_layer) network = Dense(76, activation='tanh', name='dense_2')(network) network = Dense(38, activation='tanh', name='dense_3')(network) network = Dense(4, activation='tanh', name='dense_4')(network) network = Dense(38, activation='tanh', name='dense_5')(network)
import split_train_test import fit_lstm import evaluate import SAVE import make_prediction from tensorflow.compat.v1 import flags import pandas as pd import os flags.DEFINE_string("path", "./data/catgwise/생활+건강/", "path to data file") flags.DEFINE_string("click_data", "clicks_ma_ratio", "clicks_minmax, clicks_first_ratio, clicks_ma_ratio") flags.DEFINE_integer("s", 60, "seasonality") flags.DEFINE_float("dropout", 0, "dropout rate(default=0)") flags.DEFINE_integer("epoch", 40, "epoch") flags.DEFINE_integer("batch_size", 1, "batch size") flags.DEFINE_integer("pred_time", 30, "how much time to predict") flags.DEFINE_string("pred_index", "05-01-2020", "when beginning prediction(month-date-year), default:'01-01-2020'") flags.DEFINE_boolean("bi", True,"true if bidirectional") FLAGS = flags.FLAGS catg_lst = os.listdir(FLAGS.path) #temppollsell=[[True, True, True], [True, True, False], [True, False, True], [True, False, False], #[False, True, True], [False, True, False], [False, False, True], [False,False,False]] temppollsell=[[True, True, False], [True, False, False], [False, True, False], [False,False,False]] for category in catg_lst: data_path = "{}{}".format(FLAGS.path, category) file = pd.read_csv(data_path, encoding='CP949') file['date'] = pd.to_datetime(file['date'])
from tensorflow.keras.layers import Input, Dense from tensorflow.keras.models import Model from tensorflow.keras import optimizers from tensorflow.compat.v1 import flags import tensorflow.keras as Keras from keras.callbacks import ModelCheckpoint import sys, os import config as conf #set up and parse custom flags flags.DEFINE_integer('model_version', conf.version, "Width of the image") flags.DEFINE_boolean( 'rebuild', False, "Drop the checkpoint weights and rebuild model from scratch") flags.DEFINE_string('lib_folder', conf.lib_folder, "Local library folder") flags.DEFINE_integer('encoder_version', 1, "Autoencoder version to use") FLAGS = flags.FLAGS #mount the library folder sys.path.append(os.path.abspath(FLAGS.lib_folder)) from data import MNISTProcessor #load data data_processor = MNISTProcessor(conf.data_path, conf.train_labels, conf.train_images, '', '') x_data_train, y_data_train = data_processor.load_train( normalize=True).get_training_data() # Load the autoencoder model, including its weights and then process images autoencoder = Keras.models.load_model(conf.autoencoder_model_path + '/' + str(FLAGS.encoder_version))
A simple usage example: python eval.py """ import tensorflow as tf from tensorflow.contrib import slim from tensorflow import app from tensorflow.compat.v1 import flags import data_provider import common_flags FLAGS = flags.FLAGS common_flags.define() # yapf: disable flags.DEFINE_integer('num_batches', 100, 'Number of batches to run eval for.') flags.DEFINE_string('eval_log_dir', '/tmp/attention_ocr/eval', 'Directory where the evaluation results are saved to.') flags.DEFINE_integer('eval_interval_secs', 60, 'Frequency in seconds to run evaluations.') flags.DEFINE_integer('number_of_steps', None, 'Number of times to run evaluation.') # yapf: enable def main(_): if not tf.io.gfile.exists(FLAGS.eval_log_dir): tf.io.gfile.makedirs(FLAGS.eval_log_dir)