Error while downloading data from vgg16.h5

I am getting websocket failure error while connecting and downloading model from platform.ai/models
The error message says:
HTTPServerRequest(protocol=‘http’, host=‘localhost:8888’, method=‘GET’, uri=’/api/kernels/3a89cdae-dd90-488a-bfaa-d1a0d906b6f9/channels?session_id=268F6A8A991C48608D354B4ACBE95C00’, version=‘HTTP/1.1’, remote_ip=’::1’, headers={‘Origin’: ‘http://localhost:8888’, ‘Upgrade’: ‘websocket’, ‘Accept-Language’: ‘en-US,en;q=0.8’, ‘Accept-Encoding’: ‘gzip, deflate, sdch, br’, ‘Sec-Websocket-Version’: ‘13’, ‘Host’: ‘localhost:8888’, ‘Sec-Websocket-Key’: ‘x6UrpBLdjaVzaenzu36qSw==’, ‘User-Agent’: ‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36’, ‘Connection’: ‘Upgrade’, ‘Cookie’: ‘username-localhost-8888=“2|1:0|10:1481996091|23:username-localhost-8888|44:YzUwNThlZGY5Y2ZmNDE1OWI3NjY1MjMxOGQyMWM0NTU=|a9f613e893bbb4ddc9aec4ffd886ca065e72700609c25edbfbd4e63fdf409a76”; username-localhost-8889=“2|1:0|10:1482105448|23:username-localhost-8889|44:MDVlNzRkZWUyMDA1NGU3MmFhY2JhOTgyYjI5ZTY2NWI=|4af4db6a6123a40ac4ac58bab78621ec375db0e71d1badd27661202cc1dff8ce”’, ‘Pragma’: ‘no-cache’, ‘Cache-Control’: ‘no-cache’, ‘Sec-Websocket-Extensions’: ‘permessage-deflate; client_max_window_bits’})
Traceback (most recent call last):
File “/Users/trinakarmakar/anaconda2/lib/python2.7/site-packages/tornado/web.py”, line 1425, in _stack_context_handle_exception
raise_exc_info((type, value, traceback))
File “/Users/trinakarmakar/anaconda2/lib/python2.7/site-packages/tornado/stack_context.py”, line 314, in wrapped
ret = fn(*args, **kwargs)
File “/Users/trinakarmakar/anaconda2/lib/python2.7/site-packages/zmq/eventloop/zmqstream.py”, line 191, in
self.on_recv(lambda msg: callback(self, msg), copy=copy)
File “/Users/trinakarmakar/anaconda2/lib/python2.7/site-packages/notebook/services/kernels/handlers.py”, line 373, in _on_zmq_reply
super(ZMQChannelsHandler, self)._on_zmq_reply(stream, msg)
File “/Users/trinakarmakar/anaconda2/lib/python2.7/site-packages/notebook/base/zmqhandlers.py”, line 258, in _on_zmq_reply
self.write_message(msg, binary=isinstance(msg, bytes))
File “/Users/trinakarmakar/anaconda2/lib/python2.7/site-packages/tornado/websocket.py”, line 210, in write_message
raise WebSocketClosedError()
WebSocketClosedError

Here’s a temporary workaround:

You can download the weights manually by going to:
http://www.platform.ai/models/vgg16.h5

You could then change line 82 of vgg16.py from:
model.load_weights(get_file(fname, self.FILE_PATH+fname, cache_subdir='models'))
to:
model.load_weights(path_to_manually_downloaded_vgg16_h5)

1 Like

When I modify the code line in 82. It doesn’t work. It still should download the data. What should I do.

@biss

“When I modify the code line in 82. It doesn’t work.”

Can you paste the error message if there is one?

“It still should download the data.”

The idea of the workaround is to download the data manually. For example, you can type:

wget http://www.platform.ai/models/vgg16.h5

in a terminal to download the 528 MB file.

If you use the wget command from within the directory you ran jupyter notebook from, then path_to_manually_downloaded_vgg16_h5 would be "vgg16.h5".

Your new line 82:

model.load_weights("vgg16.h5")

“What should I do.”

You will get solutions to your problems faster if you read this guide on asking for help:

http://wiki.fast.ai/index.php/How_to_ask_for_Help

Hi,

Thanks for response.

I manually downloaded weights as you suggested but didn’t change the code and ran it worked fine as shown here:

Found 23000 images belonging to 2 classes.
Found 2000 images belonging to 2 classes.
Epoch 1/1
23000/23000 [==============================] - 29294s - loss: 0.1182 - acc: 0.9681 - val_loss: 0.0713 - val_acc: 0.9850

I got as seen above 98.50% accuracy on validation set which exceeds expectation I guess. By the way I found change of the code is time consuming as there are many moving pieces like some keras modules are called behind the scene etc. Ideally this code should work just fine and I believe it will. Thanks again for such a wonderful platform for learning to learn.

Hi @Matthew,

I’m trying to run the part 1 lesson 1 notebook. However, I can’t find the file vgg16.h5. Would you have a copy somewhere else?

Thanks a lot and have a great day, Maxime

If you type the following in a terminal, you’ll download the file:

wget files.fast.ai/models/vgg16.h5

Edit:

Replaced “http://www.platform.ai” with “files.fast.ai”.

2 Likes

In this post Please note: use files.fast.ai, not platform.ai, from now on @jeremy asked folks to use files.fast.ai moving forward.

I recommend going into the vgg16.py file and updating the paths in there.

Personally I also changed the cache directory to not be in the hidden .keras folder by default. I created a folder in my user directory and changed all the cache="models" to be cach="~/models" That way I can see what I’ve cached and/or downloaded.

2 Likes

I had a similar problem after interrupting a download of the vgg16_bn weights.

The error’s trace (don’t have it to show, sorry) started at the create(.) method of vgg16bn.py. Specifically line 91 where model.load_weights(.) is called. load_weights(.) calls get_file(.), which sounds a lot like a utils.py function.

Line 35 of utils.py reads:
from keras.utils.data_utils import get_file

Reading the Keras documentation at, https://keras.io/utils/#get_file:

By default the file at the url origin is downloaded to the cache_dir ~/.keras

Ah, of course. cd’ing into .keras, there’s a models folder. Inside that: vgg16_bn.h5.

Renaming it (just in case) before deleting it, and rerunning the Jupyter notebook: instead of the error I get Downloading data from https://files.fast.ai/models/vgg16_bn.h5

It was indeed the problem file. If you, by mistake or have to, interrupt a weights-download, at least for the files in this course, remember to clear the cached file hidden away at ~/.keras/models/

Trying to fix the same issue. Don’t have vgg_nb.h5 in the models folder - it’s just empty. Don’t have wget installed - any other way around this? Did this notebook1 first run about 3 weeks ago and this all worked fine. Just getting back into it now…something must’ve changed?

Anyone seen this issue with ssl its related to grabbing the vgg16.h5 file off the net?

Exception: URL fetch failure on http://www.platform.ai/models/imagenet_class_index.json: None – EOF occurred in violation of protocol (_ssl.c:749)

But I have the file already, I renamed it, put it in ‘models’, but this error seems to precede checking, not what I was expecting. Should work as I can put it in any directory it wants and call it anything it wants but the ssl error is network related to the set up of a secure connection.

1 Like

I had the same issue. But then in my “vgg16bn.py” file, I changed line 32 to be self.FILE_PATH = 'http://files.fast.ai/models/' instead of using www.platform.ai which it was before. Then I was able to download it. :slight_smile: