learning_model 1.0.18 → 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.
- package/README.md +5 -1
- package/jest.config.js +6 -0
- package/lib/learning/mobilenet_image.test.ts +44 -0
- package/{src → lib}/learning/mobilenet_image.ts +3 -1
- package/lib/learning/util.ts +15 -0
- package/package.json +5 -4
- package/tsconfig.json +4 -6
- package/dist/index.bundle.js +0 -2
- package/dist/index.bundle.js.LICENSE.txt +0 -335
- package/dist/index.js +0 -10
- package/dist/types/index.d.ts +0 -3
- package/dist/types/learning/base.d.ts +0 -19
- package/dist/types/learning/base.js +0 -2
- package/dist/types/learning/image.d.ts +0 -40
- package/dist/types/learning/image.js +0 -259
- package/dist/types/learning/mobilenet_image.d.ts +0 -42
- package/dist/types/learning/mobilenet_image.js +0 -262
- package/dist/types/learning/mobilenet_image.test.d.ts +0 -1
- package/dist/types/public/index.d.ts +0 -1
- package/dist/types/src/index.d.ts +0 -3
- package/dist/types/src/learning/base.d.ts +0 -19
- package/dist/types/src/learning/image.d.ts +0 -40
- package/dist/types/src/learning/mobilenet_image.d.ts +0 -42
- package/public/index.css +0 -7
- package/public/index.html +0 -15
- package/public/index.ts +0 -153
- package/src/learning/mobilenet_image.test.ts +0 -63
- package/types/index.d.ts +0 -3
- package/types/learning/base.d.ts +0 -19
- package/types/learning/image.d.ts +0 -40
- package/types/learning/mobilenet_image.d.ts +0 -42
- package/types/learning/mobilenet_image.test.d.ts +0 -1
- package/types/public/index.d.ts +0 -1
- package/types/src/index.d.ts +0 -3
- package/types/src/learning/base.d.ts +0 -19
- package/types/src/learning/image.d.ts +0 -40
- package/types/src/learning/mobilenet_image.d.ts +0 -42
- /package/{src → lib}/index.ts +0 -0
- /package/{src → lib}/learning/base.ts +0 -0
- /package/{src → lib}/learning/image.ts +0 -0
package/README.md
CHANGED
package/jest.config.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as tf from '@tensorflow/tfjs';
|
|
3
|
+
import LearningMobilenetImage from './mobilenet_image';
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
const { createCanvas, loadImage } = require('canvas');
|
|
6
|
+
|
|
7
|
+
let imageTensor1: tf.Tensor3D;
|
|
8
|
+
let imageTensor2: tf.Tensor3D;
|
|
9
|
+
|
|
10
|
+
// 이미지경로를 기준으로
|
|
11
|
+
async function ImagePathToTensor(imagePath: string): Promise<tf.Tensor3D> {
|
|
12
|
+
const imageBuffer = fs.readFileSync(imagePath);
|
|
13
|
+
const image = await loadImage(imageBuffer);
|
|
14
|
+
const canvas = createCanvas(image.width, image.height);
|
|
15
|
+
const ctx = canvas.getContext('2d');
|
|
16
|
+
ctx.drawImage(image, 0, 0);
|
|
17
|
+
const imageData = ctx.getImageData(0, 0, image.width, image.height);
|
|
18
|
+
return tf.tensor3d(imageData.data, [imageData.height, imageData.width, 4], 'int32');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('LearningMobilenetImage', () => {
|
|
22
|
+
const learning = new LearningMobilenetImage({});
|
|
23
|
+
|
|
24
|
+
beforeAll(async () => {
|
|
25
|
+
const image1Path = path.join(__dirname, '../../public/images/image1.jpeg');
|
|
26
|
+
const image2Path = path.join(__dirname, '../../public/images/image2.jpeg');
|
|
27
|
+
imageTensor1 = await ImagePathToTensor(image1Path);
|
|
28
|
+
imageTensor2 = await ImagePathToTensor(image2Path);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('loads an image and converts it to a tensor', () => {
|
|
32
|
+
expect(imageTensor1).toBeDefined();
|
|
33
|
+
expect(imageTensor1 instanceof tf.Tensor).toBe(true);
|
|
34
|
+
expect(imageTensor2).toBeDefined();
|
|
35
|
+
expect(imageTensor2 instanceof tf.Tensor).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('mobilenet add data', () => {
|
|
39
|
+
learning.addData("라벨1", imageTensor1);
|
|
40
|
+
learning.addData("라벨1", imageTensor1);
|
|
41
|
+
learning.addData("라벨2", imageTensor2);
|
|
42
|
+
learning.addData("라벨2", imageTensor2);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import * as tf from '@tensorflow/tfjs';
|
|
8
8
|
import LearningInterface from './base';
|
|
9
|
+
import { ImageToTensor } from './util';
|
|
9
10
|
|
|
10
11
|
class LearningMobilenetImage implements LearningInterface {
|
|
11
12
|
model: tf.LayersModel | null;
|
|
@@ -53,10 +54,11 @@ class LearningMobilenetImage implements LearningInterface {
|
|
|
53
54
|
|
|
54
55
|
public onTrainEnd: (log: any) => void = () => {};
|
|
55
56
|
|
|
57
|
+
|
|
56
58
|
// 학습 데이타 등록
|
|
57
59
|
public async addData(label: string, data: any): Promise<void> {
|
|
58
60
|
try {
|
|
59
|
-
const tensor =
|
|
61
|
+
const tensor = ImageToTensor(data)
|
|
60
62
|
console.log('addData', tensor);
|
|
61
63
|
this.trainImages.push(tensor)
|
|
62
64
|
this.labels.push(label);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as tf from '@tensorflow/tfjs';
|
|
2
|
+
|
|
3
|
+
export function ImageToTensor(data: any): tf.Tensor3D {
|
|
4
|
+
let tensor: tf.Tensor3D;
|
|
5
|
+
|
|
6
|
+
console.log('data', data instanceof tf.Tensor, typeof data);
|
|
7
|
+
if (data instanceof tf.Tensor) {
|
|
8
|
+
tensor = data;
|
|
9
|
+
} else {
|
|
10
|
+
tensor = tf.browser.fromPixels(data);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return tensor;
|
|
14
|
+
}
|
|
15
|
+
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "learning_model",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
4
4
|
"description": "learning model develop",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"start": "webpack serve --open --mode development",
|
|
9
9
|
"watch": "webpack --watch --mode=development",
|
|
10
10
|
"build": "tsc && webpack",
|
|
11
11
|
"tsc": "tsc",
|
|
12
|
-
"test": "jest"
|
|
12
|
+
"test": "npx jest"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"tensorflow"
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"@tensorflow/tfjs": "^4.6.0",
|
|
22
22
|
"@tensorflow/tfjs-layers": "^4.6.0",
|
|
23
23
|
"canvas": "^2.11.2",
|
|
24
|
-
"jest": "^29.5.0",
|
|
25
24
|
"learning_model": "^1.0.0"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
@@ -34,8 +33,10 @@
|
|
|
34
33
|
"css-loader": "^6.8.1",
|
|
35
34
|
"glob": "^7.1.7",
|
|
36
35
|
"html-webpack-plugin": "^5.5.1",
|
|
36
|
+
"jest": "^29.5.0",
|
|
37
37
|
"style-loader": "^3.3.3",
|
|
38
38
|
"terser-webpack-plugin": "^5.3.9",
|
|
39
|
+
"ts-jest": "^29.1.0",
|
|
39
40
|
"ts-loader": "^9.4.3",
|
|
40
41
|
"typescript": "^4.4.4",
|
|
41
42
|
"webpack": "^5.51.1",
|
package/tsconfig.json
CHANGED
|
@@ -2,19 +2,17 @@
|
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ES6",
|
|
4
4
|
"module": "CommonJS",
|
|
5
|
-
"outDir": "
|
|
5
|
+
"outDir": "dist",
|
|
6
6
|
"strict": true,
|
|
7
7
|
"esModuleInterop": true,
|
|
8
|
-
"declarationDir": "./
|
|
8
|
+
"declarationDir": "./dist",
|
|
9
9
|
"declaration": true,
|
|
10
10
|
"skipLibCheck": true,
|
|
11
11
|
},
|
|
12
12
|
"include": [
|
|
13
|
-
"
|
|
13
|
+
"lib/**/*.ts"
|
|
14
14
|
],
|
|
15
15
|
"exclude": [
|
|
16
|
-
"node_modules"
|
|
17
|
-
"src/**/*.test.ts",
|
|
18
|
-
"dist"
|
|
16
|
+
"node_modules"
|
|
19
17
|
]
|
|
20
18
|
}
|