Python 使用google drive中的数据在colab中与fastai创建数据束

Python 使用google drive中的数据在colab中与fastai创建数据束,python,Python,我正在尝试使用fast.ai从我的google drive帐户加载google colab中的数据集。 我使用的数据集是《外星人与捕食者》中的kaggle,来自 我下载并加载到我的谷歌硬盘。然后我运行以下代码: # Load the Drive helper and mount from google.colab import drive drive.mount("/content/drive") %reload_ext autoreload %autoreload 2 %matplotlib

我正在尝试使用fast.ai从我的google drive帐户加载google colab中的数据集。 我使用的数据集是《外星人与捕食者》中的kaggle,来自 我下载并加载到我的谷歌硬盘。然后我运行以下代码:

# Load the Drive helper and mount
from google.colab import drive
drive.mount("/content/drive")

%reload_ext autoreload
%autoreload 2
%matplotlib inline
from fastai import *
from fastai.vision import *

path='/content/drive/My Drive/FastaiData/Alien-vs-Predator'

tfms = get_transforms(do_flip=False)

#default bs=64, set image size=100 to run successfully on colab
data = ImageDataBunch.from_folder(path,ds_tfms=tfms, size=100)
path='/content/drive/My Drive/FastaiData/Alien-vs-Predator'

tfms = get_transforms(do_flip=False)

#default bs=64, set image size=100 to run successfully on colab
data = ImageDataBunch.from_folder(path,ds_tfms=tfms, size=100)
然后我得到了这个错误:

/usr/local/lib/python3.6/dist-packages/fastai/data_block.py:399: UserWarning: Your training set is empty. Is this is by design, pass `ignore_empty=True` to remove this warning.
  warn("Your training set is empty. Is this is by design, pass `ignore_empty=True` to remove this warning.")
/usr/local/lib/python3.6/dist-packages/fastai/data_block.py:402: UserWarning: Your validation set is empty. Is this is by design, use `no_split()` 
                 or pass `ignore_empty=True` when labelling to remove this warning.
  or pass `ignore_empty=True` when labelling to remove this warning.""")
IndexError                                Traceback (most recent call last)

<ipython-input-3-5b3f66a4d360> in <module>()
      4 
      5 #default bs=64, set image size=100 to run successfully on colab
----> 6 data = ImageDataBunch.from_folder(path,ds_tfms=tfms, size=100)
      7 
      8 data.show_batch(rows=3, figsize=(10,10))

/usr/local/lib/python3.6/dist-packages/fastai/vision/data.py in from_folder(cls, path, train, valid, valid_pct, classes, **kwargs)
    118         if valid_pct is None: src = il.split_by_folder(train=train, valid=valid)
    119         else: src = il.random_split_by_pct(valid_pct)
--> 120         src = src.label_from_folder(classes=classes)
    121         return cls.create_from_ll(src, **kwargs)
    122 


and so on...
/usr/local/lib/python3.6/dist packages/fastai/data_block.py:399:UserWarning:您的培训集为空。如果这是故意的,请传递'ignore_empty=True'以删除此警告。
警告(“您的培训集是空的。这是设计的吗?传递`ignore\u empty=True`以删除此警告。”)
/usr/local/lib/python3.6/dist packages/fastai/data_block.py:402:UserWarning:您的验证集为空。如果这是故意的,请使用“no_split()”
或在添加标签时传递'ignore_empty=True'以删除此警告。
或在添加标签以删除此警告时传递“ignore_empty=True”。“”)
索引器回溯(最后一次最近调用)
在()
4.
5#默认bs=64,将图像大小设置为100以在colab上成功运行
---->6 data=ImageDataBunch.from_文件夹(路径,ds_tfms=tfms,大小=100)
7.
8数据。显示批次(行=3,图大小=(10,10))
/usr/local/lib/python3.6/dist-packages/fastai/vision/data.py在from_文件夹中(cls、path、train、valid、valid_pct、classes、**kwargs)
118如果有效的\u pct为无:src=il.split\u by\u文件夹(train=train,valid=valid)
119其他:src=il.随机按pct分割(有效pct)
-->120 src=src.label\u来自\u文件夹(classes=classes)
121返回cls。从ll创建(src,**kwargs)
122
等等
似乎它发现我指示为train和validation set的文件夹是空的,这不是真的


感谢您的帮助

将文件上载到google drive后,您应该使用PyDrive

示例代码段

!pip install -U -q PyDrive

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

# 1. Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

# PyDrive reference:
# https://gsuitedevs.github.io/PyDrive/docs/build/html/index.html

# 2. Create & upload a file text file.
uploaded = drive.CreateFile({'title': 'Sample upload.txt'})
uploaded.SetContentString('Sample upload file content')
uploaded.Upload()
print('Uploaded file with ID {}'.format(uploaded.get('id')))

# 3. Load a file by ID and print its contents.
downloaded = drive.CreateFile({'id': uploaded.get('id')})
print('Downloaded content "{}"'.format(downloaded.GetContentString()))
详情请参阅