ImportError load weights requires h5py

0 votes

Hi Guys,

I am trying to install imagenet weights to create my CNN model. But It gives me the below error.

model = MobileNet(weights='imagenet' ,include_top = False, input_shape=(224,224,3))
ImportError                               Traceback (most recent call last)
<ipython-input-2-f144cafed21b> in <module>
----> 1 model = MobileNet(weights='imagenet'  , include_top = False ,input_shape=(224,224,3))
~\anaconda3\envs\tensorflow\lib\site-packages\keras\applications\__init__.py in wrapper(*args, **kwargs)
     18         kwargs['models'] = models
     19         kwargs['utils'] = utils
---> 20         return base_fun(*args, **kwargs)
     21 
     22     return wrapper
~\anaconda3\envs\tensorflow\lib\site-packages\keras\applications\mobilenet.py in MobileNet(*args, **kwargs)
      9 @keras_modules_injection
     10 def MobileNet(*args, **kwargs):
---> 11     return mobilenet.MobileNet(*args, **kwargs)
     12 
     13 
~\anaconda3\envs\tensorflow\lib\site-packages\keras_applications\mobilenet.py in MobileNet(input_shape, alpha, depth_multiplier, dropout, include_top, weights, input_tensor, pooling, classes, **kwargs)
    294                                                 weight_path,
    295                                                 cache_subdir='models')
--> 296         model.load_weights(weights_path)
    297     elif weights is not None:
    298         model.load_weights(weights)
~\anaconda3\envs\tensorflow\lib\site-packages\keras\engine\saving.py in load_wrapper(*args, **kwargs)
    490                 os.remove(tmp_filepath)
    491             return res
--> 492         return load_function(*args, **kwargs)
    493 
    494     return load_wrapper
~\anaconda3\envs\tensorflow\lib\site-packages\keras\engine\network.py in load_weights(self, filepath, by_name, skip_mismatch, reshape)
   1218         """
   1219         if h5py is None:
-> 1220             raise ImportError('`load_weights` requires h5py.')
   1221         with h5py.File(filepath, mode='r') as f:
   1222             if 'layer_names' not in f.attrs and 'model_weights' in f:
ImportError: `load_weights` requires h5py.

How can I solve this error?​

May 18, 2020 in Machine Learning by akhtar
• 38,260 points
4,773 views

1 answer to this question.

0 votes

Hi@akhtar,

You are trying to use pre-created weight of imagenet. But in your error it shows that h5py module is missing. To avoid this error, you have to download this module.

$ conda install h5py

Hope this will help.

answered May 18, 2020 by MD
• 95,460 points

Related Questions In Machine Learning

0 votes
1 answer

ImportError: cannot import name 'train_test_split' from 'sklearn.linear_model

Hi@MD, I think in your version, linear_model  don't have train_test_split ...READ MORE

answered Apr 13, 2020 in Machine Learning by akhtar
• 38,260 points
8,222 views
0 votes
1 answer

Tensorflow ImportError: cannot import name'abs' error

Hi@akhtar, You may get this error, if you ...READ MORE

answered Apr 23, 2020 in Machine Learning by MD
• 95,460 points
6,104 views
0 votes
1 answer

ImportError: cannot import name 'LinearRegression' from 'sklearn'

Hi@akhtar, You got this error because LinearRegression is ...READ MORE

answered Apr 24, 2020 in Machine Learning by MD
• 95,460 points
24,440 views
0 votes
1 answer

ImportError: No module named seaborn

Hi@akhtar, By default it comes with Anaconda but ...READ MORE

answered Apr 28, 2020 in Machine Learning by MD
• 95,460 points
3,709 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,354 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

ImportError: cannot import name minimum_spanning_tree

Hi@akhtar, I think there may be problem in ...READ MORE

answered Apr 20, 2020 in Machine Learning by MD
• 95,460 points
2,070 views
0 votes
1 answer

ImportError: No module named 'tensorflow.contrib.rnn.python.ops.core_rnn

Hi@akhtar, I think you got this error because of incompatible ...READ MORE

answered Apr 22, 2020 in Machine Learning by MD
• 95,460 points
11,035 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP