使用角点的均值为零的卷积

问题描述 投票:1回答:1

您如何实现每个滤波器均值为零的conv2d。>

我曾尝试通过kernel_regularizer中的conv2d参数执行此操作,但由于某种原因而遇到了问题。

def zero_mean_regularizer(weight_matrix):
    # weight matrix is channel last
    return weight_matrix - K.mean(weight_matrix, axis=(1, 2), keepdims=True)

尽管出于某种原因,我从ModelCheckpoint回调中收到一个神秘的错误。

self = <keras.callbacks.ModelCheckpoint object at 0x12e890358>, epoch = 0
logs = {'loss': array([[[[-0.24377288,  0.4010657 ,  0.03990834, -0.19173835,
           0.02325685, -0.12445911,  0.34307766...0454,  0.18098758,  0.05493904,
          -0.15479018, -0.19435076,  0.07913151,  0.20207654]]]],
      dtype=float32)}

    def on_epoch_end(self, epoch, logs=None):
        logs = logs or {}
        self.epochs_since_last_save += 1
        if self.epochs_since_last_save >= self.period:
            self.epochs_since_last_save = 0
            filepath = self.filepath.format(epoch=epoch + 1, **logs)
            if self.save_best_only:
                current = logs.get(self.monitor)
                if current is None:
                    warnings.warn('Can save best model only with %s available, '
                                  'skipping.' % (self.monitor), RuntimeWarning)
                else:
>                   if self.monitor_op(current, self.best):
E                   ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

似乎此正则化程序正在导致模型为单个时期创建多个损耗值。

您如何实现conv2d,其中每个过滤器的均值为零。我尝试通过conv2d中的kernel_regularizer参数来执行此操作,但由于某种原因而遇到问题。 def ...

python tensorflow keras conv-neural-network
1个回答
2
投票

我认为您想将此用作constraint

© www.soinside.com 2019 - 2024. All rights reserved.