learning_model 1.0.25 → 1.0.28
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.bundle.js +1 -1
- package/dist/learning/base.d.ts +1 -1
- package/dist/learning/image.d.ts +2 -1
- package/dist/learning/image.js +16 -3
- package/dist/learning/mobilenet_image.d.ts +2 -1
- package/dist/learning/mobilenet_image.js +15 -3
- package/dist/lib/learning/base.d.ts +1 -1
- package/dist/lib/learning/image.d.ts +2 -1
- package/dist/lib/learning/mobilenet_image.d.ts +2 -1
- package/lib/learning/base.ts +1 -1
- package/lib/learning/image.ts +14 -3
- package/lib/learning/mobilenet_image.ts +15 -4
- package/package.json +1 -1
- package/yarn-error.log +5746 -0
package/dist/learning/base.d.ts
CHANGED
package/dist/learning/image.d.ts
CHANGED
|
@@ -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;
|
package/dist/learning/image.js
CHANGED
|
@@ -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;
|
|
@@ -137,6 +140,7 @@ class LearningImage {
|
|
|
137
140
|
// 추론하기
|
|
138
141
|
infer(data) {
|
|
139
142
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
const threshold = 1e-20; // 임계값 설정
|
|
140
144
|
if (this.model === null) {
|
|
141
145
|
throw new Error('Model is null');
|
|
142
146
|
}
|
|
@@ -147,15 +151,17 @@ class LearningImage {
|
|
|
147
151
|
const predictions = this.model.predict(reshapedTensor);
|
|
148
152
|
const predictionsData = yield predictions.data(); // 예측 텐서의 데이터를 비동기로 가져옴
|
|
149
153
|
const classProbabilities = new Map(); // 클래스별 확률 누적값을 저장할 맵
|
|
154
|
+
console.log('predictionsData', predictionsData);
|
|
150
155
|
for (let i = 0; i < predictionsData.length; i++) {
|
|
151
156
|
const className = this.labels[i]; // 클래스 이름
|
|
152
157
|
const probability = predictionsData[i];
|
|
158
|
+
const result = Math.abs(probability) < threshold ? 0 : probability;
|
|
153
159
|
const existingProbability = classProbabilities.get(className);
|
|
154
160
|
if (existingProbability !== undefined) {
|
|
155
|
-
classProbabilities.set(className, existingProbability +
|
|
161
|
+
classProbabilities.set(className, existingProbability + result);
|
|
156
162
|
}
|
|
157
163
|
else {
|
|
158
|
-
classProbabilities.set(className,
|
|
164
|
+
classProbabilities.set(className, result);
|
|
159
165
|
}
|
|
160
166
|
}
|
|
161
167
|
console.log('Class Probabilities:', classProbabilities);
|
|
@@ -168,7 +174,14 @@ class LearningImage {
|
|
|
168
174
|
}
|
|
169
175
|
// 모델 저장
|
|
170
176
|
saveModel() {
|
|
171
|
-
|
|
177
|
+
var _a;
|
|
178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
console.log('saved model');
|
|
180
|
+
if (!this.isTrainedDone) {
|
|
181
|
+
return Promise.reject(new Error('Train is not done status'));
|
|
182
|
+
}
|
|
183
|
+
yield ((_a = this.model) === null || _a === void 0 ? void 0 : _a.save('localstorage://my-model'));
|
|
184
|
+
});
|
|
172
185
|
}
|
|
173
186
|
// 진행중 여부
|
|
174
187
|
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;
|
|
@@ -144,6 +147,7 @@ class LearningMobilenetImage {
|
|
|
144
147
|
// 추론하기
|
|
145
148
|
infer(data) {
|
|
146
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
const threshold = 1e-20; // 임계값 설정
|
|
147
151
|
if (this.model === null) {
|
|
148
152
|
return Promise.reject(new Error('Model is Null'));
|
|
149
153
|
}
|
|
@@ -157,12 +161,13 @@ class LearningMobilenetImage {
|
|
|
157
161
|
for (let i = 0; i < predictionsData.length; i++) {
|
|
158
162
|
const className = this.labels[i]; // 클래스 이름
|
|
159
163
|
const probability = predictionsData[i];
|
|
164
|
+
const result = Math.abs(probability) < threshold ? 0 : probability;
|
|
160
165
|
const existingProbability = classProbabilities.get(className);
|
|
161
166
|
if (existingProbability !== undefined) {
|
|
162
|
-
classProbabilities.set(className, existingProbability +
|
|
167
|
+
classProbabilities.set(className, existingProbability + result);
|
|
163
168
|
}
|
|
164
169
|
else {
|
|
165
|
-
classProbabilities.set(className,
|
|
170
|
+
classProbabilities.set(className, result);
|
|
166
171
|
}
|
|
167
172
|
}
|
|
168
173
|
console.log('Class Probabilities:', classProbabilities);
|
|
@@ -175,7 +180,14 @@ class LearningMobilenetImage {
|
|
|
175
180
|
}
|
|
176
181
|
// 모델 저장
|
|
177
182
|
saveModel() {
|
|
178
|
-
|
|
183
|
+
var _a;
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
console.log('saved model');
|
|
186
|
+
if (!this.isTrainedDone) {
|
|
187
|
+
return Promise.reject(new Error('Train is not done status'));
|
|
188
|
+
}
|
|
189
|
+
yield ((_a = this.model) === null || _a === void 0 ? void 0 : _a.save('localstorage://my-model'));
|
|
190
|
+
});
|
|
179
191
|
}
|
|
180
192
|
// 진행중 여부
|
|
181
193
|
running() {
|
|
@@ -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;
|
package/lib/learning/base.ts
CHANGED
package/lib/learning/image.ts
CHANGED
|
@@ -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;
|
|
@@ -125,6 +129,7 @@ class LearningImage implements LearningInterface {
|
|
|
125
129
|
|
|
126
130
|
// 추론하기
|
|
127
131
|
public async infer(data: any): Promise<Map<string, number>> {
|
|
132
|
+
const threshold = 1e-20; // 임계값 설정
|
|
128
133
|
if (this.model === null) {
|
|
129
134
|
throw new Error('Model is null');
|
|
130
135
|
}
|
|
@@ -136,14 +141,16 @@ class LearningImage implements LearningInterface {
|
|
|
136
141
|
const predictions = this.model.predict(reshapedTensor) as tf.Tensor;
|
|
137
142
|
const predictionsData = await predictions.data(); // 예측 텐서의 데이터를 비동기로 가져옴
|
|
138
143
|
const classProbabilities = new Map<string, number>(); // 클래스별 확률 누적값을 저장할 맵
|
|
144
|
+
console.log('predictionsData', predictionsData);
|
|
139
145
|
for (let i = 0; i < predictionsData.length; i++) {
|
|
140
146
|
const className = this.labels[i]; // 클래스 이름
|
|
141
147
|
const probability = predictionsData[i];
|
|
148
|
+
const result = Math.abs(probability) < threshold ? 0 : probability;
|
|
142
149
|
const existingProbability = classProbabilities.get(className);
|
|
143
150
|
if (existingProbability !== undefined) {
|
|
144
|
-
classProbabilities.set(className, existingProbability +
|
|
151
|
+
classProbabilities.set(className, existingProbability + result);
|
|
145
152
|
} else {
|
|
146
|
-
classProbabilities.set(className,
|
|
153
|
+
classProbabilities.set(className, result);
|
|
147
154
|
}
|
|
148
155
|
}
|
|
149
156
|
console.log('Class Probabilities:', classProbabilities);
|
|
@@ -155,8 +162,12 @@ class LearningImage implements LearningInterface {
|
|
|
155
162
|
|
|
156
163
|
|
|
157
164
|
// 모델 저장
|
|
158
|
-
public saveModel(): void {
|
|
165
|
+
public async saveModel(): Promise<void> {
|
|
159
166
|
console.log('saved model');
|
|
167
|
+
if (!this.isTrainedDone) {
|
|
168
|
+
return Promise.reject(new Error('Train is not done status'));
|
|
169
|
+
}
|
|
170
|
+
await this.model?.save('localstorage://my-model');
|
|
160
171
|
}
|
|
161
172
|
|
|
162
173
|
|
|
@@ -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;
|
|
@@ -135,6 +139,7 @@ class LearningMobilenetImage implements LearningInterface {
|
|
|
135
139
|
|
|
136
140
|
// 추론하기
|
|
137
141
|
public async infer(data: any): Promise<Map<string, number>> {
|
|
142
|
+
const threshold = 1e-20; // 임계값 설정
|
|
138
143
|
if (this.model === null) {
|
|
139
144
|
return Promise.reject(new Error('Model is Null'));
|
|
140
145
|
}
|
|
@@ -149,11 +154,12 @@ class LearningMobilenetImage implements LearningInterface {
|
|
|
149
154
|
for (let i = 0; i < predictionsData.length; i++) {
|
|
150
155
|
const className = this.labels[i]; // 클래스 이름
|
|
151
156
|
const probability = predictionsData[i];
|
|
157
|
+
const result = Math.abs(probability) < threshold ? 0 : probability;
|
|
152
158
|
const existingProbability = classProbabilities.get(className);
|
|
153
159
|
if (existingProbability !== undefined) {
|
|
154
|
-
classProbabilities.set(className, existingProbability +
|
|
160
|
+
classProbabilities.set(className, existingProbability + result);
|
|
155
161
|
} else {
|
|
156
|
-
classProbabilities.set(className,
|
|
162
|
+
classProbabilities.set(className, result);
|
|
157
163
|
}
|
|
158
164
|
}
|
|
159
165
|
console.log('Class Probabilities:', classProbabilities);
|
|
@@ -162,14 +168,19 @@ class LearningMobilenetImage implements LearningInterface {
|
|
|
162
168
|
throw error;
|
|
163
169
|
}
|
|
164
170
|
}
|
|
165
|
-
|
|
166
171
|
|
|
172
|
+
|
|
167
173
|
// 모델 저장
|
|
168
|
-
public saveModel(): void {
|
|
174
|
+
public async saveModel(): Promise<void> {
|
|
169
175
|
console.log('saved model');
|
|
176
|
+
if (!this.isTrainedDone) {
|
|
177
|
+
return Promise.reject(new Error('Train is not done status'));
|
|
178
|
+
}
|
|
179
|
+
await this.model?.save('localstorage://my-model');
|
|
170
180
|
}
|
|
171
181
|
|
|
172
182
|
|
|
183
|
+
|
|
173
184
|
// 진행중 여부
|
|
174
185
|
public running(): boolean {
|
|
175
186
|
return this.isRunning;
|