本文整理汇总了Python中tensorflow.app.run方法的典型用法代码示例。如果您正苦于以下问题:Python app.run方法的具体用法?Python app.run怎么用?Python app.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.app
的用法示例。
在下文中一共展示了app.run方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train
# 需要导入模块: from tensorflow import app [as 别名]
# 或者: from tensorflow.app import run [as 别名]
def train(loss, init_fn, hparams):
"""Wraps slim.learning.train to run a training loop.
Args:
loss: a loss tensor
init_fn: A callable to be executed after all other initialization is done.
hparams: a model hyper parameters
"""
optimizer = create_optimizer(hparams)
if FLAGS.sync_replicas:
replica_id = tf.constant(FLAGS.task, tf.int32, shape=())
optimizer = tf.LegacySyncReplicasOptimizer(
opt=optimizer,
replicas_to_aggregate=FLAGS.replicas_to_aggregate,
replica_id=replica_id,
total_num_replicas=FLAGS.total_num_replicas)
sync_optimizer = optimizer
startup_delay_steps = 0
else:
startup_delay_steps = 0
sync_optimizer = None
train_op = slim.learning.create_train_op(
loss,
optimizer,
summarize_gradients=True,
clip_gradient_norm=FLAGS.clip_gradient_norm)
slim.learning.train(
train_op=train_op,
logdir=FLAGS.train_log_dir,
graph=loss.graph,
master=FLAGS.master,
is_chief=(FLAGS.task == 0),
number_of_steps=FLAGS.max_number_of_steps,
save_summaries_secs=FLAGS.save_summaries_secs,
save_interval_secs=FLAGS.save_interval_secs,
startup_delay_steps=startup_delay_steps,
sync_optimizer=sync_optimizer,
init_fn=init_fn)
示例2: run
# 需要导入模块: from tensorflow import app [as 别名]
# 或者: from tensorflow.app import run [as 别名]
def run(self):
"""Starts the parameter server."""
logging.info("%s: Starting parameter server within cluster %s.",
task_as_string(self.task), self.cluster.as_dict())
server = start_server(self.cluster, self.task)
server.join()
示例3: optional_assign_weights
# 需要导入模块: from tensorflow import app [as 别名]
# 或者: from tensorflow.app import run [as 别名]
def optional_assign_weights(sess, weights_input, weights_assignment):
if weights_input is not None:
weights, length = get_video_weights_array()
_ = sess.run(weights_assignment, feed_dict={weights_input: weights})
print "Assigned weights from %s" % FLAGS.sample_freq_file
else:
print "Collection weights_input not found"
示例4: main
# 需要导入模块: from tensorflow import app [as 别名]
# 或者: from tensorflow.app import run [as 别名]
def main(unused_argv):
# Load the environment.
env = json.loads(os.environ.get("TF_CONFIG", "{}"))
# Load the cluster data from the environment.
cluster_data = env.get("cluster", None)
cluster = tf.train.ClusterSpec(cluster_data) if cluster_data else None
# Load the task data from the environment.
task_data = env.get("task", None) or {"type": "master", "index": 0}
task = type("TaskSpec", (object,), task_data)
# Logging the version.
logging.set_verbosity(tf.logging.INFO)
logging.info("%s: Tensorflow version: %s.",
task_as_string(task), tf.__version__)
# Dispatch to a master, a worker, or a parameter server.
if not cluster or task.type == "master" or task.type == "worker":
Trainer(cluster, task, FLAGS.train_dir, FLAGS.log_device_placement).run(
start_new_model=FLAGS.start_new_model)
elif task.type == "ps":
ParameterServer(cluster, task).run()
else:
raise ValueError("%s: Invalid task_type: %s." %
(task_as_string(task), task.type))
示例5: main
# 需要导入模块: from tensorflow import app [as 别名]
# 或者: from tensorflow.app import run [as 别名]
def main(unused_argv):
# Load the environment.
env = json.loads(os.environ.get("TF_CONFIG", "{}"))
# Load the cluster data from the environment.
cluster_data = env.get("cluster", None)
cluster = tf.train.ClusterSpec(cluster_data) if cluster_data else None
# Load the task data from the environment.
task_data = env.get("task", None) or {"type": "master", "index": 0}
task = type("TaskSpec", (object,), task_data)
# Logging the version.
logging.set_verbosity(tf.logging.INFO)
logging.info("%s: Tensorflow version: %s.",
task_as_string(task), tf.__version__)
# Dispatch to a master, a worker, or a parameter server.
if not cluster or task.type == "master" or task.type == "worker":
Trainer(cluster, task, FLAGS.train_dir, FLAGS.log_device_placement).run(
start_new_model=FLAGS.start_new_model)
elif task.type == "ps":
ParameterServer(cluster, task).run()
else:
raise ValueError("%s: Invalid task_type: %s." %
(task_as_string(task), task.type))
示例6: main
# 需要导入模块: from tensorflow import app [as 别名]
# 或者: from tensorflow.app import run [as 别名]
def main(unused_argv):
logging.set_verbosity(tf.logging.INFO)
if FLAGS.input_model_tgz:
if FLAGS.train_dir:
raise ValueError("You cannot supply --train_dir if supplying "
"--input_model_tgz")
# Untar.
if not os.path.exists(FLAGS.untar_model_dir):
os.makedirs(FLAGS.untar_model_dir)
tarfile.open(FLAGS.input_model_tgz).extractall(FLAGS.untar_model_dir)
FLAGS.train_dir = FLAGS.untar_model_dir
flags_dict_file = os.path.join(FLAGS.train_dir, "model_flags.json")
if not file_io.file_exists(flags_dict_file):
raise IOError("Cannot find %s. Did you run eval.py?" % flags_dict_file)
flags_dict = json.loads(file_io.FileIO(flags_dict_file, "r").read())
# convert feature_names and feature_sizes to lists of values
feature_names, feature_sizes = utils.GetListOfFeatureNamesAndSizes(
flags_dict["feature_names"], flags_dict["feature_sizes"])
if flags_dict["frame_features"]:
reader = readers.YT8MFrameFeatureReader(feature_names=feature_names,
feature_sizes=feature_sizes)
else:
reader = readers.YT8MAggregatedFeatureReader(feature_names=feature_names,
feature_sizes=feature_sizes)
if not FLAGS.output_file:
raise ValueError("'output_file' was not specified. "
"Unable to continue with inference.")
if not FLAGS.input_data_pattern:
raise ValueError("'input_data_pattern' was not specified. "
"Unable to continue with inference.")
inference(reader, FLAGS.train_dir, FLAGS.input_data_pattern,
FLAGS.output_file, FLAGS.batch_size, FLAGS.top_k)
示例7: main
# 需要导入模块: from tensorflow import app [as 别名]
# 或者: from tensorflow.app import run [as 别名]
def main(unused_argv):
# Load the environment.
env = json.loads(os.environ.get("TF_CONFIG", "{}"))
# Load the cluster data from the environment.
cluster_data = env.get("cluster", None)
cluster = tf.train.ClusterSpec(cluster_data) if cluster_data else None
# Load the task data from the environment.
task_data = env.get("task", None) or {"type": "master", "index": 0}
task = type("TaskSpec", (object,), task_data)
# Logging the version.
logging.set_verbosity(tf.logging.INFO)
logging.info("%s: Tensorflow version: %s.", task_as_string(task),
tf.__version__)
# Dispatch to a master, a worker, or a parameter server.
if not cluster or task.type == "master" or task.type == "worker":
model = find_class_by_name(FLAGS.model,
[frame_level_models, video_level_models])()
reader = get_reader()
model_exporter = export_model.ModelExporter(
frame_features=FLAGS.frame_features, model=model, reader=reader)
Trainer(cluster, task, FLAGS.train_dir, model, reader, model_exporter,
FLAGS.log_device_placement, FLAGS.max_steps,
FLAGS.export_model_steps).run(start_new_model=FLAGS.start_new_model)
elif task.type == "ps":
ParameterServer(cluster, task).run()
else:
raise ValueError("%s: Invalid task_type: %s." %
(task_as_string(task), task.type))
示例8: main
# 需要导入模块: from tensorflow import app [as 别名]
# 或者: from tensorflow.app import run [as 别名]
def main(unused_argv):
logging.set_verbosity(tf.logging.INFO)
if FLAGS.input_model_tgz:
if FLAGS.train_dir:
raise ValueError("You cannot supply --train_dir if supplying "
"--input_model_tgz")
# Untar.
if not os.path.exists(FLAGS.untar_model_dir):
os.makedirs(FLAGS.untar_model_dir)
tarfile.open(FLAGS.input_model_tgz).extractall(FLAGS.untar_model_dir)
FLAGS.train_dir = FLAGS.untar_model_dir
flags_dict_file = os.path.join(FLAGS.train_dir, "model_flags.json")
if not os.path.exists(flags_dict_file):
raise IOError("Cannot find %s. Did you run eval.py?" % flags_dict_file)
flags_dict = json.loads(open(flags_dict_file).read())
# convert feature_names and feature_sizes to lists of values
feature_names, feature_sizes = utils.GetListOfFeatureNamesAndSizes(
flags_dict["feature_names"], flags_dict["feature_sizes"])
if flags_dict["frame_features"]:
reader = readers.YT8MFrameFeatureReader(feature_names=feature_names,
feature_sizes=feature_sizes)
else:
reader = readers.YT8MAggregatedFeatureReader(feature_names=feature_names,
feature_sizes=feature_sizes)
if FLAGS.output_file is "":
raise ValueError("'output_file' was not specified. "
"Unable to continue with inference.")
if FLAGS.input_data_pattern is "":
raise ValueError("'input_data_pattern' was not specified. "
"Unable to continue with inference.")
inference(reader, FLAGS.train_dir, FLAGS.input_data_pattern,
FLAGS.output_file, FLAGS.batch_size, FLAGS.top_k)
示例9: evaluate_one
# 需要导入模块: from tensorflow import app [as 别名]
# 或者: from tensorflow.app import run [as 别名]
def evaluate_one(result_root, model_name, data_split, example):
"""Compare one example on one model, returning ssim and PSNR scores."""
example_dir = os.path.join(result_root, model_name, data_split, example)
tgt_file = tf.gfile.Glob(example_dir + '/tgt_image_*')[0]
tgt_image = tf.convert_to_tensor(load_image(tgt_file), dtype=tf.float32)
pred_file = tf.gfile.Glob(example_dir + '/output_image_*')[0]
pred_image = tf.convert_to_tensor(load_image(pred_file), dtype=tf.float32)
ssim = tf.image.ssim(pred_image, tgt_image, max_val=255.0)
psnr = tf.image.psnr(pred_image, tgt_image, max_val=255.0)
with tf.Session() as sess:
return sess.run(ssim).item(), sess.run(psnr).item()
示例10: __init__
# 需要导入模块: from tensorflow import app [as 别名]
# 或者: from tensorflow.app import run [as 别名]
def __init__(self, target, target_height=0, target_threshold=4):
self.target_txt = target
self.target_height = target_height
self.sim_threshold = target_threshold
use_gpu = FLAGS.use_gpu >= 0
self.char_map = read_all_chars()
params = read_tesseract_params(use_gpu=use_gpu)
model = MyVGSLImageModel(use_gpu=use_gpu)
self.img_var = tf.placeholder(dtype=tf.float32, shape=(None, None, 4))
self.h_orig_var = tf.placeholder(dtype=tf.int64, shape=[1])
self.w_orig_var = tf.placeholder(dtype=tf.int64, shape=[1])
self.h_resized_var = tf.placeholder(dtype=tf.int64, shape=[1])
self.w_resized_var = tf.placeholder(dtype=tf.int64, shape=[1])
self.resized_dims_var = tf.cast(
tf.concat([self.h_resized_var, self.w_resized_var], axis=0),
tf.int32)
img_preproc = self.img_var
img_preproc = remove_alpha(img_preproc)
img_preproc = preprocess_tf(img_preproc,
self.h_orig_var[0],
self.w_orig_var[0])
img_large = tf.image.resize_images(img_preproc, self.resized_dims_var,
method=tf.image.ResizeMethod.BILINEAR)
img_large = tf.image.rgb_to_grayscale(img_large)
logits, _ = model(img_large, self.h_resized_var, self.w_resized_var)
self.text_output = ctc_decode(logits, model.ctc_width)
init_ops = init(params, use_gpu=use_gpu, skip=0)
self.sess = tf.Session()
self.sess.run(init_ops)