TensorflowJS花费太长时间

时间:2018-07-25 01:07:48

标签: tensorflow tensorflow.js

当我在浏览器中运行TensorflowJS时,尤其是在手机上运行时,预测需要很长时间,有时甚至无法正常工作。我已经在使用优化图了。我想知道是否有任何方法可以加快它的速度,是否可以通过在页面加载之前运行预测以使第二个更快或其他任何方式来实现。

我使用的是InceptionV3架构,图像大小为299 x 299。如果我可以减小它的尺寸,也许它可以运行得更快,但这意味着我将不得不重新训练模型。注意:我不是在使用Tensorflowjs进行培训,而只是在进行预测。这是相关代码:

    var ctx = canvas.getContext('2d');
    var file = ctx.getImageData(0,0,120,120);
    const raw = tf.fromPixels(file).toFloat();
    const resized = tf.image.resizeBilinear(raw, [299, 299])
    const offset = tf.scalar(127);
    const normalized = resized.sub(offset).div(offset);
    batched = normalized.expandDims(0);
    f = model.execute(batched).dataSync();

0 个答案:

没有答案