当前位置: 首页>>代码示例>>Python>>正文


Python timeline.Timeline方法代码示例

本文整理汇总了Python中tensorflow.python.client.timeline.Timeline方法的典型用法代码示例。如果您正苦于以下问题:Python timeline.Timeline方法的具体用法?Python timeline.Timeline怎么用?Python timeline.Timeline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.python.client.timeline的用法示例。


在下文中一共展示了timeline.Timeline方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get

# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def _get(self, feed_data, op_names):
    """ Get results of one mini-batch """
    ops = [self._model.ops[nn] for nn in op_names]

    # profile code
    if self._is_profile:
      op_results = self._session.run(
          ops,
          feed_dict=feed_data,
          options=self._run_options,
          run_metadata=self._run_metadata)
      trace = timeline.Timeline(self._run_metadata.step_stats)
      chrome_trace = trace.generate_chrome_trace_format()
      with open(os.path.join(self._save_dir, 'timeline.json'), 'w') as f:
        f.write(chrome_trace)
    else:
      op_results = self._session.run(ops, feed_dict=feed_data)

    results = {}
    for rr, name in zip(op_results, op_names):
      results[name] = rr

    return results 
开发者ID:microsoft,项目名称:graph-partition-neural-network-samples,代码行数:25,代码来源:base_runner.py

示例2: create_tf_timeline

# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def create_tf_timeline(model_dir, run_metadata):
    """
    This is helpful for profiling slow Tensorflow code.

    Args:
        model_dir:
        run_metadata:

    Returns:

    """
    tl = timeline.Timeline(run_metadata.step_stats)
    ctf = tl.generate_chrome_trace_format()
    timeline_file_path = os.path.join(model_dir,'timeline.json')
    with open(timeline_file_path, 'w') as f:
        f.write(ctf) 
开发者ID:emreaksan,项目名称:stcn,代码行数:18,代码来源:utils.py

示例3: evaluate_full_batch

# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def evaluate_full_batch(sess,model,minibatch_iter,many_runs_timeline,mode):
    """
    Full batch evaluation
    NOTE: HERE GCN RUNS THROUGH THE FULL GRAPH. HOWEVER, WE CALCULATE F1 SCORE
        FOR VALIDATION / TEST NODES ONLY. 
    """
    options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
    run_metadata = tf.RunMetadata()
    t1 = time.time()
    num_cls = minibatch_iter.class_arr.shape[-1]
    feed_dict, labels = minibatch_iter.feed_dict(mode)
    if args_global.timeline:
        preds,loss = sess.run([model.preds, model.loss], feed_dict=feed_dict, options=options, run_metadata=run_metadata)
        fetched_timeline = timeline.Timeline(run_metadata.step_stats)
        chrome_trace = fetched_timeline.generate_chrome_trace_format()
        many_runs_timeline.append(chrome_trace)
    else:
        preds,loss = sess.run([model.preds, model.loss], feed_dict=feed_dict)
    node_val_test = minibatch_iter.node_val if mode=='val' else minibatch_iter.node_test
    t2 = time.time()
    f1_scores = calc_f1(labels[node_val_test],preds[node_val_test],model.sigmoid_loss)
    return loss, f1_scores[0], f1_scores[1], (t2-t1) 
开发者ID:GraphSAINT,项目名称:GraphSAINT,代码行数:24,代码来源:train.py

示例4: cli_profile_timeline

# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def cli_profile_timeline(self):
        """Performs training profiling to produce timeline.json.  """
        # TODO integrate this into Profile.
        from tensorflow.python.client import timeline
        options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
        run_metadata = tf.RunMetadata()
        session = self._get_session('train')
        # run 100 iterations to warm up
        max_iterations = 100
        for i in range(max_iterations):
            log.info(
                'Running {}/{} iterations to warm up...'
                .format(i, max_iterations), update=True)
            session.run(session._train_op)
        log.info('Running the final iteration to generate timeline...')
        session.run(
            session._train_op, options=options, run_metadata=run_metadata)
        fetched_timeline = timeline.Timeline(run_metadata.step_stats)
        chrome_trace = fetched_timeline.generate_chrome_trace_format()
        with open('timeline.json', 'w') as f:
            f.write(chrome_trace) 
开发者ID:deep-fry,项目名称:mayo,代码行数:23,代码来源:cli.py

