Tensorflow.js是由Google开发的开源库,用于在浏览器或节点环境中运行机器学习模型以及深度学习神经网络。
.io.http() 函数用于生成将模型工件传输到 HTTP 服务器的 IOHandler 子集。此外,一个 HTTP 请求multi-part或者form-datamime 类型应传输到小路网址。其中,form-data 包含描述模型拓扑和/或模型权重的工件。
用法:
tf.io.http(path, loadOptions?)
参数:
- path:模型的指定 URL 路径。此外,它可以是完整的 HTTP 路径,即“http://localhost:8000/model-upload”或类似的路径,即“./model-upload”。它是字符串类型。
- loadOptions:用于加载目的的所述配置。它是可选的,属于 LoadOptions 类型。它包括以下字段:
- weightPathPrefix:指定的权重文件路径的可选前缀。此外,默认情况下 this 的值是从路径参数中评估的。
- fetchFunc:所述的可选自定义fetch 函数。
- onProgress:声明的可选进度回调函数,它在加载完成之前定期释放。
返回值:它返回 IOHandler。
范例1:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Calling io.http() method
const result = tf.io.http('https://js.tensorflow.org/api/latest/#io.http');
// Printing output
console.log(result);
输出:
{ "DEFAULT_METHOD":"POST", "path":"https://js.tensorflow.org/api/latest/#io.http", "requestInit":{} }
范例2:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Creating model
const model = tf.sequential();
// Adding layer to the model
model.add(
tf.layers.dense({units:2, inputShape:[10]}));
// Calling io.http() method within
// save() method
const result = await model.save(tf.io.http(
'https://js.tensorflow.org/api/latest/#io.http'));
// Printing output
console.log(result);
输出:
{ "modelArtifactsInfo":{ "dateSaved":"2021-08-26T08:43:49.648Z", "modelTopologyType":"JSON", "modelTopologyBytes":611, "weightSpecsBytes":124, "weightDataBytes":88 }, "responses":[ {} ] }
参考: https://js.tensorflow.org/api/latest/#io.http
相关用法
- PHP imagecreatetruecolor()用法及代码示例
- p5.js year()用法及代码示例
- d3.js d3.utcTuesdays()用法及代码示例
- PHP ImagickDraw getTextAlignment()用法及代码示例
- PHP Ds\Sequence last()用法及代码示例
- PHP Imagick floodFillPaintImage()用法及代码示例
- PHP geoip_continent_code_by_name()用法及代码示例
- d3.js d3.map.set()用法及代码示例
- PHP GmagickPixel setcolor()用法及代码示例
- Tensorflow.js tf.layers.embedding()用法及代码示例
- PHP opendir()用法及代码示例
- d3.js d3.bisectLeft()用法及代码示例
注:本文由纯净天空筛选整理自nidhi1352singh大神的英文原创作品 Tensorflow.js tf.io.http() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。