@srsergio/taptapp-ar 1.0.9 → 1.0.10

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 (122) hide show
  1. package/dist/compiler/controller.d.ts +15 -22
  2. package/dist/compiler/controller.js +73 -92
  3. package/dist/compiler/detector/crop-detector.d.ts +20 -51
  4. package/dist/compiler/detector/crop-detector.js +21 -15
  5. package/dist/compiler/input-loader.d.ts +15 -17
  6. package/dist/compiler/input-loader.js +58 -76
  7. package/dist/compiler/matching/hamming-distance.js +4 -4
  8. package/dist/compiler/matching/matcher.js +2 -2
  9. package/dist/compiler/matching/matching.d.ts +2 -16
  10. package/dist/compiler/matching/matching.js +72 -60
  11. package/dist/compiler/offline-compiler.d.ts +9 -29
  12. package/dist/compiler/offline-compiler.js +38 -72
  13. package/dist/compiler/three.js +0 -4
  14. package/dist/compiler/tracker/tracker.d.ts +26 -12
  15. package/dist/compiler/tracker/tracker.js +158 -259
  16. package/package.json +1 -1
  17. package/src/compiler/controller.js +71 -93
  18. package/src/compiler/detector/crop-detector.js +26 -15
  19. package/src/compiler/input-loader.js +62 -88
  20. package/src/compiler/matching/hamming-distance.js +4 -4
  21. package/src/compiler/matching/hough.js +1 -1
  22. package/src/compiler/matching/matcher.js +2 -2
  23. package/src/compiler/matching/matching.js +80 -72
  24. package/src/compiler/offline-compiler.js +38 -75
  25. package/src/compiler/three.js +0 -4
  26. package/src/compiler/tracker/tracker.js +183 -283
  27. package/dist/compiler/compiler-base.d.ts +0 -8
  28. package/dist/compiler/compiler-base.js +0 -179
  29. package/dist/compiler/compiler.d.ts +0 -9
  30. package/dist/compiler/compiler.js +0 -24
  31. package/dist/compiler/compiler.worker.d.ts +0 -1
  32. package/dist/compiler/compiler.worker.js +0 -28
  33. package/dist/compiler/detector/detector.d.ts +0 -97
  34. package/dist/compiler/detector/detector.js +0 -1042
  35. package/dist/compiler/detector/kernels/cpu/binomialFilter.d.ts +0 -6
  36. package/dist/compiler/detector/kernels/cpu/binomialFilter.js +0 -50
  37. package/dist/compiler/detector/kernels/cpu/buildExtremas.d.ts +0 -6
  38. package/dist/compiler/detector/kernels/cpu/buildExtremas.js +0 -89
  39. package/dist/compiler/detector/kernels/cpu/computeExtremaAngles.d.ts +0 -7
  40. package/dist/compiler/detector/kernels/cpu/computeExtremaAngles.js +0 -79
  41. package/dist/compiler/detector/kernels/cpu/computeExtremaFreak.d.ts +0 -6
  42. package/dist/compiler/detector/kernels/cpu/computeExtremaFreak.js +0 -68
  43. package/dist/compiler/detector/kernels/cpu/computeFreakDescriptors.d.ts +0 -6
  44. package/dist/compiler/detector/kernels/cpu/computeFreakDescriptors.js +0 -57
  45. package/dist/compiler/detector/kernels/cpu/computeLocalization.d.ts +0 -6
  46. package/dist/compiler/detector/kernels/cpu/computeLocalization.js +0 -50
  47. package/dist/compiler/detector/kernels/cpu/computeOrientationHistograms.d.ts +0 -6
  48. package/dist/compiler/detector/kernels/cpu/computeOrientationHistograms.js +0 -100
  49. package/dist/compiler/detector/kernels/cpu/downsampleBilinear.d.ts +0 -6
  50. package/dist/compiler/detector/kernels/cpu/downsampleBilinear.js +0 -29
  51. package/dist/compiler/detector/kernels/cpu/extremaReduction.d.ts +0 -6
  52. package/dist/compiler/detector/kernels/cpu/extremaReduction.js +0 -50
  53. package/dist/compiler/detector/kernels/cpu/fakeShader.d.ts +0 -20
  54. package/dist/compiler/detector/kernels/cpu/fakeShader.js +0 -80
  55. package/dist/compiler/detector/kernels/cpu/index.d.ts +0 -1
  56. package/dist/compiler/detector/kernels/cpu/index.js +0 -25
  57. package/dist/compiler/detector/kernels/cpu/prune.d.ts +0 -7
  58. package/dist/compiler/detector/kernels/cpu/prune.js +0 -62
  59. package/dist/compiler/detector/kernels/cpu/smoothHistograms.d.ts +0 -6
  60. package/dist/compiler/detector/kernels/cpu/smoothHistograms.js +0 -47
  61. package/dist/compiler/detector/kernels/cpu/upsampleBilinear.d.ts +0 -6
  62. package/dist/compiler/detector/kernels/cpu/upsampleBilinear.js +0 -43
  63. package/dist/compiler/detector/kernels/index.d.ts +0 -1
  64. package/dist/compiler/detector/kernels/index.js +0 -2
  65. package/dist/compiler/detector/kernels/webgl/binomialFilter.d.ts +0 -6
  66. package/dist/compiler/detector/kernels/webgl/binomialFilter.js +0 -67
  67. package/dist/compiler/detector/kernels/webgl/buildExtremas.d.ts +0 -6
  68. package/dist/compiler/detector/kernels/webgl/buildExtremas.js +0 -101
  69. package/dist/compiler/detector/kernels/webgl/computeExtremaAngles.d.ts +0 -6
  70. package/dist/compiler/detector/kernels/webgl/computeExtremaAngles.js +0 -78
  71. package/dist/compiler/detector/kernels/webgl/computeExtremaFreak.d.ts +0 -6
  72. package/dist/compiler/detector/kernels/webgl/computeExtremaFreak.js +0 -86
  73. package/dist/compiler/detector/kernels/webgl/computeFreakDescriptors.d.ts +0 -6
  74. package/dist/compiler/detector/kernels/webgl/computeFreakDescriptors.js +0 -52
  75. package/dist/compiler/detector/kernels/webgl/computeLocalization.d.ts +0 -6
  76. package/dist/compiler/detector/kernels/webgl/computeLocalization.js +0 -58
  77. package/dist/compiler/detector/kernels/webgl/computeOrientationHistograms.d.ts +0 -6
  78. package/dist/compiler/detector/kernels/webgl/computeOrientationHistograms.js +0 -116
  79. package/dist/compiler/detector/kernels/webgl/downsampleBilinear.d.ts +0 -6
  80. package/dist/compiler/detector/kernels/webgl/downsampleBilinear.js +0 -46
  81. package/dist/compiler/detector/kernels/webgl/extremaReduction.d.ts +0 -6
  82. package/dist/compiler/detector/kernels/webgl/extremaReduction.js +0 -48
  83. package/dist/compiler/detector/kernels/webgl/index.d.ts +0 -1
  84. package/dist/compiler/detector/kernels/webgl/index.js +0 -25
  85. package/dist/compiler/detector/kernels/webgl/smoothHistograms.d.ts +0 -6
  86. package/dist/compiler/detector/kernels/webgl/smoothHistograms.js +0 -49
  87. package/dist/compiler/detector/kernels/webgl/upsampleBilinear.d.ts +0 -6
  88. package/dist/compiler/detector/kernels/webgl/upsampleBilinear.js +0 -56
  89. package/dist/compiler/tensorflow-setup.d.ts +0 -6
  90. package/dist/compiler/tensorflow-setup.js +0 -99
  91. package/src/compiler/compiler-base.js +0 -210
  92. package/src/compiler/compiler.js +0 -25
  93. package/src/compiler/compiler.worker.js +0 -30
  94. package/src/compiler/detector/detector.js +0 -1119
  95. package/src/compiler/detector/kernels/cpu/binomialFilter.js +0 -58
  96. package/src/compiler/detector/kernels/cpu/buildExtremas.js +0 -108
  97. package/src/compiler/detector/kernels/cpu/computeExtremaAngles.js +0 -91
  98. package/src/compiler/detector/kernels/cpu/computeExtremaFreak.js +0 -92
  99. package/src/compiler/detector/kernels/cpu/computeFreakDescriptors.js +0 -68
  100. package/src/compiler/detector/kernels/cpu/computeLocalization.js +0 -67
  101. package/src/compiler/detector/kernels/cpu/computeOrientationHistograms.js +0 -124
  102. package/src/compiler/detector/kernels/cpu/downsampleBilinear.js +0 -33
  103. package/src/compiler/detector/kernels/cpu/extremaReduction.js +0 -53
  104. package/src/compiler/detector/kernels/cpu/fakeShader.js +0 -88
  105. package/src/compiler/detector/kernels/cpu/index.js +0 -26
  106. package/src/compiler/detector/kernels/cpu/prune.js +0 -78
  107. package/src/compiler/detector/kernels/cpu/smoothHistograms.js +0 -57
  108. package/src/compiler/detector/kernels/cpu/upsampleBilinear.js +0 -51
  109. package/src/compiler/detector/kernels/index.js +0 -2
  110. package/src/compiler/detector/kernels/webgl/binomialFilter.js +0 -72
  111. package/src/compiler/detector/kernels/webgl/buildExtremas.js +0 -109
  112. package/src/compiler/detector/kernels/webgl/computeExtremaAngles.js +0 -82
  113. package/src/compiler/detector/kernels/webgl/computeExtremaFreak.js +0 -105
  114. package/src/compiler/detector/kernels/webgl/computeFreakDescriptors.js +0 -56
  115. package/src/compiler/detector/kernels/webgl/computeLocalization.js +0 -70
  116. package/src/compiler/detector/kernels/webgl/computeOrientationHistograms.js +0 -129
  117. package/src/compiler/detector/kernels/webgl/downsampleBilinear.js +0 -50
  118. package/src/compiler/detector/kernels/webgl/extremaReduction.js +0 -50
  119. package/src/compiler/detector/kernels/webgl/index.js +0 -26
  120. package/src/compiler/detector/kernels/webgl/smoothHistograms.js +0 -53
  121. package/src/compiler/detector/kernels/webgl/upsampleBilinear.js +0 -62
  122. package/src/compiler/tensorflow-setup.js +0 -116
