Tensorflow.js是由Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型以及深度學習神經網絡。
.computeOutputShape() 函數用於枚舉所述層的輸出形狀。並且假定將創建圖層以匹配提供的輸入形狀。
用法:
computeOutputShape(inputShape)
參數:
- inputShape:它是規定的形狀,即整數集或形狀集列表。此外,Shape 元組可以包含 void 以支持自由大小,而不是整數。它可以是 ((null | number)[]|(null | number)[][]) 類型。
返回值:它返回 (null | number)[]|(null | number)[][]。
範例1:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Creating a model
const model = tf.sequential();
// Adding a layer
model.add(tf.layers.dense({units:1, inputShape:[3]}));
// Defining inputShape
const inputShape = [6, 2, 6];
// Calling computeOutputShape() method with its
// parameter
const val = model.layers[0].computeOutputShape(inputShape);
// Printing output
console.log(val);
輸出:
6,2,1
範例2:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Creating a model
const model = tf.sequential();
// Adding layers
model.add(tf.layers.dense({units:1, inputShape:[3]}));
model.add(tf.layers.dense({units:5}));
// Defining inputShape
const inputShape1 = [6, 2, 6, null];
const inputShape2 = [6.5, 2.6, 9.1, NaN];
// Calling computeOutputShape() method with its
// parameter
const val1 = model.layers[0].computeOutputShape(inputShape1);
const val2 = model.layers[1].computeOutputShape(inputShape2);
// Printing output
console.log(val1);
console.log(val2);
輸出:
6,2,6,1 6.5,2.6,9.1,5
參考: https://js.tensorflow.org/api/latest/#tf.layers.Layer.computeOutputShape
相關用法
- Lodash _.method()用法及代碼示例
- Node.js Http2ServerRequest.method用法及代碼示例
- Node.js http.IncomingMessage.method用法及代碼示例
- Javascript dataView.getInt16()用法及代碼示例
- Collect.js toArray()用法及代碼示例
- Javascript RegExp toString()用法及代碼示例
- Node.js URLSearchParams.has()用法及代碼示例
- Node.js hmac.update()用法及代碼示例
- HTML DOM isEqualNode()用法及代碼示例
- JavaScript Date toLocaleTimeString()用法及代碼示例
- Tensorflow.js tf.Tensor.buffer()用法及代碼示例
- Node.js crypto.createHash()用法及代碼示例
- Node.js process.send()用法及代碼示例
- Node.js writeStream.clearLine()用法及代碼示例
- HTML DOM History go()用法及代碼示例
- Node.js fs.link()用法及代碼示例
- Java ArrayList toArray()用法及代碼示例
- JavaScript Math random()用法及代碼示例
- JavaScript Math round()用法及代碼示例
- Javascript toFixed()用法及代碼示例
- Javascript toPrecision()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Tensorflow.js tf.layers computeOutputShape() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。