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


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

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

.fetch() 函数用于返回一个平台专用的 fetch 操作。此外,如果 fetch 指定为与​​全局对象(即窗口、进程等)联系,则 tf.util.fetch 返回该函数,否则返回平台专用说明。

用法:

tf.fetch(path, requestInits?)

参数:

  • path:它是字符串类型的声明路径。
  • requestInits:声明的RequestInit。它是可选的并且是字符串类型。

返回值:它返回响应的承诺。



范例1:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling fetch() method with respect 
// to global
const res = tf.env().global.fetch(
'https://js.tensorflow.org/api/latest/#tf.Sequential.evaluateDataset');
  
// Printing output
console.log(res);

输出:

[object Response]

范例2:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling fetch() method
const res = await tf.util.fetch(
  'https://js.tensorflow.org/api/latest/#fetch');
  
// Printing output
console.log(JSON.stringify(res));

输出:

{}

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

相关用法


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