Skip to content

Commit

Permalink
fix memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Mmasoud1 committed Feb 4, 2024
1 parent ee9d680 commit baa236b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
30 changes: 26 additions & 4 deletions js/brainchop/mainMeshNetFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4260,9 +4260,13 @@ class SequentialConvLayer {
// console.log("---------------------------------------------------------");
console.log(" channel loop");

let seqTimer = window.setInterval(function() {
let seqTimer = window.setInterval(async function() {

console.log(chIdx);
console.log('=======================');
const memoryInfo0 = tf.memory();
console.log(`| Number of Tensors: ${memoryInfo0.numTensors}`);
console.log(`| Number of Data Buffers: ${memoryInfo0.numDataBuffers}`);
console.log("Channel : ", chIdx);

const result = tf.tidy(() => {
const filterWeights = weights.slice([0, 0, 0, 0, chIdx], [-1, -1, -1, -1, 1]);
Expand All @@ -4274,12 +4278,27 @@ class SequentialConvLayer {
const newoutB = tf.where(greater, outA, outB);
const newoutC = tf.where(greater, tf.fill(outC.shape, chIdx), outC);
// Dispose the old tensors before reassigning
tf.dispose([outB, outC]);
tf.dispose([outB, outC, filterWeights, filterBiases, outA, greater]);
return [newoutC, newoutB];
});

// -- await showMemStatus(chIdx, self.outChannels);

const memoryInfo1 = tf.memory();
console.log(`| Number of Tensors: ${memoryInfo1.numTensors}`);
console.log(`| Number of Data Buffers: ${memoryInfo1.numDataBuffers}`);
console.log('=======================');

// Log memory usage

const memoryInfo = tf.memory();
console.log(`Iteration ${chIdx}:`);
console.log(`Number of Tensors: ${memoryInfo.numTensors}`);
console.log(`Number of Data Buffers: ${memoryInfo.numDataBuffers}`);
console.log(`Bytes In Use: ${memoryInfo.numBytes}`);
console.log(`Megabytes In Use: ${(memoryInfo.numBytes / 1048576).toFixed(3)} MB`);
console.log(`Unreliable: ${memoryInfo.unreliable}`);

// Assign the new values to outC and outB
outC = result[0];
outB = result[1];
Expand All @@ -4296,11 +4315,14 @@ class SequentialConvLayer {
} else {

chIdx++;

// Artificially introduce a pause to allow for garbage collection to catch up
await new Promise(resolve => setTimeout(resolve, 0));
document.getElementById("progressBarChild").style.width = (chIdx + 1)*100/self.outChannels + "%";
}


}, 50);
}, 0);
});

}
Expand Down
4 changes: 2 additions & 2 deletions js/brainchop/mainParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
enableCrop: true, // For speed-up inference, crop brain from background before feeding to inference model to lower memory use.
cropPadding: 2, // Padding size add to cropped brain
filterOutWithPreMask: false, // Can be used to multiply final output with premodel output mask to crean noisy areas
enableSeqConv: false, // For low memory system and low configuration, enable sequential convolution instead of last layer
enableSeqConv: true, // For low memory system and low configuration, enable sequential convolution instead of last layer
textureSize: 13585, // Requested Texture size for the model, if unknown can be 0.
warning: "This model may need dedicated graphics card. For more info please check with Browser Resources <i class='fa fa-cogs'></i>.",
inferenceDelay: 100, // Delay in ms time while looping layers applying.
Expand Down Expand Up @@ -220,7 +220,7 @@
enableCrop: true, // For speed-up inference, crop brain from background before feeding to inference model to lower memory use.
cropPadding: 2, // Padding size add to cropped brain
filterOutWithPreMask: false, // Can be used to multiply final output with premodel output mask to crean noisy areas
enableSeqConv: false, // For low memory system and low configuration, enable sequential convolution instead of last layer
enableSeqConv: true, // For low memory system and low configuration, enable sequential convolution instead of last layer
textureSize: 13585, // Requested Texture size for the model, if unknown can be 0.
warning: "This model may need dedicated graphics card. For more info please check with Browser Resources <i class='fa fa-cogs'></i>.",
inferenceDelay: 100, // Delay in ms time while looping layers applying.
Expand Down

0 comments on commit baa236b

Please sign in to comment.