我正在测试加载TensorFlow.js模型,并试图测量预测所需的毫秒数。例如,第一次,预测值大约需要300毫秒,但从第二次试验开始,时间缩短到13~20毫秒。我不是在计算模型加载的时间。我只计算模型加载后的预测值。
有人能解释为什么预测价值的时间会缩短吗?
// Calling TensorFlow.js model
const MODEL_URL = 'https://xxxx-xxxx-xxxx.xxx.xxx-xxxx-x.xxxxxx.com/model.json'
let model;
let prediction;
export async function getModel(input){
console.log("From helper function: Model is being retrieved from the server...")
model = await tf.loadLayersModel(MODEL_URL);
// measure prediction time
var str_time = new Date().getTime();
prediction = await model.predict(input)
var elapsed = new Date().getTime() - str_time;
console.log("Laoding Time for Tensorflow: " + elapsed)
console.log(prediction.arraySync())
...
}发布于 2022-03-04 02:50:50
通常,由于需要从API请求将模型加载到内存中,因此第一个预测将花费更长的时间,一旦完成,它将被缓存,您将不需要再次发出相同的API请求。
如果您想要查看实际的预测时间,重复多次(可能是1000次)对预测进行计时的过程,然后得到第99分位数值,它将显示99%的情况下的预测时间(您也可以将分位数值更改为90或50)。
https://stackoverflow.com/questions/71342922
复制相似问题