當前位置: 首頁>>代碼示例>>Python>>正文


Python app.run方法代碼示例

本文整理匯總了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) 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:43,代碼來源:train.py

示例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() 
開發者ID:antoine77340,項目名稱:Youtube-8M-WILLOW,代碼行數:9,代碼來源:train.py

示例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" 
開發者ID:wangheda,項目名稱:youtube-8m,代碼行數:9,代碼來源:train.py

示例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)) 
開發者ID:wangheda,項目名稱:youtube-8m,代碼行數:28,代碼來源:train.py

示例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)) 
開發者ID:wangheda,項目名稱:youtube-8m,代碼行數:28,代碼來源:train-with-rebuild.py

示例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) 
開發者ID:google,項目名稱:youtube-8m,代碼行數:40,代碼來源:inference.py

示例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)) 
開發者ID:google,項目名稱:youtube-8m,代碼行數:38,代碼來源:train.py

示例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) 
開發者ID:miha-skalic,項目名稱:youtube8mchallenge,代碼行數:40,代碼來源:inference_gpu.py

示例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() 
開發者ID:google,項目名稱:stereo-magnification,代碼行數:15,代碼來源:evaluate.py

示例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) 
開發者ID:ftramer,項目名稱:ad-versarial,代碼行數:38,代碼來源:model.py


注:本文中的tensorflow.app.run方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。