|
初步可以加载模型了。
下面是适配相关的额外代码。
1. 自己写一个新的platform , 后面的encode,和decode是乱写的,主要是fetch方法。(如果有问题,我明天再更新下
- const platform = {
- /**
- * Makes an HTTP request.
- * @param path The URL path to make a request to
- * @param init The request init. See init here:
- * https://developer.mozilla.org/en-US/docs/Web/API/Request/Request
- */
- fetch: function (path, requestInits) {
- console.log('发起请求')
- return new Promise((resolve,reject)=>{
- fetch.fetch({url:path,}).then((res)=>{
- var ret_res = {
- status:res.data.code,
- body: res.data.data,
- bodyUsed: false,
- ok: true,
- redirected: false,
- statusText: "OK",
- type: "basic",
- json:()=>{console.log('调用json方法');return JSON.parse(ret_res.body)},
- arrayBuffer:async ()=>{
- console.log('调用arraybuffer方法');
- const arrbuf = await file.readArrayBuffer({
- uri:ret_res.body})
- return arrbuf.data.buffer
- }
- }
- console.log(ret_res)
- resolve(ret_res)
- })
- })
- },
- /**
- * Returns the current high-resolution time in milliseconds relative to an
- * arbitrary time in the past. It works across different platforms (node.js,
- * browsers).
- */
- now: () => { return new Date().getTime() },
- /**
- * Encode the provided string into an array of bytes using the provided
- * encoding.
- */
- encode: (text, encoding) => {
- return null
- },
- /** Decode the provided bytes into a string using the provided encoding. */
- decode: (bytes, encoding) => {
- return String.fromCharCode(bytes)
- }
- }
复制代码
2. 设置平台
- tf.setPlatform('fastapp', platform)
复制代码
3. 之后就可以愉快的用url加载模型了。具体相关的内容可以到官网看
(没搜到相关资料,官网上完全没讲这块,自己乱翻源码。。。真的痛苦
|
|