@@ -23,7 +23,7 @@ public ConvLayer(Dictionary<string, object> data) : base(data)
2323 this . Pad = Convert . ToInt32 ( data [ "Pad" ] ) ;
2424 this . Filters = BuilderInstance < T > . Volume . SameAs ( data [ "Filters" ] . ToArrayOfT < T > ( ) , new Shape ( this . Width , this . Height , this . InputDepth , this . FilterCount ) ) ;
2525 this . Bias = BuilderInstance < T > . Volume . SameAs ( data [ "Bias" ] . ToArrayOfT < T > ( ) , new Shape ( 1 , 1 , this . FilterCount ) ) ;
26- this . BiasPref = ( T ) Convert . ChangeType ( data [ "BiasPref" ] , typeof ( T ) ) ;
26+ this . BiasPref = ( T ) Convert . ChangeType ( data [ "BiasPref" ] , typeof ( T ) ) ;
2727 this . FiltersGradient = BuilderInstance < T > . Volume . SameAs ( data [ "FiltersGradient" ] . ToArrayOfT < T > ( ) , new Shape ( this . Width , this . Height , this . InputDepth , this . FilterCount ) ) ;
2828 this . BiasGradient = BuilderInstance < T > . Volume . SameAs ( data [ "BiasGradient" ] . ToArrayOfT < T > ( ) , new Shape ( 1 , 1 , this . FilterCount ) ) ;
2929
@@ -172,19 +172,21 @@ internal void UpdateOutputSize()
172172 // volume exactly, the output volume will be trimmed and not contain the (incomplete) computed
173173 // final application.
174174 this . OutputWidth =
175- ( int ) Math . Floor ( ( this . InputWidth + this . Pad * 2 - this . Width ) / ( double ) this . Stride + 1 ) ;
175+ ( int ) Math . Floor ( ( this . InputWidth + this . Pad * 2 - this . Width ) / ( double ) this . Stride + 1 ) ;
176176 this . OutputHeight =
177- ( int ) Math . Floor ( ( this . InputHeight + this . Pad * 2 - this . Height ) / ( double ) this . Stride + 1 ) ;
177+ ( int ) Math . Floor ( ( this . InputHeight + this . Pad * 2 - this . Height ) / ( double ) this . Stride + 1 ) ;
178178
179179 // initializations
180180 var scale = Math . Sqrt ( 2.0 / ( this . Width * this . Height * this . InputDepth ) ) ;
181181
182- this . Filters =
183- BuilderInstance < T > . Volume . Random (
184- new Shape ( this . Width , this . Height , this . InputDepth , this . OutputDepth ) , 0.0 , scale ) ;
185- this . FiltersGradient =
186- BuilderInstance < T > . Volume . SameAs (
187- new Shape ( this . Width , this . Height , this . InputDepth , this . OutputDepth ) ) ;
182+ var shape = new Shape ( this . Width , this . Height , this . InputDepth , this . OutputDepth ) ;
183+ if ( this . Filters == null || ! this . Filters . Shape . Equals ( shape ) )
184+ {
185+ this . Filters ? . Dispose ( ) ;
186+ this . Filters = BuilderInstance < T > . Volume . Random ( shape , 0.0 , scale ) ;
187+ this . FiltersGradient ? . Dispose ( ) ;
188+ this . FiltersGradient = BuilderInstance < T > . Volume . SameAs ( shape ) ;
189+ }
188190
189191 this . Bias = BuilderInstance < T > . Volume . SameAs ( new T [ this . OutputDepth ] . Populate ( this . BiasPref ) ,
190192 new Shape ( 1 , 1 , this . OutputDepth ) ) ;
0 commit comments