我已按照大多数教程中介绍的有关如何将自定义数据集上传到google colab的所有步骤进行操作。但是我遇到了一个错误,尝试了很多错误但还是无法解决。
我正在尝试使用自定义数据集训练CNN模型。我尝试使用大多数教程中给出的代码段将其上传到colab。
运行代码段时显示以下错误
Downloading zip file
---------------------------------------------------------------------------
HttpError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pydrive/files.py in FetchMetadata(self, fields, fetch_all)
236 fields=fields)\
--> 237 .execute(http=self.http)
238 except errors.HttpError as error:
6 frames
HttpError: <HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/https%3A%2F%2Fdrive.google.com%2Fopen%3Fid%3D1RqLx88tx2FCV0Z3CHsqVtx7S3_ffE-UW?alt=json returned "File not found: https://drive.google.com/open?id=1RqLx88tx2FCV0Z3CHsqVtx7S3_ffE-UW">
During handling of the above exception, another exception occurred:
ApiRequestError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pydrive/files.py in FetchMetadata(self, fields, fetch_all)
237 .execute(http=self.http)
238 except errors.HttpError as error:
--> 239 raise ApiRequestError(error)
240 else:
241 self.uploaded = True
ApiRequestError: <HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/https%3A%2F%2Fdrive.google.com%2Fopen%3Fid%3D1RqLx88tx2FCV0Z3CHsqVtx7S3_ffE-UW?alt=json returned "File not found: https://drive.google.com/open?id=1RqLx88tx2FCV0Z3CHsqVtx7S3_ffE-UW">
#this is the code snippet I have taken from tutorials to upload dataset to google colab.
!pip install -U -q PyDrive
# Insert your file ID
# Get it by generating a share URL for the file
# An example : https://drive.google.com/file/d/1iz5JmTB4YcBvO7amj3Sy2_scSeAsN4gd/view?usp=sharing
zip_id = 'https://drive.google.com/open?id=1RqLx88tx2FCV0Z3CHsqVtx7S3_ffE-UW'
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
import zipfile, os
# 1. Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
if not os.path.exists('MODEL'):
os.makedirs('MODEL')
# 2. Download Zip
print ("Downloading zip file")
myzip = drive.CreateFile({'id': zip_id})
myzip.GetContentFile('model.zip')
# 3. Unzip
print ("Uncompressing zip file")
zip_ref = zipfile.ZipFile('model.zip', 'r')
zip_ref.extractall('MODEL/')
zip_ref.close()
答案 0 :(得分:0)
OMG。经过一个小时(几乎8个小时)的互联网研究和头脑风暴,我找到了答案。如果有任何新手在colab上工作并遇到类似错误,这就是我如何解决此错误。上面代码的问题是我们分配文件ID的方式。 zip_id ='https://drive.google.com/open?id=1RqLx88tx2FCV0Z3CHsqVtx7S3_ffE-UW'。我见过的大多数教程都告诉我们,只需右键单击google驱动器中的文件并复制共享链接地址即可获取文件ID。但是文件ID并不是我们复制的全部内容。文件ID仅在id =之后(在本例中为1RqLx88tx2FCV0Z3CHsqVtx7S3_ffE-UW)。将其指定为ID后,错误消失了。希望此回复对其他合作者有所帮助。