我正在测试加载 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())
...
}