当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Tensorflow.js tf.getBackend()用法及代码示例


Tensorflow.js是由Google开发的开源库,用于在浏览器或节点环境中运行机器学习模型和深度学习神经网络。它还可以帮助开发人员使用JavaScript语言开发ML模型,并且可以直接在浏览器或Node.js中使用ML。

tf.getBackend()函数用于返回当前的后端名称。

用法:

tf.getBackend()

参数:

  • 它不带参数

返回值:它返回一个字符串值。



范例1:

Javascript


// Setting the backend
tf.setBackend("cpu")
  
// Getting the backend using getBackend method
console.log(tf.getBackend())

输出:

cpu

范例2:在此示例中,我们将后端设置为字符串“cpu”,然后将其删除,然后将其设置为字符串“webgl”。

Javascript


// Setting the backend
tf.setBackend("cpu")
  
tf.removeBackend('cpu')
  
console.log(tf.getBackend())
  
tf.setBackend("webgl")
// Getting the backend using getBackend method
console.log(tf.getBackend())

输出:

null
webgl

参考: https://js.tensorflow.org/api/latest/#getBackend

相关用法


注:本文由纯净天空筛选整理自taran910大神的英文原创作品 Tensorflow.js tf.getBackend() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。