paint-brush
Ukuhlola I-ICP Face Recognition DApp: Umphumela Wokugcina Uzokumangazange@induction
461 ukufundwa
461 ukufundwa

Ukuhlola I-ICP Face Recognition DApp: Umphumela Wokugcina Uzokumangaza

nge Vision NP9m2024/09/21
Read on Terminal Reader

Kude kakhulu; Uzofunda

I-Internet Computer Protocol (ICP) isebenzela ukusabalalisa i-AI ngokuvumela izinhlelo zokusebenza ukuthi zisebenze nengqalasizinda yamafu ehlukaniswe ngokuphelele. Lolu hlobo lwendlela yokwahlukaniswa kwezindawo luqinisekisa ukuthi imisebenzi ye-AI isobala, ayivimbeli ukucwaninga, futhi ayithambekele ekuhlulekeni kokukodwa. Sizohlola ukuthi ukumiswa kwe-AI kusebenza kanjani ngokufanelekile ngemiboniso ecashile yesinyathelo ngasinye.
featured image - Ukuhlola I-ICP Face Recognition DApp: Umphumela Wokugcina Uzokumangaza
Vision NP HackerNoon profile picture
0-item
1-item

Iminyaka embalwa edlule ibikhethekile kumamodeli e-AI asekelwe kuseva emaphakathi afana ne-ChatGPT, i-Gemini ye-Google, i-Microsoft's Copilot, njll. Akungabazeki ukuthi amamodeli anjalo e-AI aguqule izici eziningi. Kodwa ngakolunye uhlangothi, banezinye izici ezimbi. Mhlawumbe, uzwile futhi mayelana nokucisha okumbalwa kwe-ChatGPT .


Amamodeli asekelwe kuseva amaphakathi asengozini enkulu yephuzu elilodwa lokwehluleka. Kodwa manje, isikhathi sesishintshile. Ubuchwepheshe be-Blockchain buphinde buguqule izinkambu eziningi, kuhlanganise ne-artificial intelligence (AI).


I-Internet Computer Protocol (ICP) eyakhiwe yi-Dfinity, isebenzela ukusabalalisa i-AI ngokuvumela izinhlelo zokusebenza ze-AI ukuthi zisebenze nengqalasizinda yamafu ehlukaniswe ngokuphelele. Into ehlukile ukuthi, i-ICP ivumela amamodeli nezinsizakalo ze-AI ukuthi zisatshalaliswe kunethiwekhi yonkana yezikhungo zedatha ezizimele. Lolu hlobo lwendlela yokwahlukanisa luqinisekisa ukuthi imisebenzi ye-AI isobala, ayivimbeli ukucwaninga, futhi ayithambekele kangako ekuhlulekeni okukodwa.


Lesi sihloko sihluke ekuhlolweni okusebenzayo kwe- Face Recognition DApp esekelwe ku-ICP. Sizohlola ukuthi ukumiswa kwe-AI kusebenza kanjani ngokufanelekile ngemiboniso ecashile yesinyathelo ngasinye. Sizame ukwephula imiqondo yezobuchwepheshe eyinkimbinkimbi sibe izifundo eziqondakala kalula ngakho-ke ake siqale.


Yonke iphrojekthi yokuthuthukiswa kwephrojekthi kanye nezinqubo zokuhlola zenziwa emshinini osekelwe ku-Windows, ngakho-ke sakha uhlelo olungaphansi lwe-Linux lapha ngoba amathuluzi amaningi okuthuthukisa i-ICP nemibhalo yenzelwe izimo ezisekelwe ku-Linux.


📥Izimfuneko:

  • Isistimu Esebenzayo : IWindows ene-Windows Subsystem ye-Linux (WSL) ifakiwe. Sicela ubhekisele kulo mhlahlandlela ukuze ufake.


  • Ulwazi :

    • Ukuqonda okuyisisekelo kweJavaScript , React.js , Rust , kanye neWebAssembly .

    • Ukujwayelana nemiqondo yokuthuthukisa iwebhu.


  • Amathuluzi :

    • I-DFX SDK (Uhlaka lokuthuthukisa i-ICP) .
    • I-Node.js ne-npm.
    • Ukugqwala: Faka i-Rust toolchain.
    • I-Git: Uyidinga ukuze uhlanganise indawo yokugcina. Sicela ukhethe umhlahlandlela wabo ukuze uwufake.
    • wasi2ic: Ithuluzi lokuguqula imojuli ye-Wasm encike ku-WASI ukuthi isebenze ku-ICP.
    • i-wasm-opt: I-WebAssembly optimizer.


📥Misa Indawo Yokuthuthukisa:

  1. Vula itheminali yakho ye-WSL, bese usebenzisa umyalo olandelayo ukuze ufake i-DFX:
 sh -ci "$(curl -fsSL https://smartcontracts.org/install.sh)"


