Guidance required in saving model

I was trying to save this model

I have no idea how to do. Any inputs on saving will be appreciated.

Looking forward to your support


Hi @JEEVARATHINAM, some people use Keras which allows you to save and load models. Maybe the guide here can help.

In this demo you can learn how to turn PennyLane quantum nodes into Keras layers.

I hope this helps!

Since the code which I m asking is looks like something related to forecasting.
But the demo code which you sent is related to binary classification

Can you help me by saying the change I need to do for running this code and saving the model by creating hybrid model

I m looking forward to what changes I need to incorporate in keras layers


Hi @JEEVARATHINAM, in our community demos page you will find several demos which use Keras. The one on fraud detection might be particularly helpful.

Please let me know if this helps!

i was trying to save the model as you said.

When i tried

  1. tf.keras.models.save_model(model,filepath=“dbfs:/FileStore/cc.h5”)

It shows error like

Layer KerasLayer has arguments ['self', 'qnode', 'weight_shapes', 'output_dim', 'weight_specs']
in `__init__` and therefore must override `get_config()`.


class CustomLayer(keras.layers.Layer):
    def __init__(self, arg1, arg2):
        self.arg1 = arg1
        self.arg2 = arg2

    def get_config(self):
        config = super().get_config()
            "arg1": self.arg1,
            "arg2": self.arg2,
        return config

You can this community version databricks link

looking forward to your support

Hi @JEEVARATHINAM, if you run the following code does it work for you?

def get_model():
    # Create a simple model.
    inputs = keras.Input(shape=(32,))
    outputs = keras.layers.Dense(1)(inputs)
    model = keras.Model(inputs, outputs)
    model.compile(optimizer="adam", loss="mean_squared_error")
    return model

model = get_model()

# Train the model.
test_input = np.random.random((128, 32))
test_target = np.random.random((128, 1)), test_target)

# Calling `save('my_model')` creates a SavedModel folder `my_model`."my_model")

# It can be used to reconstruct the model identically.
reconstructed_model = keras.models.load_model("my_model")

# Let's check:
    model.predict(test_input), reconstructed_model.predict(test_input)

# The reconstructed model is already compiled and has retained the optimizer
# state, so training can resume:, test_target) 

The code before is an example found here. It works for me. I wasn’t able to reproduce your problem.

I hope this helps.