Let’s say I already have a keras Model (call it classical_nn) into which I want to add a qnn.KerasLayer at the end.
Classically in tensorflow, one would add layers to a keras Model as :
classical_nn = Model(…)
pre_out = classical_nn.layers[-1].output
pre_out = Dense(16,activation=‘tanh’) (pre_out)
…
And let’s say I want to add a qnn.KerasLayer set up as:
qlayer = qml.qnn.KerasLayer(quantum_classifier, weight_shapes, output_dim=1)
How one would connect qlayer and pre_out in this case to obtain a keras.Model?
Note that we need to flatten the output of the classical network and shrink it down to a 5-dimensional input for the quantum layer. This could probably be done with a few more fully connected intermediate layers.
However, it’s also important to bear in mind that the quantum layer will add a simulation overhead to your network, due to the overhead of simulating a quantum system. Combined with the size of your classical network and resultant number of parameters (2,161,361), it will take a long time to even perform one optimization step. I’d recommend starting out with a smaller scale model as more of a prototype.