Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/ai_detect/Flower_Classification_Tensorflow.js/web/static/ drwxr-xr-x | |
| Viewing file: Select action/file-type: $("#image-selector").change(function () {
let reader = new FileReader();
reader.onload = function () {
let dataURL = reader.result;
$("#selected-image").attr("src", dataURL);
$("#prediction-list").empty();
}
let file = $("#image-selector").prop('files')[0];
reader.readAsDataURL(file);
});
let model;
$( document ).ready(async function () {
$('.progress-bar').show();
console.log( "Loading model..." );
model = await tf.loadLayersModel('model_trained/model.json');
console.log( "Model loaded." );
$('.progress-bar').hide();
});
$("#predict-button").click(async function () {
let image = $('#selected-image').get(0);
// Pre-process the image
let tensor = tf.browser.fromPixels(image)
.resizeNearestNeighbor([96,96]) // change the image size here
.mean(2)
.toFloat()
.div(tf.scalar(255.0))
.expandDims()
.expandDims(-1);
let predictions = await model.predict(tensor).data();
let top5 = Array.from(predictions)
.map(function (p, i) { // this is Array.map
return {
probability: p,
className: TARGET_CLASSES[i] // we are selecting the value from the obj
};
}).sort(function (a, b) {
return b.probability - a.probability;
}).slice(0, 2);
$("#prediction-list").empty();
top5.forEach(function (p) {
$("#prediction-list").append(`<li>${p.className}: ${p.probability.toFixed(6)}</li>`);
});
});
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0049 ]-- |