Question Details

No question body available.

Tags

python tensorflow keras

Answers (1)

January 7, 2026 Score: 2 Rep: 180 Quality: Low Completeness: 60%

It failed because there's a conflict between Keras, which automatically inferences shapes, and how TFDWT creates tensors.

When you compile the model, Keras tries to determine the shapes of the tensors in the network, so it traces the layer with a scratch graph. It calls self.dwt3d(x), which triggers dwt3d.build(), which then creates the tensor in that graph. When Keras finishes determining the shapes, it deletes this scratch graph. When the training starts, your DWT3D layer tries to use that matrix, but it can't because it belongs to a graph that was deleted.

Your solution will work, but here is a cleaner way to do it:

class DWTLayer(keras.layers.Layer):
    def init(self, kwargs):
        super().init(kwargs)
        self.dwt3d = DWT3D(wave='haar')

def build(self, inputshape): with tf.initscope(): self.dwt3d.build(inputshape) super().build(inputshape)

def call(self, x): return self.dwt3d(x)