This repository was archived by the owner on Apr 18, 2023. It is now read-only.
File tree 1 file changed +44
-0
lines changed
examples/semantic_segmentation 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -161,4 +161,48 @@ class Utils {
161
161
this . outputTensor = new Float32Array ( newModel . outputSize . reduce ( ( x , y ) => x * y ) ) ;
162
162
this . tfModel = null ;
163
163
}
164
+
165
+ // for debugging
166
+ async iterateLayers ( configs , layerList ) {
167
+ if ( ! this . initialized ) return ;
168
+
169
+ let iterators = [ ] ;
170
+ for ( let config of configs ) {
171
+ let model = await new TFliteModelImporter ( {
172
+ rawModel : this . tfModel ,
173
+ backend : config . backend ,
174
+ prefer : config . prefer || null ,
175
+ } ) ;
176
+ iterators . push ( model . layerIterator ( [ this . inputTensor ] , layerList ) ) ;
177
+ }
178
+
179
+ while ( true ) {
180
+
181
+ let layerOutputs = [ ] ;
182
+ for ( let it of iterators ) {
183
+ layerOutputs . push ( await it . next ( ) ) ;
184
+ }
185
+
186
+ let refOutput = layerOutputs [ 0 ] ;
187
+ if ( refOutput . done ) {
188
+ break ;
189
+ }
190
+
191
+ console . debug ( `\n\n\nLayer(${ refOutput . value . layerId } ) ${ refOutput . value . outputName } ` ) ;
192
+
193
+ for ( let i = 0 ; i < configs . length ; ++ i ) {
194
+ console . debug ( `\n${ configs [ i ] . backend } :` ) ;
195
+ console . debug ( `\n${ layerOutputs [ i ] . value . tensor } ` ) ;
196
+
197
+ if ( i > 0 ) {
198
+ let sum = 0 ;
199
+ for ( let j = 0 ; j < refOutput . value . tensor . length ; j ++ ) {
200
+ sum += Math . pow ( layerOutputs [ i ] . value . tensor [ j ] - refOutput . value . tensor [ j ] , 2 ) ;
201
+ }
202
+ let variance = sum / refOutput . value . tensor . length ;
203
+ console . debug ( `var with ${ configs [ 0 ] . backend } : ${ variance } ` ) ;
204
+ }
205
+ }
206
+ }
207
+ }
164
208
}
You can’t perform that action at this time.
0 commit comments