# QNN KerasLayer with Model

**URL:** <https://discuss.pennylane.ai/t/qnn-keraslayer-with-model/413>\
**Category:** PennyLane Help\
**Created:** [June 2, 2020, 10:28am UTC](https://discuss.pennylane.ai/t/qnn-keraslayer-with-model/413 "2020-06-02T10:28:43Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Tom\_Bromley](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/tom_bromley/32/129_2.png) [@Tom\_Bromley](https://discuss.pennylane.ai/u/Tom_Bromley)\
**Post date:** [June 2, 2020, 12:11pm UTC](https://discuss.pennylane.ai/t/qnn-keraslayer-with-model/413/2 "2020-06-02T12:11:22Z")

</div>

Hey @cnada,

PennyLane’s `KerasLayer` is a subclass of the [Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) class in Keras. This means that you can treat it just like any other layer in Keras.

For example, suppose we turn our QNode into a Keras Layer:

```python
qlayer = qml.qnn.KerasLayer(qnode, weight_shapes, output_dim=2)

```

We can use the `Sequential` model to create a hybrid:

```python
clayer = tf.keras.layers.Dense(2)
clayer2 = tf.keras.layers.Dense(2)
model = tf.keras.models.Sequential([clayer, qlayer, clayer2])

```

We can also use Keras’ [functional API](https://keras.io/guides/functional_api/) approach:

```python
inputs = tf.keras.Input(shape=(2,))
x = tf.keras.layers.Dense(2, activation="tanh")(inputs)
x = qlayer(x)
outputs = tf.keras.layers.Dense(2)(x)
model = tf.keras.Model(inputs=inputs, outputs=outputs)

```

You can also add `qlayer` to an existing model using:

- `model.add(qlayer)` is using a `Sequential` model
- If using the functional API approach:

```python
outputs2 = qlayer(outputs)
model = tf.keras.Model(inputs=inputs, outputs=outputs2)

```

Hope this helps!

---

_[View the full topic](https://discuss.pennylane.ai/t/qnn-keraslayer-with-model/413)._
