从Google Colab下载文件时出现错误104

Sur*_*yer 1 python google-colaboratory

试图下载保存为~100MB HDF5文件的keras模型文件.

from google.colab import files
files.download('models/mlp_mnist_l.h5')
Run Code Online (Sandbox Code Playgroud)

但我一直得到以下ConnectionResetError

----------------------------------------
Exception happened during processing of request from ('::ffff:127.0.0.1', 43270, 0, 0)
Traceback (most recent call last):
  File "/usr/lib/python3.6/socketserver.py", line 317, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 348, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.6/socketserver.py", line 696, in __init__
    self.handle()
  File "/usr/lib/python3.6/http/server.py", line 418, in handle
    self.handle_one_request()
  File "/usr/lib/python3.6/http/server.py", line 406, in handle_one_request
method()
  File "/usr/lib/python3.6/http/server.py", line 639, in do_GET
    self.copyfile(f, self.wfile)
  File "/usr/lib/python3.6/http/server.py", line 800, in copyfile
    shutil.copyfileobj(source, outputfile)
  File "/usr/lib/python3.6/shutil.py", line 82, in copyfileobj
fdst.write(buf)
  File "/usr/lib/python3.6/socketserver.py", line 775, in write
    self._sock.sendall(b)
ConnectionResetError: [Errno 104] Connection reset by peer
Run Code Online (Sandbox Code Playgroud)

我是否需要重新启动VM并重试但是我将失去经过培训的模型文件,还是有其他方式下载文件?

小智 7

保存到谷歌驱动器使用Pydrive

# Install the PyDrive wrapper & import libraries.
# This only needs to be done once in a notebook.
!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

# 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)

# Create & upload a file.
uploaded = drive.CreateFile({'title': 'filename.csv'})
uploaded.SetContentFile('filename.csv')
uploaded.Upload()
print('Uploaded file with ID {}'.format(uploaded.get('id')))
Run Code Online (Sandbox Code Playgroud)


Sam*_*ain 6

您也可以使用Google合作实验室中的项目结构下载文件。

Step 1: Click on the chevron-right icon at the top left corner.
Step 2: Select the Files tab.
Step 3: Right click on the file you want to download and select the Download option.
Run Code Online (Sandbox Code Playgroud)

这是屏幕截图: 带有下载文件的Google合作实验室屏幕截图