learning_model 1.0.17 → 1.0.22

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.
Files changed (40) hide show
  1. package/README.md +5 -1
  2. package/jest.config.js +6 -0
  3. package/lib/learning/mobilenet_image.test.ts +44 -0
  4. package/{src → lib}/learning/mobilenet_image.ts +3 -1
  5. package/lib/learning/util.ts +15 -0
  6. package/package.json +5 -4
  7. package/tsconfig.json +5 -7
  8. package/dist/index.bundle.js +0 -2
  9. package/dist/index.bundle.js.LICENSE.txt +0 -335
  10. package/dist/index.js +0 -10
  11. package/dist/types/index.d.ts +0 -3
  12. package/dist/types/learning/base.d.ts +0 -19
  13. package/dist/types/learning/base.js +0 -2
  14. package/dist/types/learning/image.d.ts +0 -40
  15. package/dist/types/learning/image.js +0 -321
  16. package/dist/types/learning/mobilenet_image.d.ts +0 -42
  17. package/dist/types/learning/mobilenet_image.js +0 -329
  18. package/dist/types/learning/mobilenet_image.test.d.ts +0 -1
  19. package/dist/types/public/index.d.ts +0 -1
  20. package/dist/types/src/index.d.ts +0 -3
  21. package/dist/types/src/learning/base.d.ts +0 -19
  22. package/dist/types/src/learning/image.d.ts +0 -40
  23. package/dist/types/src/learning/mobilenet_image.d.ts +0 -42
  24. package/public/index.css +0 -7
  25. package/public/index.html +0 -15
  26. package/public/index.ts +0 -153
  27. package/src/learning/mobilenet_image.test.ts +0 -63
  28. package/types/index.d.ts +0 -3
  29. package/types/learning/base.d.ts +0 -19
  30. package/types/learning/image.d.ts +0 -40
  31. package/types/learning/mobilenet_image.d.ts +0 -42
  32. package/types/learning/mobilenet_image.test.d.ts +0 -1
  33. package/types/public/index.d.ts +0 -1
  34. package/types/src/index.d.ts +0 -3
  35. package/types/src/learning/base.d.ts +0 -19
  36. package/types/src/learning/image.d.ts +0 -40
  37. package/types/src/learning/mobilenet_image.d.ts +0 -42
  38. /package/{src → lib}/index.ts +0 -0
  39. /package/{src → lib}/learning/base.ts +0 -0
  40. /package/{src → lib}/learning/image.ts +0 -0
