# Get leafs values in class inherits from tensorflow.keras.Model

**URL:** <https://discuss.ai.google.dev/t/get-leafs-values-in-class-inherits-from-tensorflow-keras-model/31591>\
**Category:** General Discussion\
**Tags:** tfdf, models\
**Created:** [August 2, 2023, 2:33pm UTC](https://discuss.ai.google.dev/t/get-leafs-values-in-class-inherits-from-tensorflow-keras-model/31591 "2023-08-02T14:33:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahad](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/ahad/32/18286_2.png) [@ahad](https://discuss.ai.google.dev/u/ahad)\
**Post date:** [August 2, 2023, 2:33pm UTC](https://discuss.ai.google.dev/t/get-leafs-values-in-class-inherits-from-tensorflow-keras-model/31591/1 "2023-08-02T14:33:03Z")

</div>

Hi All,

I would like to be able to get the leaves values when training ensemble that uses tfdf model as a layer, in custom class I created.

Calling tfdf(inputs) works just fine, but when trying to use tfdf.call\_get\_leaves(inputs) I got a tensor with shape None, None that I can’t use.

I reproduces the example here:

[my\_ensemble](https://colab.research.google.com/drive/1B7OeChuLw83UQ7IGAcGz5_l4qqsjkXpu?usp=sharing)

Will appreciate your help, thank you!

---

<div class="post-metadata">

**Author:** ![Aniket\_Dubey](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/aniket_dubey/32/16664_2.png) [@Aniket\_Dubey](https://discuss.ai.google.dev/u/Aniket_Dubey)\
**Post date:** [July 16, 2024, 5:33am UTC](https://discuss.ai.google.dev/t/get-leafs-values-in-class-inherits-from-tensorflow-keras-model/31591/3 "2024-07-16T05:33:00Z")

</div>

Hi @ahad ,

Here are some suggestions you can follow to resolve the issue,

1. First, ensure you’re using the correct method to get leaf values. The method `call_get_leaves` is not a standard TFDF method. Instead, you can use `get_leaves`:

```auto
leaf_values = tfdf_model.get_leaves(inputs)

```

1. If you’re still getting a tensor with shape (None, None), it might be due to the dynamic nature of the input. Try to use a concrete input shape:

```auto
leaf_values = tfdf_model.get_leaves(tf.keras.Input(shape=(your_input_shape,)))

```

1. If you’re using a custom layer, make sure you’re properly implementing the `call` method:

```auto
class CustomTFDFLayer(tf.keras.layers.Layer):
    def __init__ (self, tfdf_model):
        super(). __init__ ()
        self.tfdf_model = tfdf_model

    def call(self, inputs):
        predictions = self.tfdf_model(inputs)
        leaf_values = self.tfdf_model.get_leaves(inputs)
        return predictions, leaf_values

```

Let us know if the problem still persists,

Thank You .
