@@ -235,7 +235,7 @@ def resolve_metric(self, metric):
235235def _prepare_loss_fns (loss , output_names ):
236236 """Converts `loss` to a list of per-output loss functions or objects."""
237237 # losses for multiple outputs indexed by name
238- if isinstance (loss , collections .Mapping ):
238+ if isinstance (loss , collections .abc . Mapping ):
239239 for name in output_names :
240240 if name not in loss :
241241 raise ValueError (
@@ -247,7 +247,7 @@ def _prepare_loss_fns(loss, output_names):
247247 return [tf .keras .losses .get (loss ) for _ in output_names ]
248248
249249 # losses for multiple outputs indexed by position
250- if isinstance (loss , collections .Sequence ):
250+ if isinstance (loss , collections .abc . Sequence ):
251251 if len (loss ) != len (output_names ):
252252 raise ValueError ('`loss` should have the same number of elements as '
253253 'model output' )
@@ -262,13 +262,13 @@ def _prepare_loss_weights(loss_weights, output_names):
262262 if loss_weights is None :
263263 return [1.0 ] * len (output_names )
264264
265- if isinstance (loss_weights , collections .Sequence ):
265+ if isinstance (loss_weights , collections .abc . Sequence ):
266266 if len (loss_weights ) != len (output_names ):
267267 raise ValueError ('`loss_weights` should have the same number of elements '
268268 'as model output' )
269269 return list (map (float , loss_weights ))
270270
271- if isinstance (loss_weights , collections .Mapping ):
271+ if isinstance (loss_weights , collections .abc . Mapping ):
272272 for name in output_names :
273273 if name not in loss_weights :
274274 raise ValueError ('Loss weight for {} not found in `loss_weights` '
@@ -326,13 +326,13 @@ def _prepare_metric_fns(metrics, output_names, loss_wrappers):
326326 if metrics is None :
327327 return [[] for _ in output_names ]
328328
329- if not isinstance (metrics , (list , collections .Mapping )):
329+ if not isinstance (metrics , (list , collections .abc . Mapping )):
330330 raise TypeError ('`metrics` must be a list or a dict, got {}' .format (
331331 str (metrics )))
332332
333333 to_list = lambda x : x if isinstance (x , list ) else [x ]
334334
335- if isinstance (metrics , collections .Mapping ):
335+ if isinstance (metrics , collections .abc . Mapping ):
336336 # Converts `metrics` from a dictionary to a list of lists using the order
337337 # specified in `output_names`.
338338 metrics = [to_list (metrics .get (name , [])) for name in output_names ]
0 commit comments