Question:
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.
Answer:
you could use s3fs
to easily access your bucket as well as an image file in it.
1 2 3 4 5 6 7 8 9 10 11 12 |
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)) |