将包含 ~20K 图像的文件夹添加到 Google Colaboratory
Add a folder with ~20K of images into Google Colaboratory
我正在使用 Keras 进行猫品种识别,并尝试使用 Google Colaboratory 在 GPU 上进行训练。当我在 PyCharm 工作时,我使用了包含图像的文件夹路径:
data_dir = '//home//kate//Рабочий стол//барахло линух минт//more_breeds_all_new'
而且我无法理解,我如何才能将包含 19500 张图片的文件夹下载到 Colab,而不是像 Google 在它的笔记本中提供的那样一张一张地加载图片。
我在 Google 驱动器上也有一个包含这些图像的文件夹,但我也不知道如何将它用作带有路径的完整文件夹。
首先:.zip .tar 格式的 zip 图像文件夹,示例 folder_data.zip
并将其同步或上传 (folder_data.zip) 到 Google 驱动器。
获取 google 驱动器 file_id 的 zip 文件 ( folder_data.zip) 如 1iytA1n2z4go3uVCwE_vIKouTKyIDjEq
第二:
我建议您使用 Pydrive 将文件从 google 驱动器下载到 colab notebook VM。我用 5 秒下载了 500MB 的数据集。
1. 安装 Pydrive
!pip install PyDrive
2。 OAouth
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)
从 google 驱动器
下载文件的代码
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 ./
列表文件看起来像它
folder_data.zip
folder_data/
为圣战加油
我正在使用 Keras 进行猫品种识别,并尝试使用 Google Colaboratory 在 GPU 上进行训练。当我在 PyCharm 工作时,我使用了包含图像的文件夹路径:
data_dir = '//home//kate//Рабочий стол//барахло линух минт//more_breeds_all_new'
而且我无法理解,我如何才能将包含 19500 张图片的文件夹下载到 Colab,而不是像 Google 在它的笔记本中提供的那样一张一张地加载图片。 我在 Google 驱动器上也有一个包含这些图像的文件夹,但我也不知道如何将它用作带有路径的完整文件夹。
首先:.zip .tar 格式的 zip 图像文件夹,示例 folder_data.zip 并将其同步或上传 (folder_data.zip) 到 Google 驱动器。
获取 google 驱动器 file_id 的 zip 文件 ( folder_data.zip) 如 1iytA1n2z4go3uVCwE_vIKouTKyIDjEq
第二: 我建议您使用 Pydrive 将文件从 google 驱动器下载到 colab notebook VM。我用 5 秒下载了 500MB 的数据集。 1. 安装 Pydrive
!pip install PyDrive
2。 OAouth
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)
从 google 驱动器
下载文件的代码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 ./
列表文件看起来像它
folder_data.zip
folder_data/
为圣战加油