TensorFlow.js ကျူတိုရီရယ်
TensorFlow.js ဆိုတာဘာလဲ။
Machine Learning အတွက် နာမည်ကြီး JavaScript စာကြည့်တိုက် ။
Browser တွင် စက်သင်ယူမှုပုံစံများကို လေ့ကျင့်ပြီး အသုံးပြုခွင့် ပေးသည်။
မည်သည့် Web Application တွင် မဆို စက်သင်ယူခြင်းလုပ်ဆောင်ချက်များကို ပေါင်းထည့်နိုင်စေ ပါသည်။
TensorFlow ကိုအသုံးပြုခြင်း။
TensorFlow.js ကိုအသုံးပြုရန်၊ သင်၏ HTML ဖိုင်(များ)သို့ အောက်ပါ script tag ကို ထည့်ပါ-
ဥပမာ
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>
သင်သည် နောက်ဆုံးဗားရှင်းကို အမြဲသုံးကြောင်း သေချာစေရန်၊ ဤအရာကို အသုံးပြုပါ-
ဥပမာ ၂
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
TensorFlow ကို ပြည်တွင်း Google အသုံးပြုမှုအတွက် Google Brain Team မှ တီထွင် ခဲ့သော်လည်း 2015 ခုနှစ်တွင် အဖွင့်ဆော့ဖ်ဝဲအဖြစ် ထုတ်ဝေခဲ့သည်။
2019 ခုနှစ် ဇန်နဝါရီလတွင် Google developer များသည် TensorFlow ၏ JavaScript အကောင်အထည်ဖော်မှုဖြစ်သော TensorFlow.js ကို ထုတ်ပြန်ခဲ့သည်။
Tensorflow.js သည် Python တွင်ရေးသားထားသော မူရင်း TensorFlow စာကြည့်တိုက်ကဲ့သို့ တူညီသောအင်္ဂါရပ်များကို ဖြည့်ဆည်းပေးရန် ဒီဇိုင်းထုတ်ထားပါသည်။
တင်းဆာများ
TensorFlow.js သည် Tensor ကို သတ်မှတ်ပြီး လုပ်ဆောင်ရန် JavaScript စာကြည့်တိုက် တစ်ခုဖြစ်သည် ။
Tensor သည် multidimensional array နှင့် များစွာတူသည်။
Tensor တွင် ကိန်းဂဏာန်းတန်ဖိုးများ (တစ်ခု သို့မဟုတ် တစ်ခုထက်ပိုသော) အတိုင်းအတာပုံသဏ္ဍာန်တွင် ပါရှိသည်။
Tensor တွင် အောက်ပါ အဓိက ဂုဏ်သတ္တိများ ရှိသည်။
ပစ္စည်းဥစ္စာ | ဖော်ပြချက် |
---|---|
dtype | ဒေတာအမျိုးအစား |
အဆင့် | အတိုင်းအတာ အရေအတွက် |
ပုံသဏ္ဍာန် | အတိုင်းအတာတစ်ခုစီ၏အရွယ်အစား |
Tensor ဖန်တီးခြင်း။
Tensor ကို မည်သည့် N-dimensional array မှ ဖန်တီးနိုင်သည် ။
ဥပမာ ၁
const tensorA = tf.tensor([[1, 2], [3, 4]]);
ဥပမာ ၂
const tensorA = tf.tensor([[1, 2], [3, 4], [5, 6]]);
Tensor Shape
Tensor ကို array တစ်ခု နှင့် shape parameter တို့ မှလည်း ဖန်တီးနိုင်သည် -
ဥပမာ ၁
const shape = [2, 2];
const tensorA = tf.tensor([1, 2, 3, 4], shape);
ဥပမာ ၂
const tensorA = tf.tensor([1, 2, 3, 4], [2, 2]);
ဥပမာ ၃
const tensorA = tf.tensor([[1, 2], [3, 4]], [2, 2]);
Tensor Data အမျိုးအစားများ
Tensor တွင် အောက်ပါဒေတာအမျိုးအစားများ ရှိနိုင်သည်-
- ဘူလ်
- int32
- float32 (မူလ)
- ရှုပ်ထွေးသော၆၄
- ကြိုးတစ်ချောင်း
သင် tensor တစ်ခုကို ဖန်တီးသောအခါ၊ သင်သည် ဒေတာအမျိုးအစားကို တတိယ ကန့်သတ်ဘောင်အဖြစ် သတ်မှတ်နိုင်သည်။
ဥပမာ
const tensorA = tf.tensor([1, 2, 3, 4], [2, 2], "int32");
/*
Results:
tensorA.rank = 2
tensorA.shape = 2,2
tensorA.dtype = int32
*/
Tensor တန်ဖိုးများကို ရယူပါ။
tensor.data() ကို အသုံးပြု၍ tensor နောက်ကွယ်မှဒေတာကို သင်ရနိုင်သည် -
ဥပမာ
const tensorA = tf.tensor([[1, 2], [3, 4]]);
tensorA.data().then(data => display(data));
// Result: 1,2,3,4
function display(data) {
document.getElementById("demo").innerHTML = data;
}
tensor.array() ကို အသုံးပြု၍ tensor နောက်ကွယ်ရှိ array ကို သင် ရယူနိုင်ပါသည် ။
ဥပမာ
const tensorA = tf.tensor([[1, 2], [3, 4]]);
tensorA.array().then(array => display(array[0]));
// Result: 1,2
function display(data) {
document.getElementById("demo").innerHTML = data;
}