测量在 Tensorflow.js 中执行我的代码所用时间的问题 [英] Problem measuring the time elapsed executing my code in Tensorflow.js

查看:23
本文介绍了测量在 Tensorflow.js 中执行我的代码所用时间的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在测量在 Tensorflow.js 中执行我的代码所用的时间时遇到问题.

I am having a problem measuring the time elapsed executing my code in Tensorflow.js.

我在 tfjs 中构建了一个超分辨率模型,我想知道延迟.目前我正在使用以下方法,如下所述.

I was building a super resolution model in tfjs, and I wanted to know the latency. currently I am using the following method, as described below.

但我认为这不是正确的方法.任何形式的建议将不胜感激.

But I don't think this is the right way to it. Any kind of suggestion would be appreciated.

var w = new Date();
var r = w.getTime();

for (var q = 0; q<29; q++){
  var x = tf.concat([new_I[q++],new_I[q++], new_I[q++],new_I[q]]);
  var hr_image = await pretrainedModel.execute(x);
  var y = new Date();
  var u = y.getTime();
  console.log(u-r);
}

tf.timeDate...中使用哪一个?

Which one to use among tf.time, Date... ?

推荐答案

日期、tf.time、性能

Date 可用于指示执行函数所花费的时间.

Date can be used to indicate the time taken to execute a function.

a = new Date().getTime()
// execute function f()
b = new Date().getTime()
// executed time in milliseconds b - a

需要注意的是,此功能受系统时间的影响

The caveat is that this function is affected by the time of the system

tf.Time() 提供有关执行函数所需时间的更多详细信息.它输出后端读取数据所用的时间和挂墙时间.了解 tfjs 在内部做什么会很有用.

tf.Time() give more details regarding the time taken to execute a function. It outputs the time taken by the backend to read the data and the wall time. It can be useful to know what tfjs is doing internally.

tf.time(() => f() ) // execute f as callback

使用性能

a = performance.now()
// execute f()
b = performance.now()
// executed time in milliseconds b - a

已实施以评估执行时间.与Date不同,它独立于系统时钟.

It has been implemented to evaluate the execution timing. Unlike Date, it is independent of the system clock.

测量执行时间

谈到问题的代码,目前还不清楚衡量的是什么性能.如果目标是衡量代码的整体性能,

Coming to the code of the question, it is unclear what performance is measured. If the goal is to measured the overall performance of the code,

var w = new Date();
var r = w.getTime();

for (var q = 0; q<29; q++){
  var x = tf.concat([new_I[q++],new_I[q++], new_I[q++],new_I[q]]);
  var hr_image = await pretrainedModel.execute(x);

}

 var y = new Date();
 var u = y.getTime();
 console.log(u-r);

如果目标是测量每个预测所花费的时间

If the goal is to measure the time taken for each prediction

for (var q = 0; q<29; q++){
  var w = new Date();
  var r = w.getTime();
  var x = tf.concat([new_I[q++],new_I[q++], new_I[q++],new_I[q]]);
  var hr_image = await pretrainedModel.execute(x);
  var y = new Date();
  var u = y.getTime();
  console.log(u-r);
}

但是正如上面解释的,使用 performance.now() 比使用 Date

But as explain above using performance.now() is better than using Date

这篇关于测量在 Tensorflow.js 中执行我的代码所用时间的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