@@ -235,7 +235,7 @@ def resolve_metric(self, metric):
235
235
def _prepare_loss_fns (loss , output_names ):
236
236
"""Converts `loss` to a list of per-output loss functions or objects."""
237
237
# losses for multiple outputs indexed by name
238
- if isinstance (loss , collections .Mapping ):
238
+ if isinstance (loss , collections .abc . Mapping ):
239
239
for name in output_names :
240
240
if name not in loss :
241
241
raise ValueError (
@@ -247,7 +247,7 @@ def _prepare_loss_fns(loss, output_names):
247
247
return [tf .keras .losses .get (loss ) for _ in output_names ]
248
248
249
249
# losses for multiple outputs indexed by position
250
- if isinstance (loss , collections .Sequence ):
250
+ if isinstance (loss , collections .abc . Sequence ):
251
251
if len (loss ) != len (output_names ):
252
252
raise ValueError ('`loss` should have the same number of elements as '
253
253
'model output' )
@@ -262,13 +262,13 @@ def _prepare_loss_weights(loss_weights, output_names):
262
262
if loss_weights is None :
263
263
return [1.0 ] * len (output_names )
264
264
265
- if isinstance (loss_weights , collections .Sequence ):
265
+ if isinstance (loss_weights , collections .abc . Sequence ):
266
266
if len (loss_weights ) != len (output_names ):
267
267
raise ValueError ('`loss_weights` should have the same number of elements '
268
268
'as model output' )
269
269
return list (map (float , loss_weights ))
270
270
271
- if isinstance (loss_weights , collections .Mapping ):
271
+ if isinstance (loss_weights , collections .abc . Mapping ):
272
272
for name in output_names :
273
273
if name not in loss_weights :
274
274
raise ValueError ('Loss weight for {} not found in `loss_weights` '
@@ -326,13 +326,13 @@ def _prepare_metric_fns(metrics, output_names, loss_wrappers):
326
326
if metrics is None :
327
327
return [[] for _ in output_names ]
328
328
329
- if not isinstance (metrics , (list , collections .Mapping )):
329
+ if not isinstance (metrics , (list , collections .abc . Mapping )):
330
330
raise TypeError ('`metrics` must be a list or a dict, got {}' .format (
331
331
str (metrics )))
332
332
333
333
to_list = lambda x : x if isinstance (x , list ) else [x ]
334
334
335
- if isinstance (metrics , collections .Mapping ):
335
+ if isinstance (metrics , collections .abc . Mapping ):
336
336
# Converts `metrics` from a dictionary to a list of lists using the order
337
337
# specified in `output_names`.
338
338
metrics = [to_list (metrics .get (name , [])) for name in output_names ]
0 commit comments