歡迎您光臨本站 註冊首頁

解決tensorflow/keras時出現數組維度不匹配問題

←手機掃碼閱讀     madbeef @ 2020-06-30 , reply:0

一、環境

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的數組差不多。
 

補充知識:keras 維度不對等問題

1.在windows下面找到keras的配置文件, 修改channel_last 或者channel_first

C:UsersAdministrator.keraskeras.json

2..在linux下面找到keras的配置文件, 修改channel_last 或者channel_first

/home/.keras/keras.json

 

                                                     

   


[madbeef ] 解決tensorflow/keras時出現數組維度不匹配問題已經有240次圍觀

http://coctec.com/docs/python/shhow-post-240415.html