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.
@@ -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.50",
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
- "canvas": "^2.11.2",
24
- "learning_model": "^1.0.0"
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",