将包含约 20K 图像的文件夹添加到 Google Colaboratory

Eka*_*nai 4 keras google-colaboratory

我正在使用 Keras 进行猫品种识别,并尝试使用 Google Colaboratory 进行 GPU 训练。当我在 PyCharm 工作时,我使用了包含图像的文件夹的路径:

data_dir = '//home//kate//??????? ????//??????? ????? ????//more_breeds_all_new'
Run Code Online (Sandbox Code Playgroud)

我无法理解,如何将包含 19500 张图像的文件夹下载到 Colab,而不是像 Google 在其笔记本中提供的那样一张一张地加载图片。我在 Google Drive 上也有一个包含这些图像的文件夹,但我也不知道如何将它用作带有路径的完整文件夹。

Moh*_*had 6

首先:以 .zip .tar 格式压缩图像文件夹,示例 folder_data.zip 并将其(folder_data.zip)同步或上传到 Google Drive。

像 1iytA1n2z4go3uVCwE_vIKouTkyIDjEq 一样获取 zip 文件(folder_data.zip)的谷歌驱动器 file_id

第二:我建议您使用 Pydrive 将文件从 google drive 下载到 colab notebook VM 。我下载了 500MB 的数据集 5 秒。1.安装pydrive

!pip install PyDrive
Run Code Online (Sandbox Code Playgroud)

2. OAout

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

# Authenticate and create the PyDrive client.
# This only needs to be done once in a notebook.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
Run Code Online (Sandbox Code Playgroud)
  1. 从谷歌驱动器下载文件的代码

    fileId = drive.CreateFile({'id': 'DRIVE_FILE_ID'}) #DRIVE_FILE_ID is file id example: 1iytA1n2z4go3uVCwE_vIKouTKyIDjEq print fileId['title'] # folder_data.zip fileId.GetContentFile('folder_data.zip') # Save Drive file as a local file

最后:将它解压到文件夹,这里的例子是

!unzip folder_data.zip -d ./
Run Code Online (Sandbox Code Playgroud)

列表文件看起来像它

folder_data.zip
folder_data/
Run Code Online (Sandbox Code Playgroud)

欢呼圣战