👉Ukuqinisekisa ukufakwa:

 dfx –version


  1. Faka i-Rust ngokusebenzisa umyalo olandelayo:
 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source $HOME/.cargo/env

👉Ukuqinisekisa ukufakwa, sebenzisa:

 rustc –version


3. Faka i-Node.js ngokusebenzisa umyalo olandelayo:

 curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - sudo apt install -y nodejs


👉Ukuqinisekisa ukufakwa, sebenzisa:

 node -v npm -v


  1. Faka i-wasi2ic: Okokuqala hlanganisa inqolobane yabo ye-GitHub.
 git clone https://github.com/wasm-forge/wasi2ic.git cd wasi2ic cargo install --path .


👉Ukuze uhlole ukufakwa, sebenzisa:

 echo $PATH wasi2ic –help


  1. Faka i-wasm-opt:
 cargo install wasm-opt


📥Khipha iphrojekthi:

Sisebenzisa inqolobane yephrojekthi ye-GitHub ngezinjongo zethu zokuhlola. Ungahlola inqolobane yabo lapha .


1. Hlanganisa indawo yokugcina bese uzulazulela kuphrojekthi yokubona ubuso:

 git clone https://github.com/dfinity/examples.git cd examples/rust/face-recognition

Qaphela: Ungafinyelela amafayela akho e-Linux subsystem ngokusesha \\wsl$ ku-File Explorer noma isici sokusesha esiqondile ku-Windows OS.


📥Landa Amamodeli Wokuqaphela Ubuso


  1. Landa imodeli yokuthola ubuso:

Imodeli yokuthola ubuso izosetshenziswa ukuthola ubuso esithombeni. Gijima:

 ./download-face-detection-model.sh


  1. Landa imodeli yokubona ubuso:

Udinga ukuthekelisa imodeli ngefomethi ye-ONNX usebenzisa PyTorch ne- facenet-pytorch . Qala ngokufaka le mitapo yolwazi yePython:

 pip install torch facenet-pytorch onnx


Qaphela: Uma i-Python ingakafakwa kusistimu yakho engaphansi, zama ukufaka i-Python ne-pip kusuka lapha: https://packaging.python.org/en/latest/tutorials/installing-packages/ .


  1. Khipha imodeli ye-ONNX:

Kufayela lePython noma igobolondo, sebenzisa okulandelayo: Thayipha i-python3 kutheminali bese usebenzisa ikhodi elandelayo. Ngemva kokubulawa, thayipha ukuphuma().

 import torch import facenet_pytorch resnet = facenet_pytorch.InceptionResnetV1(pretrained='vggface2').eval() input = torch.randn(1, 3, 160, 160) torch.onnx.export(resnet, input, "face-recognition.onnx", verbose=False, opset_version=11)


Lokhu kuzokhiqiza ifayela le face-recognition.onnx . Ikopishele kumsuka wenqolobane yakho.


📥Yakha

Manje, sekuyisikhathi sokwakha iphrojekthi. Gijima:

 dfx start --background dfx deploy


Uma konke kuhamba kahle, ungabona i-URL ye-Frondend kutheminali.

Umfanekiso 1. Umlayezo wokuthunyelwa ngempumelelo kumatheminali anama-URL angaphambili

Qaphela: Uma ubhekene nephutha elithile ngenxa yeklayenti elilahlekile, zama ukufaka webpack kanye webpack-cli emhlabeni jikelele usebenzisa i-npm:

sudo npm install -g webpack webpack-cli


Futhi, ukuncika kwendawo:

npm install


📥Dala i-canister, sebenzisa:

 dfx canister create backend


Ungabona umlayezo olandelayo kutheminali.

Umfanekiso 2. Umlayezo ovezwe kutheminali kanye nenkomba yokwakhiwa ngempumelelo kwamathini

👉Manje, ungabheka isimo se-backend ye-canister:

 dfx canister status backend


Ungabona into efana nale kutheminali.

Umfanekiso 3. Isimo sangemuva se-Canister

📥Ukulayishwa kweChunk kwamamodeli

Njengoba amamodeli e-AI ngokuvamile amakhulu. Azikwazi ukushumekwa ngokuqondile ku-WebAssembly (Wasm) kanambambili yenkontileka ehlakaniphile. Kunalokho, lawa mamodeli adinga ukulayishwa ngokwehlukana. Ukusingatha lokhu, i-DecideAI ithuthukise ithuluzi lokulayisha amamodeli ngokuqhubekayo. Ungathola ithuluzi lapha: ic-file-uploader .


👉Ukufaka ithuluzi, sebenzisa umyalo olandelayo:

 cargo install ic-file-uploader


