您的位置:首页 > 其它

使用tensorflow/keras时出现数组维度不匹配问题 的解决方法

2018-07-08 14:23 821 查看
一、环境
Ubuntu    16.04
tensorflow    1.4.0
keras    2.1.3


二、训练数据时报错:
ValueError: Error when checking target: expected model_2 to have shape (None, 3) but got array with shape (4, 1
原因:数组的维度不正确。


三、解决思路

一开始的想法:tensorflow   和  keras  的版本不兼容?

经过多次安装不同版本的tensorflow   和  keras  ,发现问题依旧存在。而且在python环境下使用命令:

import tensorflow
或者
import keras
时,报错:
/home/×××/anaconda2/lib/python2.7/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters

经过了多个版本的搭配,发现问题的原因不是 tensorflow   和  keras  的版本不兼容,而是
/home/×××/anaconda2/lib/python2.7/site-packages/h5py
这个文件的原因。

最终解决方法:在终端中使用命令:pip install h5py==2.8.0rc1   


就可以正常使用了,不会再报数组唯独不匹配等问题了。


补充:h5py文件是存放两类对象的容器,数据集(dataset)和组(group),dataset类似数组类的数据集合,和numpy的数组差不多。 阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