I just started to use aws sagemaker. I tried to import images from my s3 bucket to sagemaker notebook. But I can't import images to the notebook. my image location is s3://my_bucket/train how can I import the train folder from the given path to my sagemaker notebook. I've gone through some of the solution in here and the solutions are for CSV file. All the images in my S3 bucket are in .jpeg format.
Reading objects without downloading them Similarly, if you want to upload and read small pieces of textual data such as quotes, tweets, or news articles, you can do that using the S3 resource method put(), as demonstrated in the example below (Gist).
you could use s3fs
to easily access your bucket as well as an image file in it.
from PIL import Image
import s3fs
fs = s3fs.S3FileSystem()
# To List 5 files in your accessible bucket
fs.ls('s3://bucket-name/data/')[:5]
# open it directly
with fs.open(f's3://bucket-name/data/image.png') as f:
display(Image.open(f))
You don't have to download images from S3 bucket to local SageMaker instance for training the model. If you are trying to pull them for data exploration/analysis you can use aws cli from your SageMaker notebook. You can use following command to download a sample image. This will copy sample.jpg
to images
directory in your pwd
.
aws s3 cp s3://my_bucket/train/sample.jpg ./images/sample.jpg
Try looking at amazon-sagemaker-examples repo to learn how to work with image formats on SageMaker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With