一、環(huán)境
Ubuntu 16.04
tensorflow 1.4.0
keras 2.1.3
二、訓(xùn)練數(shù)據(jù)時報錯:
ValueError: Error when checking target: expected model_2 to have shape (None, 3) but got array with shape (4, 1
三、解決思路
一開始的想法:tensorflow 和 keras 的版本不兼容?
經(jīng)過多次安裝不同版本的tensorflow 和 keras ,發(fā)現(xiàn)問題依舊存在。而且在python環(huán)境下使用命令:
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
經(jīng)過了多個版本的搭配,發(fā)現(xiàn)問題的原因不是 tensorflow 和 keras 的版本不兼容,而是
/home/×××/anaconda2/lib/python2.7/site-packages/h5py
這個文件的原因。
最終解決方法:在終端中使用命令:
pip install h5py==2.8.0rc1
就可以正常使用了,不會再報數(shù)組唯獨不匹配等問題了。
補充:h5py文件是存放兩類對象的容器,數(shù)據(jù)集(dataset)和組(group),dataset類似數(shù)組類的數(shù)據(jù)集合,和numpy的數(shù)組差不多。
補充知識:keras 維度不對等問題
1.在windows下面找到keras的配置文件, 修改channel_last 或者channel_first
C:\Users\Administrator\.keras\keras.json
2..在linux下面找到keras的配置文件, 修改channel_last 或者channel_first
/home/.keras/keras.json
以上這篇解決tensorflow/keras時出現(xiàn)數(shù)組維度不匹配問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持服務(wù)器之家。
原文鏈接:https://blog.csdn.net/qq_33033367/article/details/80959046