learning_model 1.0.32 → 1.0.35

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/dist/index.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- import LearningImage from './learning/image';
2
- import LearningMobilenetImage from './learning/mobilenet_image';
3
1
  import LearningMobilenet from './learning/mobilenet';
4
- export { LearningImage, LearningMobilenetImage, LearningMobilenet };
2
+ export { LearningMobilenet };
package/dist/index.js CHANGED
@@ -3,10 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.LearningMobilenet = exports.LearningMobilenetImage = exports.LearningImage = void 0;
7
- const image_1 = __importDefault(require("./learning/image"));
8
- exports.LearningImage = image_1.default;
9
- const mobilenet_image_1 = __importDefault(require("./learning/mobilenet_image"));
10
- exports.LearningMobilenetImage = mobilenet_image_1.default;
6
+ exports.LearningMobilenet = void 0;
11
7
  const mobilenet_1 = __importDefault(require("./learning/mobilenet"));
12
8
  exports.LearningMobilenet = mobilenet_1.default;
@@ -16,5 +16,6 @@ interface LearningInterface {
16
16
  saveModel(handlerOrURL: io.IOHandler | string, config?: io.SaveConfig): Promise<void>;
17
17
  running(): boolean;
18
18
  ready(): boolean;
19
+ load(url: string, labels: string[]): Promise<void>;
19
20
  }
20
21
  export default LearningInterface;
@@ -34,6 +34,7 @@ declare class LearningMobilenet implements LearningInterface {
34
34
  onTrainBegin: (log: any) => void;
35
35
  onTrainEnd: (log: any) => void;
36
36
  onEpochEnd: (epoch: number, logs: any) => void;
37
+ load(url: string, labels: string[]): Promise<void>;
37
38
  addData(label: string, data: any): Promise<void>;
38
39
  init(): Promise<void>;
39
40
  train(): Promise<tf.History>;
@@ -67,6 +67,25 @@ class LearningMobilenet {
67
67
  this.mobilenetModule = null;
68
68
  this.imageTensors = [];
69
69
  }
70
+ //
71
+ // 기존의 모델 로드
72
+ load(url, labels) {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ if (labels.length <= 0) {
75
+ return Promise.reject(new Error('Labels length is 0'));
76
+ }
77
+ try {
78
+ this.model = yield tf.loadLayersModel(url);
79
+ this.labels = labels;
80
+ this.isReady = true;
81
+ this.model.summary();
82
+ }
83
+ catch (error) {
84
+ console.error('Model load failed', error);
85
+ throw error;
86
+ }
87
+ });
88
+ }
70
89
  // 학습 데이타 등록
