-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
!(function(c) { | ||
var s, e, t, r; | ||
function n() { | ||
return ( | ||
(function() { | ||
try { | ||
var n = navigator.userAgent.match(/Chrome\/(\d+)\./); | ||
return !!(n && 91 <= Number(n[1])); | ||
} catch (n) { | ||
return; | ||
} | ||
})() && | ||
!/TESLA/.test(navigator.userAgent) && | ||
2 < navigator.hardwareConcurrency && | ||
'function' == typeof OffscreenCanvas | ||
); | ||
} | ||
function o(r, o) { | ||
return new Promise(function(n, e) { | ||
var t = new XMLHttpRequest(); | ||
(t.responseType = o), | ||
t.addEventListener( | ||
'load', | ||
function() { | ||
n(this.response); | ||
}, | ||
t | ||
), | ||
(t.onerror = function(n) { | ||
e(n); | ||
}), | ||
t.open('get', r, !0), | ||
t.send(); | ||
}); | ||
} | ||
function a(n) { | ||
var e, | ||
t, | ||
r = new Uint8Array(n, 0, 12), | ||
o = n.slice(12, 496936), | ||
a = new Uint8Array(n, 496936, 32), | ||
n = new Uint8Array(n, 496968, 87253); | ||
s.postMessage({ | ||
command: 'DOWNLOAD_JSON_FROM_MAIN_THREAD_OK', | ||
data: o, | ||
type: 'bin', | ||
}), | ||
(e = r), | ||
(t = n), | ||
c.crypto.subtle | ||
.importKey('raw', a, 'AES-GCM', !0, ['encrypt', 'decrypt']) | ||
.then(n => { | ||
c.crypto.subtle.decrypt({ name: 'AES-GCM', iv: e }, n, t).then(n => { | ||
n = new TextDecoder().decode(n); | ||
s.postMessage({ | ||
command: 'DOWNLOAD_JSON_FROM_MAIN_THREAD_OK', | ||
data: n, | ||
type: 'json', | ||
}); | ||
}); | ||
}); | ||
} | ||
function i() { | ||
var n = c.vbPath; | ||
n && | ||
((t = n + '/vbbuffer.bin'), | ||
(r = n + '/tf.min.js'), | ||
o((e = n + '/vbPreloadWorker.js')) | ||
.then(function(n) { | ||
(s = new Worker( | ||
c.URL.createObjectURL(new Blob(["wasmUrl = '" + e + "';" + n])), | ||
{} | ||
)), | ||
o(t, 'arraybuffer') | ||
.then(function(n) { | ||
a(n); | ||
}) | ||
.catch(function(n) { | ||
console.log(n); | ||
}), | ||
s.postMessage({ | ||
command: 'DOWNLOAD_JSON_FROM_MAIN_THREAD_OK', | ||
data: r, | ||
type: 'js', | ||
}), | ||
(s.onmessage = function(n) { | ||
n.data.command; | ||
}); | ||
}) | ||
.catch(function(n) { | ||
console.log(n); | ||
})); | ||
} | ||
n() && i(); | ||
})(window); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
!(function() { | ||
var a, | ||
o, | ||
i, | ||
f, | ||
r, | ||
d, | ||
s = new Object(), | ||
l = new Object(); | ||
(l.load = function() { | ||
return s; | ||
}), | ||
(l.save = function() {}), | ||
self.addEventListener('message', function(e) { | ||
e = e.data; | ||
if ('DOWNLOAD_JSON_FROM_MAIN_THREAD_OK' === e.command) { | ||
var t = e.data, | ||
e = e.type; | ||
if (!(i && f && r)) { | ||
if ('json' == e) { | ||
if ( | ||
((i = 1), | ||
(a = JSON.parse(t)), | ||
(s.modelTopology = a.modelTopology), | ||
(s.format = a.format), | ||
(s.generatedBy = a.generatedBy), | ||
(s.convertedBy = a.convertedBy), | ||
null != a.weightsManifest) | ||
) | ||
for (const n of a.weightsManifest) s.weightSpecs = n.weights; | ||
null != a.trainingConfig && (s.trainingConfig = a.trainingConfig), | ||
null != a.userDefinedMetadata && | ||
(s.userDefinedMetadata = a.userDefinedMetadata); | ||
} else | ||
'bin' == e | ||
? ((f = 1), (s.weightData = t)) | ||
: 'js' == e && ((r = 1), (d = t)); | ||
i && | ||
f && | ||
r && | ||
(importScripts(d), | ||
tf.setBackend('webgl'), | ||
tf | ||
.loadGraphModel(l) | ||
.then(function(e) { | ||
o = e; | ||
(e = new Float32Array(110592)), | ||
(e = tf.tensor4d(e, [1, 144, 256, 3], 'float32')); | ||
o.predict(e); | ||
}) | ||
.catch(function(e) { | ||
console.log(e); | ||
})); | ||
} | ||
} | ||
}); | ||
})(); |