我试着运行一个Keras模型,试着使用预先培训过的vgnet。-
当我运行这个命令时
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.``

我浏览了一些Github问题页面,其中有一个相关的问题,但没有给出解决方案。
有什么建议吗?

最佳答案

安装h5py:

pip install h5py

或者如果使用Conda:
conda install h5py

关于python - 负载重量需要h5py,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45624116/

10-12 22:24