{"id":13901388,"url":"https://github.com/HunterXuan/wx-tfjs-demo","last_synced_at":"2025-07-17T22:30:28.526Z","repository":{"id":37406063,"uuid":"185920554","full_name":"HunterXuan/wx-tfjs-demo","owner":"HunterXuan","description":"微信小程序运行 TensorFlow 的 Demo","archived":false,"fork":false,"pushed_at":"2024-10-29T18:59:51.000Z","size":16352,"stargazers_count":525,"open_issues_count":13,"forks_count":100,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-11-25T09:44:15.910Z","etag":null,"topics":["tensorflow","tensorflow-demo","tensorflowjs","tfjs","wechat","wechat-mini-program","wx-tfjs-demo"],"latest_commit_sha":null,"homepage":"https://hunterx.xyz/retry-tfjs-on-wx.html","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HunterXuan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-10T04:48:59.000Z","updated_at":"2024-11-13T07:35:02.000Z","dependencies_parsed_at":"2024-01-16T22:22:09.340Z","dependency_job_id":"bb5d6495-e2d9-4b3a-b840-8970d66e9154","html_url":"https://github.com/HunterXuan/wx-tfjs-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/HunterXuan/wx-tfjs-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HunterXuan%2Fwx-tfjs-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HunterXuan%2Fwx-tfjs-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HunterXuan%2Fwx-tfjs-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HunterXuan%2Fwx-tfjs-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HunterXuan","download_url":"https://codeload.github.com/HunterXuan/wx-tfjs-demo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HunterXuan%2Fwx-tfjs-demo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265672330,"owners_count":23808842,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["tensorflow","tensorflow-demo","tensorflowjs","tfjs","wechat","wechat-mini-program","wx-tfjs-demo"],"created_at":"2024-08-06T21:01:19.244Z","updated_at":"2025-07-17T22:30:28.104Z","avatar_url":"https://github.com/HunterXuan.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# wx-tfjs-demo\n\n[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FHunterXuan%2Fwx-tfjs-demo\u0026count_bg=%2379C83D\u0026title_bg=%23555555\u0026icon=\u0026icon_color=%23E7E7E7\u0026title=hits\u0026edge_flat=false)](https://hits.seeyoufarm.com)\n\n微信小程序运行 TensorFlow 的 Demo，代码与小程序「AI Pocket」不定期同步更新。\n\n# 如何运行\n\n## 运行环境要求\n\n推荐系统：MacOS\n\nNodeJS：v18.x.x\n\n微信基础库版本：\u003e= 2.29.0\n\n微信开发者工具：\u003e= v1.06.2210310\n\n微信开发者工具的项目配置：\n\n* 勾选「ES6 转 ES5」\n* 勾选「增强编译」\n* 测试时请勾选「不校验合法域名……」\n\n## 使用方式\n\n1. 克隆代码到本地\n2. 修改 project.config.json 中的 `appid` 配置\n3. `npm i` 安装依赖（有时可能需要使用 `npm i --force`）\n4. `npm run build` 编译依赖\n5. 手机扫描开发者工具的预览码\n\n# Story\n\n## 早期实现方式\n\n改造 tfjs-core，使 TensorFlow.js 可以运行在小程序中。小程序调用摄像头成像，将图片显示在 `canvas` 上，通过小程序的 API 可以获取到 `canvas` 的「类 ImageData」数据，再调用 tfjs 的 API 实现预测。\n\n对实现的坎坷经历感兴趣的，可以看看博文 [tfjs 移植到微信小程序](https://hunterx.xyz/try-tfjs-on-wx.html) 和 [TensorFlowJS 移植再次尝试](https://hunterx.xyz/retry-tfjs-on-wx.html)。\n\n## 目前实现方式\n\n由于 tfjs 已经优雅地实现对多平台的支持，具体表现为可以扩展 `platform` 实现「移植」，而且微信小程序也开放了更多有利的 API，目前不再采用侵入式地魔改 tfjs 的方式，而是借助 tfjs 的微信插件来提供模型的加载、训练、预测等功能。\n\n尽管相比以前方便多了，但是由于小程序的 `onCameraFrame` 获取到的帧数据与所展示的不一致，而且是在不同的设备上（甚至相同设备的前后摄像头）对原始帧数据的处理方式都不一样，要想得到准确的预测结果，真叫人头大。\n\n~~目前，我已经摸索出一套帧数据裁切方式，而且简单测试了下，效果不错。如果有照顾不到的机型，欢迎提 Issues \u0026 PR~~。\n\n现在小程序的帧数据裁切方式在不同平台已经趋于一致。\n\n# 小程序 Demo\n小程序改名「AI Pocket」了，感觉还是挺有意义的，所以我打算认真做好这个小程序了。附上小程序二维码，欢迎大家体验 \u0026 提出改进意见！\n\n![AIPocket](https://i.endpot.com/image/CIDDI/AIPocket.jpg)\n\n# 合作与交流\n\n## 合作\n\n本人在前后端开发、Docker \u0026 Swarm、持续部署、人工智能 NLP 领域都有所积累，能够快速提供成套的解决方案，如果有机会，欢迎通过各种联系方式咨询合作事宜。\n\n另外，本项目代码开源，欢迎各位感兴趣的同学一起添砖加瓦。当然，也不限制商用，但是请尊重他人的劳动成果，不要做一些「不厚道」的事。如果本项目对你有帮助，欢迎随意打赏。\n\n![打赏](https://i.endpot.com/image/DGB9R/reward.jpg)\n\n## 交流\n\n可以关注下我的 [个人博客](https://hunterx.xyz)，或者个人微信公众号「猎人杂货铺」，会经常有一些技术分享 \u0026 生活感悟，欢迎多多交流！\n\n**关注公众号，留言获取「AI Pocket 交流群」的二维码，方便交流！~**\n\n![猎人杂货铺 • 微信公众号](https://i.endpot.com/image/V4NUH/%E6%89%AB%E7%A0%81-%E7%8C%8E%E4%BA%BA%E6%9D%82%E8%B4%A7%E9%93%BA.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHunterXuan%2Fwx-tfjs-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHunterXuan%2Fwx-tfjs-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHunterXuan%2Fwx-tfjs-demo/lists"}