learning_model 1.0.25 → 1.0.26

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.
@@ -12,7 +12,7 @@ interface LearningInterface {
12
12
  addData(label: string, data: any): Promise<void>;
13
13
  train(): Promise<tf.History>;
14
14
  infer(data: any): Promise<any>;
15
- saveModel(): void;
15
+ saveModel(): Promise<void>;
16
16
  running(): boolean;
17
17
  ready(): boolean;
18
18
  }
@@ -9,6 +9,7 @@ declare class LearningImage implements LearningInterface {
9
9
  labels: string[];
10
10
  isRunning: boolean;
11
11
  isReady: boolean;
12
+ isTrainedDone: boolean;
12
13
  limitSize: number;
13
14
  trainImages: tf.Tensor3D[];
14
15
  readonly MOBILE_NET_INPUT_WIDTH = 224;
@@ -31,7 +32,7 @@ declare class LearningImage implements LearningInterface {
31
32
  addData(label: string, data: any): Promise<void>;
32
33
  train(): Promise<tf.History>;
33
34
  infer(data: any): Promise<Map<string, number>>;
34
- saveModel(): void;
35
+ saveModel(): Promise<void>;
35
36
  running(): boolean;
36
37
  ready(): boolean;
37
38
  private _preprocessedTargetData;
@@ -53,6 +53,7 @@ class LearningImage {
53
53
  this.labels = [];
54
54
  this.isRunning = false;
55
55
  this.isReady = false;
56
+ this.isTrainedDone = false;
56
57
  this.limitSize = 2;
57
58
  }
58
59
  // 학습 데이타 등록
@@ -83,10 +84,12 @@ class LearningImage {
83
84
  // 콜백 정의
84
85
  const customCallback = {
85
86
  onTrainBegin: (log) => {
87
+ this.isTrainedDone = false;
86
88
  this.onTrainBegin(log);
87
89
  console.log('Training has started.');
88
90
  },
89
91
  onTrainEnd: (log) => {
92
+ this.isTrainedDone = true;
90
93
  this.onTrainEnd(log);
91
94
  console.log('Training has ended.');
92
95
  this.isRunning = false;
@@ -168,7 +171,14 @@ class LearningImage {
168
171
  }
169
172
  // 모델 저장
170
173
  saveModel() {
171
- console.log('saved model');
174
+ var _a;
175
+ return __awaiter(this, void 0, void 0, function* () {
176
+ console.log('saved model');
177
+ if (!this.isTrainedDone) {
178
+ return Promise.reject(new Error('Train is not done status'));
179
+ }
180
+ yield ((_a = this.model) === null || _a === void 0 ? void 0 : _a.save('localstorage://my-model'));
181
+ });
172
182
  }
173
183
  // 진행중 여부
174
184
  running() {
@@ -10,6 +10,7 @@ declare class LearningMobilenetImage implements LearningInterface {
10
10
  modelURL: string;
11
11
  isRunning: boolean;
12
12
  isReady: boolean;
13
+ isTrainedDone: boolean;
13
14
  limitSize: number;
14
15
  trainImages: tf.Tensor3D[];
15
16
  readonly MOBILE_NET_INPUT_WIDTH = 224;
@@ -33,7 +34,7 @@ declare class LearningMobilenetImage implements LearningInterface {
33
34
  addData(label: string, data: any): Promise<void>;
34
35
  train(): Promise<tf.History>;
35
36
  infer(data: any): Promise<Map<string, number>>;
36
- saveModel(): void;
37
+ saveModel(): Promise<void>;
37
38
  running(): boolean;
38
39
  ready(): boolean;
39
40
  private _preprocessedTargetData;
@@ -62,6 +62,7 @@ class LearningMobilenetImage {
62
62
  this.modelURL = modelURL;
63
63
  this.isRunning = false;
64
64
  this.isReady = false;
65
+ this.isTrainedDone = false;
65
66
  this.limitSize = limitSize;
66
67
  }
67
68
  // 학습 데이타 등록
@@ -92,10 +93,12 @@ class LearningMobilenetImage {
92
93
  // 콜백 정의
93
94
  const customCallback = {
94
95
  onTrainBegin: (log) => {
96
+ this.isTrainedDone = false;
95
97
  this.onTrainBegin(log);
96
98
  console.log('Training has started.');
97
99
  },
98
100
  onTrainEnd: (log) => {
101
+ this.isTrainedDone = true;
99
102
  this.onTrainEnd(log);
100
103
  console.log('Training has ended.');
101
104
  this.isRunning = false;
@@ -175,7 +178,14 @@ class LearningMobilenetImage {
175
178
  }
176
179
  // 모델 저장
177
180
  saveModel() {
178
- console.log('saved model');
181
+ var _a;
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ console.log('saved model');
184
+ if (!this.isTrainedDone) {
185
+ return Promise.reject(new Error('Train is not done status'));
186
+ }
187
+ yield ((_a = this.model) === null || _a === void 0 ? void 0 : _a.save('localstorage://my-model'));
188
+ });
179
189
  }
180
190
  // 진행중 여부
181
191
  running() {
@@ -12,7 +12,7 @@ interface LearningInterface {
12
12
  addData(label: string, data: any): Promise<void>;
13
13
  train(): Promise<tf.History>;
14
14
  infer(data: any): Promise<any>;
15
- saveModel(): void;
15
+ saveModel(): Promise<void>;
16
16
  running(): boolean;
17
17
  ready(): boolean;
18
18
  }
@@ -9,6 +9,7 @@ declare class LearningImage implements LearningInterface {
9
9
  labels: string[];
10
10
  isRunning: boolean;
11
11
  isReady: boolean;
12
+ isTrainedDone: boolean;
12
13
  limitSize: number;
13
14
  trainImages: tf.Tensor3D[];
14
15
  readonly MOBILE_NET_INPUT_WIDTH = 224;
@@ -31,7 +32,7 @@ declare class LearningImage implements LearningInterface {
31
32
  addData(label: string, data: any): Promise<void>;
32
33
  train(): Promise<tf.History>;
33
34
  infer(data: any): Promise<Map<string, number>>;
34
- saveModel(): void;
35
+ saveModel(): Promise<void>;
35
36
  running(): boolean;
36
37
  ready(): boolean;
37
38
  private _preprocessedTargetData;
@@ -10,6 +10,7 @@ declare class LearningMobilenetImage implements LearningInterface {
10
10
  modelURL: string;
11
11
  isRunning: boolean;
12
12
  isReady: boolean;
13
+ isTrainedDone: boolean;
13
14
  limitSize: number;
14
15
  trainImages: tf.Tensor3D[];
15
16
  readonly MOBILE_NET_INPUT_WIDTH = 224;
@@ -33,7 +34,7 @@ declare class LearningMobilenetImage implements LearningInterface {
33
34
  addData(label: string, data: any): Promise<void>;
34
35
  train(): Promise<tf.History>;
35
36
  infer(data: any): Promise<Map<string, number>>;
36
- saveModel(): void;
37
+ saveModel(): Promise<void>;
37
38
  running(): boolean;
38
39
  ready(): boolean;
39
40
  private _preprocessedTargetData;
@@ -36,7 +36,7 @@ interface LearningInterface {
36
36
  infer(data: any): Promise<any>;
37
37
 
38
38
  // 모델 저장
39
- saveModel(): void;
39
+ saveModel(): Promise<void>;
40
40
 
41
41
  // 학습 진행 여부
42
42
  running(): boolean;
@@ -10,6 +10,7 @@ class LearningImage implements LearningInterface {
10
10
  labels: string[];
11
11
  isRunning: boolean;
12
12
  isReady: boolean;
13
+ isTrainedDone: boolean;
13
14
  limitSize: number;
14
15
  trainImages: tf.Tensor3D[] = [];
15
16
 
@@ -33,6 +34,7 @@ class LearningImage implements LearningInterface {
33
34
  this.labels = [];
34
35
  this.isRunning = false;
35
36
  this.isReady = false;
37
+ this.isTrainedDone = false;
36
38
  this.limitSize = 2;
37
39
  }
38
40
 
@@ -72,10 +74,12 @@ class LearningImage implements LearningInterface {
72
74
  // 콜백 정의
73
75
  const customCallback = {
74
76
  onTrainBegin: (log: any) => {
77
+ this.isTrainedDone = false;
75
78
  this.onTrainBegin(log);
76
79
  console.log('Training has started.');
77
80
  },
78
81
  onTrainEnd: (log: any) => {
82
+ this.isTrainedDone = true;
79
83
  this.onTrainEnd(log);
80
84
  console.log('Training has ended.');
81
85
  this.isRunning = false;
@@ -155,8 +159,12 @@ class LearningImage implements LearningInterface {
155
159
 
156
160
 
157
161
  // 모델 저장
158
- public saveModel(): void {
162
+ public async saveModel(): Promise<void> {
159
163
  console.log('saved model');
164
+ if (!this.isTrainedDone) {
165
+ return Promise.reject(new Error('Train is not done status'));
166
+ }
167
+ await this.model?.save('localstorage://my-model');
160
168
  }
161
169
 
162
170
 
@@ -18,6 +18,7 @@ class LearningMobilenetImage implements LearningInterface {
18
18
  modelURL: string;
19
19
  isRunning: boolean;
20
20
  isReady: boolean;
21
+ isTrainedDone: boolean;
21
22
  limitSize: number;
22
23
  trainImages: tf.Tensor3D[] = [];
23
24
 
@@ -43,6 +44,7 @@ class LearningMobilenetImage implements LearningInterface {
43
44
  this.modelURL = modelURL;
44
45
  this.isRunning = false;
45
46
  this.isReady = false;
47
+ this.isTrainedDone = false;
46
48
  this.limitSize = limitSize;
47
49
  }
48
50
 
@@ -84,10 +86,12 @@ class LearningMobilenetImage implements LearningInterface {
84
86
  // 콜백 정의
85
87
  const customCallback = {
86
88
  onTrainBegin: (log: any) => {
89
+ this.isTrainedDone = false;
87
90
  this.onTrainBegin(log);
88
91
  console.log('Training has started.');
89
92
  },
90
93
  onTrainEnd: (log: any) => {
94
+ this.isTrainedDone = true;
91
95
  this.onTrainEnd(log);
92
96
  console.log('Training has ended.');
93
97
  this.isRunning = false;
@@ -162,14 +166,19 @@ class LearningMobilenetImage implements LearningInterface {
162
166
  throw error;
163
167
  }
164
168
  }
165
-
166
169
 
170
+
167
171
  // 모델 저장
168
- public saveModel(): void {
172
+ public async saveModel(): Promise<void> {
169
173
  console.log('saved model');
174
+ if (!this.isTrainedDone) {
175
+ return Promise.reject(new Error('Train is not done status'));
176
+ }
177
+ await this.model?.save('localstorage://my-model');
170
178
  }
171
179
 
172
180
 
181
+
173
182
  // 진행중 여부
174
183
  public running(): boolean {
175
184
  return this.isRunning;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "learning_model",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "description": "learning model develop",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",