Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 负载重量要求为h5py_Python_Tensorflow_Keras - Fatal编程技术网

Python 负载重量要求为h5py

Python 负载重量要求为h5py,python,tensorflow,keras,Python,Tensorflow,Keras,我试着运行一个keras模型,试着使用预先训练过的VGGnet- 当我运行这个命令时 base\u model=applications.VGG16(weights='imagenet',include\u top=False,input\u shape=(img\u行、img\u列、img\u通道)) 我得到这个错误: ``------------------------------------------------------------------ --------- ImportE

我试着运行一个keras模型,试着使用预先训练过的VGGnet- 当我运行这个命令时
base\u model=applications.VGG16(weights='imagenet',include\u top=False,input\u shape=(img\u行、img\u列、img\u通道))

我得到这个错误:

  ``------------------------------------------------------------------
---------
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.``
``------------------------------------------------------------------
---------
ImportError回溯(最近的呼叫)
最后)
在()
1.
---->2 base_model=applications.VGG16(weights='imagenet',
include_top=False,输入_shape=(img_行、img_列、img_通道))
/usr/local/lib/python3.5/dist-packages/keras/applications/vgg16.py in
VGG16(包括顶部、权重、输入张量、输入形状、池、,
(课程)
167重量(路径)(无)(顶部),,
168缓存_subdir='models')
-->169型号.负载重量(重量路径)
170如果K.backend()=“theano”:
171层使用。在模型(模型)中转换所有内核
/中的usr/local/lib/python3.5/dist-packages/keras/engine/topology.py
加载权重(self、filepath、按名称)
2563         """
2564如果h5py为无:
->2565升高高度(“‘负载重量’需要h5py”。)
2566 f=h5py.File(文件路径,mode='r')
2567如果f.attrs中没有“图层名称”,f中没有“模型权重”:
ImportError:'load_weights'需要h5py``
我浏览了一些github问题页面,其中提出了相关问题,但没有给出解决方案。 有什么建议吗?

安装h5py:

pip install h5py
或者如果使用conda:

conda install h5py

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

pip install cython
sudo apt-get install libhdf5-dev
pip install h5py

然后重新启动jupyter记事本。

如果“pip install h5py”不起作用,您会看到如下内容:“。。。在Python3中使用“pip3安装h5py”/这将起作用。

以下步骤解决了我的问题

conda uninstall h5py
pip install h5py 

@Ryan检查您的python路径:
echo$PYTHONPATH
。它可以阻止加载它。使用conda之后,请检查您是否处于正确的环境中。如何检查我的python路径?@Ryan正如我在终端中所说:
echo$PYTHONPATH
@Ryan确定,如果使用conda,则意味着它将只使用加载了c的包当前环境。如果您只导入h5py是否有效?让我们看看。这就是一个!
sudo apt get install libhdf5
为我修复了它:)谢谢!!