簡體   English   中英

在 tensorflow.js 中加載圖像並轉換為張量

[英]load image and convert into tensor in tensorflow.js

我最近使用tensorflow.js在瀏覽器中學習圖像分類,現在我只是將一張圖片轉換為張量,但我想加載很多圖片,它不起作用,只有一張圖片轉換為張量,這是我的只轉換一張圖片時的代碼:

 const im = new Image() im.src = "/folder_name/1.jpg"; im.onload = () => { const a = tf.fromPixels(im, 4) a.print() console.log(a.shape) }

這是我嘗試轉換大量圖像時的代碼:

 const im = new Image() for(let i=1;i<= 15;i++){ im.src = "folder_name/"+i+".jpg"; im.onload[i] = () => { const a = tf.browser.fromPixels(im, 4) console.log(a.shape); } }

當我打開控制台時,只有一個 output,就像我轉換單個圖像時一樣

使用此代碼解決問題

for(let i=1;i<=15;i++){ const im = new Image() im.src = "eyes/"+i+".jpg"; im.onload = () => { const a = tf.browser.fromPixels(im, 4) a.print() console.log(a.shape) } }

我可以加載所有圖像並將其轉換為張量

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM