Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flyq/ic_ai
Last synced: 20 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/flyq/ic_ai
- Owner: flyq
- Created: 2024-05-04T07:52:31.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-05-05T07:31:25.000Z (8 months ago)
- Last Synced: 2024-05-05T08:37:29.262Z (8 months ago)
- Language: Rust
- Size: 12.6 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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:- the backend canister embeds the [the Tract ONNX inference engine](https://github.com/sonos/tract) with [the MobileNet v2-7 model](https://github.com/onnx/models/tree/main/validated/vision/classification/mobilenet). It provides a `classify()` endpoint for the frontend code to call.
- the frontend canister contains the Web assets such as HTML, JS, CSS that are served to the browser.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](https://dashboard.internetcomputer.org/release/463296c0bc82ad5999b70245e5f125c14ba7d090) 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:
- Install `wasi-skd-21.0` from https://github.com/WebAssembly/wasi-sdk/releases/tag/wasi-sdk-21
- Export `CC_wasm32_wasi` in your shell such that it points to WASI clang and sysroot. Example:```
export CC_wasm32_wasi="/path/to/wasi-sdk-21.0/bin/clang --sysroot=/path/to/wasi-sdk-21.0/share/wasi-sysroot"
```Install `wasi2ic`:
- Follow the steps in https://github.com/wasm-forge/wasi2ic
- Make sure that `wasi2ic` binary is in your `$PATH`.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.