# wasm-tf-app **Repository Path**: xudan16/wasm-tf-app ## Basic Information - **Project Name**: wasm-tf-app - **Description**: AI APPs with Rust which can be compiled by Webassembly - **Primary Language**: Rust - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-07-14 - **Last Updated**: 2021-12-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # wasm-tf-app ## 1 介绍 本repo中包含由Rust实现的基于TensorFlow(TF)框架的AI算法与TF模型。提供的AI应用如下: - [人脸检测](face-detection) - [通用图像分类](image-classification) - [鸟类图像分类](image-classification-birds) 所有AI应用均可以通过以下docker容器方式进行编译得到wasm文件,并对外提供基于网页的AI服务。 除docker和git外,不需要安装其他额外工具。 ## 2 编译指导 首先需要将Rust语言编写的算法与TF模型编译成wasm文件,下面以face-detection应用为例介绍如何编译, 其他应用只需要将`docker run`命令中的应用名“face-detection”替换即可: ``` git clone https://gitee.com/xudan16/wasm-tf-app.git cd wasm-tf-app docker pull swr.ap-southeast-1.myhuaweicloud.com/edgegallery/wasm-tf-build-x86:20210812 docker run -v $(pwd)/face-detection:/usr/app swr.ap-southeast-1.myhuaweicloud.com/edgegallery/wasm-tf-build-x86:20210812 ``` 上述`docker run`命令会创建容器并在容器内执行wasm编译,会有一两分钟等待时间,并非卡住或出错。 编译成功完成后会出现如下提示: ``` [INFO]: Installing wasm-bindgen... [INFO]: Installing wasm-opt... [INFO]: Optimizing wasm binaries with `wasm-opt`... [INFO]: Installing wasmedgec... [INFO]: Compiling AOT binaries with `wasmedgec`... [INFO]: Optional fields missing from Cargo.toml: 'description', 'repository', and 'license'. These are not necessary, but recommended [INFO]: :-) Done in 1m 27s [INFO]: :-) Your wasm pkg is ready to publish at /usr/app/pkg. ``` 根据上述提示,生成的wasm文件在容器内的`/usr/app/pkg`目录下,即本地`wasm-tf-app/face-detection/pkg`目录下。 ## 3 运行应用 Repo中每个应用的目录下有一个`html`目录,里面是预先写好的nodejs以及网页文件,可以用来调用`pkg`下生成的wasm文件提供AI服务。 以face-detection应用为例介绍如何启动服务,其他应用只需将`docker run`命令中的应用名“face-detection”替换即可: ``` cd wasm-tf-app docker pull swr.ap-southeast-1.myhuaweicloud.com/edgegallery/wasm-tf-run-x86:20210812 docker run -d -v $(pwd)/face-detection:/usr/run/app -p 3001:3000 swr.ap-southeast-1.myhuaweicloud.com/edgegallery/wasm-tf-run-x86:20210812 docker ps -a ``` 能够查看到容器正在运行,则代表服务以成功启动,可在浏览器中输入地址已查看并使用服务。 ``` http://:3001 ```