负载重量需要h5py

Rya*_*an 12 python keras tensorflow

我试图运行keras模型,尝试使用预先训练的VGGnet-当我运行此命令 base_model = applications.VGG16(weights='imagenet', include_top=False, input_shape=(img_rows, img_cols, img_channel))

我收到此错误:

  ``------------------------------------------------------------------
---------
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.``
Run Code Online (Sandbox Code Playgroud)

我浏览了一些github问题页面,其中询问了相关问题,但没有给出解决方案.有什么建议?

Y0d*_*0da 17

安装h5py:

pip install h5py
Run Code Online (Sandbox Code Playgroud)

或者如果使用conda:

conda install h5py
Run Code Online (Sandbox Code Playgroud)

  • 我尝试过,但它仍然会抛出相同的错误 (4认同)

Jag*_*jan 5

从技术上讲,您需要依赖项,例如:

pip install cython
sudo apt-get install libhdf5-dev
pip install h5py
Run Code Online (Sandbox Code Playgroud)

并重新启动您的jupyter notebok。