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.
@@ -1,335 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2017 Google LLC. All Rights Reserved.
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- * =============================================================================
16
- */
17
-
18
- /**
19
- * @license
20
- * Copyright 2018 Google LLC
21
- *
22
- * Use of this source code is governed by an MIT-style
23
- * license that can be found in the LICENSE file or at
24
- * https://opensource.org/licenses/MIT.
25
- * =============================================================================
26
- */
27
-
28
- /**
29
- * @license
30
- * Copyright 2018 Google LLC. All Rights Reserved.
31
- * Licensed under the Apache License, Version 2.0 (the "License");
32
- * you may not use this file except in compliance with the License.
33
- * You may obtain a copy of the License at
34
- *
35
- * http://www.apache.org/licenses/LICENSE-2.0
36
- *
37
- * Unless required by applicable law or agreed to in writing, software
38
- * distributed under the License is distributed on an "AS IS" BASIS,
39
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40
- * See the License for the specific language governing permissions and
41
- * limitations under the License.
42
- *
43
- * =============================================================================
44
- */
45
-
46
- /**
47
- * @license
48
- * Copyright 2018 Google LLC. All Rights Reserved.
49
- * Licensed under the Apache License, Version 2.0 (the "License");
50
- * you may not use this file except in compliance with the License.
51
- * You may obtain a copy of the License at
52
- *
53
- * http://www.apache.org/licenses/LICENSE-2.0
54
- *
55
- * Unless required by applicable law or agreed to in writing, software
56
- * distributed under the License is distributed on an "AS IS" BASIS,
57
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
58
- * See the License for the specific language governing permissions and
59
- * limitations under the License.
60
- * =============================================================================
61
- */
62
-
63
- /**
64
- * @license
65
- * Copyright 2019 Google LLC
66
- *
67
- * Use of this source code is governed by an MIT-style
68
- * license that can be found in the LICENSE file or at
69
- * https://opensource.org/licenses/MIT.
70
- * =============================================================================
71
- */
72
-
73
- /**
74
- * @license
75
- * Copyright 2019 Google LLC. All Rights Reserved.
76
- * Licensed under the Apache License, Version 2.0 (the "License");
77
- * you may not use this file except in compliance with the License.
78
- * You may obtain a copy of the License at
79
- *
80
- * http://www.apache.org/licenses/LICENSE-2.0
81
- *
82
- * Unless required by applicable law or agreed to in writing, software
83
- * distributed under the License is distributed on an "AS IS" BASIS,
84
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
85
- * See the License for the specific language governing permissions and
86
- * limitations under the License.
87
- *
88
- * =============================================================================
89
- */
90
-
91
- /**
92
- * @license
93
- * Copyright 2019 Google LLC. All Rights Reserved.
94
- * Licensed under the Apache License, Version 2.0 (the "License");
95
- * you may not use this file except in compliance with the License.
96
- * You may obtain a copy of the License at
97
- *
98
- * http://www.apache.org/licenses/LICENSE-2.0
99
- *
100
- * Unless required by applicable law or agreed to in writing, software
101
- * distributed under the License is distributed on an "AS IS" BASIS,
102
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
103
- * See the License for the specific language governing permissions and
104
- * limitations under the License.
105
- * =============================================================================
106
- */
107
-
108
- /**
109
- * @license
110
- * Copyright 2020 Google Inc. All Rights Reserved.
111
- * Licensed under the Apache License, Version 2.0 (the "License");
112
- * you may not use this file except in compliance with the License.
113
- * You may obtain a copy of the License at
114
- *
115
- * http://www.apache.org/licenses/LICENSE-2.0
116
- *
117
- * Unless required by applicable law or agreed to in writing, software
118
- * distributed under the License is distributed on an "AS IS" BASIS,
119
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120
- * See the License for the specific language governing permissions and
121
- * limitations under the License.
122
- * =============================================================================
123
- */
124
-
125
- /**
126
- * @license
127
- * Copyright 2020 Google LLC
128
- *
129
- * Use of this source code is governed by an MIT-style
130
- * license that can be found in the LICENSE file or at
131
- * https://opensource.org/licenses/MIT.
132
- * =============================================================================
133
- */
134
-
135
- /**
136
- * @license
137
- * Copyright 2020 Google LLC. All Rights Reserved.
138
- * Licensed under the Apache License, Version 2.0 (the "License");
139
- * you may not use this file except in compliance with the License.
140
- * You may obtain a copy of the License at
141
- *
142
- * http://www.apache.org/licenses/LICENSE-2.0
143
- *
144
- * Unless required by applicable law or agreed to in writing, software
145
- * distributed under the License is distributed on an "AS IS" BASIS,
146
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
147
- * See the License for the specific language governing permissions and
148
- * limitations under the License.
149
- * =============================================================================
150
- */
151
-
152
- /**
153
- * @license
154
- * Copyright 2020 Google LLC. All Rights Reserved.
155
- * Licensed under the Apache License, Version 2.0 (the License);
156
- * you may not use this file except in compliance with the License.
157
- * You may obtain a copy of the License at
158
- *
159
- * http://www.apache.org/licenses/LICENSE-2.0
160
- *
161
- * Unless required by applicable law or agreed to in writing, software
162
- * distributed under the License is distributed on an AS IS BASIS,
163
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
164
- * See the License for the specific language governing permissions and
165
- * limitations under the License.
166
- * =============================================================================
167
- */
168
-
169
- /**
170
- * @license
171
- * Copyright 2021 Google LLC. All Rights Reserved.
172
- * Licensed under the Apache License, Version 2.0 (the "License");
173
- * you may not use this file except in compliance with the License.
174
- * You may obtain a copy of the License at
175
- *
176
- * http://www.apache.org/licenses/LICENSE-2.0
177
- *
178
- * Unless required by applicable law or agreed to in writing, software
179
- * distributed under the License is distributed on an "AS IS" BASIS,
180
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
181
- * See the License for the specific language governing permissions and
182
- * limitations under the License.
183
- * =============================================================================
184
- */
185
-
186
- /**
187
- * @license
188
- * Copyright 2021 Google LLC. All Rights Reserved.
189
- * Licensed under the Apache License, Version 2.0 (the "License");
190
- * you may not use this file except in compliance with the License.
191
- * You may obtain a copy of the License at
192
- *
193
- * https://www.apache.org/licenses/LICENSE-2.0
194
- *
195
- * Unless required by applicable law or agreed to in writing, software
196
- * distributed under the License is distributed on an "AS IS" BASIS,
197
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
198
- * See the License for the specific language governing permissions and
199
- * limitations under the License.
200
- * =============================================================================
201
- */
202
-
203
- /**
204
- * @license
205
- * Copyright 2022 CodeSmith LLC
206
- *
207
- * Use of this source code is governed by an MIT-style
208
- * license that can be found in the LICENSE file or at
209
- * https://opensource.org/licenses/MIT.
210
- * =============================================================================
211
- */
212
-
213
- /**
214
- * @license
215
- * Copyright 2022 Google Inc. All Rights Reserved.
216
- * Licensed under the Apache License, Version 2.0 (the "License");
217
- * you may not use this file except in compliance with the License.
218
- * You may obtain a copy of the License at
219
- *
220
- * http://www.apache.org/licenses/LICENSE-2.0
221
- *
222
- * Unless required by applicable law or agreed to in writing, software
223
- * distributed under the License is distributed on an "AS IS" BASIS,
224
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
225
- * See the License for the specific language governing permissions and
226
- * limitations under the License.
227
- * =============================================================================
228
- */
229
-
230
- /**
231
- * @license
232
- * Copyright 2022 Google LLC
233
- *
234
- * Use of this source code is governed by an MIT-style
235
- * license that can be found in the LICENSE file or at
236
- * https://opensource.org/licenses/MIT.
237
- * =============================================================================
238
- */
239
-
240
- /**
241
- * @license
242
- * Copyright 2022 Google LLC.
243
- * Licensed under the Apache License, Version 2.0 (the "License");
244
- * you may not use this file except in compliance with the License.
245
- * You may obtain a copy of the License at
246
- *
247
- * http://www.apache.org/licenses/LICENSE-2.0
248
- *
249
- * Unless required by applicable law or agreed to in writing, software
250
- * distributed under the License is distributed on an "AS IS" BASIS,
251
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
252
- * See the License for the specific language governing permissions and
253
- * limitations under the License.
254
- * =============================================================================
255
- */
256
-
257
- /**
258
- * @license
259
- * Copyright 2022 Google LLC. All Rights Reserved.
260
- * Licensed under the Apache License, Version 2.0 (the "License");
261
- * you may not use this file except in compliance with the License.
262
- * You may obtain a copy of the License at
263
- *
264
- * http://www.apache.org/licenses/LICENSE-2.0
265
- *
266
- * Unless required by applicable law or agreed to in writing, software
267
- * distributed under the License is distributed on an "AS IS" BASIS,
268
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
269
- * See the License for the specific language governing permissions and
270
- * limitations under the License.
271
- * =============================================================================
272
- */
273
-
274
- /**
275
- * @license
276
- * Copyright 2022 Google LLC. All Rights Reserved.
277
- * Licensed under the Apache License, Version 2.0 (the 'License');
278
- * you may not use this file except in compliance with the License.
279
- * You may obtain a copy of the License at
280
- *
281
- * http://www.apache.org/licenses/LICENSE-2.0
282
- *
283
- * Unless required by applicable law or agreed to in writing, software
284
- * distributed under the License is distributed on an 'AS IS' BASIS,
285
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286
- * See the License for the specific language governing permissions and
287
- * limitations under the License.
288
- * =============================================================================
289
- */
290
-
291
- /**
292
- * @license
293
- * Copyright 2023 CodeSmith LLC
294
- *
295
- * Use of this source code is governed by an MIT-style
296
- * license that can be found in the LICENSE file or at
297
- * https://opensource.org/licenses/MIT.
298
- * =============================================================================
299
- */
300
-
301
- /**
302
- * @license
303
- * Copyright 2023 Google LLC.
304
- * Licensed under the Apache License, Version 2.0 (the "License");
305
- * you may not use this file except in compliance with the License.
306
- * You may obtain a copy of the License at
307
- *
308
- * http://www.apache.org/licenses/LICENSE-2.0
309
- *
310
- * Unless required by applicable law or agreed to in writing, software
311
- * distributed under the License is distributed on an "AS IS" BASIS,
312
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
313
- * See the License for the specific language governing permissions and
314
- * limitations under the License.
315
- * =============================================================================
316
- */
317
-
318
- /**
319
- * @license
320
- * Copyright 2023 Google LLC. All Rights Reserved.
321
- * Licensed under the Apache License, Version 2.0 (the "License");
322
- * you may not use this file except in compliance with the License.
323
- * You may obtain a copy of the License at
324
- *
325
- * http://www.apache.org/licenses/LICENSE-2.0
326
- *
327
- * Unless required by applicable law or agreed to in writing, software
328
- * distributed under the License is distributed on an "AS IS" BASIS,
329
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
330
- * See the License for the specific language governing permissions and
331
- * limitations under the License.
332
- * =============================================================================
333
- */
334
-
335
- /** @license See the LICENSE file. */
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import LearningMobilenet from './learning/mobilenet';
2
- import DataModel from './learning/data_model';
3
- export { LearningMobilenet, DataModel };
package/dist/index.html DELETED
@@ -1 +0,0 @@
1
- <!doctype html><html><head><link rel="stylesheet" href="index.css"><title>My CNN Module</title><script defer="defer" src="index.bundle.js"></script></head><body><div id="loss-bar"></div><div id="progress-bar"></div><div id="root"></div><div id="container"><canvas id="canvas"></canvas></div></body></html>
package/dist/index.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DataModel = exports.LearningMobilenet = void 0;
7
- const mobilenet_1 = __importDefault(require("./learning/mobilenet"));
8
- exports.LearningMobilenet = mobilenet_1.default;
9
- const data_model_1 = __importDefault(require("./learning/data_model"));
10
- exports.DataModel = data_model_1.default;
@@ -1,23 +0,0 @@
1
- import * as tf from '@tensorflow/tfjs';
2
- import { io } from '@tensorflow/tfjs-core';
3
- interface LearningInterface {
4
- model: tf.LayersModel | null;
5
- isRunning: boolean;
6
- isReady: boolean;
7
- onProgress(progress: number): void;
8
- onLoss(loss: number): void;
9
- onTrainBegin(log: any): void;
10
- onTrainEnd(log: any): void;
11
- onEpochEnd(epoch: number, logs: any): void;
12
- addData(label: string, data: any): Promise<void>;
13
- train(): Promise<tf.History>;
14
- infer(data: any): Promise<any>;
15
- saveModel(handlerOrURL: io.IOHandler | string, config?: io.SaveConfig): Promise<void>;
16
- running(): boolean;
17
- ready(): boolean;
18
- load({ jsonURL, labels }: {
19
- jsonURL: string;
20
- labels: Array<string>;
21
- }): Promise<void>;
22
- }
23
- export default LearningInterface;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,41 +0,0 @@
1
- import * as tf from '@tensorflow/tfjs';
2
- import { io } from '@tensorflow/tfjs-core';
3
- import LearningInterface from './base';
4
- import DataManager from '../utils/data_manager';
5
- declare class DataModel implements LearningInterface {
6
- epochs: number;
7
- batchSize: number;
8
- learningRate: number;
9
- validateRate: number;
10
- isTrainedDone: boolean;
11
- limitSize: number;
12
- isRunning: boolean;
13
- isReady: boolean;
14
- model: tf.LayersModel | null;
15
- dataManager: DataManager;
16
- constructor({ epochs, batchSize, limitSize, learningRate, validateRate, }?: {
17
- epochs?: number;
18
- batchSize?: number;
19
- limitSize?: number;
20
- learningRate?: number;
21
- validateRate?: number;
22
- });
23
- onProgress(progress: number): void;
24
- onLoss(loss: number): void;
25
- onTrainBegin(log: any): void;
26
- onTrainEnd(log: any): void;
27
- onEpochEnd(epoch: number, logs: any): void;
28
- addData(label: string, data: number[]): Promise<void>;
29
- augmentData(data: number[]): number[];
30
- normalizeData(data: number[]): number[];
31
- train(): Promise<tf.History>;
32
- infer(data: number[]): Promise<Map<string, number>>;
33
- saveModel(handlerOrURL: io.IOHandler | string, config?: io.SaveConfig): Promise<void>;
34
- running(): boolean;
35
- ready(): boolean;
36
- load({ jsonURL, labels }: {
37
- jsonURL: string;
38
- labels: Array<string>;
39
- }): Promise<void>;
40
- }
41
- export default DataModel;
@@ -1,205 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- const tf = __importStar(require("@tensorflow/tfjs"));
39
- const data_manager_1 = __importDefault(require("../utils/data_manager"));
40
- class DataModel {
41
- constructor({ epochs = 50, batchSize = 16, limitSize = 2, learningRate = 0.001, validateRate = 0.15, } = {}) {
42
- this.model = null;
43
- this.dataManager = new data_manager_1.default();
44
- this.epochs = epochs;
45
- this.batchSize = batchSize;
46
- this.learningRate = learningRate;
47
- this.validateRate = validateRate;
48
- this.isRunning = false;
49
- this.isReady = false;
50
- this.isTrainedDone = false;
51
- this.limitSize = limitSize;
52
- }
53
- onProgress(progress) {
54
- console.log(`Training progress: ${progress}%`);
55
- }
56
- onLoss(loss) {
57
- console.log(`Loss: ${loss}`);
58
- }
59
- onTrainBegin(log) {
60
- console.log('Training started', log);
61
- }
62
- onTrainEnd(log) {
63
- console.log('Training ended', log);
64
- }
65
- onEpochEnd(epoch, logs) {
66
- console.log(`Epoch ${epoch} ended with logs:`, logs);
67
- }
68
- addData(label, data) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const normalizedData = this.normalizeData(data);
71
- const augmentedData = this.augmentData(normalizedData);
72
- yield this.dataManager.addData(label, augmentedData);
73
- });
74
- }
75
- augmentData(data) {
76
- return data.map(value => value + (Math.random() * 0.1 - 0.05)); // 약간의 노이즈 추가
77
- }
78
- normalizeData(data) {
79
- const mean = data.reduce((sum, value) => sum + value, 0) / data.length;
80
- const std = Math.sqrt(data.reduce((sum, value) => sum + Math.pow(value - mean, 2), 0) / data.length);
81
- return data.map(value => (value - mean) / std);
82
- }
83
- train() {
84
- return __awaiter(this, void 0, void 0, function* () {
85
- if (this.isRunning) {
86
- throw new Error('Training is already in progress');
87
- }
88
- const { xs, ys } = this.dataManager.convertToTensors();
89
- const jointModel = tf.sequential();
90
- jointModel.add(tf.layers.dense({
91
- units: 32,
92
- activation: 'relu',
93
- inputShape: [xs.shape[1]],
94
- kernelRegularizer: tf.regularizers.l2({ l2: 0.01 }) // L2 정규화 추가
95
- }));
96
- jointModel.add(tf.layers.dropout({ rate: 0.5 })); // 드롭아웃 레이어 추가
97
- jointModel.add(tf.layers.dense({
98
- units: 16,
99
- activation: 'relu',
100
- kernelRegularizer: tf.regularizers.l2({ l2: 0.01 }) // L2 정규화 추가
101
- }));
102
- jointModel.add(tf.layers.dropout({ rate: 0.5 })); // 드롭아웃 레이어 추가
103
- jointModel.add(tf.layers.dense({ units: Object.keys(this.dataManager.getLabelMap()).length, activation: 'softmax' }));
104
- jointModel.compile({
105
- optimizer: tf.train.adam(this.learningRate),
106
- loss: 'sparseCategoricalCrossentropy',
107
- metrics: ['accuracy']
108
- });
109
- this.model = jointModel;
110
- this.isRunning = true;
111
- const history = yield jointModel.fit(xs, ys, {
112
- epochs: this.epochs,
113
- batchSize: this.batchSize,
114
- validationSplit: 0.2,
115
- callbacks: {
116
- onEpochEnd: (epoch, logs) => this.onEpochEnd(epoch, logs),
117
- onBatchEnd: (batch, logs) => {
118
- },
119
- onTrainBegin: (logs) => this.onTrainBegin(logs),
120
- onTrainEnd: (logs) => {
121
- this.isRunning = false;
122
- this.isReady = true;
123
- this.onTrainEnd(logs);
124
- },
125
- }
126
- });
127
- return history;
128
- });
129
- }
130
- infer(data) {
131
- return __awaiter(this, void 0, void 0, function* () {
132
- if (!this.isReady || !this.model) {
133
- throw new Error('Model is not ready');
134
- }
135
- // 입력 데이터를 텐서로 변환
136
- const input = tf.tensor2d([data], [1, data.length], 'float32');
137
- try {
138
- // 모델 예측 수행
139
- const prediction = this.model.predict(input);
140
- // 예측 결과 값들을 추출
141
- const values = yield prediction.data();
142
- // 클래스 이름과 확률을 저장할 Map 생성
143
- const classProbabilities = new Map();
144
- const EPSILON = 1e-6; // 매우 작은 값을 표현하기 위한 엡실론
145
- // 라벨 맵을 가져옴
146
- const labelMap = this.dataManager.getLabelMap();
147
- const reverseLabelMap = Object.entries(labelMap).reduce((acc, [key, value]) => {
148
- acc[value] = key;
149
- return acc;
150
- }, {});
151
- // 각 클래스의 확률 계산 및 조정
152
- for (let i = 0; i < values.length; i++) {
153
- let probability = Math.max(0, Math.min(1, values[i])); // 확률 값을 0과 1 사이로 조정
154
- probability = probability < EPSILON ? 0 : probability; // 매우 작은 확률 값을 0으로 간주
155
- const className = reverseLabelMap[i]; // 클래스 이름을 문자열로 가져옴
156
- if (className) {
157
- const existingProbability = classProbabilities.get(className);
158
- if (existingProbability !== undefined) {
159
- classProbabilities.set(className, existingProbability + probability);
160
- }
161
- else {
162
- classProbabilities.set(className, probability);
163
- }
164
- }
165
- }
166
- // 텐서 해제
167
- prediction.dispose();
168
- input.dispose();
169
- console.log('classProbabilities', classProbabilities);
170
- return classProbabilities;
171
- }
172
- catch (error) {
173
- // 텐서 해제
174
- input.dispose();
175
- throw error;
176
- }
177
- });
178
- }
179
- saveModel(handlerOrURL, config) {
180
- return __awaiter(this, void 0, void 0, function* () {
181
- if (!this.model) {
182
- throw new Error('No model to save');
183
- }
184
- yield this.model.save(handlerOrURL, config);
185
- });
186
- }
187
- running() {
188
- return this.isRunning;
189
- }
190
- ready() {
191
- return this.isReady;
192
- }
193
- load({ jsonURL, labels }) {
194
- return __awaiter(this, void 0, void 0, function* () {
195
- this.model = yield tf.loadLayersModel(jsonURL);
196
- this.isReady = true;
197
- // Assuming the labels are provided in the correct order
198
- this.dataManager = new data_manager_1.default();
199
- labels.forEach((label, index) => {
200
- this.dataManager.getLabelMap()[label] = index;
201
- });
202
- });
203
- }
204
- }
205
- exports.default = DataModel;
@@ -1 +0,0 @@
1
- export {};