python-3.x - 如何在 Google Drive 中搜索 TensorFlow 文件?
问题描述
我在这里关注文档:https ://colab.research.google.com/github/google/earthengine-api/blob/master/python/examples/ipynb/TF_demo1_keras.ipynb#scrollTo=43-c0JNFI_m6了解如何将 TensorFlow 与 GEE 一起使用。本教程的一部分是检查导出文件的存在。在文档中,示例代码是:
fileNameSuffix = '.tfrecord.gz'
trainFilePath = 'gs://' + outputBucket + '/' + trainFilePrefix + fileNameSuffix
testFilePath = 'gs://' + outputBucket + '/' + testFilePrefix + fileNameSuffix
print('Found training file.' if tf.gfile.Exists(trainFilePath)
else 'No training file found.')
print('Found testing file.' if tf.gfile.Exists(testFilePath)
else 'No testing file found.')
就我而言,我只是将文件导出到 Google Drive 而不是 Google Cloud 存储桶。我将如何更改trainFilePath
并testFilePath
指向 Google Drive 文件夹?FWIW,当我进入 Google Drive 文件夹时,我确实看到了文件。
解决方案
解决方案
您可以使用强大的PyDrive库从 Google Collab 轻松访问您的 Drive 文件,从而检查您拥有或已导出的文件等。
以下代码是一个示例,它列出了您的 Google Drive API 根目录中的所有文件。这已在此答案中找到 (是的,我正在将此答案作为社区 wiki 帖子):
# Install the library
!pip install -U -q PyDrive
# Install the rest of the services/libraries needed
import os
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# 1. Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
# choose a local (colab) directory to store the data.
local_download_path = os.path.expanduser('~/data')
try:
os.makedirs(local_download_path)
except: pass
# 2. Auto-iterate using the query syntax, in this case as I am using the main directory of Drive this would be root
# https://developers.google.com/drive/v2/web/search-parameters
file_list = drive.ListFile(
{'q': "'root' in parents"}).GetList()
for f in file_list:
# 3. Print the name and id of the files
print('title: %s, id: %s' % (f['title'], f['id']))
注意:当您执行此操作时,colab 将带您到另一个页面进行身份验证并让您插入密钥。只需按照服务指示您执行的操作即可,这非常简单。
我希望这对你有所帮助。让我知道您是否需要其他任何内容,或者您是否不理解某些内容。:)
推荐阅读
- excel - 选择超链接目标单元格的整行并向左滚动目标单元格
- aws-amplify - 从分叉分支构建的 AWS Ampify 控制台预览版
- postgresql - 如何使用 pgAdmin 从 .pg_dump 文件中恢复数据库
- apache-spark - 在笔记本上使用 pyspark 从表中删除行
- javascript - 在循环中,使所有其他值除了匹配条件的值被赋予样式
- java - 当我导入 JPA 注释并仅使用单个休眠属性时,我是否在用例中处理 JPA 或休眠?
- api - 处理 ErrorException (E_NOTICE) 未定义的偏移量:0
- java - 如何通过 Gradle 7.0+ 制作具有依赖关系的 Jar 文件?
- ios - 如何在页脚中使用 segue 将标签数据传递到不同的部分?
- github - 将 slack 与 github 集成以获取推送到特定分支的通知