learning_model 1.0.26 → 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.
@@ -140,6 +140,7 @@ class LearningImage {
140
140
  // 추론하기
141
141
  infer(data) {
142
142
  return __awaiter(this, void 0, void 0, function* () {
143
+ const threshold = 1e-20; // 임계값 설정
143
144
  if (this.model === null) {
144
145
  throw new Error('Model is null');
145
146
  }
@@ -150,15 +151,17 @@ class LearningImage {
150
151
  const predictions = this.model.predict(reshapedTensor);
151
152
  const predictionsData = yield predictions.data(); // 예측 텐서의 데이터를 비동기로 가져옴
152
153
  const classProbabilities = new Map(); // 클래스별 확률 누적값을 저장할 맵
154
+ console.log('predictionsData', predictionsData);
153
155
  for (let i = 0; i < predictionsData.length; i++) {
154
156
  const className = this.labels[i]; // 클래스 이름
155
157
  const probability = predictionsData[i];
158
+ const result = Math.abs(probability) < threshold ? 0 : probability;
156
159
  const existingProbability = classProbabilities.get(className);
157
160
  if (existingProbability !== undefined) {
158
- classProbabilities.set(className, existingProbability + probability);
161
+ classProbabilities.set(className, existingProbability + result);
159
162
  }
160
163
  else {
161
- classProbabilities.set(className, probability);
164
+ classProbabilities.set(className, result);
162
165
  }
163
166
  }
164
167
  console.log('Class Probabilities:', classProbabilities);
@@ -147,6 +147,7 @@ class LearningMobilenetImage {
147
147
  // 추론하기
148
148
  infer(data) {
149
149
  return __awaiter(this, void 0, void 0, function* () {
150
+ const threshold = 1e-20; // 임계값 설정
150
151
  if (this.model === null) {
151
152
  return Promise.reject(new Error('Model is Null'));
152
153
  }
@@ -160,12 +161,13 @@ class LearningMobilenetImage {
160
161
  for (let i = 0; i < predictionsData.length; i++) {
161
162
  const className = this.labels[i]; // 클래스 이름
162
163
  const probability = predictionsData[i];
164
+ const result = Math.abs(probability) < threshold ? 0 : probability;
163
165
  const existingProbability = classProbabilities.get(className);
164
166
  if (existingProbability !== undefined) {
165
- classProbabilities.set(className, existingProbability + probability);
167
+ classProbabilities.set(className, existingProbability + result);
166
168
  }
167
169
  else {
168
- classProbabilities.set(className, probability);
170
+ classProbabilities.set(className, result);
169
171
  }
170
172
  }
171
173
  console.log('Class Probabilities:', classProbabilities);
@@ -129,6 +129,7 @@ class LearningImage implements LearningInterface {
129
129
 
130
130
  // 추론하기
131
131
  public async infer(data: any): Promise<Map<string, number>> {
132
+ const threshold = 1e-20; // 임계값 설정
132
133
  if (this.model === null) {
133
134
  throw new Error('Model is null');
134
135
  }
@@ -140,14 +141,16 @@ class LearningImage implements LearningInterface {
140
141
  const predictions = this.model.predict(reshapedTensor) as tf.Tensor;
141
142
  const predictionsData = await predictions.data(); // 예측 텐서의 데이터를 비동기로 가져옴
142
143
  const classProbabilities = new Map<string, number>(); // 클래스별 확률 누적값을 저장할 맵
144
+ console.log('predictionsData', predictionsData);
143
145
  for (let i = 0; i < predictionsData.length; i++) {
144
146
  const className = this.labels[i]; // 클래스 이름
145
147
  const probability = predictionsData[i];
148
+ const result = Math.abs(probability) < threshold ? 0 : probability;
146
149
  const existingProbability = classProbabilities.get(className);
147
150
  if (existingProbability !== undefined) {
148
- classProbabilities.set(className, existingProbability + probability);
151
+ classProbabilities.set(className, existingProbability + result);
149
152
  } else {
150
- classProbabilities.set(className, probability);
153
+ classProbabilities.set(className, result);
151
154
  }
152
155
  }
153
156
  console.log('Class Probabilities:', classProbabilities);
@@ -139,6 +139,7 @@ class LearningMobilenetImage implements LearningInterface {
139
139
 
140
140
  // 추론하기
141
141
  public async infer(data: any): Promise<Map<string, number>> {
142
+ const threshold = 1e-20; // 임계값 설정
142
143
  if (this.model === null) {
143
144
  return Promise.reject(new Error('Model is Null'));
144
145
  }
@@ -153,11 +154,12 @@ class LearningMobilenetImage implements LearningInterface {
153
154
  for (let i = 0; i < predictionsData.length; i++) {
154
155
  const className = this.labels[i]; // 클래스 이름
155
156
  const probability = predictionsData[i];
157
+ const result = Math.abs(probability) < threshold ? 0 : probability;
156
158
  const existingProbability = classProbabilities.get(className);
157
159
  if (existingProbability !== undefined) {
158
- classProbabilities.set(className, existingProbability + probability);
160
+ classProbabilities.set(className, existingProbability + result);
159
161
  } else {
160
- classProbabilities.set(className, probability);
162
+ classProbabilities.set(className, result);
161
163
  }
162
164
  }
163
165
  console.log('Class Probabilities:', classProbabilities);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "learning_model",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "learning model develop",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",