Tensorflow.js是由Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型以及深度學習神經網絡。
.stridedSlice() 函數用於拉出指定輸入張量的跨步部分。
注意:從指定的輸入張量開始。從 begin 給定的位置開始,切片通過在所有測量值大於 end 之前將步幅附加到規定的索引來進行。此外,步幅也可能是負數,這會導致反向切片。
用法:
tf.stridedSlice(x, begin, end, strides?, beginMask?, endMask?,
ellipsisMask?, newAxisMask?, shrinkAxisMask?)
Parameters:
- x:規定的張量以跨過切片。它可以是 tf.Tensor、TypedArray 或 Array 類型。
- begin:切片開始的指定坐標。它的類型為 number[]。
- end:切片結束的指定坐標。它的類型為 number[]。
- strides:切片的規定長度。它是可選的,類型為 number[]。
- beginMask:它是一個可選參數,類型為 number。如果 beginMask 的第 i 位是固定的,則忽略 begin[i] 並且相反地利用該維度中的最大可達到範圍。
- endMask:它是一個可選參數,類型為 number。如果 endMask 的第 i 位是固定的,則忽略 end[i] 並且相反地利用該維度中的最大可達到範圍。
- ellipsisMask:它是類型為 number 的可選參數。
- newAxisMask:它是類型為 number 的可選參數。
- shrinkAxisMask:指定的位掩碼,其中位 i 表示第 i 個指定必須縮小容量。開始和結束應該指示長度為 1 的切片。它是可選的,類型為 number。
返回值:它返回tf.Tensor。
範例1:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Defining tensor input
const tn = tf.tensor3d([5, 5, 5 ,7, 7, 7, 13,
13, 13, 14, 14, 14, 1, 1, 1, 2, 2, 2],
[3, 3, 2]);
// Calling stridedSlice() method and
// Printing output
tn.stridedSlice([5, 0, 5], [7, 5, 7], [2, 2, 2]).print();
輸出:
Tensor [[[1], [2]]]
範例2:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Defining tensor input
const tn = tf.tensor3d([5, 5, 5 ,7, 7, 7, 13,
13, 13, 14, 14, 14, 1, 1, 1, 2, 2, 2],
[3, 3, 2]);
// Defining all the parameters
const x = [-5, 5, 7];
const begin = [-7, 13, 14];
const end = [-7, 13, 13];
const strides = [1];
const beginMask = 2;
const endMask = 0;
const ellipsisMask = 2;
const shrinkAxisMask = 15;
// Calling stridedSlice() method and
// Printing output
tn.stridedSlice(x, begin, end, strides, beginMask,
endMask, ellipsisMask, shrinkAxisMask).print();
輸出:
Tensor 2
參考: https://js.tensorflow.org/api/latest/#stridedSlice
相關用法
- 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.stridedSlice() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。