當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Tensorflow.js tf.maxPool3d()用法及代碼示例

Tensorflow.js是Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型和深度學習神經網絡。

tf.maxPool3d()函數用於計算3D max池。

用法:

tf.maxPool3d (x, filterSize, strides, pad, 
                   dimRoundingMode?, dataFormat?)

參數:此函數接受如下所示的參數:

  • x:這指定了等級5或等級4的輸入張量。
  • filterSize:這指定filterDepth,filterHeight,filterWidth。如果指定的filterSize是單個數字,則filterWidth == filterHeight == filterDepth。
  • strides:指定池的跨步:[strideDepth,strideHeight,strideWidth]。如果指定的步幅是單個數字,則strideWidth == strideHeight == strideDepth。
  • pad:這指定了填充算法的類型。
  • dimRoundingMode:這是可選的。這指定了以下字符串:‘ceil’,“ round”,‘floor’。如果未提供任何內容,則它將默認將其值截斷。
  • dataFormat:這是可選的。這指定輸出和輸入數據的數據格式。

返回值:它返回張量元素的3D最大合並。



範例1:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing a tensor of some elements
let pool = tf.tensor5d([11, 12, 13, 14], [2, 1, 1, 1, 2]);
  
// Calling the .maxPool3d()
let output = tf.maxPool3d(pool, 1, 2, 'valid');
  
// Printing the output.
output.print();

輸出:

Tensor
    [ [ [ [[11, 12],]]],

      [ [ [[13, 14],]]]]

範例2:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing a tensor of some elements
let maxPool = tf.tensor5d([51, 52, 53, 54, 55, 56, 57, 58], [1, 2, 2, 2, 1]);
  
// Calling the .avgPool3d() function and
 // printing the result.
tf.avgPool3d(maxPool, 2, 1, 'valid').print();

輸出:

Tensor
     [ [ [ [[54.5],]]]]

參考:https://js.tensorflow.org/api/3.6.0/#maxPool3d

相關用法


注:本文由純淨天空篩選整理自thacker_shahid大神的英文原創作品 Tensorflow.js tf.maxPool3d() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。