@@ -4094,7 +4094,6 @@ showMemStatus = async(chIdx, totalChannels) => {
4094
4094
4095
4095
}
4096
4096
4097
-
4098
4097
class SequentialConvLayer {
4099
4098
constructor ( model , chunkSize , isChannelLast ) {
4100
4099
this . model = model ;
@@ -4150,37 +4149,30 @@ class SequentialConvLayer {
4150
4149
const self = this ;
4151
4150
// Important to avoid "undefined" class var members inside the timer.
4152
4151
// "this" has another meaning inside the timer.
4153
-
4154
- // *** WARNING!!! if you uncomment this line the memory leak will break webGL and may reboot your machine
4155
- //document.getElementById("progressBarChild").parentElement.style.visibility = "visible";
4156
-
4157
- return new Promise ( ( resolve , reject ) => {
4158
-
4159
- const startTime = performance . now ( ) ;
4160
-
4161
- const convLayer = self . model . layers [ self . model . layers . length - 1 ] ;
4162
- const weights = convLayer . getWeights ( ) [ 0 ] ; //
4163
- const biases = convLayer . getWeights ( ) [ 1 ] ;
4164
- const outputShape = self . isChannelLast ? inputTensor . shape . slice ( 1 , - 1 ) : inputTensor . shape . slice ( 2 ) ;
4165
-
4166
- //-- e.g. outputShape : [256,256,256] or cropped Dim
4167
- //-- if inputTensor [ 1, D, H, W, 50 ], channelLast true -> outputShape : outputShape [D, H, W]
4168
- //-- if inputTensor [ 1, 50, D, H, W ], channelLast false -> outputShape : outputShape [D, H, W]
4169
-
4170
- let outB = tf . mul ( tf . ones ( outputShape ) , - 10000 ) ;
4171
- //-- e.g. outB.shape [256,256,256]
4172
- let outC = tf . zeros ( outputShape ) ;
4173
- //-- e.g. outC.shape [256,256,256]
4174
- let chIdx = 0 ;
4175
-
4176
- // console.log("---------------------------------------------------------");
4177
- console . log ( " channel loop" ) ;
4178
-
4179
- let seqTimer = window . setInterval ( function ( ) {
4180
-
4152
+ const startTime = performance . now ( ) ;
4153
+
4154
+ const convLayer = self . model . layers [ self . model . layers . length - 1 ] ;
4155
+ const weights = convLayer . getWeights ( ) [ 0 ] ; //
4156
+ const biases = convLayer . getWeights ( ) [ 1 ] ;
4157
+ const outputShape = self . isChannelLast ? inputTensor . shape . slice ( 1 , - 1 ) : inputTensor . shape . slice ( 2 ) ;
4158
+
4159
+ //-- e.g. outputShape : [256,256,256] or cropped Dim
4160
+ //-- if inputTensor [ 1, D, H, W, 50 ], channelLast true -> outputShape : outputShape [D, H, W]
4161
+ //-- if inputTensor [ 1, 50, D, H, W ], channelLast false -> outputShape : outputShape [D, H, W]
4162
+
4163
+ let outB = tf . mul ( tf . ones ( outputShape ) , - 10000 ) ;
4164
+ //-- e.g. outB.shape [256,256,256]
4165
+ let outC = tf . zeros ( outputShape ) ;
4166
+ //-- e.g. outC.shape [256,256,256]
4167
+ let chIdx = 0 ;
4168
+
4169
+ // console.log("---------------------------------------------------------");
4170
+ console . log ( " channel loop" ) ;
4171
+
4172
+ for ( let chIdx = 0 ; chIdx < this . outChannels ; chIdx ++ ) {
4181
4173
console . log ( chIdx ) ;
4182
4174
4183
- const result = tf . tidy ( ( ) => {
4175
+ const result = tf . tidy ( ( ) => {
4184
4176
const filterWeights = weights . slice ( [ 0 , 0 , 0 , 0 , chIdx ] , [ - 1 , - 1 , - 1 , - 1 , 1 ] ) ;
4185
4177
// -- e.g. filterWeights.shape [ 1, 1, 1, 5, 1 ]
4186
4178
const filterBiases = biases . slice ( [ chIdx ] , [ 1 ] ) ;
@@ -4202,32 +4194,23 @@ class SequentialConvLayer {
4202
4194
console . log ( `Number of Data Buffers: ${ memoryInfo . numDataBuffers } ` ) ;
4203
4195
console . log ( `Bytes In Use: ${ memoryInfo . numBytes } ` ) ;
4204
4196
console . log ( `Megabytes In Use: ${ ( memoryInfo . numBytes / 1048576 ) . toFixed ( 3 ) } MB` ) ;
4205
- console . log ( `Unreliable: ${ memoryInfo . unreliable } ` ) ;
4197
+ console . log ( `Unreliable: ${ memoryInfo . unreliable } ` ) ;
4206
4198
4207
4199
// Assign the new values to outC and outB
4208
4200
outC = result [ 0 ] ;
4209
- outB = result [ 1 ] ;
4210
-
4211
- if ( chIdx == ( self . outChannels - 1 ) ) {
4212
-
4213
- window . clearInterval ( seqTimer ) ;
4214
- // *** WARNING!!! if you uncomment this line the memory leak will break webGL and may reboot your machine
4215
- // document.getElementById("progressBarChild").style.width = 0 + "%";
4216
- tf . dispose ( outB ) ;
4217
- const endTime = performance . now ( ) ;
4218
- const executionTime = endTime - startTime ;
4219
- console . log ( `Execution time for output layer: ${ executionTime } milliseconds` ) ;
4220
- resolve ( outC ) ;
4221
- }
4222
- chIdx ++ ;
4223
- // *** WARNING!!! if you uncomment this line the memory leak will break webGL and may reboot your machine
4224
- //document.getElementById("progressBarChild").style.width = (chIdx + 1)*100/self.outChannels + "%";
4225
- } , 100 ) ;
4226
- } ) ;
4201
+ outB = result [ 1 ] ;
4227
4202
4228
- }
4229
- }
4203
+ // Artificially introduce a pause to allow for garbage collection to catch up
4204
+ await new Promise ( resolve => setTimeout ( resolve , 0 ) ) ;
4230
4205
4206
+ }
4207
+ tf . dispose ( outB ) ;
4208
+ const endTime = performance . now ( ) ;
4209
+ const executionTime = endTime - startTime ;
4210
+ console . log ( `Execution time for output layer: ${ executionTime } milliseconds` ) ;
4211
+ return outC ;
4212
+ }
4213
+ }
4231
4214
4232
4215
4233
4216
/**
0 commit comments