简体   繁体   English

如何对 tensorflow 中的 CNN kernel 进行限制?

[英]How to make restrictions to the CNN kernel in tensorflow?

Our specific training problem requires that all the weights in a CNN kernel must be positive.我们的具体训练问题要求 CNN kernel 中的所有权重必须为正。 Anyone knows how to do that?有谁知道该怎么做?

You are looking for kernel constraints, this link here has the answer to your question.您正在寻找 kernel 约束, 此处的此链接可以回答您的问题。 You can either use kernel constraints or simply adopt the lagrange optimization technique to add a term to your overall loss function that removes the feature of the weights that you don't need.您可以使用 kernel 约束,也可以简单地采用拉格朗日优化技术来为您的整体损失 function 添加一个项,以消除您不需要的权重特征。 Something like this (as it is mentioned in the referenced answer),像这样的东西(正如参考答案中提到的那样),

added_loss = -tf.minimum(tf.reduce_min(theta),0)
final_loss = your_loss + added_loss
optimizer.minimize(final_loss)

It is also necessary to note that, adding this loss only encourages the optimization to look for a solution which has theta or as you say weights to be all positive, there is no guarantee that the best fit parameters are all positive.还需要注意的是,添加这种损失只会鼓励优化寻找具有 theta 的解决方案,或者正如您所说的权重都是正的,不能保证最佳拟合参数都是正的。 To ensure such a behaviour, you can clip the weights between 0 and +infinity.为了确保这种行为,您可以将权重限制在 0 和 +infinity 之间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM