为Keras卷积网络指定一些不可训练的过滤器 [英] Specify some untrainable filters for Keras convolutional network

查看:286
本文介绍了为Keras卷积网络指定一些不可训练的过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一种卷积网络体系结构,其中在第一层(在这种情况下为Conv1D)中,我要指定不可训练的固定滤波器的某些部分,同时还要有几个模型可以学习的可训练的滤波器.这可能吗,怎么办?

I would like to develop a convolutional network architecture where in the first layer (Conv1D in this case), I would like to prespecify some portion of untrainable fixed filters, while also having several trainable filters that the model can learn. Is this possible and how would this be done?

我的直觉是,我可以制作两个单独的Conv1D层-一层可训练,一层不可训练,然后以某种方式将它们连接起来,但是我不确定代码中的样子.另外,对于不可训练的过滤器,我该如何预先指定权重?

My intuition is that I can make two separate Conv1D layers - one trainable and one untrainable - and then somehow concatenate them, but I'm not sure what this would look like in code. Also, for the untrainable filters, how do I prespecify the weights?

推荐答案

使用功能性API相当简单:

This is quite easy with the functional API:

in = Input(....)
convA = Conv1D(filters1, kernel_size1, ...)
convB = Conv1D(filters2, kernel_size2, ...)

convB.trainable = False
convB.set_weights(some_weight_array)

conv1 = convA(in)
conv2 = convB(in)

convFinal = Concatenate(axis = -1)([conv1, conv2])

我还没有尝试过代码,但是在填写了一些小细节之后它应该可以正常工作了.

I haven't tried the code but it should be working after filling the small details.

这篇关于为Keras卷积网络指定一些不可训练的过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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