@@ -1,52 +0,0 @@
1
- import { FREAKPOINTS } from "../../freak.js";
2
- const FREAK_CONPARISON_COUNT = ((FREAKPOINTS.length - 1) * FREAKPOINTS.length) / 2;
3
- const descriptorCount = Math.ceil(FREAK_CONPARISON_COUNT / 8);
4
- const cache = {};
5
- function GetProgram(extremaFreaks) {
6
- const key = `${extremaFreaks.shape[0]}`;
7
- if (!cache.hasOwnProperty(key)) {
8
- const kernel = {
9
- variableNames: ["freak", "p"],
10
- outputShape: [extremaFreaks.shape[0], descriptorCount],
11
- userCode: `
12
- void main() {
13
- ivec2 coords = getOutputCoords();
14
- int featureIndex = coords[0];
15
- int descIndex = coords[1] * 8;
16
-
17
- int sum = 0;
18
- for (int i = 0; i < 8; i++) {
19
- if (descIndex + i >= ${FREAK_CONPARISON_COUNT}) {
20
- continue;
21
- }
22
-
23
- int p1 = int(getP(descIndex + i, 0));
24
- int p2 = int(getP(descIndex + i, 1));
25
-
26
- float v1 = getFreak(featureIndex, p1);
27
- float v2 = getFreak(featureIndex, p2);
28
-
29
- if (v1 < v2 + 0.01) {
30
- sum += int(pow(2.0, float(7 - i)));
31
- }
32
- }
33
- setOutput(float(sum));
34
- }
35
- `,
36
- };
37
- cache[key] = kernel;
38
- }
39
- return cache[key];
40
- }
41
- export const computeFreakDescriptor = (args) => {
42
- const { extremaFreaks, positionT } = args.inputs;
43
- const { backend } = args;
44
- const program = GetProgram(extremaFreaks);
45
- return backend.runWebGLProgram(program, [extremaFreaks, positionT], "int32");
46
- };
47
- export const computeFreakDescriptorConfig = {
48
- //: KernelConfig
49
- kernelName: "ComputeFreakDescriptors",
50
- backendName: "webgl",
51
- kernelFunc: computeFreakDescriptor, // as {} as KernelFunc,
52
- };
@@ -1,6 +0,0 @@
1
- export function computeLocalization(args: any): any;
2
- export namespace computeLocalizationConfig {
3
- export let kernelName: string;
4
- export let backendName: string;
5
- export { computeLocalization as kernelFunc };
6
- }
@@ -1,58 +0,0 @@
1
- import { tensor } from "@tensorflow/tfjs";
2
- const cache = {};
3
- function GetProgram(numDogPyramidImages, extremasListLength) {
4
- const kernelKey = `${numDogPyramidImages}|${extremasListLength}`;
5
- if (!cache.hasOwnProperty(kernelKey)) {
6
- const dogVariableNames = [];
7
- let dogSubCodes = `float getPixel(int octave, int y, int x) {`;
8
- for (let i = 1; i < numDogPyramidImages; i++) {
9
- // extrema starts from second octave
10
- dogVariableNames.push("image" + i);
11
- dogSubCodes += `
12
- if (octave == ${i}) {
13
- return getImage${i}(y, x);
14
- }
15
- `;
16
- }
17
- dogSubCodes += `}`;
18
- cache[kernelKey] = {
19
- variableNames: [...dogVariableNames, "extrema"],
20
- outputShape: [extremasListLength, 3, 3], // 3x3 pixels around the extrema
21
- userCode: `
22
- ${dogSubCodes}
23
-
24
- void main() {
25
- ivec3 coords = getOutputCoords();
26
- int featureIndex = coords[0];
27
- float score = getExtrema(featureIndex, 0);
28
- if (score == 0.0) {
29
- return;
30
- }
31
-
32
- int dy = coords[1]-1;
33
- int dx = coords[2]-1;
34
- int octave = int(getExtrema(featureIndex, 1));
35
- int y = int(getExtrema(featureIndex, 2));
36
- int x = int(getExtrema(featureIndex, 3));
37
- setOutput(getPixel(octave, y+dy, x+dx));
38
- }
39
- `,
40
- };
41
- }
42
- return cache[kernelKey];
43
- }
44
- export const computeLocalization = (args) => {
45
- /** @type {import('@tensorflow/tfjs').TensorInfo} */
46
- const { prunedExtremasList, dogPyramidImagesT } = args.inputs;
47
- /** @type {MathBackendWebGL} */
48
- const backend = args.backend;
49
- const program = GetProgram(dogPyramidImagesT.length, prunedExtremasList.length);
50
- const prunedExtremasT = tensor(prunedExtremasList, [prunedExtremasList.length, prunedExtremasList[0].length], "int32");
51
- return backend.runWebGLProgram(program, [...dogPyramidImagesT.slice(1), prunedExtremasT], dogPyramidImagesT[0].dtype);
52
- };
53
- export const computeLocalizationConfig = {
54
- //: KernelConfig
55
- kernelName: "ComputeLocalization",
56
- backendName: "webgl",
57
- kernelFunc: computeLocalization, // as {} as KernelFunc,
58
- };
@@ -1,6 +0,0 @@
1
- export function computeOrientationHistograms(args: any): any;
2
- export namespace computeOrientationHistogramsConfig {
3
- export let kernelName: string;
4
- export let backendName: string;
5
- export { computeOrientationHistograms as kernelFunc };
6
- }
@@ -1,116 +0,0 @@
1
- const oneOver2PI = 0.159154943091895;
2
- const ORIENTATION_NUM_BINS = 36;
3
- const cache = {};
4
- function GetPrograms(prunedExtremasT, radialPropertiesT, pyramidImagesLength) {
5
- const key = `${pyramidImagesLength}|${prunedExtremasT.shape[0]}|${radialPropertiesT.shape[0]}`;
6
- if (!cache.hasOwnProperty(key)) {
7
- const imageVariableNames = [];
8
- for (let i = 1; i < pyramidImagesLength; i++) {
9
- imageVariableNames.push("image" + i);
10
- }
11
- let kernel1SubCodes = `float getPixel(int octave, int y, int x) {`;
12
- for (let i = 1; i < pyramidImagesLength; i++) {
13
- kernel1SubCodes += `
14
- if (octave == ${i}) {
15
- return getImage${i}(y, x);
16
- }
17
- `;
18
- }
19
- kernel1SubCodes += `}`;
20
- const kernel1 = {
21
- variableNames: [...imageVariableNames, "extrema", "radial"],
22
- outputShape: [prunedExtremasT.shape[0], radialPropertiesT.shape[0], 2], // last dimension: [fbin, magnitude]
23
- userCode: `
24
- ${kernel1SubCodes}
25
-
26
- void main() {
27
- ivec3 coords = getOutputCoords();
28
- int featureIndex = coords[0];
29
- int radialIndex = coords[1];
30
- int propertyIndex = coords[2];
31
-
32
- int radialY = int(getRadial(radialIndex, 0));
33
- int radialX = int(getRadial(radialIndex, 1));
34
- float radialW = getRadial(radialIndex, 2);
35
-
36
- int octave = int(getExtrema(featureIndex, 1));
37
- int y = int(getExtrema(featureIndex, 2));
38
- int x = int(getExtrema(featureIndex, 3));
39
-
40
- int xp = x + radialX;
41
- int yp = y + radialY;
42
-
43
- float dy = getPixel(octave, yp+1, xp) - getPixel(octave, yp-1, xp);
44
- float dx = getPixel(octave, yp, xp+1) - getPixel(octave, yp, xp-1);
45
-
46
- if (propertyIndex == 0) {
47
- // be careful that atan(0, 0) gives 1.57 instead of 0 (different from js), but doesn't matter here, coz magnitude is 0
48
-
49
- float angle = atan(dy, dx) + ${Math.PI};
50
- float fbin = angle * ${ORIENTATION_NUM_BINS}. * ${oneOver2PI};
51
- setOutput(fbin);
52
- return;
53
- }
54
-
55
- if (propertyIndex == 1) {
56
- float mag = sqrt(dx * dx + dy * dy);
57
- float magnitude = radialW * mag;
58
- setOutput(magnitude);
59
- return;
60
- }
61
- }
62
-
63
- `,
64
- };
65
- const kernel2 = {
66
- variableNames: ["fbinMag"],
67
- outputShape: [prunedExtremasT.shape[0], ORIENTATION_NUM_BINS],
68
- userCode: `
69
- void main() {
70
- ivec2 coords = getOutputCoords();
71
- int featureIndex = coords[0];
72
- int binIndex = coords[1];
73
-
74
- float sum = 0.;
75
- for (int i = 0; i < ${radialPropertiesT.shape[0]}; i++) {
76
- float fbin = getFbinMag(featureIndex, i, 0);
77
- int bin = int(floor(fbin - 0.5));
78
- int b1 = imod(bin + ${ORIENTATION_NUM_BINS}, ${ORIENTATION_NUM_BINS});
79
- int b2 = imod(bin + 1 + ${ORIENTATION_NUM_BINS}, ${ORIENTATION_NUM_BINS});
80
-
81
- if (b1 == binIndex || b2 == binIndex) {
82
- float magnitude = getFbinMag(featureIndex, i, 1);
83
- float w2 = fbin - float(bin) - 0.5;
84
- float w1 = w2 * -1. + 1.;
85
-
86
- if (b1 == binIndex) {
87
- sum += w1 * magnitude;
88
- }
89
- if (b2 == binIndex) {
90
- sum += w2 * magnitude;
91
- }
92
- }
93
- }
94
- setOutput(sum);
95
- }
96
- `,
97
- };
98
- cache[key] = [kernel1, kernel2];
99
- }
100
- return cache[key];
101
- }
102
- export const computeOrientationHistograms = (args) => {
103
- const { gaussianImagesT, prunedExtremasT, radialPropertiesT, pyramidImagesLength } = args.inputs;
104
- /** @type {MathBackendWebGL} */
105
- const backend = args.backend;
106
- const [program1, program2] = GetPrograms(prunedExtremasT, radialPropertiesT, pyramidImagesLength);
107
- const result1 = backend.runWebGLProgram(program1, [...gaussianImagesT, prunedExtremasT, radialPropertiesT], radialPropertiesT.dtype);
108
- const result2 = backend.runWebGLProgram(program2, [result1], radialPropertiesT.dtype);
109
- backend.disposeIntermediateTensorInfo(result1);
110
- return result2;
111
- };
112
- export const computeOrientationHistogramsConfig = {
113
- kernelName: "ComputeOrientationHistograms",
114
- backendName: "webgl",
115
- kernelFunc: computeOrientationHistograms, // as {} as KernelFunc,
116
- };
@@ -1,6 +0,0 @@
1
- export function downsampleBilinear(args: any): any;
2
- export namespace downsampleBilinearConfig {
3
- export let kernelName: string;
4
- export let backendName: string;
5
- export { downsampleBilinear as kernelFunc };
6
- }
@@ -1,46 +0,0 @@
1
- const cache = {};
2
- /**
3
- *
4
- * @param {TensorInfo} image
5
- * @returns {GPGPUProgram}
6
- */
7
- function GetProgram(image) {
8
- const imageWidth = image.shape[1];
9
- const imageHeight = image.shape[0];
10
- const kernelKey = "w" + imageWidth + "h" + imageHeight;
11
- if (!cache.hasOwnProperty(kernelKey)) {
12
- const kernel = {
13
- variableNames: ["p"],
14
- outputShape: [Math.floor(imageHeight / 2), Math.floor(imageWidth / 2)],
15
- userCode: `
16
- void main() {
17
- ivec2 coords = getOutputCoords();
18
- int y = coords[0] * 2;
19
- int x = coords[1] * 2;
20
-
21
- float sum = getP(y, x) * 0.25;
22
- sum += getP(y+1,x) * 0.25;
23
- sum += getP(y, x+1) * 0.25;
24
- sum += getP(y+1,x+1) * 0.25;
25
- setOutput(sum);
26
- }
27
- `,
28
- };
29
- cache[kernelKey] = kernel;
30
- }
31
- return cache[kernelKey];
32
- }
33
- export const downsampleBilinear = (args) => {
34
- /** @type {import('@tensorflow/tfjs').TensorInfo} */
35
- const image = args.inputs.image;
36
- /** @type {MathBackendWebGL} */
37
- const backend = args.backend;
38
- const program = GetProgram(image);
39
- return backend.runWebGLProgram(program, [image], image.dtype);
40
- };
41
- export const downsampleBilinearConfig = {
42
- //: KernelConfig
43
- kernelName: "DownsampleBilinear",
44
- backendName: "webgl",
45
- kernelFunc: downsampleBilinear, // as {} as KernelFunc,
46
- };
@@ -1,6 +0,0 @@
1
- export function extremaReduction(args: any): any;
2
- export namespace extremaReductionConfig {
3
- export let kernelName: string;
4
- export let backendName: string;
5
- export { extremaReduction as kernelFunc };
6
- }
@@ -1,48 +0,0 @@
1
- export const extremaReduction = (args) => {
2
- /** @type {import('@tensorflow/tfjs').TensorInfo[]} */
3
- const { extremasResultT } = args.inputs;
4
- /** @type {MathBackendWebGL} */
5
- const backend = args.backend;
6
- const extremaHeight = extremasResultT.shape[0];
7
- const extremaWidth = extremasResultT.shape[1];
8
- const kernel = {
9
- variableNames: ["extrema"],
10
- outputShape: [Math.floor(extremaHeight / 2), Math.floor(extremaWidth / 2)],
11
- userCode: `
12
- void main() {
13
- ivec2 coords = getOutputCoords();
14
- int y = coords[0] * 2;
15
- int x = coords[1] * 2;
16
-
17
- float location = 0.0;
18
- float values = getExtrema(y, x);
19
-
20
- if (getExtrema(y+1, x) != 0.0) {
21
- location = 1.0;
22
- values = getExtrema(y+1, x);
23
- }
24
- else if (getExtrema(y, x+1) != 0.0) {
25
- location = 2.0;
26
- values = getExtrema(y, x+1);
27
- }
28
- else if (getExtrema(y+1, x+1) != 0.0) {
29
- location = 3.0;
30
- values = getExtrema(y+1, x+1);
31
- }
32
-
33
- if (values < 0.0) {
34
- setOutput(location * -1000.0 + values);
35
- } else {
36
- setOutput(location * 1000.0 + values);
37
- }
38
- }
39
- `,
40
- };
41
- return backend.runWebGLProgram(kernel, [extremasResultT], extremasResultT.dtype);
42
- };
43
- export const extremaReductionConfig = {
44
- //: KernelConfig
45
- kernelName: "ExtremaReduction",
46
- backendName: "webgl",
47
- kernelFunc: extremaReduction, // as {} as KernelFunc,
48
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,25 +0,0 @@
1
- import { registerKernel } from "@tensorflow/tfjs";
2
- import { binomialFilterConfig } from "./binomialFilter.js";
3
- import { buildExtremasConfig } from "./buildExtremas.js";
4
- import { computeExtremaAnglesConfig } from "./computeExtremaAngles.js";
5
- import { computeExtremaFreakConfig } from "./computeExtremaFreak.js";
6
- import { computeFreakDescriptorConfig } from "./computeFreakDescriptors.js";
7
- import { computeLocalizationConfig } from "./computeLocalization.js";
8
- import { computeOrientationHistogramsConfig } from "./computeOrientationHistograms.js";
9
- import { downsampleBilinearConfig } from "./downsampleBilinear.js";
10
- import { extremaReductionConfig } from "./extremaReduction.js";
11
- import { smoothHistogramsConfig } from "./smoothHistograms.js";
12
- import { upsampleBilinearConfig } from "./upsampleBilinear.js";
13
- //export function Register(){
14
- registerKernel(binomialFilterConfig);
15
- registerKernel(buildExtremasConfig);
16
- registerKernel(computeExtremaAnglesConfig);
17
- registerKernel(computeExtremaFreakConfig);
18
- registerKernel(computeFreakDescriptorConfig);
19
- registerKernel(computeLocalizationConfig);
20
- registerKernel(computeOrientationHistogramsConfig);
21
- registerKernel(downsampleBilinearConfig);
22
- registerKernel(extremaReductionConfig);
23
- registerKernel(smoothHistogramsConfig);
24
- registerKernel(upsampleBilinearConfig);
25
- //}
@@ -1,6 +0,0 @@
1
- export function smoothHistograms(args: any): any;
2
- export namespace smoothHistogramsConfig {
3
- export let kernelName: string;
4
- export let backendName: string;
5
- export { smoothHistograms as kernelFunc };
6
- }
@@ -1,49 +0,0 @@
1
- const ORIENTATION_NUM_BINS = 36;
2
- const ORIENTATION_SMOOTHING_ITERATIONS = 5;
3
- const cache = {};
4
- function GetProgram(histograms) {
5
- const kernelKey = `h${histograms.shape[0]}`;
6
- if (!cache.hasOwnProperty(kernelKey)) {
7
- const kernel = {
8
- variableNames: ["histogram"],
9
- outputShape: [histograms.shape[0], ORIENTATION_NUM_BINS],
10
- userCode: `
11
- void main() {
12
- ivec2 coords = getOutputCoords();
13
-
14
- int featureIndex = coords[0];
15
- int binIndex = coords[1];
16
-
17
- int prevBin = imod(binIndex - 1 + ${ORIENTATION_NUM_BINS}, ${ORIENTATION_NUM_BINS});
18
- int nextBin = imod(binIndex + 1, ${ORIENTATION_NUM_BINS});
19
- float result = 0.274068619061197 * getHistogram(featureIndex, prevBin) + 0.451862761877606 * getHistogram(featureIndex, binIndex) + 0.274068619061197 * getHistogram(featureIndex, nextBin);
20
-
21
- setOutput(result);
22
- }
23
- `,
24
- };
25
- cache[kernelKey] = kernel;
26
- }
27
- return cache[kernelKey];
28
- }
29
- export const smoothHistograms = (args) => {
30
- /** @type {import('@tensorflow/tfjs').TensorInfo} */
31
- let { histograms } = args.inputs;
32
- /** @type {MathBackendWebGL} */
33
- const backend = args.backend;
34
- const program = GetProgram(histograms);
35
- for (let i = 0; i < ORIENTATION_SMOOTHING_ITERATIONS; i++) {
36
- const _histograms = histograms;
37
- histograms = backend.runWebGLProgram(program, [histograms], histograms.dtype); //this._compileAndRun(program, [histograms]);
38
- if (i > 0) {
39
- backend.disposeIntermediateTensorInfo(_histograms);
40
- }
41
- }
42
- return histograms;
43
- };
44
- export const smoothHistogramsConfig = {
45
- //: KernelConfig
46
- kernelName: "SmoothHistograms",
47
- backendName: "webgl",
48
- kernelFunc: smoothHistograms, // as {} as KernelFunc,
49
- };
@@ -1,6 +0,0 @@
1
- export function upsampleBilinear(args: any): any;
2
- export namespace upsampleBilinearConfig {
3
- export let kernelName: string;
4
- export let backendName: string;
5
- export { upsampleBilinear as kernelFunc };
6
- }
@@ -1,56 +0,0 @@
1
- import { MathBackendWebGL } from "@tensorflow/tfjs-backend-webgl";
2
- const cache = {};
3
- function GetProgram(targetImage) {
4
- const targetImageWidth = targetImage.shape[1];
5
- const targetImageHeight = targetImage.shape[0];
6
- const kernelKey = "w" + targetImageWidth + "h" + targetImageHeight;
7
- if (!cache.hasOwnProperty(kernelKey)) {
8
- const kernel = {
9
- variableNames: ["p"],
10
- outputShape: [targetImageHeight, targetImageWidth],
11
- userCode: `
12
- void main() {
13
- ivec2 coords = getOutputCoords();
14
- int j = coords[0];
15
- int i = coords[1];
16
-
17
- float sj = 0.5 * float(j) - 0.25;
18
- float si = 0.5 * float(i) - 0.25;
19
-
20
- float sj0 = floor(sj);
21
- float sj1 = ceil(sj);
22
- float si0 = floor(si);
23
- float si1 = ceil(si);
24
-
25
- int sj0I = int(sj0);
26
- int sj1I = int(sj1);
27
- int si0I = int(si0);
28
- int si1I = int(si1);
29
-
30
- float sum = 0.0;
31
- sum += getP(sj0I, si0I) * (si1 - si) * (sj1 - sj);
32
- sum += getP(sj1I, si0I) * (si1 - si) * (sj - sj0);
33
- sum += getP(sj0I, si1I) * (si - si0) * (sj1 - sj);
34
- sum += getP(sj1I, si1I) * (si - si0) * (sj - sj0);
35
- setOutput(sum);
36
- }
37
- `,
38
- };
39
- cache[kernelKey] = kernel;
40
- }
41
- return cache[kernelKey];
42
- }
43
- export const upsampleBilinear = (args) => {
44
- /** @type {import('@tensorflow/tfjs').TensorInfo} */
45
- const { image, targetImage } = args.inputs;
46
- /** @type {MathBackendWebGL} */
47
- const backend = args.backend;
48
- const program = GetProgram(targetImage);
49
- return backend.runWebGLProgram(program, [image], image.dtype);
50
- };
51
- export const upsampleBilinearConfig = {
52
- //: KernelConfig
53
- kernelName: "UpsampleBilinear",
54
- backendName: "webgl",
55
- kernelFunc: upsampleBilinear, // as {} as KernelFunc,
56
- };
@@ -1,6 +0,0 @@
1
- /**
2
- * Configuración optimizada de TensorFlow para diferentes entornos
3
- * @returns {Promise<string>} El backend activo ('webgl', 'cpu')
4
- */
5
- export function setupTensorFlow(): Promise<string>;
6
- export { tf };
@@ -1,99 +0,0 @@
1
- import * as tf from "@tensorflow/tfjs";
2
- // Registrar backends básicos
3
- import "@tensorflow/tfjs-backend-cpu";
4
- import "@tensorflow/tfjs-backend-webgl";
5
- // Registrar kernels personalizados
6
- import "./detector/kernels/cpu/index.js";
7
- import "./detector/kernels/webgl/index.js";
8
- /**
9
- * Intenta cargar el backend de Node.js si está disponible
10
- */
11
- const loadNodeBackend = async () => {
12
- if (typeof process !== "undefined" && process.versions && process.versions.node) {
13
- try {
14
- // Usar import dinámico para evitar errores en el navegador
15
- await import("@tensorflow/tfjs-node");
16
- console.log("🚀 TensorFlow Node.js backend cargado correctamente");
17
- return true;
18
- }
19
- catch (e) {
20
- console.warn("⚠️ No se pudo cargar @tensorflow/tfjs-node, usando fallback");
21
- return false;
22
- }
23
- }
24
- return false;
25
- };
26
- /**
27
- * Configuración optimizada de TensorFlow para diferentes entornos
28
- * @returns {Promise<string>} El backend activo ('webgl', 'cpu')
29
- */
30
- export async function setupTensorFlow() {
31
- console.log("🔧 Iniciando configuración optimizada de TensorFlow.js...");
32
- try {
33
- // Intentar cargar backend de Node.js primero
34
- const nodeBackendLoaded = await loadNodeBackend();
35
- // Optimizaciones base para todos los backends
36
- tf.ENV.set("DEBUG", false);
37
- tf.ENV.set("WEBGL_CPU_FORWARD", false);
38
- tf.ENV.set("WEBGL_FORCE_F16_TEXTURES", true);
39
- // Configuración adaptativa de memoria según el entorno
40
- const isServerless = typeof window === "undefined";
41
- const memoryThreshold = isServerless ? 1024 * 1024 * 4 : 1024 * 1024 * 8;
42
- tf.ENV.set("CPU_HANDOFF_SIZE_THRESHOLD", memoryThreshold);
43
- if (nodeBackendLoaded) {
44
- await tf.setBackend("tensorflow");
45
- console.log("🚀 Backend TensorFlow (Node.js) activado");
46
- await tf.ready();
47
- return "tensorflow";
48
- }
49
- // Configuración específica para entorno serverless
50
- if (isServerless) {
51
- try {
52
- await tf.setBackend("cpu");
53
- console.log("🚀 Backend CPU optimizado para entorno serverless");
54
- // Optimizaciones específicas para CPU en serverless
55
- tf.ENV.set("CPU_HANDOFF_SIZE_THRESHOLD", 1024 * 1024 * 2); // 2MB
56
- tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD", 0);
57
- // Precalentar el backend
58
- await tf.ready();
59
- return "cpu";
60
- }
61
- catch (cpuError) {
62
- console.error("❌ Error crítico en configuración CPU:", cpuError);
63
- throw new Error("No se pudo inicializar TensorFlow.js en modo serverless");
64
- }
65
- }
66
- // Configuración optimizada para navegador (WebGL)
67
- try {
68
- // Optimizaciones avanzadas para WebGL
69
- tf.ENV.set("WEBGL_PACK", true);
70
- tf.ENV.set("WEBGL_PACK_DEPTHWISECONV", true);
71
- tf.ENV.set("WEBGL_MAX_TEXTURE_SIZE", 4096);
72
- tf.ENV.set("WEBGL_USE_SHAPES_UNIFORMS", true);
73
- tf.ENV.set("WEBGL_CONV_IM2COL", true);
74
- await tf.setBackend("webgl");
75
- console.log("🎮 Backend WebGL activado con optimizaciones avanzadas");
76
- // Precalentar el backend
77
- await tf.ready();
78
- return "webgl";
79
- }
80
- catch (webglError) {
81
- console.warn(`No se pudo activar WebGL: ${webglError.message}, usando CPU como último recurso`);
82
- }
83
- // CPU Backend (más lento, último recurso)
84
- await tf.setBackend("cpu");
85
- console.log("⚠️ Backend CPU activado (rendimiento sub-óptimo)");
86
- // Optimizaciones específicas para CPU
87
- tf.ENV.set("CPU_HANDOFF_SIZE_THRESHOLD", 1024 * 1024 * 2); // 2MB
88
- }
89
- catch (error) {
90
- console.error("Error crítico configurando backends de TensorFlow:", error);
91
- throw new Error("No se pudo inicializar TensorFlow.js con ningún backend");
92
- }
93
- // Registrar kernels específicos para el backend activo
94
- const backend = tf.getBackend();
95
- console.log(`Backend activo: ${backend}`);
96
- return backend;
97
- }
98
- // Exportamos tf para poder usarlo en otros archivos
99
- export { tf };