我正在尝试运行一个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.``
我浏览了一些 Github 的问题页面,发现有一个相关的问题被提出,但没有给出解决方案。
任何建议?
echo $PYTHONPATH
。它可能会防止加载。之后,你使用 conda 吗?如果是这样,请检查你是否在正确的环境中。 - tupuiecho $PYTHONPATH
- tupui