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


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

Tensorflow.js是由Google开发的开源库,用于在浏览器或节点环境中运行机器学习模型以及深度学习神经网络。

.engine() 函数用于返回全局引擎,该引擎保存每个张量和后端的路径。

用法:

tf.engine()

参数:该方法不持有任何参数。

返回值:它返回引擎。



范例1:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling engine() and startScope()
// method
tf.engine().startScope();  
  
// Calling ones() method
const res = tf.ones([200, 250]);
  
// Printing output
console.log(res);

输出:此处,范围未结束,因此返回张量。

Tensor
    [[1, 1, 1, ..., 1, 1, 1],
     [1, 1, 1, ..., 1, 1, 1],
     [1, 1, 1, ..., 1, 1, 1],
     ...,
     [1, 1, 1, ..., 1, 1, 1],
     [1, 1, 1, ..., 1, 1, 1],
     [1, 1, 1, ..., 1, 1, 1]]

范例2:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling engine() and startScope()
// method
tf.engine().startScope();  
  
// Calling ones() method
const t1 = tf.ones([200, 250]);
  
// Calling tidy() and min() method
// with respect to t1
const t2 = tf.tidy(() => t1.min());
  
// Calling engine() and endScope()
// method
tf.engine().endScope();
  
// Printing output
console.log(t2);

输出:在这里,范围结束,因此正在处理结果张量。

An error occured on line:20
Tensor is disposed.

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




相关用法


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