First, you need to find the S3 bucket that contains the model’s artifacts. You can do so by going to “Amazon SageMaker” > “Inference” > “Models”, and clicking on your model’s name.Then, copy the “Model data location” to your clipboard.
With the model data location in hand, you can use the following code, which downloads the model’s artifacts from S3, saves it to disk, and untars the downloaded file.
Copy
Ask AI
import boto3import tarfile# The AWS profile that has access to the S3 bucketAWS_PROFILE = "your_profile"# Information about the location of the dataset in the S3 bucketS3_BUCKET = "bucket_name"S3_KEY = "path/to/your/model.tar.gz" # This is what you copied from "Model data location"OUTPUT_FILE = "model.tar.gz"session = boto3.session.Session( profile_name=AWS_PROFILE)s3 = session.client("s3")s3.download_file( Bucket=S3_BUCKET, Key=S3_KEY, Filename=OUTPUT_FILE)# Untar the downloaded filetarfile.open(OUTPUT_FILE).extractall("model")