本文介绍了如何在笔记本电脑的云端硬盘中读取文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从Google Colab Notbook内的驱动器读取数据集.我怎样才能做到这一点?我做了这样的事情,但是没有用.
I want to read the dataset from drive inside Google Colab Notbook.how can I do that?I did something like this but it's not working.
train_data_dir = "data/train/"
validation_data_dir = "data/validation/"
数据文件夹如下:
data/
train/
dogs/
dog001.jpg
dog002.jpg
...
cats/
cat001.jpg
cat002.jpg
...
validation/
dogs/
dog001.jpg
dog002.jpg
...
cats/
cat001.jpg
cat002.jpg
...
推荐答案
我找到了使用驱动器FUSE包装器
您必须先安装驱动器保险丝包装,然后创建一个目录,然后将其安装,该目录是驱动器的根目录,将您的数据集上传到您的google驱动器,然后使用"/content/name_of_your_directory/dataset_name/"
you have to install the drive fuse wrapper then make a directory then mount it, that directory is the root directory of your drive, upload your dataset to your google drive and access it using "/content/name_of_your_directory/dataset_name/"
就我而言,我按照以下步骤操作:
in my case I followed these steps:
!apt-get update -qq 2>&1 > /dev/null
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
然后
from google.colab import auth
auth.authenticate_user()
3-为Drive FUSE库生成凭据.
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
4-在Jupyter中解决STREAM和STDIN的顺序错误.
prompt = !google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass(prompt[0] + '\n\nEnter verification code: ')
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
5-创建目录并使用该目录挂载Google云端硬盘.
!mkdir -p yourdirectory
!google-drive-ocamlfuse yourdirectory
6-从类似于我的情况下的代码访问此目录
train_data_dir = "/content/yourdirectory/data/train/"
validation_data_dir = "/content/yourdirectory/data/validation/"
这篇关于如何在笔记本电脑的云端硬盘中读取文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!