当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Tensorflow.js tf.image.rotateWithOffset()用法及代码示例

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




相关用法


注:本文由纯净天空筛选整理自nidhi1352singh大神的英文原创作品 Tensorflow.js tf.image.rotateWithOffset() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。