keras搬砖系列-Flatten ValueError

keras搬砖系列-Flatten ValueError

之前总是会出现,ValueError: The shape of the input to "Flatten" is not fully defined (got (0, 6, 80). Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model.
我用的theano,而且我的.keras.json也改为了theano。

后面通过:
keras.backend.image_data_format()
发现为 'channels_last'。emmm,我也不知道,但是我的.keras.json为'channels_first'。不管他了。

解决方法:
from keras import backend as K
K.set_image_data_format('channels_first')

如果你是tensorflow的,所以你得设置为
channels_last








  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
ValueError Traceback (most recent call last) <ipython-input-54-536a68c200e5> in <module> 52 return model 53 # lstm network ---> 54 model = create_LSTM_model(X_train,n_steps,n_length, n_features) 55 # summary 56 print(model.summary()) <ipython-input-54-536a68c200e5> in create_LSTM_model(X_train, n_steps, n_length, n_features) 22 X_train = X_train.reshape((X_train.shape[0], n_steps, 1, n_length, n_features)) 23 ---> 24 model.add(ConvLSTM2D(filters=64, kernel_size=(1,3), activation='relu', 25 input_shape=(n_steps, 1, n_length, n_features))) 26 model.add(Flatten()) ~\anaconda3\lib\site-packages\tensorflow\python\trackable\base.py in _method_wrapper(self, *args, **kwargs) 203 self._self_setattr_tracking = False # pylint: disable=protected-access 204 try: --> 205 result = method(self, *args, **kwargs) 206 finally: 207 self._self_setattr_tracking = previous_value # pylint: disable=protected-access ~\anaconda3\lib\site-packages\keras\utils\traceback_utils.py in error_handler(*args, **kwargs) 68 # To get the full stack trace, call: 69 # `tf.debugging.disable_traceback_filtering()` ---> 70 raise e.with_traceback(filtered_tb) from None 71 finally: 72 del filtered_tb ~\anaconda3\lib\site-packages\keras\engine\input_spec.py in assert_input_compatibility(input_spec, inputs, layer_name) 233 ndim = shape.rank 234 if ndim != spec.ndim: --> 235 raise ValueError( 236 f'Input {input_index} of layer "{layer_name}" ' 237 "is incompatible with the layer: " ValueError: Input 0 of layer "conv_lstm2d_12" is incompatible with the layer: expected ndim=5, found ndim=3. Full shape received: (None, 10, 5)解决该错误
最新发布
05-26

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值