TensorFlow.js的性能如何,Google官方做了一份基于MobileNet的评测,可以作为参考。具体评测是基于MobileNet的TensorFlow模型,将其JavaScript版本和Python版本各运行两百次。
其评测结论如下。
TensorFlow.js在手机浏览器中运行一次推理:
与 TensorFlow Lite 代码基准相比,手机浏览器中的 TensorFlow.js 在 IPhoneX 上的运行时间为基准的1.2倍,在 Pixel3 上运行的时间为基准的 1.8 倍。
在浏览器中,TensorFlow.js可以使用WebGL进行硬件加速,将GPU资源使用起来。
TensorFlow.js在浏览器中运行一次推理:
与Python代码基准相比,浏览器中的TensorFlow.js在CPU上的运行时间为基准的1.7倍,在GPU(WebGL)上运行的时间为基准的3.8倍。
在 Node.js 中,TensorFlow.js 使用 TensorFlow 的 C Binding ,所以基本上可以达到和 Python 接近的效果。
TensorFlow.js 在 Node.js 运行一次推理:
与 Python 代码基准相比,Node.js 的 TensorFlow.js 在 CPU 上的运行时间与基准相同,在 GPU(CUDA) 上运行的时间是基准的1.6倍。