# Data re-uploading impelementation in hybrid NN with keras layer

**URL:** <https://discuss.pennylane.ai/t/data-re-uploading-impelementation-in-hybrid-nn-with-keras-layer/1145>\
**Category:** PennyLane Help\
**Created:** [June 25, 2021, 7:01am UTC](https://discuss.pennylane.ai/t/data-re-uploading-impelementation-in-hybrid-nn-with-keras-layer/1145 "2021-06-25T07:01:58Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Kuma-quant](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/kuma-quant/32/582_2.png) [@Kuma-quant](https://discuss.pennylane.ai/u/Kuma-quant)\
**Post date:** [June 27, 2021, 2:30pm UTC](https://discuss.pennylane.ai/t/data-re-uploading-impelementation-in-hybrid-nn-with-keras-layer/1145/4 "2021-06-27T14:30:17Z")

</div>

I have found a **temporary** solution.  
It worked!

I pushed layer-dimension on 3rd-dimension of weight.

```auto
@qml.qnode(dev, diff_method='adjoint')
def qnode(inputs, weights):
    for i in range(layers):
        qml.templates.AngleEmbedding(inputs, wires=range(n_qubits))
        qml.templates.StronglyEntanglingLayers(weights[:,:,3*i:3*(i+1)], wires=range(n_qubits))
    return [qml.expval(qml.PauliZ(i)) for i in range(n_qubits)]

weight_shapes = {"weights": (1, n_qubits,3*layers)}

```

```auto
Epoch 1/30
1/1 [==============================] - 0s 140ms/step - loss: 0.8418 - val_loss: 0.1298
Epoch 2/30
1/1 [==============================] - 0s 65ms/step - loss: 0.1251 - val_loss: 0.1253
Epoch 3/30
1/1 [==============================] - 0s 65ms/step - loss: 0.0714 - val_loss: 0.1183

```

No error occurs.

To check if the model is correct, I have investigated the number of trainable parameters.

```auto
model.summary()

```

```auto
Model: "sequential_14"
_________________________________________________________________
Layer (type) Output Shape Param #   
=================================================================
dense_28 (Dense) (1, 1) 2         
_________________________________________________________________
keras_layer_14 (KerasLayer) (1, 1) 6         
_________________________________________________________________
dense_29 (Dense) (1, 1) 2         
=================================================================
Total params: 10
Trainable params: 10
Non-trainable params: 0

```

Since a StronglyEntanglingLayer requires 3 trainable parameters, the number of trainable parameters should be 6 for two StronglyEntanglingLayer.  
Therefore, the above result is reasonable!

But the implementation would not be beautiful.  
If there is some better idea, please teach me.

---

_[View the full topic](https://discuss.pennylane.ai/t/data-re-uploading-impelementation-in-hybrid-nn-with-keras-layer/1145)._
