我有一个名为的存储桶my_bucket
和一个名为Images
. 我正在尝试读取文件Image
夹内的文件(图像)。
file = pd.read_csv(some_csv_file)
X = file.values[:,0]
role = get_execution_role()
bucket='my_bucket'
data_key = 'Images'
data_dir = 's3://{}/{}'.format(bucket, data_key)
s = '/'
for img_name in X:
seq = (data_dir, img_name)
img_path = s.join(seq)
img = imread(img_path)
但它给出了以下错误:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-20-a273242ed30e> in <module>()
43 img_path = s.join(seq)
44 print(img_path)
---> 45 img = imread(img_path)
46 img = imresize(img, (32, 32))
47 img = img.astype('float32') # this will help us in later stage
~/anaconda3/envs/python3/lib/python3.6/site-packages/numpy/lib/utils.py in newfunc(*args, **kwds)
99 """`arrayrange` is deprecated, use `arange` instead!"""
100 warnings.warn(depdoc, DeprecationWarning, stacklevel=2)
--> 101 return func(*args, **kwds)
102
103 newfunc = _set_function_name(newfunc, old_name)
~/anaconda3/envs/python3/lib/python3.6/site-packages/scipy/misc/pilutil.py in imread(name, flatten, mode)
162 """
163
--> 164 im = Image.open(name)
165 return fromimage(im, flatten=flatten, mode=mode)
166
~/anaconda3/envs/python3/lib/python3.6/site-packages/PIL/Image.py in open(fp, mode)
2541
2542 if filename:
-> 2543 fp = builtins.open(filename, "rb")
2544 exclusive_fp = True
2545
FileNotFoundError: [Errno 2] No such file or directory: 's3://my_bucket/Images/377.jpg'
377.jpg
是 中的第一行X
。我在 S3 存储中手动检查;该文件存在于那里。那么,为什么我会收到此错误,以及如何解决?我能想到的唯一原因是,可能指定 S3 路径的过程是错误的——但在 S3 文档中,指定存储的过程被给出为's3://{}/{}'.format(bucket, data_key)
. 此外,在错误消息的最后一行中,文件名是s3://my_bucket/Images/377.jpg
,这是我手动导航以在存储桶中定位文件的路径。