@@ -39,8 +39,8 @@ augmenter.run({images: [img], points: [[[25, 90], [12, 32]]]})
3939// => { images : [Mat], points: [[<first point new position>, <second point new position>]] }
4040**/
4141class AbstractAugmenter extends Abstract {
42- constructor ( opts ) {
43- super ( opts ) ;
42+ constructor ( opts , ia ) {
43+ super ( opts , ia ) ;
4444 this . _augmenter = true ;
4545 }
4646 /**
@@ -71,8 +71,6 @@ class AbstractAugmenter extends Abstract {
7171
7272 const metadata = this . backend . getMetadata ( params1 . images ) ;
7373
74- debug ( `buildHasard ${ this . _name } ` ) ;
75-
7674 const o2 = Object . assign ( { } , metadata , params1 ) ;
7775 const { nImages} = metadata ;
7876
@@ -81,23 +79,31 @@ class AbstractAugmenter extends Abstract {
8179 if ( typeof ( this . buildAllImagesHasard ) === 'function' ) {
8280 resolved = this . buildAllImagesHasard ( o2 ) . runOnce ( runOpts ) ;
8381 } else {
84- debug ( `runOnce ${ this . _name } ` ) ;
82+ debug ( `buildHasard ${ this . _name } ( ${ this . backend . _tf && this . backend . _tf . memory ( ) . numTensors } ) ` ) ;
8583 const params = this . buildHasard ( o2 ) ;
84+ debug ( `runOnce ${ this . _name } (${ this . backend . _tf && this . backend . _tf . memory ( ) . numTensors } )` ) ;
85+
8686 // Every image hasard is generated independantly
8787 for ( let i = 0 ; i < nImages ; i ++ ) {
8888 const resolvedParams = hasard . isHasard ( params ) ? params . runOnce ( runOpts ) : params ;
8989 resolved . push ( resolvedParams ) ;
9090 }
9191 }
9292
93- // Console.log({resolved, params})
94- debug ( `augment ${ this . _name } ` ) ;
93+
94+ debug ( `augment ${ this . _name } (${ this . backend . _tf && this . backend . _tf . memory ( ) . numTensors } )` ) ;
95+
9596 return Promise . resolve ( this . augment ( o2 , resolved , runOpts ) ) ;
9697 }
9798
9899 fromFilenames ( { filenames} ) {
99100 return this . backend . readImages ( filenames ) . then ( images => {
100- this . runAugmenter ( { images} ) ;
101+ return this . runAugmenter ( { images} ) . then ( res => {
102+ images . forEach ( im => {
103+ this . backend . dispose ( im )
104+ } )
105+ return res ;
106+ } ) ;
101107 } ) ;
102108 }
103109
@@ -128,11 +134,12 @@ class AbstractAugmenter extends Abstract {
128134 // }
129135 // }
130136 augment ( attrs , opts , runOpts ) {
137+ debug ( `start augment ${ this . _name } (${ this . backend . _tf && this . backend . _tf . memory ( ) . numTensors } )` ) ;
138+
131139 opts . forEach ( o => {
132140 this . checkParams ( o ) ;
133141 } ) ;
134-
135- const res = this . backend . splitImages ( attrs . images ) . map ( ( image , index ) => {
142+ const res = this . backend . splitImages ( attrs . images , false ) . map ( ( image , index ) => {
136143 const points = ( ( attrs . points && attrs . points [ index ] ) || [ ] ) . map ( p => {
137144 if ( Array . isArray ( p ) ) {
138145 return this . backend . point ( p [ 0 ] , p [ 1 ] ) ;
@@ -148,26 +155,35 @@ class AbstractAugmenter extends Abstract {
148155 { points} ,
149156 { boxes : ( attrs . boxes && attrs . boxes [ index ] ) || [ ] }
150157 ) ;
151- return this . augmentOne (
158+ const res = this . augmentOne (
152159 newAttrs ,
153160 opts [ index ] ,
154161 runOpts
155162 ) ;
163+ this . backend . dispose ( image ) ;
164+ return res ;
156165 } ) ;
157-
158- return {
159- images : this . backend . mergeImages ( res . map ( r => r . image ) ) ,
166+ const res2 = {
167+ images : this . backend . mergeImages ( res . map ( r => r . image ) , true ) ,
160168 boxes : res . map ( r => r . boxes ) ,
161169 points : res . map ( r => r . points )
162170 } ;
171+ debug ( `end augment ${ this . _name } (${ this . backend . _tf && this . backend . _tf . memory ( ) . numTensors } )` ) ;
172+ return res2 ;
163173 }
164174
165175 augmentOne ( attr , opts , runOpts ) {
166- return {
176+ debug ( `start augmentOne ${ this . _name } (${ this . backend . _tf && this . backend . _tf . memory ( ) . numTensors } )` ) ;
177+
178+ const res = {
167179 image : this . augmentImage ( attr , opts , runOpts ) ,
168180 boxes : this . augmentBoxes ( attr , opts , runOpts ) ,
169181 points : this . augmentPoints ( attr , opts , runOpts )
170182 } ;
183+
184+ debug ( `end augmentOne ${ this . _name } (${ this . backend . _tf && this . backend . _tf . memory ( ) . numTensors } )` ) ;
185+
186+ return res ;
171187 }
172188
173189 augmentImage ( { images} , opts , runOpts ) {
0 commit comments