<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How can I save a keras model from a python notebook in databricks to an s3 bucket? in Machine Learning</title>
    <link>https://community.databricks.com/t5/machine-learning/how-can-i-save-a-keras-model-from-a-python-notebook-in/m-p/39799#M2035</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/86165"&gt;@manupmanoos&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Thank you for posting your question in Databricks community.&lt;/P&gt;&lt;P&gt;Here are the steps to save a Keras model from a Python notebook in Databricks to AWS S3 bucket:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Install the AWS SDK and set up your credentials using Databricks Secret Manager or environment variables.&lt;/LI&gt;&lt;LI&gt;Train a Keras model, for example using&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;model = keras.models.Sequential().&lt;/LI&gt;&lt;LI&gt;Save the model locally using&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;model.save('/dbfs/models/model.h5')&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;command.&lt;/LI&gt;&lt;LI&gt;Use the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;aws&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;command to copy the saved model file to an S3 bucket. Here is an example:&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Set credentials and create S3 client
import boto3
import os

aws_access_key_id = dbutils.secrets.get(scope="&amp;lt;scope-name&amp;gt;", key="&amp;lt;key-name&amp;gt;")
aws_secret_access_key = dbutils.secrets.get(scope="&amp;lt;scope-name&amp;gt;", key="&amp;lt;key-name&amp;gt;")
os.environ['AWS_ACCESS_KEY_ID'] = aws_access_key_id
os.environ['AWS_SECRET_ACCESS_KEY'] = aws_secret_access_key

s3_client = boto3.client('s3')

# Upload the saved model from local file system to S3 bucket
s3_bucket = "&amp;lt;bucket-name&amp;gt;"
s3_prefix = "&amp;lt;bucket-prefix&amp;gt;"

model_path = "/dbfs/models/model.h5"
s3_key = "{}/model.h5".format(s3_prefix)

s3_client.upload_file(model_path, s3_bucket, s3_key)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 14 Aug 2023 06:48:58 GMT</pubDate>
    <dc:creator>Kumaran</dc:creator>
    <dc:date>2023-08-14T06:48:58Z</dc:date>
    <item>
      <title>How can I save a keras model from a python notebook in databricks to an s3 bucket?</title>
      <link>https://community.databricks.com/t5/machine-learning/how-can-i-save-a-keras-model-from-a-python-notebook-in/m-p/39441#M2027</link>
      <description>&lt;P&gt;I have a trained model on Databricks python notebook. How can I save this to an s3 bucket.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2023 12:51:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/how-can-i-save-a-keras-model-from-a-python-notebook-in/m-p/39441#M2027</guid>
      <dc:creator>manupmanoos</dc:creator>
      <dc:date>2023-08-09T12:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: How can I save a keras model from a python notebook in databricks to an s3 bucket?</title>
      <link>https://community.databricks.com/t5/machine-learning/how-can-i-save-a-keras-model-from-a-python-notebook-in/m-p/39799#M2035</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/86165"&gt;@manupmanoos&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Thank you for posting your question in Databricks community.&lt;/P&gt;&lt;P&gt;Here are the steps to save a Keras model from a Python notebook in Databricks to AWS S3 bucket:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Install the AWS SDK and set up your credentials using Databricks Secret Manager or environment variables.&lt;/LI&gt;&lt;LI&gt;Train a Keras model, for example using&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;model = keras.models.Sequential().&lt;/LI&gt;&lt;LI&gt;Save the model locally using&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;model.save('/dbfs/models/model.h5')&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;command.&lt;/LI&gt;&lt;LI&gt;Use the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;aws&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;command to copy the saved model file to an S3 bucket. Here is an example:&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Set credentials and create S3 client
import boto3
import os

aws_access_key_id = dbutils.secrets.get(scope="&amp;lt;scope-name&amp;gt;", key="&amp;lt;key-name&amp;gt;")
aws_secret_access_key = dbutils.secrets.get(scope="&amp;lt;scope-name&amp;gt;", key="&amp;lt;key-name&amp;gt;")
os.environ['AWS_ACCESS_KEY_ID'] = aws_access_key_id
os.environ['AWS_SECRET_ACCESS_KEY'] = aws_secret_access_key

s3_client = boto3.client('s3')

# Upload the saved model from local file system to S3 bucket
s3_bucket = "&amp;lt;bucket-name&amp;gt;"
s3_prefix = "&amp;lt;bucket-prefix&amp;gt;"

model_path = "/dbfs/models/model.h5"
s3_key = "{}/model.h5".format(s3_prefix)

s3_client.upload_file(model_path, s3_bucket, s3_key)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2023 06:48:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/how-can-i-save-a-keras-model-from-a-python-notebook-in/m-p/39799#M2035</guid>
      <dc:creator>Kumaran</dc:creator>
      <dc:date>2023-08-14T06:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: How can I save a keras model from a python notebook in databricks to an s3 bucket?</title>
      <link>https://community.databricks.com/t5/machine-learning/how-can-i-save-a-keras-model-from-a-python-notebook-in/m-p/39949#M2045</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/63081"&gt;@Kumaran&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Could you please let me know how we would we load the same saved model back to a databricks notebook?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Manu&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 15:02:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/how-can-i-save-a-keras-model-from-a-python-notebook-in/m-p/39949#M2045</guid>
      <dc:creator>manupmanoos</dc:creator>
      <dc:date>2023-08-15T15:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: How can I save a keras model from a python notebook in databricks to an s3 bucket?</title>
      <link>https://community.databricks.com/t5/machine-learning/how-can-i-save-a-keras-model-from-a-python-notebook-in/m-p/39959#M2046</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/86165"&gt;@manupmanoos&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Thank you for posting your question in the Databricks community.&lt;/P&gt;&lt;P&gt;Below is an example of how to&amp;nbsp;&lt;SPAN&gt;load the same saved model back to a Databricks notebook&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; keras.models &lt;/SPAN&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; load_model&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;model = load_model&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'/dbfs/models/model.h5'&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 15 Aug 2023 15:38:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/how-can-i-save-a-keras-model-from-a-python-notebook-in/m-p/39959#M2046</guid>
      <dc:creator>Kumaran</dc:creator>
      <dc:date>2023-08-15T15:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: How can I save a keras model from a python notebook in databricks to an s3 bucket?</title>
      <link>https://community.databricks.com/t5/machine-learning/how-can-i-save-a-keras-model-from-a-python-notebook-in/m-p/39965#M2047</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/63081"&gt;@Kumaran&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Sorry, I was not clear with my question. How do we load the saved model back from the s3 bucket?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Manu&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 15:44:51 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/how-can-i-save-a-keras-model-from-a-python-notebook-in/m-p/39965#M2047</guid>
      <dc:creator>manupmanoos</dc:creator>
      <dc:date>2023-08-15T15:44:51Z</dc:date>
    </item>
    <item>
      <title>Re: How can I save a keras model from a python notebook in databricks to an s3 bucket?</title>
      <link>https://community.databricks.com/t5/machine-learning/how-can-i-save-a-keras-model-from-a-python-notebook-in/m-p/39976#M2048</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/86165"&gt;@manupmanoos&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Please check the below code on&amp;nbsp;&lt;SPAN&gt;how to load the saved model back from the s3 bucket&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import boto3
import os
from keras.models import load_model

# Set credentials and create S3 client
aws_access_key_id = dbutils.secrets.get(scope="&amp;lt;scope-name&amp;gt;", key="&amp;lt;key-name&amp;gt;")
aws_secret_access_key = dbutils.secrets.get(scope="&amp;lt;scope-name&amp;gt;", key="&amp;lt;key-name&amp;gt;")
os.environ['AWS_ACCESS_KEY_ID'] = aws_access_key_id
os.environ['AWS_SECRET_ACCESS_KEY'] = aws_secret_access_key

s3_client = boto3.client('s3')

# Specify the S3 bucket and model file path
s3_bucket = "&amp;lt;bucket-name&amp;gt;"
s3_prefix = "&amp;lt;bucket-prefix&amp;gt;"
s3_key = "{}/model.h5".format(s3_prefix)

# Download the model file from S3
local_model_path = "/dbfs/models/model.h5"
s3_client.download_file(s3_bucket, s3_key, local_model_path)

# Load the model using Keras
loaded_model = load_model(local_model_path)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 15 Aug 2023 17:35:46 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/how-can-i-save-a-keras-model-from-a-python-notebook-in/m-p/39976#M2048</guid>
      <dc:creator>Kumaran</dc:creator>
      <dc:date>2023-08-15T17:35:46Z</dc:date>
    </item>
  </channel>
</rss>

