第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 JavaScript 中將文件轉(zhuǎn)換為張量

如何在 JavaScript 中將文件轉(zhuǎn)換為張量

守著星空守著你 2021-12-23 15:54:07
我正在嘗試使用 MobileNet 創(chuàng)建一個簡單的圖像分類示例。我試圖讓它與react-dropzone 一起工作,在這種情況下,我最終需要將圖像轉(zhuǎn)換為Fileto的類型Tensor才能將其傳遞給model.classify.我也嘗試使用,fromPixels但為此,我必須將圖像轉(zhuǎn)換為ImageData.export default function ImageClassification() {  const [isModelLoaded, setModelLoaded] = useState(false);  const [uploadedFile, setUploadedFile] = useState();  const [classifier, setClassifier] = useState();  useEffect(() => {    async function modelReady() {      console.log("Not loaded:" + isModelLoaded);      setClassifier(        await MobileNet.load().then(model => {          setModelLoaded(true);          return model;        })      );    }    modelReady();  }, []);  function onDrop(acceptedFiles: File[]) {    console.log(acceptedFiles);    setUploadedFile(acceptedFiles);    console.log("After setting");  }  function prepareImage(inputFile: File) {    // How to convert inputFile to Tensor???    return image;  }  const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });  return (    <React.Fragment>      {!isModelLoaded ? (        <CircularProgress />      ) : (        <div {...getRootProps()}>          <input {...getInputProps()} />          {isDragActive ? (            <p>Drop the files here.. </p>          ) : (            <p>Drag 'n' drop some files here, or click to select files</p>          )}          {uploadedFile &&            uploadedFile.map((item: File) => {              const input = prepareImage(item);              classifier.classify(input);              return <h1>{item.name}</h1>;            })}        </div>      )}    </React.Fragment>  );}任何有關(guān)這些的幫助將不勝感激。
查看完整描述

1 回答

?
千萬里不及你

TA貢獻(xiàn)1784條經(jīng)驗 獲得超9個贊

需要讀取文件并將其結(jié)果分配給圖像標(biāo)簽。加載圖像后,可以將其轉(zhuǎn)換為張量。


    const im = new Image()

    var fr = new FileReader();

    fr.onload = function () {

        im.src = fr.result;

    }

    fr.readAsDataURL(inputFile);

    im.onload = () => {

      const a = tf.browser.fromPixels(im)

    }


查看完整回答
反對 回復(fù) 2021-12-23
  • 1 回答
  • 0 關(guān)注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號