ValueError: Shape must be rank 1 but is rank 0 for 'bn_conv1/cond/Reshape_4' (op: 'Resha

Posted wind-chaser

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ValueError: Shape must be rank 1 but is rank 0 for 'bn_conv1/cond/Reshape_4' (op: 'Resha相关的知识,希望对你有一定的参考价值。

运行demo报错

ValueError: Shape must be rank 1 but is rank 0 for ‘bn_conv1/cond/Reshape_4‘ (op: ‘Reshape‘) with input shapes: [1,64,1,1], [].

技术图片

经过查阅,发现是BatchNormalization的问题,如下代码也会类似报错

from keras.layers import BatchNormalization, Input

 x = Input(shape=(1, 2, 2)) 

BatchNormalization(axis=1)(x)   

报错:InvalidArgumentError: Shape must be rank 1 but is rank 0 for ‘batch_normalization_1/cond/Reshape_4‘ (op: ‘Reshape‘) with input shapes: [1,1,1,1], [].

在CPU版的keras 2.2.0上没有问题,在gup版本的keras有问题。因此将keras 降低版本为2.1.2:

 pip3 uninstall keras

 pip3 install keras==2.1.2  -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

ref:https://blog.csdn.net/weixin_40755306/article/details/84944008

 

以上是关于ValueError: Shape must be rank 1 but is rank 0 for 'bn_conv1/cond/Reshape_4' (op: 'Resha的主要内容,如果未能解决你的问题,请参考以下文章

无法将列表转换为数据框。不断收到错误“ValueError: Must pass 2-d input.shape=(1, 4, 5)”

ValueError: TextEncodeInput must be Union[TextInputSequence, Tuple[InputSequence, InputSequence]] -

正则化器导致“ValueError:Shapes must be equal rank”

使用python发生此类错误 ValueError: endog must be in the unit interval.

ValueError: total size of new array must be unchanged

ValueError: Bin labels must be one fewer than the number of bin edges