摘要:原博地址源碼演示開(kāi)始時(shí)需要加載大概的訓(xùn)練數(shù)據(jù)稍等片刻調(diào)整訓(xùn)練集的大小觀察測(cè)試結(jié)果的準(zhǔn)確性數(shù)據(jù)來(lái)源數(shù)據(jù)來(lái)源與中的一道題目題目給出條訓(xùn)練數(shù)據(jù)包含圖片和標(biāo)簽以及條測(cè)試數(shù)據(jù)只包含圖片要求給這些測(cè)試數(shù)據(jù)打上標(biāo)簽要盡可能的準(zhǔn)確網(wǎng)站中還有許多其
原博地址https://laboo.top/2018/11/21/tfjs-dr/
源碼digit-recognizer
demohttps://github-laziji.github.io/digit-recognizer/
演示開(kāi)始時(shí)需要加載大概100M的訓(xùn)練數(shù)據(jù), 稍等片刻
調(diào)整訓(xùn)練集的大小, 觀察測(cè)試結(jié)果的準(zhǔn)確性
數(shù)據(jù)來(lái)源數(shù)據(jù)來(lái)源與 https://www.kaggle.com 中的一道題目 digit-recognizer
題目給出42000條訓(xùn)練數(shù)據(jù)(包含圖片和標(biāo)簽)以及28000條測(cè)試數(shù)據(jù)(只包含圖片)
要求給這些測(cè)試數(shù)據(jù)打上標(biāo)簽[0,1,2,3....,9] 要盡可能的準(zhǔn)確
網(wǎng)站中還有許多其他的機(jī)器學(xué)習(xí)的題目以及數(shù)據(jù), 是個(gè)很好的練手的地方
實(shí)現(xiàn)這里我們使用TensorFlow.js來(lái)實(shí)現(xiàn)這個(gè)項(xiàng)目
創(chuàng)建模型卷積神經(jīng)網(wǎng)絡(luò)的第一層有兩種作用, 它既是輸入層也是執(zhí)行層, 接收IMAGE_H * IMAGE_W大小的黑白像素
最后一層是輸出層, 有10個(gè)輸出單元, 代表著0-9這十個(gè)值的概率分布, 例如 Label=2 , 輸出為[0.02,0.01,0.9,...,0.01]
function createConvModel() { const model = tf.sequential(); model.add(tf.layers.conv2d({ inputShape: [IMAGE_H, IMAGE_W, 1], kernelSize: 3, filters: 16, activation: "relu" })); model.add(tf.layers.maxPooling2d({ poolSize: 2, strides: 2 })); model.add(tf.layers.conv2d({ kernelSize: 3, filters: 32, activation: "relu" })); model.add(tf.layers.maxPooling2d({ poolSize: 2, strides: 2 })); model.add(tf.layers.conv2d({ kernelSize: 3, filters: 32, activation: "relu" })); model.add(tf.layers.flatten({})); model.add(tf.layers.dense({ units: 64, activation: "relu" })); model.add(tf.layers.dense({ units: 10, activation: "softmax" })); return model; }訓(xùn)練模型
我們選擇適當(dāng)?shù)膬?yōu)化器和損失函數(shù), 來(lái)編譯模型
async function train() { ui.trainLog("Create model..."); model = createConvModel(); ui.trainLog("Compile model..."); const optimizer = "rmsprop"; model.compile({ optimizer, loss: "categoricalCrossentropy", metrics: ["accuracy"], }); const trainData = Data.getTrainData(ui.getTrainNum()); ui.trainLog("Training model..."); await model.fit(trainData.xs, trainData.labels, {}); ui.trainLog("Completed!"); ui.trainCompleted(); }測(cè)試
這里測(cè)試一組測(cè)試數(shù)據(jù), 返回對(duì)應(yīng)的標(biāo)簽, 即十個(gè)輸出單元中概率最高的下標(biāo)
function testOne(xs){ if(!model){ ui.viewLog("Need to train the model first"); return; } ui.viewLog("Testing..."); let output = model.predict(xs); ui.viewLog("Completed!"); output.print(); const axis = 1; const predictions = output.argMax(axis).dataSync(); return predictions[0]; }
歡迎關(guān)注我的博客公眾號(hào)
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/108790.html
摘要:神經(jīng)網(wǎng)絡(luò)是一組特定的算法,對(duì)機(jī)器學(xué)習(xí)領(lǐng)域發(fā)生了革命性的變化。在這篇博客文章中,我想分享我認(rèn)為機(jī)器學(xué)習(xí)研究人員應(yīng)該熟悉的課程中的個(gè)神經(jīng)網(wǎng)絡(luò)架構(gòu),以推進(jìn)他們的工作。卷積神經(jīng)網(wǎng)絡(luò)機(jī)器學(xué)習(xí)研究一直以來(lái)都集中在對(duì)象檢測(cè)問(wèn)題上。 摘要: 本文簡(jiǎn)要講述了8種機(jī)器學(xué)習(xí)架構(gòu),希望可以給大家?guī)?lái)幫助 showImg(https://segmentfault.com/img/bV8Hby?w=1000&h=...
閱讀 2519·2021-11-18 10:02
閱讀 750·2021-10-08 10:04
閱讀 2391·2021-09-03 10:51
閱讀 3626·2019-08-30 15:44
閱讀 2886·2019-08-29 14:09
閱讀 2538·2019-08-29 12:21
閱讀 2132·2019-08-26 13:45
閱讀 1882·2019-08-26 13:25