@epfml/discojs 2.1.2-p20240717102015.0 → 2.1.2-p20240718132634.0
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as tf from '@tensorflow/tfjs';
|
|
1
2
|
/**
|
|
2
3
|
* Abstract class representing an immutable Disco dataset, including a TF.js dataset,
|
|
3
4
|
* Disco task and set of preprocessing functions.
|
|
@@ -59,8 +60,18 @@ export class Data {
|
|
|
59
60
|
if (applyPreprocessing.size === 0) {
|
|
60
61
|
return x => Promise.resolve(x);
|
|
61
62
|
}
|
|
62
|
-
const preprocessingChain =
|
|
63
|
-
|
|
63
|
+
const preprocessingChain = async (input) => {
|
|
64
|
+
let currentContainer = await input; // Start with the initial tensor container
|
|
65
|
+
for (const fn of applyPreprocessing) {
|
|
66
|
+
const newContainer = await fn(Promise.resolve(currentContainer), this.task);
|
|
67
|
+
if (currentContainer !== newContainer) {
|
|
68
|
+
tf.dispose(currentContainer); // Dispose of the old container
|
|
69
|
+
}
|
|
70
|
+
currentContainer = newContainer;
|
|
71
|
+
}
|
|
72
|
+
return currentContainer; // Return the final tensor container
|
|
73
|
+
};
|
|
74
|
+
return async (entry) => await preprocessingChain(Promise.resolve(entry));
|
|
64
75
|
}
|
|
65
76
|
/**
|
|
66
77
|
* The TF.js dataset preprocessing according to the set of preprocessing functions and the task's
|
|
@@ -25,10 +25,12 @@ const normalize = {
|
|
|
25
25
|
type: ImagePreprocessing.Normalize,
|
|
26
26
|
apply: async (entry) => {
|
|
27
27
|
const { xs, ys } = await entry;
|
|
28
|
-
return {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
return tf.tidy(() => {
|
|
29
|
+
return {
|
|
30
|
+
xs: xs.div(tf.scalar(255)),
|
|
31
|
+
ys
|
|
32
|
+
};
|
|
33
|
+
});
|
|
32
34
|
}
|
|
33
35
|
};
|
|
34
36
|
/**
|