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.bundle.js +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -5
- package/dist/learning/base.d.ts +1 -0
- package/dist/learning/mobilenet.d.ts +1 -0
- package/dist/learning/mobilenet.js +31 -2
- package/dist/lib/index.d.ts +1 -3
- package/dist/lib/learning/base.d.ts +1 -0
- package/dist/lib/learning/mobilenet.d.ts +1 -0
- package/lib/index.ts +2 -4
- package/lib/learning/base.ts +3 -0
- package/lib/learning/mobilenet.ts +37 -3
- package/package.json +1 -1
- package/dist/learning/image.d.ts +0 -45
- package/dist/learning/image.js +0 -285
- package/dist/learning/mobilenet_image.d.ts +0 -47
- package/dist/learning/mobilenet_image.js +0 -276
- package/dist/learning/mobilenet_image.test.d.ts +0 -1
- package/dist/learning/mobilenet_image.test.js +0 -77
- package/dist/lib/learning/image.d.ts +0 -45
- package/dist/lib/learning/mobilenet_image.d.ts +0 -47
- package/dist/lib/learning/mobilenet_image.test.d.ts +0 -1
- package/lib/learning/image.ts +0 -283
- package/lib/learning/mobilenet_image.test.ts +0 -44
- package/lib/learning/mobilenet_image.ts +0 -277
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
///////////////////////////////////////////////////////////////////////////
|
|
3
|
-
///////////////////////////////////////////////////////////////////////////
|
|
4
|
-
///////////////////////////////////////////////////////////////////////////
|
|
5
|
-
// mobilenet 모델을 이용한 전이학습 방법
|
|
6
|
-
///////////////////////////////////////////////////////////////////////////
|
|
7
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
-
if (k2 === undefined) k2 = k;
|
|
9
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
24
|
-
if (mod && mod.__esModule) return mod;
|
|
25
|
-
var result = {};
|
|
26
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
27
|
-
__setModuleDefault(result, mod);
|
|
28
|
-
return result;
|
|
29
|
-
};
|
|
30
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
31
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
32
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
33
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
34
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
35
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
36
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
const tf = __importStar(require("@tensorflow/tfjs"));
|
|
41
|
-
const util_1 = require("./util");
|
|
42
|
-
class LearningMobilenetImage {
|
|
43
|
-
constructor({ modelURL = 'https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_0.25_224/model.json', // 디폴트 mobilenet 이미지
|
|
44
|
-
epochs = 10, batchSize = 16, limitSize = 2, learningRate = 0.001, validateRate = 0.2, } = {}) {
|
|
45
|
-
this.trainImages = [];
|
|
46
|
-
this.MOBILE_NET_INPUT_WIDTH = 224;
|
|
47
|
-
this.MOBILE_NET_INPUT_HEIGHT = 224;
|
|
48
|
-
this.MOBILE_NET_INPUT_CHANNEL = 3;
|
|
49
|
-
this.IMAGE_NORMALIZATION_FACTOR = 255.0;
|
|
50
|
-
// 진행 상태를 나타내는 이벤트를 정의합니다.
|
|
51
|
-
this.onProgress = () => { };
|
|
52
|
-
this.onLoss = () => { };
|
|
53
|
-
this.onEvents = () => { };
|
|
54
|
-
this.onTrainBegin = () => { };
|
|
55
|
-
this.onTrainEnd = () => { };
|
|
56
|
-
this.onEpochEnd = () => { };
|
|
57
|
-
this.model = null;
|
|
58
|
-
this.epochs = epochs;
|
|
59
|
-
this.batchSize = batchSize;
|
|
60
|
-
this.learningRate = learningRate;
|
|
61
|
-
this.validateRate = validateRate;
|
|
62
|
-
this.labels = [];
|
|
63
|
-
this.modelURL = modelURL;
|
|
64
|
-
this.isRunning = false;
|
|
65
|
-
this.isReady = false;
|
|
66
|
-
this.isTrainedDone = false;
|
|
67
|
-
this.limitSize = limitSize;
|
|
68
|
-
}
|
|
69
|
-
// 학습 데이타 등록
|
|
70
|
-
addData(label, data) {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
try {
|
|
73
|
-
const tensor = (0, util_1.ImageToTensor)(data);
|
|
74
|
-
console.log('addData', tensor);
|
|
75
|
-
this.trainImages.push(tensor);
|
|
76
|
-
this.labels.push(label);
|
|
77
|
-
if (this.labels.length >= this.limitSize) {
|
|
78
|
-
this.isReady = true;
|
|
79
|
-
}
|
|
80
|
-
return Promise.resolve();
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
console.error('Model training failed', error);
|
|
84
|
-
throw error;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
// 모델 학습 처리
|
|
89
|
-
train() {
|
|
90
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
if (this.isRunning) {
|
|
92
|
-
return Promise.reject(new Error('Training is already in progress.'));
|
|
93
|
-
}
|
|
94
|
-
// 콜백 정의
|
|
95
|
-
const customCallback = {
|
|
96
|
-
onTrainBegin: (log) => {
|
|
97
|
-
this.isTrainedDone = false;
|
|
98
|
-
this.onTrainBegin(log);
|
|
99
|
-
console.log('Training has started.');
|
|
100
|
-
},
|
|
101
|
-
onTrainEnd: (log) => {
|
|
102
|
-
this.isTrainedDone = true;
|
|
103
|
-
this.onTrainEnd(log);
|
|
104
|
-
console.log('Training has ended.');
|
|
105
|
-
this.isRunning = false;
|
|
106
|
-
},
|
|
107
|
-
onBatchBegin: (batch, logs) => {
|
|
108
|
-
console.log(`Batch ${batch} is starting.`);
|
|
109
|
-
},
|
|
110
|
-
onBatchEnd: (batch, logs) => {
|
|
111
|
-
console.log(`Batch ${batch} has ended.`);
|
|
112
|
-
},
|
|
113
|
-
onEpochBegin: (epoch, logs) => {
|
|
114
|
-
console.log(`Epoch ${epoch + 1} is starting.`, logs);
|
|
115
|
-
},
|
|
116
|
-
onEpochEnd: (epoch, logs) => {
|
|
117
|
-
console.log(`Epoch ${epoch + 1} has ended.`);
|
|
118
|
-
console.log('Loss:', logs);
|
|
119
|
-
this.onLoss(logs.loss);
|
|
120
|
-
this.onProgress(epoch + 1);
|
|
121
|
-
this.onEvents(logs);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
try {
|
|
125
|
-
this.isRunning = true;
|
|
126
|
-
if (this.labels.length < this.limitSize) {
|
|
127
|
-
return Promise.reject(new Error('Please train Data need over 2 data length'));
|
|
128
|
-
}
|
|
129
|
-
this.model = yield this._createModel(this.labels.length);
|
|
130
|
-
const inputData = this._preprocessedInputData(this.model);
|
|
131
|
-
const targetData = this._preprocessedTargetData();
|
|
132
|
-
const history = yield this.model.fit(inputData, targetData, {
|
|
133
|
-
epochs: this.epochs,
|
|
134
|
-
batchSize: this.batchSize,
|
|
135
|
-
validationSplit: this.validateRate,
|
|
136
|
-
callbacks: customCallback
|
|
137
|
-
});
|
|
138
|
-
console.log('Model training completed', history);
|
|
139
|
-
return history;
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
this.isRunning = false;
|
|
143
|
-
console.error('Model training failed', error);
|
|
144
|
-
throw error;
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
// 추론하기
|
|
149
|
-
infer(data) {
|
|
150
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
if (this.model === null) {
|
|
152
|
-
return Promise.reject(new Error('Model is Null'));
|
|
153
|
-
}
|
|
154
|
-
try {
|
|
155
|
-
const tensor = tf.browser.fromPixels(data);
|
|
156
|
-
const resizedTensor = tf.image.resizeBilinear(tensor, [this.MOBILE_NET_INPUT_WIDTH, this.MOBILE_NET_INPUT_HEIGHT]);
|
|
157
|
-
const reshapedTensor = resizedTensor.expandDims(0); // 배치 크기 1을 추가하여 4차원으로 변환
|
|
158
|
-
const predictions = this.model.predict(reshapedTensor);
|
|
159
|
-
const predictionsData = yield predictions.data(); // 예측 텐서의 데이터를 비동기로 가져옴
|
|
160
|
-
const classProbabilities = new Map(); // 클래스별 확률 누적값을 저장할 맵
|
|
161
|
-
for (let i = 0; i < predictionsData.length; i++) {
|
|
162
|
-
const className = this.labels[i]; // 클래스 이름
|
|
163
|
-
const probability = predictionsData[i];
|
|
164
|
-
const existingProbability = classProbabilities.get(className);
|
|
165
|
-
if (existingProbability !== undefined) {
|
|
166
|
-
classProbabilities.set(className, existingProbability + probability);
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
classProbabilities.set(className, probability);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
console.log('Class Probabilities:', classProbabilities);
|
|
173
|
-
return classProbabilities;
|
|
174
|
-
}
|
|
175
|
-
catch (error) {
|
|
176
|
-
throw error;
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
// 모델 저장
|
|
181
|
-
saveModel(handlerOrURL, config) {
|
|
182
|
-
var _a;
|
|
183
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
-
console.log('saved model');
|
|
185
|
-
if (!this.isTrainedDone) {
|
|
186
|
-
return Promise.reject(new Error('Train is not done status'));
|
|
187
|
-
}
|
|
188
|
-
yield ((_a = this.model) === null || _a === void 0 ? void 0 : _a.save(handlerOrURL, config));
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
// 진행중 여부
|
|
192
|
-
running() {
|
|
193
|
-
return this.isRunning;
|
|
194
|
-
}
|
|
195
|
-
ready() {
|
|
196
|
-
return this.isReady;
|
|
197
|
-
}
|
|
198
|
-
// target 라벨 데이타
|
|
199
|
-
_preprocessedTargetData() {
|
|
200
|
-
// 라벨 unique 처리 & 배열 리턴
|
|
201
|
-
console.log('uniqueLabels.length', this.labels, this.labels.length);
|
|
202
|
-
const labelIndices = this.labels.map((label) => this.labels.indexOf(label));
|
|
203
|
-
console.log('labelIndices', labelIndices);
|
|
204
|
-
const oneHotEncode = tf.oneHot(tf.tensor1d(labelIndices, 'int32'), this.labels.length);
|
|
205
|
-
console.log('oneHotEncode', oneHotEncode);
|
|
206
|
-
return oneHotEncode;
|
|
207
|
-
}
|
|
208
|
-
// 입력 이미지 데이타
|
|
209
|
-
_preprocessedInputData(model) {
|
|
210
|
-
// 이미지 배열을 배치로 변환 - [null, 224, 224, 3]
|
|
211
|
-
const inputShape = model.inputs[0].shape;
|
|
212
|
-
console.log('inputShape', inputShape);
|
|
213
|
-
// inputShape를 이와 같이 포멧 맞춘다. for reshape to [224, 224, 3]
|
|
214
|
-
const inputShapeArray = inputShape.slice(1);
|
|
215
|
-
console.log('inputShapeArray', inputShapeArray);
|
|
216
|
-
const inputBatch = tf.stack(this.trainImages.map((image) => {
|
|
217
|
-
// 이미지 전처리 및 크기 조정 등을 수행한 후에
|
|
218
|
-
// 모델의 입력 형태로 변환하여 반환
|
|
219
|
-
const xs = this._preprocessData(image); // 전처리 함수는 사용자 정의해야 함
|
|
220
|
-
return tf.reshape(xs, inputShapeArray);
|
|
221
|
-
}));
|
|
222
|
-
return inputBatch;
|
|
223
|
-
}
|
|
224
|
-
// 모델 학습하기 위한 데이타 전처리 단계
|
|
225
|
-
_preprocessData(tensor) {
|
|
226
|
-
try {
|
|
227
|
-
// mobilenet model summary를 하면 위와 같이 224,224 사이즈의 입력값 설정되어 있다. ex) input_1 (InputLayer) [null,224,224,3]
|
|
228
|
-
const resizedImage = tf.image.resizeBilinear(tensor, [this.MOBILE_NET_INPUT_WIDTH, this.MOBILE_NET_INPUT_HEIGHT]);
|
|
229
|
-
// 이미지를 [0,1] 범위로 정규화 255로 나뉜 픽셀값
|
|
230
|
-
const normalizedImage = resizedImage.div(this.IMAGE_NORMALIZATION_FACTOR);
|
|
231
|
-
// expandDims(0)을 하여 차원을 추가하여 4D텐서 반환
|
|
232
|
-
return normalizedImage.expandDims(0);
|
|
233
|
-
}
|
|
234
|
-
catch (error) {
|
|
235
|
-
console.error('Failed to _preprocessData data', error);
|
|
236
|
-
throw error;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
// 모델 저장
|
|
240
|
-
_createModel(numClasses) {
|
|
241
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
242
|
-
try {
|
|
243
|
-
const load_model = yield tf.loadLayersModel(this.modelURL);
|
|
244
|
-
// 기존 MobileNet 모델에서 마지막 레이어 제외
|
|
245
|
-
const truncatedModel = tf.model({
|
|
246
|
-
inputs: load_model.inputs,
|
|
247
|
-
outputs: load_model.layers[load_model.layers.length - 2].output
|
|
248
|
-
});
|
|
249
|
-
// 모델을 학습 가능하게 설정하고 선택한 레이어까지 고정
|
|
250
|
-
for (let layer of truncatedModel.layers) {
|
|
251
|
-
layer.trainable = false;
|
|
252
|
-
}
|
|
253
|
-
const model = tf.sequential();
|
|
254
|
-
model.add(truncatedModel);
|
|
255
|
-
model.add(tf.layers.flatten()); // 필요한 경우 Flatten 레이어 추가
|
|
256
|
-
model.add(tf.layers.dense({
|
|
257
|
-
units: numClasses,
|
|
258
|
-
activation: 'softmax'
|
|
259
|
-
}));
|
|
260
|
-
const optimizer = tf.train.adam(this.learningRate); // Optimizer를 생성하고 학습률을 설정합니다.
|
|
261
|
-
model.compile({
|
|
262
|
-
loss: (numClasses === 2) ? 'binaryCrossentropy' : 'categoricalCrossentropy',
|
|
263
|
-
optimizer: optimizer,
|
|
264
|
-
metrics: ['accuracy', 'acc']
|
|
265
|
-
});
|
|
266
|
-
model.summary();
|
|
267
|
-
return model;
|
|
268
|
-
}
|
|
269
|
-
catch (error) {
|
|
270
|
-
console.error('Failed to load model', error);
|
|
271
|
-
throw error;
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
exports.default = LearningMobilenetImage;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,77 +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 path = __importStar(require("path"));
|
|
39
|
-
const tf = __importStar(require("@tensorflow/tfjs"));
|
|
40
|
-
const mobilenet_image_1 = __importDefault(require("./mobilenet_image"));
|
|
41
|
-
const fs = __importStar(require("fs"));
|
|
42
|
-
const { createCanvas, loadImage } = require('canvas');
|
|
43
|
-
let imageTensor1;
|
|
44
|
-
let imageTensor2;
|
|
45
|
-
// 이미지경로를 기준으로
|
|
46
|
-
function ImagePathToTensor(imagePath) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const imageBuffer = fs.readFileSync(imagePath);
|
|
49
|
-
const image = yield loadImage(imageBuffer);
|
|
50
|
-
const canvas = createCanvas(image.width, image.height);
|
|
51
|
-
const ctx = canvas.getContext('2d');
|
|
52
|
-
ctx.drawImage(image, 0, 0);
|
|
53
|
-
const imageData = ctx.getImageData(0, 0, image.width, image.height);
|
|
54
|
-
return tf.tensor3d(imageData.data, [imageData.height, imageData.width, 4], 'int32');
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
describe('LearningMobilenetImage', () => {
|
|
58
|
-
const learning = new mobilenet_image_1.default({});
|
|
59
|
-
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
-
const image1Path = path.join(__dirname, '../../public/images/image1.jpeg');
|
|
61
|
-
const image2Path = path.join(__dirname, '../../public/images/image2.jpeg');
|
|
62
|
-
imageTensor1 = yield ImagePathToTensor(image1Path);
|
|
63
|
-
imageTensor2 = yield ImagePathToTensor(image2Path);
|
|
64
|
-
}));
|
|
65
|
-
test('loads an image and converts it to a tensor', () => {
|
|
66
|
-
expect(imageTensor1).toBeDefined();
|
|
67
|
-
expect(imageTensor1 instanceof tf.Tensor).toBe(true);
|
|
68
|
-
expect(imageTensor2).toBeDefined();
|
|
69
|
-
expect(imageTensor2 instanceof tf.Tensor).toBe(true);
|
|
70
|
-
});
|
|
71
|
-
test('mobilenet add data', () => {
|
|
72
|
-
learning.addData("라벨1", imageTensor1);
|
|
73
|
-
learning.addData("라벨1", imageTensor1);
|
|
74
|
-
learning.addData("라벨2", imageTensor2);
|
|
75
|
-
learning.addData("라벨2", imageTensor2);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
@@ -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,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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|