@@ -23,8 +23,7 @@ public partial class Functional : Model
2323 List < KerasHistory > _output_coordinates ;
2424 public string [ ] NetworkNodes { get ; set ; }
2525
26- Dictionary < int , int > tensor_usage_count ;
27- public Dictionary < int , int > TensorUsageCount => tensor_usage_count ;
26+ Dictionary < long , int > tensor_usage_count ;
2827
2928 public Functional ( Tensors inputs , Tensors outputs , string name = null )
3029 : base ( new ModelArgs
@@ -38,7 +37,7 @@ public Functional(Tensors inputs, Tensors outputs, string name = null)
3837 _output_layers = new List < ILayer > ( ) ;
3938 _input_coordinates = new List < KerasHistory > ( ) ;
4039 _output_coordinates = new List < KerasHistory > ( ) ;
41- tensor_usage_count = new Dictionary < int , int > ( ) ;
40+ tensor_usage_count = new Dictionary < long , int > ( ) ;
4241 if ( this is Sequential )
4342 return ;
4443 _init_graph_network ( inputs , outputs ) ;
@@ -116,33 +115,33 @@ void _set_output_names()
116115
117116 void ComputeTensorUsageCount ( )
118117 {
119- var available_tensors = inputs . Select ( x => x . GetHashCode ( ) ) . ToList ( ) ;
118+ var available_tensors = inputs . Select ( x => x . Id ) . ToList ( ) ;
120119 var depth_keys = NodesByDepth . Keys . OrderBy ( x => x ) . Reverse ( ) . Skip ( 1 ) . ToArray ( ) ;
121120 foreach ( var depth in depth_keys )
122121 {
123122 foreach ( var node in NodesByDepth [ depth ] )
124123 {
125- var input_tensors = node . KerasInputs . Select ( x => x . GetHashCode ( ) ) . ToArray ( ) ;
124+ var input_tensors = node . KerasInputs . Select ( x => x . Id ) . ToArray ( ) ;
126125 if ( input_tensors . issubset ( available_tensors ) )
127126 {
128127 foreach ( var tensor in node . KerasInputs )
129128 {
130- if ( ! tensor_usage_count . ContainsKey ( tensor . GetHashCode ( ) ) )
131- tensor_usage_count [ tensor . GetHashCode ( ) ] = 0 ;
132- tensor_usage_count [ tensor . GetHashCode ( ) ] += 1 ;
129+ if ( ! tensor_usage_count . ContainsKey ( tensor . Id ) )
130+ tensor_usage_count [ tensor . Id ] = 0 ;
131+ tensor_usage_count [ tensor . Id ] += 1 ;
133132 }
134133
135134 foreach ( var output_tensor in node . Outputs )
136- available_tensors . Add ( output_tensor . GetHashCode ( ) ) ;
135+ available_tensors . Add ( output_tensor . Id ) ;
137136 }
138137 }
139138 }
140139
141140 foreach ( var tensor in outputs )
142141 {
143- if ( ! tensor_usage_count . ContainsKey ( tensor . GetHashCode ( ) ) )
144- tensor_usage_count [ tensor . GetHashCode ( ) ] = 0 ;
145- tensor_usage_count [ tensor . GetHashCode ( ) ] += 1 ;
142+ if ( ! tensor_usage_count . ContainsKey ( tensor . Id ) )
143+ tensor_usage_count [ tensor . Id ] = 0 ;
144+ tensor_usage_count [ tensor . Id ] += 1 ;
146145 }
147146 }
148147
@@ -316,12 +315,11 @@ Tensors run_internal_graph(Tensors inputs, bool training = false, Tensors mask =
316315 input_t . KerasMask = masks [ i ] ;
317316 }
318317
319- var tensor_dict = new Dictionary < int , Queue < Tensor > > ( ) ;
318+ var tensor_dict = new Dictionary < long , Queue < Tensor > > ( ) ;
320319 foreach ( var ( x , y ) in zip ( this . inputs , inputs ) )
321320 {
322321 var y1 = conform_to_reference_input ( y , x ) ;
323- var x_id = x . GetHashCode ( ) ;
324- tensor_dict [ x_id ] = new Queue < Tensor > ( Enumerable . Range ( 0 , tensor_usage_count [ x_id ] ) . Select ( x => y1 ) ) ;
322+ tensor_dict [ x . Id ] = new Queue < Tensor > ( Enumerable . Range ( 0 , tensor_usage_count [ x . Id ] ) . Select ( x => y1 ) ) ;
325323 }
326324
327325 var depth_keys = NodesByDepth . Keys . OrderBy ( x => x ) . Reverse ( ) . ToArray ( ) ;
@@ -347,13 +345,10 @@ Tensors run_internal_graph(Tensors inputs, bool training = false, Tensors mask =
347345 }
348346 }
349347
350- var output_tensors = new List < Tensor > ( ) ;
348+ var output_tensors = new Tensors ( ) ;
351349
352350 foreach ( var x in outputs )
353- {
354- var x_id = x . GetHashCode ( ) ;
355- output_tensors . append ( tensor_dict [ x_id ] . Dequeue ( ) ) ;
356- }
351+ output_tensors . Add ( tensor_dict [ x . Id ] . Dequeue ( ) ) ;
357352
358353 return output_tensors ;
359354 }
0 commit comments