/ic_ai

Primary LanguageRust

ICP Image Classification

https://internetcomputer.org/docs/current/developer-docs/ai/ai-on-chain

https://github.com/dfinity/examples/tree/6edfa86177fed55ac2cb641ee2359de6a6bbccf9/rust/image-classification

official canister: https://qmbwn-qaaaa-aaaak-aknvq-cai.icp0.io/ my canister: https://nlb26-cyaaa-aaaak-akqwq-cai.icp0.io/

This is an ICP smart contract that accepts an image from the user and runs image classification inference. The smart contract consists of two canisters:

Note that currently Wasm execution is not optimized for this workload. A single call executes about 24B instructions (~10s).

This is expected to improve in the future with:

  • faster deterministic floating-point operations.
  • Wasm SIMD (Single-Instruction Multiple Data).

The ICP mainnet subnets and dfx running a replica version older than 463296 may fail with an instruction-limit-exceeded error.

Dependencies

Install dfx, Rust, etc: https://internetcomputer.org/docs/current/developer-docs/getting-started/hello-world

Install WASI SDK 21:

export CC_wasm32_wasi="/path/to/wasi-sdk-21.0/bin/clang --sysroot=/path/to/wasi-sdk-21.0/share/wasi-sysroot"

Install wasi2ic:

Download MobileNet v2-7 to src/backend/assets/mobilenetv2-7.onnx:

./downdload_model.sh

Install NodeJS dependencies for the frontend:

yarn install

Build

dfx start --background
dfx deploy

If the deployment is successfull, the it will show the frontend URL. Open that URL in browser to interact with the smart contract.