Hello!
Recently, I am encountering with an error using KerasLayer. I tried the same code last week and got the imported the package. But from yesterday, I’m unable to import the KerasLayer from pennylane. Changing to custom keraslayer also leads to more errors and have also tried using the torch, but still it is not achieving the expected output and causes more errors.
#
import pennylane as qml
from pennylane.qnn.keras import KerasLayer
IMG_SIZE = (224,224)
N_QUBITS = 8
dev = qml.device("default.qubit", wires=N_QUBITS)
@qml.qnode(dev, interface="tf")
def quantum_circuit(inputs, weights):
qml.templates.AngleEmbedding(inputs, wires=range(N_QUBITS))
qml.templates.StronglyEntanglingLayers(weights, wires=range(N_QUBITS), ranges=[3, 3, 3])
return [qml.expval(qml.PauliZ(i)) for i in range(N_QUBITS)]
weight_shapes = {"weights": (3, N_QUBITS, 3)}
qlayer = KerasLayer(quantum_circuit, weight_shapes=weight_shapes, output_dim=N_QUBITS)
Attaching the error i got,
# PennyLane: 0.38.0
NumPy: 1.23.5
TensorFlow: 2.12.0
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
/tmp/ipython-input-1-2185407428.py in <cell line: 0>()
----> 1 from pennylane.qnn.tensorflow import KerasLayer
2 print("✅ KerasLayer loaded successfully!")
ModuleNotFoundError: No module named 'pennylane.qnn.tensorflow'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
Kindly help me with this and let me know how to import the KerasLayer. I’m running this code in google colab.