Tensorflow.js是Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型和深度學習神經網絡。
tf.layers apply() 方法用於執行層計算並在我們使用 tf.Tensor(s) 調用它時返回 Tensor(s)。如果我們使用 tf.SymbolicTensor(s) 調用它,那麽將為未來執行準備層。
用法:
apply (inputs, kwargs)
參數:
- inputs:此參數將數組作為輸入。
- kwargs[可選]:它是一個可選參數,包含要傳遞給 call() 的附加關鍵字參數。
返回值:它返回相同數據類型的張量或符號張量。
下麵的例子說明了 Tensorflow.js tf.layers apply() 方法:
範例1:
Javascript
import * as tf from "@tensorflow/tfjs"
const denseLayer = tf.layers.dense({
units:1,
kernelInitializer:'ones',
useBias:false
});
const input = tf.ones([2, 2]);
const output = denseLayer.apply(input);
// Print the output
print(output)
輸出:
Tensor [[2], [2]]
範例2:
Javascript
import * as tf from "@tensorflow/tfjs"
const denseLayer = tf.layers.dense({
units:1,
kernelInitializer:'zeros',
useBias:false
});
const input = tf.ones([2, 2]);
const output = denseLayer.apply(input);
// Print the output
print(output)
輸出:
Tensor [[0], [0]]
參考:https://js.tensorflow.org/api/latest/#tf.layers.Layer.apply
相關用法
- Javascript Reflect.apply()用法及代碼示例
- Javascript handler.apply()用法及代碼示例
- PHP Ds\Vector apply()用法及代碼示例
- PHP Ds\Deque apply()用法及代碼示例
- Javascript call和apply的區別用法及代碼示例
- PHP Ds\Sequence apply()用法及代碼示例
注:本文由純淨天空篩選整理自skyridetim大神的英文原創作品 Tensorflow.js tf.layers apply() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。