-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
60 lines (54 loc) · 2.06 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
$(document).ready(function () {
//$('#results').fadeOut(1);
initializeTensorModel();
});
function submitModel() {
if (!window.model) {
swal("Hata Oluştu!", "Model Oluşturulurken hata oluştu! Lütfen tekrar deneyin.", "error");
return;
}
var image = document.getElementById('validatedCustomFile').value;
if (!image) {
swal("Hata Oluştu!", "Resim seçilirken hata oluştu.", "error");
}
console.warn(image);
predict();
}
async function predict() {
//tf.ENV.set('WEBGL_PACK', false)
//const model = await tf.loadLayersModel('https://localhost:44329/model/model.json');
tf.tidy(() => {
var image = tf.browser.fromPixels(document.getElementById('image')).toFloat();
const offset = tf.scalar(127.5);
const normalized = image.sub(offset).div(offset);
const batched = normalized.reshape([1, window.image_size, window.image_size, 3]);
const prediction = window.model.predict(batched);
const tensorData = prediction.dataSync();
const normalProb = tensorData[0];
const anormalProb = tensorData[1];
$('#zatureLabel').html('Zatüre Olma İhtimali : ' + anormalProb.toString().substring(0,4));
$('#normalLabel').html('Normal Olma İhtimali : ' + normalProb.toString().substring(0, 4));
$('#results').removeAttr('hidden');
$('#image').attr('hidden', 'hidden');
console.warn(tensorData);
});
}
async function initializeTensorModel() {
tf.ENV.set('WEBGL_PACK', false)
const model = await tf.loadLayersModel('https://localhost:44329/model/model.json');
window.model = model;
window.image_size = 224;
};
function onFileSelected(event) {
$('#results').attr('hidden','hidden');
$('#image').removeAttr('hidden');
var selectedFile = event.target.files[0];
var reader = new FileReader();
var imgtag = document.getElementById("image");
imgtag.title = selectedFile.name;
reader.onload = function (event) {
imgtag.src = event.target.result;
};
reader.readAsDataURL(selectedFile);
}