Skip to content

Type of model.input is KerasTensor in 3.9 and list in 3.10 #21328

Open
@mmtrebuchet

Description

@mmtrebuchet

This seems to be a breaking change and I don't see it documented in the release notes.

If you save a model and then load it, the type of model.input was KerasTensor in 3.9.2 (and as far back as I can remember), but it's now list in 3.10.0. If you don't save and then re-load the model, the input type is KerasTensor, so I think this qualifies as a bug.

Here is a minimal example:

#!/usr/bin/env python3

import keras as k
import keras.layers as kl
from keras import models as km
def runTest():
    il = kl.Input((1024, 4))
    cl = kl.Conv1D(filters=5, kernel_size=10, padding="valid", activation="relu")(il)
    m = km.Model(inputs=il, outputs=[cl])
    print(m.input.shape)
    m.save("test.keras")

def runLoad():
    m = km.load_model("test.keras")
    print(type(m.input))
    print(m.input.shape)

runTest()
runLoad()

Under Keras 3.9.2, I get the following:

(None, 1024, 4)
<class 'keras.src.backend.common.keras_tensor.KerasTensor'>
(None, 1024, 4)

Whereas with 3.10.0, I get:

(None, 1024, 4)
<class 'list'>
Traceback (most recent call last):
  File "/dev/shm/./testModel.py", line 22, in <module>
    runLoad()
  File "/dev/shm/./testModel.py", line 16, in runLoad
    print(m.input.shape)
          ^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'shape'

I'm using the Tensorflow backend (TF 2.19.0 in both environments I'm using).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions