keras-team/keras · error · AttributeError

You must build the layer before accessing `kernel`.

Error message

You must build the layer before accessing `kernel`.

What it means

Error "You must build the layer before accessing `kernel`." thrown in keras-team/keras.

Source

Thrown at keras/src/layers/convolutional/base_conv.py:230

            self.bias = self.add_weight(
                name="bias",
                shape=(self.filters,),
                initializer=self.bias_initializer,
                regularizer=self.bias_regularizer,
                constraint=self.bias_constraint,
                trainable=True,
                dtype=self.dtype,
            )
        else:
            self.bias = None
        self.built = True
        if self.lora_rank:
            self.enable_lora(self.lora_rank, lora_alpha=self.lora_alpha)

    @property
    def kernel(self):
        if not self.built:
            raise AttributeError(
                "You must build the layer before accessing `kernel`."
            )
        kernel = self._kernel
        if self.lora_enabled:
            kernel = ops.cast(
                ops.add(
                    kernel,
                    (self.lora_alpha / self.lora_rank)
                    * ops.matmul(self.lora_kernel_a, self.lora_kernel_b),
                ),
                dtype=self.compute_dtype,
            )
        return kernel

    def convolution_op(self, inputs, kernel):
        return ops.conv(
            inputs,
            kernel,

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/layers/convolutional/base_conv.py:230 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/ca5bfcaf09a69a10. Report an issue: GitHub.