Parthapratim Neog
Parthapratim Neog

Reputation: 4478

Unable to load model created in Google Colaboratory

I had trained a CNN using Keras in Google Colab, but, after downloading the model, I am not able to load the hdf5 file in my local system ( Windows ).

I have done this before, and never had any issue. This is the error that I am getting.

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)

For loading the model, I'm doing a base load_model call

from keras.models import load_model
model = load_model('model.hdf5')

To save & download the model from Google Colab I'm using the following snippet.

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

# download model
from google.colab import files
files.download('model.hdf5')

I get the following error in Google colb at the line files.download() after the file is downloaded.

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

Upvotes: 1

Views: 4378

Answers (3)

Inder
Inder

Reputation: 3826

I did face the same issue, what I did differently was to download the files from the files manager instead and the same worked just fine.

Click on the little arrow on the top left corner of the screen just below the colab sign looks something like

this

Then you will need to click on the files and navigate to the required file right click and download the required file. This worked better for me and there was no connection error, which was the case in files.download method

files

Upvotes: 2

DirtyBit
DirtyBit

Reputation: 16792

Coming from the description here

"Connection reset by peer" is the TCP/IP equivalent of slamming the phone back on the hook. It's more polite than merely not replying, leaving one hanging. But it's not the FIN-ACK expected of the truly polite TCP/IP converseur

Upvotes: 1

Parthapratim Neog
Parthapratim Neog

Reputation: 4478

Looks like there was some issue with the internet connection. I switched to another WiFi, and it worked fine.

The question sounds silly now, but keeping it, and answering this in hopes that it helps someone who comes across the same problem.

Upvotes: 0

Related Questions