-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsteps_tfliteStep.js.html
More file actions
116 lines (71 loc) · 3.17 KB
/
steps_tfliteStep.js.html
File metadata and controls
116 lines (71 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: steps/tfliteStep.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: steps/tfliteStep.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import Step from '../step'
import createTFLiteSIMDModule from '../tflite/tflite-simd.js'
import createTFLiteModule from '../tflite/tflite.js'
const model = require('binary-loader!../tflite/segm_lite_v681.tflite');
/** The TFLite Step handles execution of the TF Lite module */
class TFLiteStep extends Step{
static segmentationWidth = 160;
static segmentationHeight = 96;
constructor(context, params) {
super(context, params);
}
/** The TFLite setup relies on the model and WASM files being loaded directly from memory in Webpack, so nothing is being loaded at runtime over the network */
async setup(){
const tflite = await createTFLiteSIMDModule();
const modelArrayBuffer = new Uint8Array(model.length);
for (let i = 0; i < model.length; i++) {
modelArrayBuffer[i] = model.charCodeAt(i);
}
const modelBufferOffset = tflite._getModelBufferMemoryOffset();
tflite.HEAPU8.set(modelArrayBuffer, modelBufferOffset);
tflite._loadModel(modelArrayBuffer.byteLength);
this.tflite = tflite;
}
/** This code comes straight from the [Volcomix repo](https://github.com/Volcomix/virtual-background) */
run(inputPixels) {
const tflite = this.tflite;
const tfliteInputMemoryOffset = tflite._getInputMemoryOffset() / 4;
for (let i = 0; i < TFLiteStep.segmentationWidth*TFLiteStep.segmentationHeight; i++) {
const outputIndex = i * 4;
const tfliteIndex = tfliteInputMemoryOffset + i * 3;
tflite.HEAPF32[tfliteIndex] = inputPixels[outputIndex] / 255
tflite.HEAPF32[tfliteIndex + 1] = inputPixels[outputIndex + 1] / 255
tflite.HEAPF32[tfliteIndex + 2] = inputPixels[outputIndex + 2] / 255
}
tflite._runInference();
return tflite;
}
}
export default TFLiteStep;</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Pipeline.html">Pipeline</a></li><li><a href="Step.html">Step</a></li><li><a href="TFLiteStep.html">TFLiteStep</a></li><li><a href="VirtualBackgroundFilter.html">VirtualBackgroundFilter</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Sat Jan 08 2022 19:43:10 GMT-0800 (Pacific Standard Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>