Keras:Lambda函数中Conv2D层中的消失参数 [英] Keras: Vanishing parameters in Conv2D layer within Lambda function

查看:192
本文介绍了Keras:Lambda函数中Conv2D层中的消失参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用使用Conv2D层的函数定义Lambda层.

I am defining a Lambda layer with a function that uses the Conv2D layer.

def lambda_func(x,k):
    y = Conv2D(k, (3,3), padding='same')(x)
    return y

并使用

k = 64
x = Conv2D(k, (3,3), data_format='channels_last', padding='same', name='block1_conv1')(inputs)
y = Lambda(lambda_func, arguments={'k':k}, name = 'block1_conv1_loc')(x)

但是在model.summary()中,lambda层没有显示任何参数!

But in model.summary(), the lambda layer is showing no parameters!

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         (None, 224, 224, 3)       0         
_________________________________________________________________
block1_conv1 (Conv2D)        (None, 224, 224, 64)      1792      
_________________________________________________________________
block1_conv1_loc (Lambda)    (None, 224, 224, 64)      0         
_________________________________________________________________
activation_1 (Activation)    (None, 224, 224, 64)      0         
_________________________________________________________________
block1_pool (MaxPooling2D)   (None, 112, 112, 64)      0         
_________________________________________________________________
flatten (Flatten)            (None, 802816)            0         
_________________________________________________________________

(在它下面有一个Dense层,在它下面有一个Softmax 2类分类器).如何确保Lambda层的Conv2D参数显示出来并且也是可训练的?我还尝试过在Lambda函数中使用trainable=True.

(There is a Dense layer under it, and a Softmax 2-class classifier under that). How can I ensure the Conv2D parameters of the Lambda layer show up and are also trainable? I have also tried using trainable=True in the Lambda function.

def lambda_func(x,k):
    y = Conv2D(k, (3,3), padding='same', trainable=True)(x)
    return y

但这没什么区别.

推荐答案

Lambda图层没有参数.

Lambda layers don't have parameters.

摘要中的参数是可以学习"的变量. Lambda层永远不会学习,它们是您创建的函数.

Parameters, in the summary, are the variables that can "learn". Lambda layers never learn, they're functions created by you.

如果您确实打算使用卷积层",请在lambda层之外使用它.
现在,如果要使用卷积运算",则可以在lambda层中使用它,但是没有可学习的参数,则可以自己定义过滤器.

If you do intend to use a "Convolutional Layer", use it outside of the lambda layer.
Now, if you want to use a "convolution operation", then use it inside the lambda layer, but there is no learnable parameter, you define the filters yourself.

如果您想创建一个以不同方式学习的特殊层,请创建一个自定义层.

If you want to create a special layer that learns in a different way, then create a custom layer.

这篇关于Keras:Lambda函数中Conv2D层中的消失参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