Skip to content

second-state/tencent-tensorflow-scf

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
cos
 
 
 
 
scf
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

English | 视频演示 | Live demo! | 教程

快速开始

Clone 这个 repo。从 repo 的根目录,您可以拉取我们预先配置的 dev Docker image 并登录进去。请见国内的 Docker hub 镜像

$ git clone https://gitee.com/secondstate/tencent-tensorflow-scf
$ cd tencent-tensorflow-scf

$ docker pull secondstate/tencent-tensorflow-scf
$ docker run --rm -it -v $(pwd):/app secondstate/tencent-tensorflow-scf
(docker) $

你不一定要使用我们的 Docker image。要在您自己的计算机或容器上构建,请确保您已经安装了Serverless 框架, Rust, 和rustwasmc.

在 Docker 容器中运行以下命令,以构建和部署整个应用程序。

(docker) $ cd /app
(docker) $ sls deploy
... ...
  website:       https://sls-website-ap-hongkong-kfdilz-1302315972.cos-website.ap-hongkong.myqcloud.com
  vendorMessage: null

63s › tencent-tensorflow-scf › "deploy" ran for 3 apps successfully.

在浏览器中加载网站 URL,就开始使用函数来识别照片中的对象啦。

在中国大陆,如果 GitHub 很慢,可以用我们在 Gitee 的镜像。git clone https://gitee.com/secondstate/tencent-tensorflow-scf.git

创建你自己的 Tensorflow 云函数

Fork 这个 repo,使用 Code | Open with Codespaces 按钮来在浏览器中打开 Github Codespaces IDE 。第一次启动时,需要花费几分钟。

低代码开发

一旦 Codespaces IDE 启动了, 你就可以根据自己的应用程序需求来对源代码进行修改,自定义函数。 查看教程

  • src/lib.rs 文件中更改 TensorFlow 模型以及数据预处理和后处理逻辑。
  • website/content/index.html 文件中对前端UI进行更改。

创建

在 Codespaces 打开 Terminal 窗口, 然后运行下面的命令行来创建云函数。

$ rustwasmc build --enable-aot

部署

Terminal 窗口,运行下面的命令行将 TensorFlow 云函数部署到腾讯云上。

$ cp pkg/scf.so scf/

$ sls deploy
... ...
  website:       https://sls-website-ap-hongkong-kfdilz-1302315972.cos-website.ap-hongkong.myqcloud.com

在浏览器内加载部署好的 URL。 Have fun!

在本地机器上部署

如果你不能或不想使用 Github Codespaces,那可以在自己的计算机(或Docker映像)上安装 rustwasmc 和 serverless framework 工具链来构建和部署 Tensorflow serverless 函数。 安装 rustwasmc 工具

通过 NPM 安装 Serverless Framework。

$ npm install -g serverless

准备工作已经做完了,现在你可以参照上文提到的 Codespaces 的创建和部署教程来创建自己的云函数。