示例5: run

# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def run(self, fetches, feed_dict=None):
        """like Session.run, but return a Timeline object in Chrome trace format (JSON).

        Save the json to a file, go to chrome://tracing, and open the file.

        Args:
            fetches
            feed_dict

        Returns:
            dict: a JSON dict
        """
        options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
        run_metadata = tf.RunMetadata()
        super(ProfiledSession, self).run(fetches, feed_dict, options=options, run_metadata=run_metadata)

        # Create the Timeline object, and write it to a json
        tl = timeline.Timeline(run_metadata.step_stats)
        ctf = tl.generate_chrome_trace_format()
        return json.loads(ctf) 
开发者ID:kelvinguu,项目名称:lang2program,代码行数:22,代码来源:profile.py

示例6: E_val

# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def E_val(self, X):
        with self.graph.as_default(), tf.device(self.energy_device):
            if self.prof_run:
                run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
                run_metadata = tf.RunMetadata()

                energy = self.sess.run(self.energy_op, feed_dict={self.state_pl: X},
                                       options=run_options, run_metadata=run_metadata)
                tf_tl  = timeline.Timeline(run_metadata.step_stats)
                ctf = tf_tl.generate_chrome_trace_format()
                log_path = expanduser('~/tmp/logs/tf_{}_energy_timeline_{}.json'.format(self.name, time.time()))
                with open(log_path, 'w') as log_file:
                    log_file.write(ctf)
            else:
                energy = self.sess.run(self.energy_op, feed_dict={self.state_pl: X})
            return energy 
开发者ID:rueberger,项目名称:MJHMC,代码行数:18,代码来源:tf_distributions.py

示例7: dEdX_val

# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def dEdX_val(self, X):
        with self.graph.as_default(), tf.device(self.grad_device):
            if self.prof_run:
                run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
                run_metadata = tf.RunMetadata()

                grad = self.sess.run(self.grad_op, feed_dict={self.state_pl: X},
                                       options=run_options, run_metadata=run_metadata)

                tf_tl  = timeline.Timeline(run_metadata.step_stats)
                ctf = tf_tl.generate_chrome_trace_format()
                log_path = expanduser('~/tmp/logs/tf_{}_grad_timeline_{}.json'.format(self.name, time.time()))
                with open(log_path, 'w') as log_file:
                    log_file.write(ctf)
            else:
                grad = self.sess.run(self.grad_op, feed_dict={self.state_pl: X})
            return grad 
开发者ID:rueberger,项目名称:MJHMC,代码行数:19,代码来源:tf_distributions.py

示例8: profiled_run

# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def profiled_run(sess, ops, feed_dict, is_profiling=False, log_dir=None):
    if not is_profiling:
        return sess.run(ops, feed_dict=feed_dict)
    else:
        if log_dir is None:
            raise ValueError("You need to provide a log_dir for profiling.")
        run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
        run_metadata = tf.RunMetadata()
        outputs = sess.run(ops, feed_dict=feed_dict, options=run_options, run_metadata=run_metadata)

        # Create the Timeline object, and write it to a json
        tl = timeline.Timeline(run_metadata.step_stats)
        ctf = tl.generate_chrome_trace_format()
        with open(os.path.join(log_dir, 'timeline.json'), 'w') as f:
            f.write(ctf)

        return outputs 
开发者ID:ElementAI,项目名称:am3,代码行数:19,代码来源:util.py

示例9: save_checkpoint_chrome_trace

# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def save_checkpoint_chrome_trace(dataset: str, model_name: str, log_base: PathLike, batch_size: int = 32):
    def trace_solver_solution(save_path: PathLike, train_ds, solver):
        import tensorflow.compat.v1 as tf1
        from tensorflow.python.client import timeline

        data_iter = train_ds.__iter__()
        data_list = [x.numpy() for x in data_iter.next()]
        with tf1.Session() as sess:
            sqrtn_fn, *_ = _build_model_via_solver(dataset, model_name, train_ds.element_spec, solver)
            out = sqrtn_fn(*[tf1.convert_to_tensor(x) for x in data_list])

            run_meta = tf1.RunMetadata()
            sess.run(tf1.global_variables_initializer())
            sess.run(out, options=tf1.RunOptions(trace_level=tf1.RunOptions.FULL_TRACE), run_metadata=run_meta)
            t1 = timeline.Timeline(run_meta.step_stats)
            lctf = t1.generate_chrome_trace_format()

        with Path(save_path).open("w") as f:
            f.write(lctf)

    log_base = Path(log_base)
    log_base.mkdir(parents=True, exist_ok=True)
    train_ds, test_ds = get_data(dataset, batch_size=batch_size)
    trace_solver_solution(log_base / "check_all.json", train_ds, solve_checkpoint_all)
    trace_solver_solution(log_base / "check_sqrtn_noap.json", train_ds, solve_chen_sqrtn_noap) 
