【发布时间】:2018-06-29 13:29:16
【问题描述】:
我的自定义激活函数的 i/p 将是一个 19 * 19 * 5 张量,比如 x。该函数需要将 sigmoid 应用于第一层,即 x[:,:,0:1],并将 relu 应用于其余层,即 x[:,:,1:5]。我已经使用以下代码定义了一个自定义激活函数:
def custom_activation(x):
return tf.concat([tf.sigmoid(x[:,:,:,0:1]) , tf.nn.relu(x[:,:,:,1:5])],axis = 3)
get_custom_objects().update({'custom_activation': Activation(custom_activation)})
第四个维度出现了,因为我在函数 custom_activation 中获得的输入将批量大小作为另一个维度。所以输入张量的形状是[bathc_size,19,19,5]。
有人能告诉我这是否是正确的做法吗?
【问题讨论】:
标签: python tensorflow keras