Save Model Keras AZ Synapse

Londono Quintero Ferney De Jesus 0 Reputation points

How to save a keras file using python Notebook in Azure Synapse?

Azure Data Lake Storage
Azure Data Lake Storage
An Azure service that provides an enterprise-wide hyper-scale repository for big data analytic workloads and is integrated with Azure Blob Storage.
1,127 questions
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
3,542 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ShaikMaheer-MSFT 34,536 Reputation points Microsoft Employee

    Hi Londono Quintero Ferney De Jesus,

    Thank you for posting query in Microsoft Q&A Platform.

    To save a Keras file using a Python Notebook in Azure Synapse, you can use the save method of the Keras model object. Here's an example:

    from tensorflow import keras
    # create a Keras model
    model = keras.Sequential([
        keras.layers.Dense(64, activation='relu', input_shape=(784,)),
        keras.layers.Dense(10, activation='softmax')
    # train the model
    model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy']), y_train, epochs=10, batch_size=32)
    # save the model to a file'my_model.h5')

    In the above example, we first create a Keras model using the Sequential API. We then train the model using the compile and fit methods. Finally, we save the model to a file using the save method and specifying the file name as 'my_model.h5'.

    Note that the save method saves the entire model, including the architecture, weights, and optimizer state. You can load the saved model using the load_model function from the tensorflow.keras.models module:

    from tensorflow.keras.models import load_model
    # load the saved model
    model = load_model('my_model.h5')

    In the above example, we use the load_model function to load the saved model from the file 'my_model.h5'. Once the model is loaded, you can use it to make predictions on new data.

    Hope this helps. please try and let me know how it goes.

    Please consider hitting Accept Answer button. Accepted answers help community as well.