开发者ID:parasj,项目名称:checkmate,代码行数:27,代码来源:test_tf2_execution.py

示例10: profile

# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def profile(self, session):
        evals = [self.model.cost]
        for batch in self.batcher:
            state, att_states, att_ids, att_counts = get_initial_state(self.model)

            for seq_batch in self.batcher.sequence_iterator(batch):
                feed_dict = construct_feed_dict(self.model, seq_batch, state, att_states, att_ids, att_counts)
                run_metadata = tf.RunMetadata()
                session.run(evals, feed_dict=feed_dict,
                            options=tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE),
                            run_metadata=run_metadata)
                break

        from tensorflow.python.client import timeline
        trace = timeline.Timeline(step_stats=run_metadata.step_stats)
        trace_file = open('timeline.ctf.json', 'w')
        trace_file.write(trace.generate_chrome_trace_format()) 
开发者ID:uclnlp,项目名称:pycodesuggest,代码行数:19,代码来源:evaluation.py

示例11: _save

# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def _save(self, step, save_path, step_stats):
    logging.info("Saving timeline for %d into '%s'.", step, save_path)
    with gfile.Open(save_path, "w") as f:
      trace = timeline.Timeline(step_stats)
      f.write(trace.generate_chrome_trace_format(
          show_dataflow=self._show_dataflow,
          show_memory=self._show_memory)) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:9,代码来源:profiler_hook.py

示例12: update_timeline_if_necessary

# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def update_timeline_if_necessary(self):
        """
        Writes a timeline json file according to specification.
        """
        if self.timeline_step % self.timeline_frequency == 0:
            fetched_timeline = timeline.Timeline(self.run_metadata.step_stats)
            chrome_trace = fetched_timeline.generate_chrome_trace_format()
            with open("timeline_{:02d}.json".format(self.timeline_step), "w") as f:
                f.write(chrome_trace)
        self.timeline_step += 1 
开发者ID:rlgraph,项目名称:rlgraph,代码行数:12,代码来源:tensorflow_executor.py

示例13: trace

# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def trace(config, sess, model, train_data):
    run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
    run_metadata = tf.RunMetadata()

    X, Q, Y = random_batch(*train_data, config.batch_size)
    model.batch_fit(X, Q, Y, learning_rate, run_options, run_metadata)
    train_writer.add_run_metadata(run_metadata, 'step%d' % step)

    from tensorflow.python.client import timeline
    tl = timeline.Timeline(run_metadata.step_stats)
    ctf = tl.generate_chrome_trace_format()
    with open('timeline.json', 'w') as f:
        f.write(ctf)
    return 
开发者ID:nschuc,项目名称:alternating-reader-tf,代码行数:16,代码来源:train.py

示例14: write_timeline

# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def write_timeline(self,step_stats,file_name):
        fetched_timeline = timeline.Timeline(step_stats)
        chrome_trace = fetched_timeline.generate_chrome_trace_format()
        with open(file_name, 'w') as f:
        	f.write(chrome_trace) 
开发者ID:gustavz,项目名称:realtime_object_detection,代码行数:7,代码来源:helper.py

示例15: testSimpleTimeline

# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def testSimpleTimeline(self):
    run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
    run_metadata = tf.RunMetadata()

    with tf.device('/cpu:0'):
      with tf.Session() as sess:
        sess.run(
            tf.constant(1.0),
            options=run_options,
            run_metadata=run_metadata)
    self.assertTrue(run_metadata.HasField('step_stats'))
    tl = timeline.Timeline(run_metadata.step_stats)
    ctf = tl.generate_chrome_trace_format()
    self._validateTrace(ctf) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:16,代码来源:timeline_test.py


注:本文中的tensorflow.python.client.timeline.Timeline方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。