Tensorflow.js是Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型和深度學習神經網絡。
tf.browser.toPixels()函數用於在瀏覽器中將張量轉換為圖像。
用法:
tf.browser.toPixels(img, Canvas);
參數:
- img (tf.Tensor2D | tf.Tensor3D | TypedArray | Array):形狀為[height,width]的等級2的張量,或形狀為[height,width,numChannels]的等級3的張量。
- 畫布[可選] (HTMLCanvasElement):要繪製的畫布。
返回值:它返回一個承諾,當渲染完成時,該承諾將解決。
範例1:在此示例中,我們將創建一個張量並使用該張量調用tf.browser.toPixels()函數。
Javascript
import * as tf from "@tensorflow/tfjs"
const tensonA = tf.randomUniform([400, 400, 3]);
tf.browser.toPixels(tensorA).then(() => {
console.log("tf.browser.toPixels() called");
});
輸出:
tf.browser.toPixels() called
範例2:在此示例中,我們將創建一個張量並獲取畫布引用,並使用張量和畫布引用調用tf.browser.toPixels()函數。
Javascript
const tensorA = tf.randomUniform([400, 400, 3]);
const canvasA = document.getElementById("CanvasHTML");
tf.browser.toPixels(tensorA, canvasA).then(() => {
tensorA.dispose();
console.log(
"Make sure we cleaned up",
tf.memory().numTensors
);
});
輸出:
Make sure we cleaned up 2
相關用法
- 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()用法及代碼示例
- PHP GmagickPixel setcolor()用法及代碼示例
- PHP opendir()用法及代碼示例
- PHP cal_to_jd()用法及代碼示例
- d3.js d3.bisectLeft()用法及代碼示例
- PHP stream_get_transports()用法及代碼示例
- PHP Ds\Deque pop()用法及代碼示例
注:本文由純淨天空篩選整理自rohitsingh07052大神的英文原創作品 Tensorflow.js tf.browser.toPixels() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。