Uma isifakiwe, ungasebenzisa i- upload-models-to-canister.sh script ngokusebenzisa ./upload-models-to-canister.sh kutheminali ukuze ulayishe amamodeli. Lesi script senza izinyathelo ezilandelayo:


  1. Isula amamodeli e-AI akhona ku-canister:
 dfx canister call backend clear_face_detection_model_bytes dfx canister call backend clear_face_recognition_model_bytes


  1. Ilayisha amamodeli amasha ngokwandayo:
 ic-file-uploader backend append_face_detection_model_bytes version-RFB-320.onnx ic-file-uploader backend append_face_recognition_model_bytes face-recognition.onnx


  1. Ekugcineni, iskripthi simisa amamodeli alayishiwe:
 dfx canister call backend setup_models


Manje, usungakwazi ukusebenzisana ne-Frontind ngokusebenzisa i-URL oyithole kutheminali ngenkathi dfx deploy command (Umfanekiso 1)


Umfanekiso 4. I-Frontend interface ye-dApp enesithombe esilayishiwe sika-Nikola Tesla. Ibhokisi lengxoxo liyavela ukuze kwengezwe igama ngemva kokuchofoza inkinobho ethi "Engeza umuntu".


Uma usulayishe isithombe ngokuchofoza kulogo ye-ICP, zama ukwengeza igama lomuntu ngokuchofoza inkinobho ethi “ Engeza umuntu ” ukuze uqeqeshe imodeli.

Ibona ubuso obunophawu oluzenzakalelayo lukanxande ebusweni. Uma usetha igama, libonisa umlayezo wokwengeza okuyimpumelelo njengokulandelayo:

Umfanekiso 5. Umlayezo ukhonjiswa ngemva kokwengeza igama

I-AI ikhumbula igama olisethele ubuso ukuze ukwazi ukuhlola ukuthi ingabe ihlonza ubuso bezithombe ezihlukene zomuntu oyedwa noma cha. Lapha, izithombe ezahlukene zikaNikola Tesla zithathwa. Ukuze ulayishe esinye Isithombe ukuze sitholwe ubuso, layisha kabusha ikhasi, bese uchofoza inketho ethi “ Bona ”. Asibone; ikhombe ngempumelelo ubuso bukaNikola Tesla ngomehluko omncane kusukela kowokuqala.

Umfanekiso 6. I-AI ithole ngempumelelo ubuso buka-Nikola Tesla kwesinye isithombe esinomehluko we-0.68

Lapha, isithombe esenziwe nge-AI sika-Nikola Tesla sihanjiswa kumodeli, futhi ngokumangalisayo, sithole ngokunembile ubuso, ake sibone lapha:

Umfanekiso 7. Ubuso obukhiqizwe be-AI buka-Nikola Tesla butholwe yi-dApp ngomehluko ongu-0.77 kuphela.

Iqinisekise ngempumelelo ukuthi i-ICP Face Recognizing DApp isebenza kahle njengoba ithole ngempumelelo ubuso buka-Nikola Tesla. Ungakuzama wedwa.


Njengoba ingeyezinjongo zokuhlola, i-UI nezici kunqunyelwe. Ungakwazi ukwengeza izici ezengeziwe namasevisi uma uphuthuma ukwakha i-dApp elungele ukukhiqiza ku-ICP ngezinjongo zokubuka ubuso. Ungazama izici ezilandelayo ngezibonelo zekhodi. Sicela uqaphele ukuthi kufanele wengeze noma wenze ngendlela oyifisayo amakhodi ngokwezidingo zakho.


📥Nawa amathiphu akho:

  1. Engeza ukuqinisekiswa komsebenzisi nge-inthanethi Identity

Uma ungeza lesi sici kule dApp, abasebenzisi ababhalisiwe kuphela abakwazi ukufinyelela i-DApp. Nansi indlela ongakwengeza ngayo ubuqiniso usebenzisa i-Internet Identity. Ungakwazi ukuhlanganisa ubunikazi be-inthanethi ngokungeza inkinobho yokungena ye-Inthanethi ekhasini eliyisiqalo. Uma umsebenzisi esengenile, bonisa ideshibhodi yomuntu siqu.


Ungeza kanjani:

👉Faka ukuncika kobunikazi be-inthanethi:

 npm install @dfinity/agent @dfinity/auth-client


