Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions keras/engine/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .. import losses
from .. import metrics as metrics_module
from ..utils.generic_utils import slice_arrays
from ..utils.generic_utils import to_list
from ..utils.generic_utils import unpack_singleton
from ..legacy import interfaces

Expand Down Expand Up @@ -155,8 +156,7 @@ def compile(self, optimizer,
masks = self.compute_mask(self.inputs, mask=None)
if masks is None:
masks = [None for _ in self.outputs]
if not isinstance(masks, list):
masks = [masks]
masks = to_list(masks)

# Prepare loss weights.
if loss_weights is None:
Expand Down
19 changes: 7 additions & 12 deletions keras/engine/training_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .. import callbacks as cbks
from ..utils.generic_utils import Progbar
from ..utils.generic_utils import slice_arrays
from ..utils.generic_utils import to_list
from ..utils.generic_utils import unpack_singleton


Expand Down Expand Up @@ -152,8 +153,7 @@ def fit_loop(model, f, ins,
callbacks.on_batch_begin(step_index, batch_logs)
outs = f(ins)

if not isinstance(outs, list):
outs = [outs]
outs = to_list(outs)
for l, o in zip(out_labels, outs):
batch_logs[l] = o

Expand All @@ -165,8 +165,7 @@ def fit_loop(model, f, ins,
val_outs = test_loop(model, val_f, val_ins,
steps=validation_steps,
verbose=0)
if not isinstance(val_outs, list):
val_outs = [val_outs]
val_outs = to_list(val_outs)
# Same labels assumed.
for l, o in zip(out_labels, val_outs):
epoch_logs['val_' + l] = o
Expand Down Expand Up @@ -198,8 +197,7 @@ def fit_loop(model, f, ins,
ins_batch[i] = ins_batch[i].toarray()

outs = f(ins_batch)
if not isinstance(outs, list):
outs = [outs]
outs = to_list(outs)
for l, o in zip(out_labels, outs):
batch_logs[l] = o

Expand All @@ -212,8 +210,7 @@ def fit_loop(model, f, ins,
val_outs = test_loop(model, val_f, val_ins,
batch_size=batch_size,
verbose=0)
if not isinstance(val_outs, list):
val_outs = [val_outs]
val_outs = to_list(val_outs)
# Same labels assumed.
for l, o in zip(out_labels, val_outs):
epoch_logs['val_' + l] = o
Expand Down Expand Up @@ -267,8 +264,7 @@ def predict_loop(model, f, ins, batch_size=32, verbose=0, steps=None):
unconcatenated_outs = []
for step in range(steps):
batch_outs = f(ins)
if not isinstance(batch_outs, list):
batch_outs = [batch_outs]
batch_outs = to_list(batch_outs)
if step == 0:
for batch_out in batch_outs:
unconcatenated_outs.append([])
Expand Down Expand Up @@ -296,8 +292,7 @@ def predict_loop(model, f, ins, batch_size=32, verbose=0, steps=None):
ins_batch[i] = ins_batch[i].toarray()

batch_outs = f(ins_batch)
if not isinstance(batch_outs, list):
batch_outs = [batch_outs]
batch_outs = to_list(batch_outs)
if batch_index == 0:
# Pre-allocate the results arrays.
for batch_out in batch_outs:
Expand Down
13 changes: 5 additions & 8 deletions keras/engine/training_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ..utils.data_utils import GeneratorEnqueuer
from ..utils.data_utils import OrderedEnqueuer
from ..utils.generic_utils import Progbar
from ..utils.generic_utils import to_list
from ..utils.generic_utils import unpack_singleton
from .. import callbacks as cbks

Expand Down Expand Up @@ -211,8 +212,7 @@ def fit_generator(model,
sample_weight=sample_weight,
class_weight=class_weight)

if not isinstance(outs, list):
outs = [outs]
outs = to_list(outs)
for l, o in zip(out_labels, outs):
batch_logs[l] = o

Expand All @@ -236,8 +236,7 @@ def fit_generator(model,
batch_size=batch_size,
sample_weight=val_sample_weights,
verbose=0)
if not isinstance(val_outs, list):
val_outs = [val_outs]
val_outs = to_list(val_outs)
# Same labels assumed.
for l, o in zip(out_labels, val_outs):
epoch_logs['val_' + l] = o
Expand Down Expand Up @@ -342,8 +341,7 @@ def evaluate_generator(model, generator,
'or (x, y). Found: ' +
str(generator_output))
outs = model.test_on_batch(x, y, sample_weight=sample_weight)
if not isinstance(outs, list):
outs = [outs]
outs = to_list(outs)
outs_per_batch.append(outs)

if x is None or len(x) == 0:
Expand Down Expand Up @@ -450,8 +448,7 @@ def predict_generator(model, generator,
x = generator_output

outs = model.predict_on_batch(x)
if not isinstance(outs, list):
outs = [outs]
outs = to_list(outs)

if not all_outs:
for out in outs:
Expand Down
4 changes: 2 additions & 2 deletions keras/engine/training_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from .. import backend as K
from .. import losses
from ..utils.generic_utils import to_list


def standardize_single_array(x):
Expand Down Expand Up @@ -321,8 +322,7 @@ def collect_metrics(metrics, output_names):
nested_metrics = []
for name in output_names:
output_metrics = metrics.get(name, [])
if not isinstance(output_metrics, list):
output_metrics = [output_metrics]
output_metrics = to_list(output_metrics)
nested_metrics.append(output_metrics)
return nested_metrics
else:
Expand Down
7 changes: 3 additions & 4 deletions keras/legacy/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ..engine import Layer, InputSpec
from .. import backend as K
from ..utils import conv_utils
from ..utils.generic_utils import to_list
from .. import regularizers
from .. import constraints
from .. import activations
Expand Down Expand Up @@ -521,10 +522,8 @@ def __call__(self, inputs, initial_state=None, **kwargs):
# Compute the full input spec, including state
input_spec = self.input_spec
state_spec = self.state_spec
if not isinstance(input_spec, list):
input_spec = [input_spec]
if not isinstance(state_spec, list):
state_spec = [state_spec]
input_spec = to_list(input_spec)
state_spec = to_list(state_spec)
self.input_spec = input_spec + state_spec

# Compute the full inputs, including state
Expand Down
3 changes: 1 addition & 2 deletions keras/utils/multi_gpu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ def get_slice(data, i, parts):
# Apply model on slice
# (creating a model replica on the target device).
outputs = model(inputs)
if not isinstance(outputs, list):
outputs = [outputs]
outputs = to_list(outputs)

# Save the outputs for merging back together later.
for o in range(len(outputs)):
Expand Down
4 changes: 2 additions & 2 deletions keras/wrappers/scikit_learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from ..utils.np_utils import to_categorical
from ..utils.generic_utils import has_arg
from ..utils.generic_utils import to_list
from ..models import Sequential


Expand Down Expand Up @@ -291,8 +292,7 @@ def score(self, x, y, **kwargs):
y = to_categorical(y)

outputs = self.model.evaluate(x, y, **kwargs)
if not isinstance(outputs, list):
outputs = [outputs]
outputs = to_list(outputs)
for name, output in zip(self.model.metrics_names, outputs):
if name == 'acc':
return output
Expand Down