请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册
搜索

开发问题 快应用可以实现做人脸识别吗?

2
回复
1261
查看
[复制链接]

2

主题

5

帖子

35

积分

 楼主| 2019-8-14 15:50:12 显示全部楼层 |阅读模式
我用npm装了tensorflow.js ,加载模型遇到问题 1. tensorflow.js 无法发出网络请求。应该是因为快应用的环境和浏览器环境不同,网络请求方式不同。 2. 我尝试把模型下载到本地。。。tensorflow.js 可以通过 File对象创建模型,但是快应用没有 File和Blob对象(头疼 人脸识别除了用tensorflow.js还有其它方案吗?(本地做人脸检测 或者tensorflow.js应该怎么做才能在快应用上加载模型并运行?
回复

使用道具 举报

2

主题

5

帖子

35

积分

 楼主| 2019-8-14 18:15:19 显示全部楼层
初步可以加载模型了。 下面是适配相关的额外代码。 1. 自己写一个新的platform , 后面的encode,和decode是乱写的,主要是fetch方法。(如果有问题,我明天再更新下
  1. const platform = {
  2. /**
  3. * Makes an HTTP request.
  4. * @param path The URL path to make a request to
  5. * @param init The request init. See init here:
  6. * https://developer.mozilla.org/en-US/docs/Web/API/Request/Request
  7. */
  8. fetch: function (path, requestInits) {
  9. console.log('发起请求')
  10. return new Promise((resolve,reject)=>{
  11. fetch.fetch({url:path,}).then((res)=>{
  12. var ret_res = {
  13. status:res.data.code,
  14. body: res.data.data,
  15. bodyUsed: false,
  16. ok: true,
  17. redirected: false,
  18. statusText: "OK",
  19. type: "basic",
  20. json:()=>{console.log('调用json方法');return JSON.parse(ret_res.body)},
  21. arrayBuffer:async ()=>{
  22. console.log('调用arraybuffer方法');
  23. const arrbuf = await file.readArrayBuffer({
  24. uri:ret_res.body})
  25. return arrbuf.data.buffer
  26. }
  27. }
  28. console.log(ret_res)
  29. resolve(ret_res)
  30. })
  31. })
  32. },
  33. /**
  34. * Returns the current high-resolution time in milliseconds relative to an
  35. * arbitrary time in the past. It works across different platforms (node.js,
  36. * browsers).
  37. */
  38. now: () => { return new Date().getTime() },
  39. /**
  40. * Encode the provided string into an array of bytes using the provided
  41. * encoding.
  42. */
  43. encode: (text, encoding) => {
  44. return null
  45. },
  46. /** Decode the provided bytes into a string using the provided encoding. */
  47. decode: (bytes, encoding) => {
  48. return String.fromCharCode(bytes)
  49. }
  50. }
复制代码
2. 设置平台
  1. tf.setPlatform('fastapp', platform)
复制代码
3. 之后就可以愉快的用url加载模型了。具体相关的内容可以到官网看 (没搜到相关资料,官网上完全没讲这块,自己乱翻源码。。。真的痛苦
回复

使用道具 举报

464

主题

759

帖子

6440

积分

2019-8-14 18:49:02 显示全部楼层
好厉害呀
官方客服微信:kuaiyingyongguanKF
官方QQ群2:1012199894
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册