【问题标题】:Problem with loading TIFF image on Google Colab在 Google Colab 上加载 TIFF 图像时出现问题
【发布时间】:2020-09-06 21:24:05
【问题描述】:

我在 Google Storage 上有一个包含 tiff 图像的存储桶。我做错了什么?

from PIL import Image
im = Image.open("gs://bucket/train_images/0005f7aaab2800f6170c399693a96917.tiff")
im
FileNotFoundError: [Errno 2] No such file or directory: 'gs://bucket/train_images/0005f7aaab2800f6170c399693a96917.tiff'

Gsutil 显示:

!gsutil ls gs://bucket/train_images/ | head -10
gs://bucket/train_images/0005f7aaab2800f6170c399693a96917.tiff
gs://bucket/train_images/000920ad0b612851f8e01bcc880d9b3d.tiff
gs://bucket/train_images/0018ae58b01bdadc8e347995b69f99aa.tiff
gs://bucket/train_images/001c62abd11fa4b57bf7a6c603a11bb9.tiff
gs://bucket/train_images/001d865e65ef5d2579c190a0e0350d8f.tiff
gs://bucket/train_images/002a4db09dad406c85505a00fb6f6144.tiff
gs://bucket/train_images/003046e27c8ead3e3db155780dc5498e.tiff
gs://bucket/train_images/0032bfa835ce0f43a92ae0bbab6871cb.tiff
gs://bucket/train_images/003a91841da04a5a31f808fb5c21538a.tiff
gs://bucket/train_images/003d4dd6bd61221ebc0bfb9350db333f.tiff

我什至可以尝试使用 pandas 和相同的路径读取图像:

df = pd.read_csv("gs://bucket/train_images/0018ae58b01bdadc8e347995b69f99aa.tiff")
ParserError: Error tokenizing data. C error: Expected 1 fields in line 49, saw 2

Imread 返回不同的错误:

import tifffile as tiff
a = tiff.imread("gs://bucket/train_images/0005f7aaab2800f6170c399693a96917.tiff.tif")

FileNotFoundError: [Errno 2] No such file or directory: '/content/gs:/bucket/train_images/0005f7aaab2800f6170c399693a96917.tiff'

我应该或可以以某种方式切换到 /gs: 吗?

@@@ 在本地我也有同样的问题。

gsutil ls gs://bucket/train_images/ | head -10
gs://bucket/train_images/0005f7aaab2800f6170c399693a96917.tiff
gs://bucket/train_images/000920ad0b612851f8e01bcc880d9b3d.tiff
gs://bucket/train_images/0018ae58b01bdadc8e347995b69f99aa.tiff
gs://bucket/train_images/001c62abd11fa4b57bf7a6c603a11bb9.tiff
gs://bucket/train_images/001d865e65ef5d2579c190a0e0350d8f.tiff
gs://bucket/train_images/002a4db09dad406c85505a00fb6f6144.tiff
gs://bucket/train_images/003046e27c8ead3e3db155780dc5498e.tiff
gs://bucket/train_images/0032bfa835ce0f43a92ae0bbab6871cb.tiff
gs://bucket/train_images/003a91841da04a5a31f808fb5c21538a.tiff
gs://bucket/train_images/003d4dd6bd61221ebc0bfb9350db333f.tiff
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe

尝试 PIL:

Python 2.7.17 (default, Apr 15 2020, 17:20:14) 
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> im = Image.open("gs://bucket/train_images/0005f7aaab2800f6170c399693a96917.tiff")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/---/Desktop/gcloud/env/lib/python2.7/site-packages/PIL/Image.py", line 2766, in open
    fp = builtins.open(filename, "rb")
IOError: [Errno 2] No such file or directory: 'gs://bucket/train_images/0005f7aaab2800f6170c399693a96917.tiff'
>>> 
[3]+  Stopped                 python

【问题讨论】:

标签: python google-cloud-platform python-imaging-library google-colaboratory tiff


【解决方案1】:

我不知道问题出在哪里,但是当我需要从 GS 存储桶中读取某些内容时,我只需将文件(通常是整个存储桶)设为公开可读,然后传入通常的 https 链接.它从来没有让我失望过。

【讨论】:

  • 嗯,这可能是一个解决方案......内存和效率呢?数据集相当大,超过 350GB。
  • @Ironwing 我建议的方法只是更改了一些权限,因此根本不会影响内存和效率。但是,如果您使用的是免费的 colab,那么它可能会在这么大的数据集上耗尽资源。
  • 是的,我知道,我可能需要读取块中的图像,但我仍然无法理解为什么 PIL 库无法打开该 tiff 文件。我该如何阅读使用带有 http 链接的库的 tiff 图像?
  • @Ironwing 只需使用公共 url 而不是 gs URL(我假设它会是相同的,gs 替换为 https)。
  • @Ironwing 但同样,您必须先将其公开。
猜你喜欢
  • 1970-01-01
  • 2018-08-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-11
  • 2011-09-13
相关资源
最近更新 更多