learning_model 1.0.50 → 1.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/learning/mobilenet.ts +26 -0
- package/package.json +3 -3
- package/dist/index.bundle.js +0 -2
- package/dist/index.bundle.js.LICENSE.txt +0 -335
- package/dist/index.d.ts +0 -3
- package/dist/index.html +0 -1
- package/dist/index.js +0 -10
- package/dist/learning/base.d.ts +0 -23
- package/dist/learning/base.js +0 -2
- package/dist/learning/data_model.d.ts +0 -41
- package/dist/learning/data_model.js +0 -205
- package/dist/learning/data_model.test.d.ts +0 -1
- package/dist/learning/data_model.test.js +0 -56
- package/dist/learning/mobilenet.d.ts +0 -49
- package/dist/learning/mobilenet.js +0 -345
- package/dist/learning/mobilenet.test.d.ts +0 -1
- package/dist/learning/mobilenet.test.js +0 -79
- package/dist/lib/index.d.ts +0 -3
- package/dist/lib/learning/base.d.ts +0 -23
- package/dist/lib/learning/data_model.d.ts +0 -41
- package/dist/lib/learning/data_model.test.d.ts +0 -1
- package/dist/lib/learning/mobilenet.d.ts +0 -49
- package/dist/lib/learning/mobilenet.test.d.ts +0 -1
- package/dist/lib/utils/canvas.d.ts +0 -3
- package/dist/lib/utils/data_manager.d.ts +0 -15
- package/dist/lib/utils/dataset.d.ts +0 -6
- package/dist/lib/utils/tf.d.ts +0 -7
- package/dist/utils/canvas.d.ts +0 -3
- package/dist/utils/canvas.js +0 -47
- package/dist/utils/data_manager.d.ts +0 -15
- package/dist/utils/data_manager.js +0 -62
- package/dist/utils/dataset.d.ts +0 -6
- package/dist/utils/dataset.js +0 -21
- package/dist/utils/tf.d.ts +0 -7
- package/dist/utils/tf.js +0 -126
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
///////////////////////////////////////////////////////////////////////////
|
|
6
6
|
|
|
7
7
|
import * as tf from '@tensorflow/tfjs';
|
|
8
|
+
import { setWasmPaths } from '@tensorflow/tfjs-backend-wasm';
|
|
8
9
|
import { dispose } from '@tensorflow/tfjs';
|
|
9
10
|
import { io } from '@tensorflow/tfjs-core';
|
|
10
11
|
import LearningInterface from './base';
|
|
@@ -188,6 +189,8 @@ class LearningMobilenet implements LearningInterface {
|
|
|
188
189
|
|
|
189
190
|
public async init() {
|
|
190
191
|
try {
|
|
192
|
+
console.log('init call')
|
|
193
|
+
await this.setupBackend();
|
|
191
194
|
this.mobilenetModule = await loadModel();
|
|
192
195
|
} catch(error) {
|
|
193
196
|
console.log('init Error', error);
|
|
@@ -195,6 +198,29 @@ class LearningMobilenet implements LearningInterface {
|
|
|
195
198
|
}
|
|
196
199
|
}
|
|
197
200
|
|
|
201
|
+
private async setupBackend() {
|
|
202
|
+
const isWasmSupported = await this.checkWasmSupport();
|
|
203
|
+
if (isWasmSupported) {
|
|
204
|
+
console.log('Backend is set to WebAssembly');
|
|
205
|
+
} else {
|
|
206
|
+
await tf.setBackend('cpu');
|
|
207
|
+
await tf.ready();
|
|
208
|
+
console.log('Backend is set to CPU');
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private async checkWasmSupport(): Promise<boolean> {
|
|
213
|
+
try {
|
|
214
|
+
const wasmVersion = tf.version['tfjs-backend-wasm'] || tf.version['tfjs-core'];
|
|
215
|
+
setWasmPaths(`https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${wasmVersion}/dist/`);
|
|
216
|
+
await tf.setBackend('wasm');
|
|
217
|
+
await tf.ready();
|
|
218
|
+
return true;
|
|
219
|
+
} catch (error) {
|
|
220
|
+
console.warn('WASM backend is not supported in this environment.', error);
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
198
224
|
|
|
199
225
|
// 모델 학습 처리
|
|
200
226
|
public async train(): Promise<tf.History> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "learning_model",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.52",
|
|
4
4
|
"description": "learning model develop",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"@tensorflow-models/mobilenet": "^2.1.0",
|
|
21
21
|
"@tensorflow/tfjs": "^4.6.0",
|
|
22
22
|
"@tensorflow/tfjs-layers": "^4.6.0",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
23
|
+
"@tensorflow/tfjs-backend-wasm": "^4.20.0",
|
|
24
|
+
"canvas": "^2.11.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@babel/core": "^7.15.0",
|