小编BLB*_*LBA的帖子

在 Keras/Tensorflow 中实现可训练的广义 Bump 函数层

我正在尝试编写按组件应用的Bump 函数的以下变体:

广义凹凸函数方程,

在哪里 ?可训练;但它不起作用(下面报告了错误)。


我的尝试:

这是我到目前为止编码的内容(如果有帮助的话)。假设我有两个函数(例如):

  def f_True(x):
    # Compute Bump Function
    bump_value = 1-tf.math.pow(x,2)
    bump_value = -tf.math.pow(bump_value,-1)
    bump_value = tf.math.exp(bump_value)
    return(bump_value)

  def f_False(x):
    # Compute Bump Function
    x_out = 0*x
    return(x_out)

class trainable_bump_layer(tf.keras.layers.Layer):

    def __init__(self, *args, **kwargs):
        super(trainable_bump_layer, self).__init__(*args, **kwargs)

    def build(self, input_shape):
        self.threshold_level = self.add_weight(name='threshlevel',
                                    shape=[1],
                                    initializer='GlorotUniform',
                                    trainable=True)

    def call(self, input):
        # Determine Thresholding Logic
        The_Logic = tf.math.less(input,self.threshold_level)
        # Apply Logic
        output_step_3 = tf.cond(The_Logic, 
                                lambda: f_True(input),
                                lambda: f_False(input))
        return output_step_3
Run Code Online (Sandbox Code Playgroud)

错误报告:

    Train on 100 samples …
Run Code Online (Sandbox Code Playgroud)

python machine-learning keras tensorflow tf.keras

7
推荐指数
0
解决办法
486
查看次数

标签 统计

keras ×1

machine-learning ×1

python ×1

tensorflow ×1

tf.keras ×1