Tensorflow.js是由Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型以及深度學習神經網絡。
.separableConv2d() 函數用於確定二維並發症以及可分離的過濾器。它執行深度複雜性,該複雜性在通過點複雜性追求的通道上明顯起作用,這有助於混合通道。此外,它指定 [1, 2] 和 3 維內的可分離性,絕對不是 1 和 2 維內的結構可分離性。
用法:
tf.separableConv2d(x, depthwiseFilter, pointwiseFilter, strides, pad, dilation?, dataFormat?)
參數:
- x:指定的輸入張量是 3 級或 4 級,形狀為:[batch, height, width, inChannels]。此外,如果等級為 3,則假定批次大小為 1。它可以是 tf.Tensor3D、tf.Tensor4D、TypedArray 或 Array 類型。
- depthwiseFilter:等級為 4 的所述深度濾波器張量和形狀:[filterHeight, filterWidth, inChannels, channelMultiplier]。但是,它是在初始階段使用的。它可以是 tf.Tensor4D、TypedArray 或 Array 類型。
- pointwiseFilter:等級 4 和形狀的所述逐點濾波器張量:[1, 1, inChannels * channelMultiplier, outChannels]。但是,它用於操作的第二階段。它可以是 tf.Tensor4D、TypedArray 或 Array 類型。
- strides:形狀複雜度的規定步幅:[strideHeight, strideWidth]。如果所述步幅是單數,則 strideHeight == strideWidth。它可以是 [number, number] 或 number 類型。
- pad:規定的填充算法類型。它可以是有效或相同的類型。
- 在這裏,對於 ‘same’ 和步長 1,輸出將具有與輸入相同的大小,而與濾波器大小無關。
- 因為,‘valid’ 輸出應小於輸入,以防濾波器大小大於 1*1×1。
- dilation:規定的膨脹。它是可選的,類型為 [number, number] 或 number。
- dataFormat:來自 “NHWC” 或 “NCHW” 的指定選修字符串。它指定所述輸入和輸出數據的數據形狀。默認值為“NHWC”。而且這裏的數據按如下順序保存:[batch, height, width, channels]。它是可選的,屬於“NHWC”類型。
返回值:它返回 tf.Tensor3D 或 tf.Tensor4D。
範例1:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Defining input tensor
const x = tf.tensor4d([1, 2, 3, 4], [1, 1, 2, 2]);
// Defining depthwise filter tensor
const y = tf.tensor4d([1, 1, 0, 4], [1, 1, 2, 2]);
// Defining pointwise filter tensor
const z = tf.tensor4d([1, 1, 0, 4], [1, 1, 4, 1]);
// Calling separableConv2d() method
const result = tf.separableConv2d(x, y, z, 2, 'valid');
// Printing output
result.print();
輸出:
Tensor [ [ [[34],]]]
範例2:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Calling separableConv2d() method
tf.separableConv2d(
tf.tensor4d([1.1, 2.2, 3.3, 4.4], [1, 1, 2, 2]),
tf.tensor4d([1.2, 1.1, 0.3, 4.5], [1, 1, 2, 2]),
tf.tensor4d([1.4, 1.6, 0.5, 4.8], [1, 1, 4, 1]),
1, 'same', 1, 'NHWC').print();
輸出:
Tensor [[[[51.6340065 ], [107.0520096]]]]
參考:https://js.tensorflow.org/api/latest/#separableConv2d
相關用法
- PHP imagecreatetruecolor()用法及代碼示例
- p5.js year()用法及代碼示例
- d3.js d3.utcTuesdays()用法及代碼示例
- PHP ImagickDraw getTextAlignment()用法及代碼示例
- PHP Ds\Sequence last()用法及代碼示例
- PHP Imagick floodFillPaintImage()用法及代碼示例
- PHP array_udiff_uassoc()用法及代碼示例
- PHP geoip_continent_code_by_name()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Tensorflow.js tf.separableConv2d() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。