将包含约20K图片的文件夹添加到Google合作实验室 [英] Add a folder with ~20K of images into Google Colaboratory

查看:110
本文介绍了将包含约20K图片的文件夹添加到Google合作实验室的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working with cat breeds recognition with Keras and try to use Google Colaboratory for training on GPU. When I worked in PyCharm, I used a path to folder with images:

data_dir = '//home//kate//Рабочий стол//барахло линух минт//more_breeds_all_new'

我不明白,我该如何将包含19500张图像的文件夹下载到Colab,而不是像Google在笔记本中一样逐张地将图片加载到Colab. 我在Google云端硬盘上也有一个包含这些图像的文件夹,但是我也不知道如何将其用作具有路径的完整文件夹.

And I can not understand, how can I download a folder with 19500 images to Colab instead loading pictures there one by one like Google offers in it's notebook. I also have a folder with these images on Google Drive, but I also do not know how to use it as a full folder with it's path.

推荐答案

首先:.zip .tar格式的zip图像文件夹,例如folder_data.zip 并将其(folder_data.zip)同步或上传到Google云端硬盘.

First: zip image folder in .zip .tar format,example folder_data.zip and sync or upload it( folder_data.zip) to Google Drive.

获取诸如1iytA1n2z4go3uVCwE_vIKouTKyIDjEq之类的zip文件(folder_data.zip)的Google驱动器file_id

Get google drive file_id of zip file( folder_data.zip) like 1iytA1n2z4go3uVCwE_vIKouTKyIDjEq

第二: 我建议您使用Pydrive将文件从Google驱动器下载到colab笔记本VM.我下载500MB数据集持续5秒. 1.安装Pydrive

Second: I recommend you use Pydrive to download your file from google drive to colab notebook VM . I download 500MB dataset for 5s. 1. install Pydrive

!pip install PyDrive

2. OAouth

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)

  1. 从Google驱动器下载文件的代码

  1. code for download file from google drive

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

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

最后:将其解压缩到文件夹,这里的示例是

Finaly: unzip it to folder, example in here is

!unzip folder_data.zip -d ./

列表文件看起来像

folder_data.zip
folder_data/

莫拉圣战队

这篇关于将包含约20K图片的文件夹添加到Google合作实验室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