Ryan
Ryan

Reputation: 10109

load weights require h5py

Im trying to run a keras model,trying to use pre-trained VGGnet- When i run this Command base_model = applications.VGG16(weights='imagenet', include_top=False, input_shape=(img_rows, img_cols, img_channel))

I get this error:

  ``------------------------------------------------------------------
---------
ImportError                               Traceback (most recent call 
last)
<ipython-input-79-9b18deb3bc0f> in <module>()
  1 
----> 2 base_model = applications.VGG16(weights='imagenet', 
include_top=False, input_shape=(img_rows, img_cols, img_channel))

/usr/local/lib/python3.5/dist-packages/keras/applications/vgg16.py in 
VGG16(include_top, weights, input_tensor, input_shape, pooling, 
classes)
167                                     WEIGHTS_PATH_NO_TOP,
168                                     cache_subdir='models')
--> 169         model.load_weights(weights_path)
170         if K.backend() == 'theano':
171             layer_utils.convert_all_kernels_in_model(model)

/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py in 
load_weights(self, filepath, by_name)
   2563         """
   2564         if h5py is None:
-> 2565             raise ImportError('`load_weights` requires h5py.')
   2566         f = h5py.File(filepath, mode='r')
   2567         if 'layer_names' not in f.attrs and 'model_weights' in f:

ImportError: `load_weights` requires h5py.``

I went through some github issues page where a relevant question was asked,but no solutions were given. Any suggestions?

Upvotes: 17

Views: 28314

Answers (6)

Stefan
Stefan

Reputation: 1

you can delete files and install lover version of h5py (do it old classic way select files and delete). this actualy fix my problem (I install h5py 3.10 with pip install somehow you cant install lower version with pip install h5py==3.10 or conda install h5py==3.10 wthout delete files)

Upvotes: 0

hossein beirami
hossein beirami

Reputation: 1

the below steps solve this error for me :

conda uninstall h5py
pip uninstall h5py 

then install with conda:

conda  install -c anaconda  h5py

Upvotes: 0

issam
issam

Reputation: 93

the below steps solved my issue

conda uninstall h5py
pip install h5py 

Upvotes: 1

Jagesh Maharjan
Jagesh Maharjan

Reputation: 913

technically you need dependencies, such as:

pip install cython
sudo apt-get install libhdf5-dev
pip install h5py

And restart your jupyter notebok.

Upvotes: 7

Ali
Ali

Reputation: 407

in the case that "pip install h5py" does not work, and you see something like: "... already satisfied". in python 3 use "pip3 install h5py"/ this will work.

Upvotes: 2

tupui
tupui

Reputation: 6528

Install h5py:

pip install h5py

Or if using conda:

conda install h5py

Upvotes: 24

Related Questions