Kumaran
Databricks Employee
Databricks Employee

Hi @manupmanoos,

Please check the below code on how to load the saved model back from the s3 bucket

import boto3
import os
from keras.models import load_model

# Set credentials and create S3 client
aws_access_key_id = dbutils.secrets.get(scope="<scope-name>", key="<key-name>")
aws_secret_access_key = dbutils.secrets.get(scope="<scope-name>", key="<key-name>")
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 = "<bucket-name>"
s3_prefix = "<bucket-prefix>"
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)

View solution in original post