@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,4 +1,4 @@
1
- import type tf from '@tensorflow/tfjs';
1
+ import * as tf from '@tensorflow/tfjs';
2
2
  import type { List } from 'immutable';
3
3
  import type { Task } from '../../index.js';
4
4
  import type { Dataset } from '../index.js';
@@ -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 = applyPreprocessing.reduce((acc, fn) => x => fn(acc(x), this.task), (x) => x);
63
- return x => preprocessingChain(Promise.resolve(x));
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
- xs: xs.div(tf.scalar(255)),
30
- ys
31
- };
28
+ return tf.tidy(() => {
29
+ return {
30
+ xs: xs.div(tf.scalar(255)),
31
+ ys
32
+ };
33
+ });
32
34
  }
33
35
  };
34
36
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epfml/discojs",
3
- "version": "2.1.2-p20240717102015.0",
3
+ "version": "2.1.2-p20240718132634.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",