加载本地数据Google Colab [英] Loading local data google colab

查看:1024
本文介绍了加载本地数据Google Colab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个npy文件(largeFIle.npy)保存在我的google colab笔记本保存在我的google驱动器的同一可折叠笔记本"文件夹中.下面的代码,但下面出现错误.当我在笔记本电脑上本地运行该代码并将笔记本电脑与文件放在同一文件夹中时,此代码可以正常工作.在Google Colab中使用笔记本加载数据时,我需要做些其他事情吗?我刚开始合作.

I have a npy file, (largeFIle.npy) saved in the same "colab notebooks" folder on my google drive that I have my google colab notebook saved in. I'm trying to load the data into my notebook with the code below but I'm getting the error below. This code works fine when I run it locally on my laptop with the notebook in the same folder as the file. Is there something different I need to do when loading data with notebooks in google colab? I'm very new to colab.

code:

dataset_name = 'largeFIle.npy'

dataset = np.load(dataset_name, encoding='bytes')


Error:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-6-db02a0bfcf1d> in <module>()
----> 1 dataset = np.load(dataset_name, encoding='bytes')

/usr/local/lib/python3.6/dist-packages/numpy/lib/npyio.py in load(file, mmap_mode, allow_pickle, fix_imports, encoding)
    370     own_fid = False
    371     if isinstance(file, basestring):
--> 372         fid = open(file, "rb")
    373         own_fid = True
    374     elif is_pathlib_path(file):

FileNotFoundError: [Errno 2] No such file or directory: 'largeFIle.npy'

推荐答案

在colab上启动新笔记本时,它将与您的远程计算机连接12个小时,您所拥有的便是笔记本和预加载的功能.要访问驱动器上的文件夹,您需要将远程实例连接到驱动器并进行身份验证.

When you launch a new notebook on colab, it connects you with a remote machine for 12 hours and all you have there is the notebook and preloaded functions. To access your folders on drive, you need to connect the remote instance to your drive and authenticate it.

这东西在我刚开始的时候也困扰着我,所以我正在创建一个要点 a>,并在我了解更多信息时对其进行更新.对于您的情况,请查看第2节(与驱动器连接).您无需编辑或了解任何内容,只需复制单元并运行即可.它会运行很多功能,然后为您提供身份验证链接.您需要转到该链接并使用Google登录,您将在那里获得访问令牌.将其放回输入框中,然后按Enter.如果它不起作用或出现一些错误,请再次运行该单元格.

This thing bugged me for sometime when I was beginning too, so I'm creating a gist and I'll update it as I learn more. For your case, check out section 2 (Connecting with Drive). You don't have to edit or understand anything, just copy the cell and run it. It will run a bunch of functions and then give you an authentication link. You need to go to that link and sign-in with Google, you'll get an access token there. Put it back in the input box and press Enter. If it doesn't work or if there's some error, run the cell again.

在下一部分中,我将驱动器安装到文件夹"/drive".因此,现在,驱动器上的所有内容都包含在此文件夹中,包括笔记本电脑.接下来,您可以更改工作目录.对我来说,我将所有笔记本保留在"/Colab"文件夹中,并进行相应的编辑.

In the next part I mount my drive to the folder '/drive'. So now, everything that's on your drive exists in this folder, including your notebook. Next, you can change your working directory. For me, I'm keeping all my notebooks in '/Colab' folder, edit it accordingly.

希望它对您有帮助.在您了解更多信息时,随时建议我对要点进行编辑. :)

Hope it helps you. Feel free to suggest me edits to the gist as you learn more. :)

这篇关于加载本地数据Google Colab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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