Skip to content

Revert "Fixes inconsistent serialization logic for inputs (#20993) #21336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2025
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
2 changes: 2 additions & 0 deletions keras/src/models/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ def map_tensors(tensors):

input_tensors = map_tensors(functional_config["input_layers"])
output_tensors = map_tensors(functional_config["output_layers"])
if isinstance(input_tensors, list) and len(input_tensors) == 1:
input_tensors = input_tensors[0]
if isinstance(output_tensors, list) and len(output_tensors) == 1:
output_tensors = output_tensors[0]

Expand Down
14 changes: 0 additions & 14 deletions keras/src/models/functional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from keras.src.models import Functional
from keras.src.models import Model
from keras.src.models import Sequential
from keras.src.models.model import model_from_json


class FunctionalTest(testing.TestCase):
Expand Down Expand Up @@ -274,19 +273,6 @@ def test_restored_multi_output_type(self, out_type):
out_val = model_restored(Input(shape=(3,), batch_size=2))
self.assertIsInstance(out_val, out_type)

def test_restored_nested_input(self):
input_a = Input(shape=(3,), batch_size=2, name="input_a")
x = layers.Dense(5)(input_a)
outputs = layers.Dense(4)(x)
model = Functional([[input_a]], outputs)

# Serialize and deserialize the model
json_config = model.to_json()
restored_json_config = model_from_json(json_config).to_json()

# Check that the serialized model is the same as the original
self.assertEqual(json_config, restored_json_config)

@pytest.mark.requires_trainable_backend
def test_layer_getters(self):
# Test mixing ops and layers
Expand Down