71
90
  addData(label, data) {
72
91
  return __awaiter(this, void 0, void 0, function* () {
@@ -210,6 +229,7 @@ class LearningMobilenet {
210
229
  console.log('classId', classId, this.labels[classId]);
211
230
  const predictionsData = yield predictions.data(); // 예측 텐서의 데이터를 비동기로 가져옴
212
231
  const classProbabilities = new Map(); // 클래스별 확률 누적값을 저장할 맵
232
+ console.log('predictionsData', predictionsData);
213
233
  const EPSILON = 1e-6; // 매우 작은 값을 표현하기 위한 엡실론
214
234
  for (let i = 0; i < predictionsData.length; i++) {
215
235
  let probability = Math.max(0, Math.min(1, predictionsData[i])); // 확률 값을 0과 1 사이로 조정
@@ -291,13 +311,22 @@ class LearningMobilenet {
291
311
  return __awaiter(this, void 0, void 0, function* () {
292
312
  try {
293
313
  const truncatedModel = yield this.loadModel();
294
- console.log('truncatedModel', truncatedModel, truncatedModel.outputs[0].shape.slice(1));
295
314
  // 입력 이미지 크기에 맞게 모델 구조 수정
296
315
  const model = tf.sequential();
297
- model.add(tf.layers.flatten({
316
+ // 추가적인 합성곱 층
317
+ model.add(tf.layers.conv2d({
318
+ filters: 64,
319
+ kernelSize: 3,
320
+ activation: 'relu',
321
+ padding: 'same',
298
322
  inputShape: truncatedModel.outputs[0].shape.slice(1)
299
323
  }));
324
+ model.add(tf.layers.flatten());
325
+ // 더 깊은 밀집층
326
+ model.add(tf.layers.dense({ units: 100, activation: 'relu' }));
300
327
  model.add(tf.layers.dense({ units: 100, activation: 'relu' }));
328
+ // 드롭아웃 층
329
+ model.add(tf.layers.dropout({ rate: 0.5 }));
301
330
  model.add(tf.layers.dense({ units: this.labels.length, activation: 'softmax' }));
302
331
  const optimizer = tf.train.adam(this.learningRate); // Optimizer를 생성하고 학습률을 설정합니다.
303
332
  model.compile({
@@ -1,4 +1,2 @@
1
- import LearningImage from './learning/image';
2
- import LearningMobilenetImage from './learning/mobilenet_image';
3
1
  import LearningMobilenet from './learning/mobilenet';
4
- export { LearningImage, LearningMobilenetImage, LearningMobilenet };
2
+ export { LearningMobilenet };
@@ -16,5 +16,6 @@ interface LearningInterface {
16
16
  saveModel(handlerOrURL: io.IOHandler | string, config?: io.SaveConfig): Promise<void>;
17
17
  running(): boolean;
18
18
  ready(): boolean;
19
+ load(url: string, labels: string[]): Promise<void>;
19
20
  }
20
21
  export default LearningInterface;
@@ -34,6 +34,7 @@ declare class LearningMobilenet implements LearningInterface {
34
34
  onTrainBegin: (log: any) => void;
35
35
  onTrainEnd: (log: any) => void;
36
36
  onEpochEnd: (epoch: number, logs: any) => void;
37
+ load(url: string, labels: string[]): Promise<void>;
37
38
  addData(label: string, data: any): Promise<void>;
38
39
  init(): Promise<void>;
39
40
  train(): Promise<tf.History>;
package/lib/index.ts CHANGED
@@ -1,5 +1,3 @@
1
- import LearningImage from './learning/image';
2
- import LearningMobilenetImage from './learning/mobilenet_image';
3
- import LearningMobilenet from './learning/mobilenet';
1
+ import LearningMobilenet from './learning/mobilenet';
4
2
 
5
- export { LearningImage, LearningMobilenetImage, LearningMobilenet };
3
+ export { LearningMobilenet };
@@ -43,6 +43,9 @@ interface LearningInterface {
43
43
 
44
44
  // 모델 준비 여부
45
45
  ready(): boolean;
46
+
47
+ // 모델 로드
48
+ load(url: string, labels: string[]): Promise<void>;
46
49
  }
47
50
 
48
51
  export default LearningInterface;
@@ -65,6 +65,25 @@ class LearningMobilenet implements LearningInterface {
65
65
 
66
66
  public onEpochEnd: (epoch: number, logs: any) => void = () => {};
67
67
 
68
+ //
69
+ // 기존의 모델 로드
70
+ public async load(url: string, labels: string[]): Promise<void> {
71
+ if (labels.length <= 0) {
72
+ return Promise.reject(new Error('Labels length is 0'));
73
+ }
74
+
75
+ try {
76
+ this.model = await tf.loadLayersModel(url);
77
+ this.labels = labels;
78
+ this.isReady = true;
79
+ this.model.summary();
80
+ } catch (error) {
81
+ console.error('Model load failed', error);
82
+ throw error;
83
+ }
84
+
85
+ }
86
+
68
87
  // 학습 데이타 등록
69
88
  public async addData(label: string, data: any): Promise<void> {
70
89
  try {
@@ -207,7 +226,8 @@ class LearningMobilenet implements LearningInterface {
207
226
  console.log('classId', classId, this.labels[classId]);
208
227
  const predictionsData = await predictions.data(); // 예측 텐서의 데이터를 비동기로 가져옴
209
228
  const classProbabilities = new Map<string, number>(); // 클래스별 확률 누적값을 저장할 맵
210
-
229
+
230
+ console.log('predictionsData', predictionsData);
211
231
  const EPSILON = 1e-6; // 매우 작은 값을 표현하기 위한 엡실론
212
232
  for (let i = 0; i < predictionsData.length; i++) {
213
233
  let probability = Math.max(0, Math.min(1, predictionsData[i])); // 확률 값을 0과 1 사이로 조정
@@ -293,15 +313,29 @@ class LearningMobilenet implements LearningInterface {
293
313
  private async _createModel(numClasses: number): Promise<tf.Sequential> {
294
314
  try {
295
315
  const truncatedModel = await this.loadModel()
296
- console.log('truncatedModel', truncatedModel, truncatedModel.outputs[0].shape.slice(1));
297
316
  // 입력 이미지 크기에 맞게 모델 구조 수정
298
317
  const model = tf.sequential();
299
- model.add(tf.layers.flatten({
318
+ // 추가적인 합성곱 층
319
+ model.add(tf.layers.conv2d({
320
+ filters: 64,
321
+ kernelSize: 3,
322
+ activation: 'relu',
323
+ padding: 'same',
300
324
  inputShape: truncatedModel.outputs[0].shape.slice(1)
301
325
  }));
326
+
327
+ model.add(tf.layers.flatten());
328
+
329
+ // 더 깊은 밀집층
302
330
  model.add(tf.layers.dense({ units: 100, activation: 'relu' }));
331
+ model.add(tf.layers.dense({ units: 100, activation: 'relu' }));
332
+
333
+ // 드롭아웃 층
334
+ model.add(tf.layers.dropout({ rate: 0.5 }));
335
+
303
336
  model.add(tf.layers.dense({ units: this.labels.length, activation: 'softmax' }));
304
337
 
338
+
305
339
  const optimizer = tf.train.adam(this.learningRate); // Optimizer를 생성하고 학습률을 설정합니다.
306
340
  model.compile({
307
341
  loss: (numClasses === 2) ? 'binaryCrossentropy': 'categoricalCrossentropy',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "learning_model",
3
- "version": "1.0.32",
3
+ "version": "1.0.35",
4
4
  "description": "learning model develop",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,45 +0,0 @@
1
- import * as tf from '@tensorflow/tfjs';
2
- import { io } from '@tensorflow/tfjs-core';
3
- import LearningInterface from './base';
4
- declare class LearningImage implements LearningInterface {
5
- model: tf.LayersModel | null;
6
- epochs: number;
7
- batchSize: number;
8
- learningRate: number;
9
- validateRate: number;
10
- labels: string[];
11
- isRunning: boolean;
12
- isReady: boolean;
13
- isTrainedDone: boolean;
14
- limitSize: number;
15
- trainImages: tf.Tensor3D[];
16
- readonly MOBILE_NET_INPUT_WIDTH = 224;
17
- readonly MOBILE_NET_INPUT_HEIGHT = 224;
18
- readonly MOBILE_NET_INPUT_CHANNEL = 3;
19
- readonly IMAGE_NORMALIZATION_FACTOR = 255;
20
- constructor({ epochs, batchSize, limitSize, learningRate, validateRate, }?: {
21
- modelURL?: string;
22
- epochs?: number;
23
- batchSize?: number;
24
- limitSize?: number;
25
- learningRate?: number;
26
- validateRate?: number;
27
- });
28
- onProgress: (progress: number) => void;
29
- onLoss: (loss: number) => void;
30
- onEvents: (logs: any) => void;
31
- onTrainBegin: (log: any) => void;
32
- onTrainEnd: (log: any) => void;
33
- onEpochEnd: (epoch: number, logs: any) => void;
34
- addData(label: string, data: any): Promise<void>;
35
- train(): Promise<tf.History>;
36
- infer(data: any): Promise<Map<string, number>>;
37
- saveModel(handlerOrURL: io.IOHandler | string, config?: io.SaveConfig): Promise<void>;
38
- running(): boolean;
39
- ready(): boolean;
40
- private _preprocessedTargetData;
41
- private _preprocessedInputData;
42
- private _preprocessData;
43
- private _createModel;
44
- }
45
- export default LearningImage;
@@ -1,285 +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
- Object.defineProperty(exports, "__esModule", { value: true });
35
- const tf = __importStar(require("@tensorflow/tfjs"));
36
- class LearningImage {
37
- constructor({ epochs = 10, batchSize = 16, limitSize = 2, learningRate = 0.001, validateRate = 0.2, } = {}) {
38
- this.trainImages = [];
39
- this.MOBILE_NET_INPUT_WIDTH = 224;
40
- this.MOBILE_NET_INPUT_HEIGHT = 224;
41
- this.MOBILE_NET_INPUT_CHANNEL = 3;
42
- this.IMAGE_NORMALIZATION_FACTOR = 255.0;
43
- this.onProgress = () => { };
44
- this.onLoss = () => { };
45
- this.onEvents = () => { };
46
- this.onTrainBegin = () => { };
47
- this.onTrainEnd = () => { };
48
- this.onEpochEnd = () => { };
49
- this.model = null;
50
- this.epochs = epochs;
51
- this.batchSize = batchSize;
52
- this.learningRate = learningRate;
53
- this.validateRate = validateRate;
54
- this.labels = [];
55
- this.isRunning = false;
56
- this.isReady = false;
57
- this.isTrainedDone = false;
58
- this.limitSize = 2;
59
- }
60
- // 학습 데이타 등록
61
- addData(label, data) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- try {
64
- const tensor = tf.browser.fromPixels(data);
65
- console.log('addData', tensor);
66
- this.trainImages.push(tensor);
67
- this.labels.push(label);
68
- if (this.labels.length >= this.limitSize) {
69
- this.isReady = true;
70
- }
71
- return Promise.resolve();
72
- }
73
- catch (error) {
74
- console.error('Model training failed', error);
75
- throw error;
76
- }
77
- });
78
- }
79
- // 모델 학습 처리
80
- train() {
81
- return __awaiter(this, void 0, void 0, function* () {
82
- if (this.isRunning) {
83
- return Promise.reject(new Error('Training is already in progress.'));
84
- }
85
- // 콜백 정의
86
- const customCallback = {
87
- onTrainBegin: (log) => {
88
- this.isTrainedDone = false;
89
- this.onTrainBegin(log);
90
- console.log('Training has started.');
91
- },
92
- onTrainEnd: (log) => {
93
- this.isTrainedDone = true;
94
- this.onTrainEnd(log);
95
- console.log('Training has ended.');
96
- this.isRunning = false;
97
- },
98
- onBatchBegin: (batch, logs) => {
99
- console.log(`Batch ${batch} is starting.`);
100
- },
101
- onBatchEnd: (batch, logs) => {
102
- console.log(`Batch ${batch} has ended.`);
103
- },
104
- onEpochBegin: (epoch, logs) => {
105
- console.log(`Epoch ${epoch + 1} is starting.`, logs);
106
- },
107
- onEpochEnd: (epoch, logs) => {
108
- console.log(`Epoch ${epoch + 1} has ended.`);
109
- this.onLoss(logs.loss);
110
- console.log('Loss:', logs);
111
- this.onEvents(logs);
112
- this.onProgress(epoch + 1);
113
- }
114
- };
115
- try {
116
- this.isRunning = true;
117
- if (this.labels.length < this.limitSize) {
118
- return Promise.reject(new Error('Please train Data need over 2 data length'));
119
- }
120
- this.model = yield this._createModel(this.labels.length);
121
- const inputData = this._preprocessedInputData(this.model);
122
- console.log('inputData', inputData);
123
- const targetData = this._preprocessedTargetData();
124
- console.log('targetData', targetData);
125
- const history = yield this.model.fit(inputData, targetData, {
126
- epochs: this.epochs,
127
- batchSize: this.batchSize,
128
- validationSplit: this.validateRate,
129
- callbacks: customCallback
130
- });
131
- console.log('Model training completed', history);
132
- return history;
133
- }
134
- catch (error) {
135
- this.isRunning = false;
136
- console.error('Model training failed', error);
137
- throw error;
138
- }
139
- });
140
- }
141
- // 추론하기
142
- infer(data) {
143
- return __awaiter(this, void 0, void 0, function* () {
144
- if (this.model === null) {
145
- throw new Error('Model is null');
146
- }
147
- try {
148
- const tensor = tf.browser.fromPixels(data);
149
- const resizedTensor = tf.image.resizeBilinear(tensor, [this.MOBILE_NET_INPUT_WIDTH, this.MOBILE_NET_INPUT_HEIGHT]);
150
- const reshapedTensor = resizedTensor.expandDims(0); // 배치 크기 1을 추가하여 4차원으로 변환
151
- const predictions = this.model.predict(reshapedTensor);
152
- const predictionsData = yield predictions.data(); // 예측 텐서의 데이터를 비동기로 가져옴
153
- const classProbabilities = new Map(); // 클래스별 확률 누적값을 저장할 맵
154
- for (let i = 0; i < predictionsData.length; i++) {
155
- const className = this.labels[i]; // 클래스 이름
156
- const probability = predictionsData[i];
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
- console.log('Class Probabilities:', classProbabilities);
166
- return classProbabilities;
167
- }
168
- catch (error) {
169
- throw error;
170
- }
171
- });
172
- }
173
- // 모델 저장
174
- saveModel(handlerOrURL, config) {
175
- var _a;
176
- return __awaiter(this, void 0, void 0, function* () {
177
- console.log('saved model');
178
- if (!this.isTrainedDone) {
179
- return Promise.reject(new Error('Train is not done status'));
180
- }
181
- yield ((_a = this.model) === null || _a === void 0 ? void 0 : _a.save(handlerOrURL, config));
182
- });
183
- }
184
- // 진행중 여부
185
- running() {
186
- return this.isRunning;
187
- }
188
- ready() {
189
- return this.isReady;
190
- }
191
- // target 라벨 데이타
192
- _preprocessedTargetData() {
193
- // 라벨 unique 처리 & 배열 리턴
194
- console.log('uniqueLabels.length', this.labels, this.labels.length);
195
- const labelIndices = this.labels.map((label) => this.labels.indexOf(label));
196
- console.log('labelIndices', labelIndices);
197
- const oneHotEncode = tf.oneHot(tf.tensor1d(labelIndices, 'int32'), this.labels.length);
198
- console.log('oneHotEncode', oneHotEncode);
199
- return oneHotEncode;
200
- }
201
- // 입력 이미지 데이타
202
- _preprocessedInputData(model) {
203
- // 이미지 배열을 배치로 변환 - [null, 224, 224, 3]
204
- const inputShape = model.inputs[0].shape;
205
- console.log('inputShape', inputShape);
206
- // inputShape를 이와 같이 포멧 맞춘다. for reshape to [224, 224, 3]
207
- const inputShapeArray = inputShape.slice(1);
208
- console.log('inputShapeArray', inputShapeArray);
209
- const inputBatch = tf.stack(this.trainImages.map((image) => {
210
- // 이미지 전처리 및 크기 조정 등을 수행한 후에
211
- // 모델의 입력 형태로 변환하여 반환
212
- const xs = this._preprocessData(image); // 전처리 함수는 사용자 정의해야 함
213
- return tf.reshape(xs, inputShapeArray);
214
- }));
215
- return inputBatch;
216
- }
217
- // 모델 학습하기 위한 데이타 전처리 단계
218
- _preprocessData(tensor) {
219
- try {
220
- // mobilenet model summary를 하면 위와 같이 224,224 사이즈의 입력값 설정되어 있다. ex) input_1 (InputLayer) [null,224,224,3]
221
- const resizedImage = tf.image.resizeBilinear(tensor, [this.MOBILE_NET_INPUT_WIDTH, this.MOBILE_NET_INPUT_HEIGHT]);
222
- // 이미지를 [0,1] 범위로 정규화 255로 나뉜 픽셀값
223
- const normalizedImage = resizedImage.div(this.IMAGE_NORMALIZATION_FACTOR);
224
- // expandDims(0)을 하여 차원을 추가하여 4D텐서 반환
225
- return normalizedImage.expandDims(0);
226
- }
227
- catch (error) {
228
- console.error('Failed to _preprocessData data', error);
229
- throw error;
230
- }
231
- }
232
- // 모델 저장
233
- _createModel(numClasses) {
234
- return __awaiter(this, void 0, void 0, function* () {
235
- try {
236
- const inputShape = [this.MOBILE_NET_INPUT_WIDTH, this.MOBILE_NET_INPUT_HEIGHT, this.MOBILE_NET_INPUT_CHANNEL];
237
- const model = tf.sequential();
238
- model.add(tf.layers.conv2d({
239
- activation: "relu",
240
- filters: 32,
241
- inputShape: inputShape,
242
- kernelSize: 3,
243
- }));
244
- model.add(tf.layers.conv2d({
245
- activation: "relu",
246
- filters: 32,
247
- kernelSize: 3,
248
- }));
249
- model.add(tf.layers.maxPooling2d({ poolSize: [2, 2] }));
250
- model.add(tf.layers.conv2d({
251
- activation: "relu",
252
- filters: 64,
253
- kernelSize: 3,
254
- }));
255
- model.add(tf.layers.conv2d({
256
- activation: "relu",
257
- filters: 64,
258
- kernelSize: 3,
259
- }));
260
- model.add(tf.layers.maxPooling2d({ poolSize: [2, 2] }));
261
- model.add(tf.layers.flatten());
262
- model.add(tf.layers.dropout({ rate: 0.25 }));
263
- model.add(tf.layers.dense({ units: 512, activation: "relu" }));
264
- model.add(tf.layers.dropout({ rate: 0.5 }));
265
- model.add(tf.layers.dense({
266
- units: numClasses,
267
- activation: 'softmax'
268
- }));
269
- const optimizer = tf.train.adam(this.learningRate); // Optimizer를 생성하고 학습률을 설정합니다.
270
- model.compile({
271
- loss: (numClasses === 2) ? 'binaryCrossentropy' : 'categoricalCrossentropy',
272
- optimizer: optimizer,
273
- metrics: ['accuracy', 'acc']
274
- });
275
- model.summary();
276
- return model;
277
- }
278
- catch (error) {
279
- console.error('Failed to load model', error);
280
- throw error;
281
- }
282
- });
283
- }
284
- }
285
- exports.default = LearningImage;
@@ -1,47 +0,0 @@
1
- import * as tf from '@tensorflow/tfjs';
2
- import { io } from '@tensorflow/tfjs-core';
3
- import LearningInterface from './base';
4
- declare class LearningMobilenetImage implements LearningInterface {
5
- model: tf.LayersModel | null;
6
- epochs: number;
7
- batchSize: number;
8
- learningRate: number;
9
- validateRate: number;
10
- labels: string[];
11
- modelURL: string;
12
- isRunning: boolean;
13
- isReady: boolean;
14
- isTrainedDone: boolean;
15
- limitSize: number;
16
- trainImages: tf.Tensor3D[];
17
- readonly MOBILE_NET_INPUT_WIDTH = 224;
18
- readonly MOBILE_NET_INPUT_HEIGHT = 224;
19
- readonly MOBILE_NET_INPUT_CHANNEL = 3;
20
- readonly IMAGE_NORMALIZATION_FACTOR = 255;
21
- constructor({ modelURL, // 디폴트 mobilenet 이미지
22
- epochs, batchSize, limitSize, learningRate, validateRate, }?: {
23
- modelURL?: string;
24
- epochs?: number;
25
- batchSize?: number;
26
- limitSize?: number;
27
- learningRate?: number;
28
- validateRate?: number;
29
- });
30
- onProgress: (progress: number) => void;
31
- onLoss: (loss: number) => void;
32
- onEvents: (logs: any) => void;
33
- onTrainBegin: (log: any) => void;
34
- onTrainEnd: (log: any) => void;
35
- onEpochEnd: (epoch: number, logs: any) => void;
36
- addData(label: string, data: any): Promise<void>;
37
- train(): Promise<tf.History>;
38
- infer(data: any): Promise<Map<string, number>>;
39
- saveModel(handlerOrURL: io.IOHandler | string, config?: io.SaveConfig): Promise<void>;
40
- running(): boolean;
41
- ready(): boolean;
42
- private _preprocessedTargetData;
43
- private _preprocessedInputData;
44
- private _preprocessData;
45
- private _createModel;
46
- }
47
- export default LearningMobilenetImage;