Links
🌐

Tarayıcıda CNNler

🚀 CNN'leri Tarayıcıya Uygulama İle İlgili Notlar
CNN tabanlı çalışmalarımızı Tarayıcıda uygulamak için Tensorflow.JS kullanmalıyız 🚀

👷‍♀️ İş Akışı

  1. 1.
    🚙 Import Tensorflow.js
  2. 2.
    👷‍♀️ Modeli kur
  3. 3.
    👩‍🏫 Eğit
  4. 4.
    👩‍⚖️ Modeli kullan

🚙 Tensorflow.js' Import Etme

Tensorflow.js'yi aşağıdaki şekilde import edebiliriz
<script
src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest">
</script>

👷‍♀️ Modeli Kurma

😎 Python'da yaptığımız gibi:
  1. 1.
    🐣 Sequential objesi tanımla
  2. 2.
    👩‍🔧 Katmanları ekle
  3. 3.
    🚀 Modeli derle .compile()
  4. 4.
    👩‍🎓 Eğit (fit)
  5. 5.
    🐥 Modeli tahmin için kullan
// create sequential
const model = tf.sequential();
// add layer(s)
model.add(tf.layers.dense({units: 1, inputShape: [1]}));
// set compiling parameters and compile the model
model.compile({loss:'meanSquaredError',
optimizer:'sgd'});
// get summary of the mdoel
model.summary();
// create sample data set
const xs = tf.tensor2d([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], [6, 1]);
const ys = tf.tensor2d([-3.0, -1.0, 2.0, 3.0, 5.0, 7.0], [6, 1]);
// train
doTraining(model).then(() => {
// after training
predict = model.predict(tf.tensor2d([10], [1,1]));
predict.print();
});
([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], [6, 1])
[-1.0, 0.0, 1.0, 2.0, 3.0, 4.0]: Veri seti değerleri (girişler)
[6, 1]: Girişin boyutu

👁‍🗨 Dikkat

  • 🐢 Eğitim uzun bir süreç olduğundan onu asenkron bir fonksiyonda yapmalıyız
async function doTraining(model){
const history =
await model.fit(xs, ys,
{ epochs: 500,
callbacks:{
onEpochEnd: async(epoch, logs) =>{
console.log("Epoch:"
+ epoch
+ " Loss:"
+ logs.loss);
}
}
});
}

👩‍💻 Kodun tamamı

🌞 Yazının Aslı