Debug 路漫漫-08:Keras 版本升級函數變換導致的問題


 

在使用 CNN的時候,報錯: TypeError: ('Keyword argument not understood:', 'padding')

 

將“padding”改為“border_mode”,即可:

 

 

原因:padding 是Keras 2.X的語法,而我的PC安裝的是 Keras 1.X版本。

二者的API 有一些地方是有變化的。

如下:(從 1.X 到 2.X )

 

 ========【Models】

1、Constructor arguments for Model have been renamed:

  • input -> inputs
  • output -> outputs

2、The Sequential model not longer supports the set_input method.

3、For any model saved with Keras 2.0 or higher, weights trained with backend X will be converted to work with backend Y without any manual conversion step.

 

========【Layers】

 1、Dense layer

  • Changed interface:
  • output_dim -> units
  • init -> kernel_initializer
  • added bias_initializer argument
  • W_regularizer -> kernel_regularizer
  • b_regularizer -> bias_regularizer
  • b_constraint -> bias_constraint
  • bias -> use_bias

2、Embedding

Convolutional layers :

Interface changes common to all convolutional layers:

  • nb_filter -> filters
  • float kernel dimension arguments become a single tuple argument, kernel size. E.g. a legacy call Conv2D(10, 3, 3) becomes Conv2D(10, (3, 3))
  • kernel_size can be set to an integer instead of a tuple, e.g. Conv2D(10, 3) is equivalent toConv2D(10, (3, 3)).
  • subsample -> strides. Can also be set to an integer.
  • border_mode -> padding
  • init -> kernel_initializer
  • added bias_initializer argument
  • W_regularizer -> kernel_regularizer
  • b_regularizer -> bias_regularizer
  • b_constraint -> bias_constraint
  • bias -> use_bias
  • dim_ordering -> data_format
  • In the SeparableConv2D layers, init is split into depthwise_initializer andpointwise_initializer.
  • Added dilation_rate argument in Conv2D and Conv1D.
  • 1D convolution kernels are now saved as a 3D tensor (instead of 4D as before).
  • 2D and 3D convolution kernels are now saved in format spatial_dims + (input_depth, depth)), even with data_format="channels_first".

3、Pooling1D

  • pool_length -> pool_size
  • stride -> strides
  • border_mode -> padding

4、Pooling2D,3D

  • border_mode -> padding
  • dim_ordering -> data_format

 

 

 

 

 

【Reference】

1、Keras 2.x和1.x的區別 :https://blog.csdn.net/ch1209498273/article/details/78287145

2、Keras 官方發布的 :Keras 2.0 release notes :https://github.com/keras-team/keras/wiki/Keras-2.0-release-notes


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM