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


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

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

.image.flipLeftRight() 函數用於將所述圖像從左側翻轉到右側。目前,它可以在 CPU、WebGL 以及 WASM 後端中訪問。

用法:

tf.image.flipLeftRight(image)

Parameters: 

  • image:它是結構 [batch, imageHeight, imageWidth, depth] 的規定 4d 張量。它可以是 tf.Tensor4D、TypedArray 或 Array 類型。

返回值:它返回 tf.Tensor4D 對象。



範例1:在這個例子中,我們將看到在 Tensorflow.js tf.image.flipLeftRight() 函數中使用 4d 張量的用法。

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling image.flipLeftRight() method and
// Printing output
tf.image.flipLeftRight(tf.tensor4d([[
  
  [[4, 7], [21, 9]],
  
  [[8, 9], [1, 5]]
  
]])).print();

輸出:

Tensor
    [[[[21, 9],
       [4 , 7]],

      [[1 , 5],
       [8 , 9]]]]

範例2:在這個例子中,我們將看到在 Tensorflow.js tf.image.flipLeftRight() 函數中使用浮點數組。

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Defining an array of floats
const arr = [[
  
  [[1.1, 1.7, 1.5, 1.1], 
  [1.7, 1.9, 8.1, 6.3]],
  [[3.3, 3.4, 3.7, 4.0], 
  [5.1, 5.2, 5.3, 5.9]]
  
]];
  
// Calling image.flipLeftRight() method and
// Printing output
tf.image.flipLeftRight(arr).print();

輸出:

Tensor
    [[[[1.7      , 1.9      , 8.1000004, 6.3000002],
       [1.1      , 1.7      , 1.5      , 1.1      ]],

      [[5.0999999, 5.1999998, 5.3000002, 5.9000001],
       [3.3      , 3.4000001, 3.7      , 4        ]]]]

參考: https://js.tensorflow.org/api/latest/#image.flipLeftRight




相關用法


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