File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -207,9 +207,17 @@ def convert_preprocessing_outputs(x):
207207 def convert (x ):
208208 if x is None :
209209 return x
210- if isinstance (x , tf .RaggedTensor ) or x .dtype == tf .string :
210+ if isinstance (x , tf .RaggedTensor ):
211+ return tensor_to_list (x )
212+ dtype = getattr (x , "dtype" , None )
213+
214+ if dtype is None :
215+ return x
216+
217+ if dtype == tf .string :
211218 return tensor_to_list (x )
212- dtype = keras .backend .standardize_dtype (x .dtype )
219+
220+ dtype = keras .backend .standardize_dtype (dtype )
213221 return ops .convert_to_tensor (x , dtype = dtype )
214222
215223 return keras .tree .map_structure (convert , x )
Original file line number Diff line number Diff line change @@ -85,6 +85,16 @@ def test_composite(self):
8585 self .assertTrue (is_tensor_type (outputs [1 ]))
8686 self .assertTrue (is_tensor_type (outputs [2 ]))
8787
88+ def test_python_native_outputs (self ):
89+ inputs = "hello world"
90+ outputs = convert_preprocessing_outputs (inputs )
91+ self .assertEqual (outputs , "hello world" )
92+ self .assertIsInstance (outputs , str )
93+ inputs = ["hello" , "world" ]
94+ outputs = convert_preprocessing_outputs (inputs )
95+ self .assertEqual (outputs , ["hello" , "world" ])
96+ self .assertIsInstance (outputs , list )
97+
8898 def to_list (x ):
8999 return ops .convert_to_numpy (x ).tolist () if is_tensor_type (x ) else x
90100
You can’t perform that action at this time.
0 commit comments