👉Engeza ikhodi elandelayo ku-frontend yakho ukuze unike amandla ubuqiniso:

 import { AuthClient } from "@dfinity/auth-client"; async function init() { const authClient = await AuthClient.create(); if (await authClient.isAuthenticated()) { // Display dashboard or personalized content } else { authClient.login({ identityProvider: "https://identity.ic0.app/#authorize", onSuccess: () => { // Once authenticated, display personalized features }, }); } } init();


👉Ngemva kokungena ngemvume, umsebenzisi angabona umlando wabo wobuso obaziwayo noma enye idatha yomuntu siqu.


  1. Layisha isithombe ngokuhudula bese uphonsa umsebenzi

Yenza umsebenzi wokulayisha isithombe futhi wenze kube lula ngokuvumela abasebenzisi ukuthi bahudule futhi bawise izithombe ukuze zitholwe ubuso.


Ungeza kanjani :

👉Sebenzisa umsebenzi we-HTML5 wokudonsa nokuwisa:

 <div id="drop-area"> <p>Drag and drop an image here or click to select</p> <input type="file" id="file-input" hidden /> </div>


👉Engeza i-JavaScript ukuze ubambe isenzo sokudonsa nokuwisa:

 const dropArea = document.getElementById("drop-area"); dropArea.addEventListener("dragover", (event) => { event.preventDefault(); }); dropArea.addEventListener("drop", (event) => { event.preventDefault(); const files = event.dataTransfer.files; // Process the uploaded image });


👉Qiniseka ukuthi ihlangana kahle nomsebenzi wakho okhona wokuthola ubuso.


  1. Ibha Yenqubekelaphambili Yokubonwa Kobuso

Kuzoba isici esibandakanyayo ukubonisa ibha yokuqhubeka uma isithombe silayishwa ukuze sazise abasebenzisi ukuthi isistimu icubungula isithombe.


Ungeza kanjani:

👉Sebenzisa ibha yenqubekelaphambili ye-HTML elula:

 <div id="progress-bar"> <div id="progress-fill" style="width: 0%;"></div> </div>


👉Buyekeza ngokunamandla ibha yokuqhubeka njengoba isithombe sicutshungulwa:

 const progressFill = document.getElementById("progress-fill"); let progress = 0; const interval = setInterval(() => { progress += 10; progressFill.style.width = `${progress}%`; if (progress === 100) { clearInterval(interval); } }, 100); // Simulate progress every 100ms


  1. Izaziso zemiphumela yokubonwa kobuso

Ungakwazi ukwengeza isici ukuze unikeze izaziso zesikhathi sangempela uma ukubonwa kobuso sekuqedile, ngesaziso se-modal noma se-toast.


Ungeza kanjani :

👉 Ungasebenzisa umtapo wezincwadi ongasindi njenge -Toastr noma izaziso zethosti yangokwezifiso.

 <div id="notification" class="hidden">Face Recognition Complete!</div>


👉Ku-JavaScript yakho, bonisa isaziso lapho i-backend ibuyisela umphumela:

 function showNotification(message) { const notification = document.getElementById("notification"); notification.innerHTML = message; notification.classList.remove("hidden"); setTimeout(() => { notification.classList.add("hidden"); }, 3000); // Hide notification after 3 seconds } // Call this after face recognition is done showNotification("Face detected and recognized!");


📥Izinyathelo Zokugcina: Yakha kabusha futhi Usebenzise

Ngemva kokwenza lezi zici ezintsha:


👉Yakha kabusha iphrojekthi:

 dfx build


👉Thumela ku-testnet: Iwukuhlola kuqala ngaphambi kokuphuthuma ku-mainnet.

 dfx deploy --network ic


Lezi yizibonelo ezimbalwa kanye nemibono ngezinjongo zokubonisa. Ungazivivinya uwedwa futhi usazise ukuqhubeka kwakho esigabeni sokuphawula. Futhi, ungenza okwengeziwe ngayo ukusabalalisa i-AI ku-ICP.

Isiphetho:

Sihlole ngempumelelo i-Face Recognizing DApp ku-ICP okuwumzamo wangempela wokusabalalisa i-AI (DeAI). Njengokuhlolwa kwethu, izimpendulo ze-DApp zazishesha, futhi ukutholwa kobuso kwakunembayo. Ingqalasizinda eyingqayizivele ye-ICP ingasisiza ekwenzeni imisebenzi eyinkimbinkimbi efana nokubona ubuso ngaphandle kokuthembela kumasistimu aphakathi nendawo.


Akugcini nje ngokuthuthukisa ukuphepha nobumfihlo kodwa futhi kukhombisa amandla ezinhlelo zokusebenza ze-AI (DeAI) ezisatshalaliswayo ukuthi ziguquke ngokushesha. Njengoba i-ICP iqhubeka nokuthuthuka, ikhono lokusebenzisa amamodeli amakhulu nokwenza inkomba ye-AI on-chain kungavula amathuba amasha okwenziwa okusha. Singalindela i-AI ehlukaniselwe ukuba ngumdlali obalulekile esikhathini esizayo sezixazululo ezinokwethenjelwa nezinokwehla. Onjiniyela futhi banamathuba amasha okudala imikhiqizo eminingi namasevisi ku-ICP.