Python 无法加载在Google Colaboratory中创建的模型

Python 无法加载在Google Colaboratory中创建的模型,python,keras,google-colaboratory,Python,Keras,Google Colaboratory,我在Google Colab中使用Keras训练了一名CNN,但是在下载模型后,我无法在本地系统(Windows)中加载hdf5文件 我以前做过,从来没有任何问题。这就是我得到的错误 Traceback (most recent call last): File "D:/Work/binary-face-recognition/predict-test.py", line 27, in <module> model = load_model('model.hdf5')

我在Google Colab中使用Keras训练了一名CNN,但是在下载模型后,我无法在本地系统(Windows)中加载
hdf5
文件

我以前做过,从来没有任何问题。这就是我得到的错误

Traceback (most recent call last):
  File "D:/Work/binary-face-recognition/predict-test.py", line 27, in <module>
    model = load_model('model.hdf5')
  File "C:\Users\PARTHA.N\AppData\Local\Continuum\anaconda3\envs\face\lib\site-packages\keras\engine\saving.py", line 417, in load_model
    f = h5dict(filepath, 'r')
  File "C:\Users\PARTHA.N\AppData\Local\Continuum\anaconda3\envs\face\lib\site-packages\keras\utils\io_utils.py", line 186, in __init__
    self.data = h5py.File(path, mode=mode)
  File "C:\Users\PARTHA.N\AppData\Local\Continuum\anaconda3\envs\face\lib\site-packages\h5py\_hl\files.py", line 312, in __init__
    fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
  File "C:\Users\PARTHA.N\AppData\Local\Continuum\anaconda3\envs\face\lib\site-packages\h5py\_hl\files.py", line 142, in make_fid
    fid = h5f.open(name, flags, fapl=fapl)
  File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py\h5f.pyx", line 78, in h5py.h5f.open
OSError: Unable to open file (truncated file: eof = 38486016, sblock->base_addr = 0, stored_eof = 72708080)
为了从GoogleColab保存并下载模型,我使用以下代码片段

# save model
model.save('model.hdf5')

# download model
from google.colab import files
files.download('model.hdf5')
下载文件后,我在Google colb的
files.download()行中发现以下错误

----------------------------------------
Exception happened during processing of request from ('::ffff:172.28.0.1', 47132, 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 721, 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 800, in write
    self._sock.sendall(b)
ConnectionResetError: [Errno 104] Connection reset by peer
----------------------------------------

看起来互联网连接有问题。我换了另一个WiFi,效果很好

这个问题现在听起来很傻,但保留下来,回答这个问题希望能帮助遇到同样问题的人

来自

“由对等方重置连接”是TCP/IP协议的等价物 把电话挂回去。这比不回答更礼貌, 留下一个挂着。但这并不是真正意义上的金融危机 礼貌的TCP/IP交谈者


我确实遇到了同样的问题,我所做的不同之处是从文件管理器下载文件,同样的工作很好

点击屏幕左上角colab标志下方的小箭头

然后,您需要单击这些文件并导航到所需文件右键单击并下载所需文件。这对我来说效果更好,并且没有连接错误,这是files.download方法中的情况


我不知道我们能做到。谢谢
----------------------------------------
Exception happened during processing of request from ('::ffff:172.28.0.1', 47132, 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 721, 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 800, in write
    self._sock.sendall(b)
ConnectionResetError: [Errno 104] Connection reset by peer
----------------------------------------