Tensorflow.js是Google開發的開放源代碼庫,用於在瀏覽器或節點環境中運行機器學習模型以及深度學習神經網絡。
.image.rotateWithOffset() 函數用於逆時針旋轉輸入圖像張量以及旋轉的替代偏移中心。目前,它可以在 CPU、WebGL 以及 WASM 後端訪問。
用法:
tf.image.rotateWithOffset(image, radians, fillValue?, center?)
參數:
- images:所述的 4d 張量,其配置為 [batch, imageHeight, imageWidth, depth]。它可以是 tf.Tensor4D、TypedArray 或 Array 類型。
- radians:規定的旋轉次數。它是類型號。
- fillValue:它是可選值,用於填充輪換後未使用的空位。它可以是單個灰度值,即從 0 到 255,也可以是三個數字的數組,即 [red, green, blue] 表示紅色、綠色和藍色通道。默認值為零,即黑色通道。它可以是 number 或 [number, number, number] 類型。
- center:它是規定的旋轉中心。它可以是單個值,即從 0 到 1,也可以是兩個數字的數組,即 [centerX, centerY]。默認值為 0.5。它可以是 number 或 [number, number] 類型。
返回值:它返回 tf.Tensor4D。
範例1:在此示例中,我們將在 tf.image.rotateWithOffset() 函數中使用 4d 張量和弧度參數。
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Calling image.rotateWithOffset() method and
// Printing output
tf.image.rotateWithOffset(tf.tensor4d([[
[[4, 7], [21, 9]],
[[8, 9], [1, 33]]
]]), 3).print();
輸出:
Tensor [[[[0, 0 ], [0, 0 ]], [[0, 0 ], [1, 33]]]]
範例2:在這個例子中,我們將使用一個浮點數組、fillValue 和 center。
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.rotateWithOffset() method and
// Printing output
tf.image.rotateWithOffset(arr, 5, [1, 2, 3], [1, 1]).print();
輸出:
Tensor [[[[1, 2, 3, 3], [1, 2, 3, 3]], [[1, 2, 3, 3], [1, 2, 3, 3]]]]
參考: https://js.tensorflow.org/api/latest/#image.rotateWithOffset
相關用法
- 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()用法及代碼示例
- PHP cal_to_jd()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Tensorflow.js tf.image.rotateWithOffset() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。