@@ -1,63 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import * as tf from '@tensorflow/tfjs';
4
- import LearningMobilenetImage from './mobilenet_image';
5
-
6
- describe('LearningMobilenetImage', () => {
7
- let learning: LearningMobilenetImage;
8
- const imagePath = path.join(__dirname, 'data/images/image.jpg'); // 이미지 파일 경로
9
-
10
- beforeEach(() => {
11
- learning = new LearningMobilenetImage({});
12
- });
13
-
14
- afterEach(() => {
15
- // 테스트 후에 모델 저장
16
- learning.saveModel();
17
- });
18
-
19
- it('should add data', () => {
20
- const label = 'label1';
21
- const image = fs.readFileSync(imagePath); // 이미지 파일 읽어오기
22
-
23
- learning.addData(label, image);
24
-
25
- expect(learning.labels).toContain(label);
26
- expect(learning.trainImages.length).toBe(1);
27
- });
28
-
29
- it('should not train if data is insufficient', async () => {
30
- spyOn(console, 'error'); // 콘솔 에러 로그를 가로채기 위해 spyOn 사용
31
-
32
- const result = await learning.train().catch((error: any) => error);
33
-
34
- expect(result).toBeInstanceOf(Error);
35
- expect(result.message).toBe('Please train Data need over 2 data length');
36
- expect(console.error).toHaveBeenCalledWith('Model training failed', result);
37
- expect(learning.model).toBeNull();
38
- });
39
-
40
- it('should train and infer', async () => {
41
- const label1 = 'label1';
42
- const image1 = fs.readFileSync(imagePath); // 이미지 파일 읽어오기
43
- const label2 = 'label2';
44
- const image2 = fs.readFileSync(imagePath); // 이미지 파일 읽어오기
45
- const testData = fs.readFileSync(imagePath); // 테스트 데이터 읽어오기
46
-
47
- learning.addData(label1, image1);
48
- learning.addData(label2, image2);
49
-
50
- const history = await learning.train();
51
-
52
- expect(history).toBeDefined();
53
- expect(learning.model).toBeInstanceOf(tf.LayersModel);
54
- expect(learning.isRunning).toBe(false);
55
-
56
- const predictions = await learning.infer(testData);
57
-
58
- expect(predictions).toBeInstanceOf(Map);
59
- expect(predictions.size).toBe(2);
60
- // expect(predictions.get(label1)).toBeCloseTo(/* 예측값 */);
61
- // expect(predictions.get(label2)).toBeCloseTo(/* 예측값 */);
62
- });
63
- });
package/types/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import LearningImage from './learning/image';
2
- import LearningMobilenetImage from './learning/mobilenet_image';
3
- export { LearningImage, LearningMobilenetImage };
@@ -1,19 +0,0 @@
1
- import * as tf from '@tensorflow/tfjs';
2
- interface LearningInterface {
3
- model: tf.LayersModel | null;
4
- labels: string[];
5
- isRunning: boolean;
6
- isReady: boolean;
7
- onProgress(progress: number): void;
8
- onLoss(loss: number): void;
9
- onEvents(logs: any): void;
10
- onTrainBegin(log: any): void;
11
- onTrainEnd(log: any): void;
12
- addData(label: string, data: any): Promise<void>;
13
- train(): Promise<tf.History>;
14
- infer(data: any): Promise<any>;
15
- saveModel(): void;
16
- running(): boolean;
17
- ready(): boolean;
18
- }
19
- export default LearningInterface;
@@ -1,40 +0,0 @@
1
- import * as tf from '@tensorflow/tfjs';
2
- import LearningInterface from './base';
3
- declare class LearningImage implements LearningInterface {
4
- model: tf.LayersModel | null;
5
- epochs: number;
6
- batchSize: number;
7
- learningRate: number;
8
- labels: string[];
9
- isRunning: boolean;
10
- isReady: boolean;
11
- limitSize: number;
12
- trainImages: tf.Tensor3D[];
13
- readonly MOBILE_NET_INPUT_WIDTH = 224;
14
- readonly MOBILE_NET_INPUT_HEIGHT = 224;
15
- readonly MOBILE_NET_INPUT_CHANNEL = 3;
16
- readonly IMAGE_NORMALIZATION_FACTOR = 255;
17
- constructor({ epochs, batchSize, limitSize, learningRate, }?: {
18
- modelURL?: string;
19
- epochs?: number;
20
- batchSize?: number;
21
- limitSize?: number;
22
- learningRate?: number;
23
- });
24
- onProgress: (progress: number) => void;
25
- onLoss: (loss: number) => void;
26
- onEvents: (logs: any) => void;
27
- onTrainBegin: (log: any) => void;
28
- onTrainEnd: (log: any) => void;
29
- addData(label: string, data: any): Promise<void>;
30
- train(): Promise<tf.History>;
31
- infer(data: any): Promise<Map<string, number>>;
32
- saveModel(): void;
33
- running(): boolean;
34
- ready(): boolean;
35
- private _preprocessedTargetData;
36
- private _preprocessedInputData;
37
- private _preprocessData;
38
- private _createModel;
39
- }
40
- export default LearningImage;
@@ -1,42 +0,0 @@
1
- import * as tf from '@tensorflow/tfjs';
2
- import LearningInterface from './base';
3
- declare class LearningMobilenetImage implements LearningInterface {
4
- model: tf.LayersModel | null;
5
- epochs: number;
6
- batchSize: number;
7
- learningRate: number;
8
- labels: string[];
9
- modelURL: string;
10
- isRunning: boolean;
11
- isReady: boolean;
12
- limitSize: number;
13
- trainImages: tf.Tensor3D[];
14
- readonly MOBILE_NET_INPUT_WIDTH = 224;
15
- readonly MOBILE_NET_INPUT_HEIGHT = 224;
16
- readonly MOBILE_NET_INPUT_CHANNEL = 3;
17
- readonly IMAGE_NORMALIZATION_FACTOR = 255;
18
- constructor({ modelURL, // 디폴트 mobilenet 이미지
19
- epochs, batchSize, limitSize, learningRate, }?: {
20
- modelURL?: string;
21
- epochs?: number;
22
- batchSize?: number;
23
- limitSize?: number;
24
- learningRate?: number;
25
- });
26
- onProgress: (progress: number) => void;
27
- onLoss: (loss: number) => void;
28
- onEvents: (logs: any) => void;
29
- onTrainBegin: (log: any) => void;
30
- onTrainEnd: (log: any) => void;
31
- addData(label: string, data: any): Promise<void>;
32
- train(): Promise<tf.History>;
33
- infer(data: any): Promise<Map<string, number>>;
34
- saveModel(): void;
35
- running(): boolean;
36
- ready(): boolean;
37
- private _preprocessedTargetData;
38
- private _preprocessedInputData;
39
- private _preprocessData;
40
- private _createModel;
41
- }
42
- export default LearningMobilenetImage;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import LearningImage from './learning/image';
2
- import LearningMobilenetImage from './learning/mobilenet_image';
3
- export { LearningImage, LearningMobilenetImage };
@@ -1,19 +0,0 @@
1
- import * as tf from '@tensorflow/tfjs';
2
- interface LearningInterface {
3
- model: tf.LayersModel | null;
4
- labels: string[];
5
- isRunning: boolean;
6
- isReady: boolean;
7
- onProgress(progress: number): void;
8
- onLoss(loss: number): void;
9
- onEvents(logs: any): void;
10
- onTrainBegin(log: any): void;
11
- onTrainEnd(log: any): void;
12
- addData(label: string, data: any): Promise<void>;
13
- train(): Promise<tf.History>;
14
- infer(data: any): Promise<any>;
15
- saveModel(): void;
16
- running(): boolean;
17
- ready(): boolean;
18
- }
19
- export default LearningInterface;
@@ -1,40 +0,0 @@
1
- import * as tf from '@tensorflow/tfjs';
2
- import LearningInterface from './base';
3
- declare class LearningImage implements LearningInterface {
4
- model: tf.LayersModel | null;
5
- epochs: number;
6
- batchSize: number;
7
- learningRate: number;
8
- labels: string[];
9
- isRunning: boolean;
10
- isReady: boolean;
11
- limitSize: number;
12
- trainImages: tf.Tensor3D[];
13
- readonly MOBILE_NET_INPUT_WIDTH = 224;
14
- readonly MOBILE_NET_INPUT_HEIGHT = 224;
15
- readonly MOBILE_NET_INPUT_CHANNEL = 3;
16
- readonly IMAGE_NORMALIZATION_FACTOR = 255;
17
- constructor({ epochs, batchSize, limitSize, learningRate, }?: {
18
- modelURL?: string;
19
- epochs?: number;
20
- batchSize?: number;
21
- limitSize?: number;
22
- learningRate?: number;
23
- });
24
- onProgress: (progress: number) => void;
25
- onLoss: (loss: number) => void;
26
- onEvents: (logs: any) => void;
27
- onTrainBegin: (log: any) => void;
28
- onTrainEnd: (log: any) => void;
29
- addData(label: string, data: any): Promise<void>;
30
- train(): Promise<tf.History>;
31
- infer(data: any): Promise<Map<string, number>>;
32
- saveModel(): void;
33
- running(): boolean;
34
- ready(): boolean;
35
- private _preprocessedTargetData;
36
- private _preprocessedInputData;
37
- private _preprocessData;
38
- private _createModel;
39
- }
40
- export default LearningImage;
@@ -1,42 +0,0 @@
1
- import * as tf from '@tensorflow/tfjs';
2
- import LearningInterface from './base';
3
- declare class LearningMobilenetImage implements LearningInterface {
4
- model: tf.LayersModel | null;
5
- epochs: number;
6
- batchSize: number;
7
- learningRate: number;
8
- labels: string[];
9
- modelURL: string;
10
- isRunning: boolean;
11
- isReady: boolean;
12
- limitSize: number;
13
- trainImages: tf.Tensor3D[];
14
- readonly MOBILE_NET_INPUT_WIDTH = 224;
15
- readonly MOBILE_NET_INPUT_HEIGHT = 224;
16
- readonly MOBILE_NET_INPUT_CHANNEL = 3;
17
- readonly IMAGE_NORMALIZATION_FACTOR = 255;
18
- constructor({ modelURL, // 디폴트 mobilenet 이미지
19
- epochs, batchSize, limitSize, learningRate, }?: {
20
- modelURL?: string;
21
- epochs?: number;
22
- batchSize?: number;
23
- limitSize?: number;
24
- learningRate?: number;
25
- });
26
- onProgress: (progress: number) => void;
27
- onLoss: (loss: number) => void;
28
- onEvents: (logs: any) => void;
29
- onTrainBegin: (log: any) => void;
30
- onTrainEnd: (log: any) => void;
31
- addData(label: string, data: any): Promise<void>;
32
- train(): Promise<tf.History>;
33
- infer(data: any): Promise<Map<string, number>>;
34
- saveModel(): void;
35
- running(): boolean;
36
- ready(): boolean;
37
- private _preprocessedTargetData;
38
- private _preprocessedInputData;
39
- private _preprocessData;
40
- private _createModel;
41
- }
42
- export default LearningMobilenetImage;
File without changes
File without changes
File without changes