【发布时间】:2021-04-30 16:08:25
【问题描述】:
我正在尝试使用 TPU 引擎打开存储在 google-colab 工作簿中的 google-storage 存储桶中的文件。然而,我总是面临错误:
FileNotFoundError: [Errno 2] No such file or directory: 'gs://vocab_jb/merges.txt'
我的问题很简单:我应该如何让 google-storage 中的存储桶可以从 google-colab 读取?我已经尝试了一切:
- 使用 IAM 公开存储桶
- 为所有者分配一个特殊的电子邮件地址
- 通过 LCA 选项公开文件
- 关注 x 不同 tutorials
- 我每次都尝试通过“gs://bucket”或“https://...”调用存储桶
但是没有一个选项能正常工作。更让我困惑的是,将存储桶公开的时间有限。我也读过this post,但答案没有帮助。另外,我并不真正关心阅读或写作的权利。
我正在通过以下方式初始化我的 TPU:
import os
use_tpu = True #@param {type:"boolean"}
bucket = 'vocab_jb'
if use_tpu:
assert 'COLAB_TPU_ADDR' in os.environ, 'Missing TPU; did you request a TPU in Notebook Settings?'
from google.colab import auth
auth.authenticate_user()
%tensorflow_version 2.x
import tensorflow as tf
print("Tensorflow version " + tf.__version__)
try:
tpu = tf.distribute.cluster_resolver.TPUClusterResolver('grpc://' + os.environ['COLAB_TPU_ADDR']) # TPU detection
print('Running on TPU ', tpu.cluster_spec().as_dict()['worker'])
except ValueError:
raise BaseException('ERROR: Not connected to a TPU runtime; please see the previous cell in this notebook for instructions!')
tf.config.experimental_connect_to_cluster(tpu)
tf.tpu.experimental.initialize_tpu_system(tpu)
tpu_strategy = tf.distribute.experimental.TPUStrategy(tpu)
with open("gs://vocab_jb/merges.txt", 'rb') as f:
a = f.read()
FileNotFoundError: [Errno 2] No such file or directory: 'gs://vocab_jb/merges.txt'
【问题讨论】:
-
如果您在存储桶中使对象公开可读,我看不到您实际下载文件的代码部分。使用任何模块作为请求或 urllib 来实际下载文件(例如检查这个post),只有在文件下载后你才能尝试打开它。此外,我强烈建议您从帖子中删除您的存储桶名称和任何其他 PII,因为这可能会导致隐私问题。
标签: python google-cloud-platform google-cloud-storage google-colaboratory bucket