我試着運行keras模型,試圖用預先訓練VGGnet- 當我運行此命令 base_model = applications.VGG16(weights='imagenet', include_top=False, input_shape=(img_rows, img_cols, img_channel))
負載權重需要h5py
我得到這個錯誤:
``------------------------------------------------------------------
---------
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問題頁面提出了相關問題,但沒有給出解決方案。 有什麼建議嗎?如果使用暢達
pip install h5py
或者:
我試過了,但仍然拋出相同的錯誤 – Ryan
@Ryan檢查你的Python路徑:'echo $ PYTHONPATH'。它可以防止它被加載。之後,你使用conda?如果是這樣,請檢查您是否處於正確的環境中。 – Y0da
我該如何檢查我的Python路徑? – Ryan