【问题标题】:in keras, how can apply filter ( where ) funtion?在 keras 中,如何应用过滤器( where )功能?
【发布时间】:2018-04-10 22:10:43
【问题描述】:

类似于 functools 包中的过滤器功能,我想在张量中找到超过 0.5 的元素。

这是用于此的代码,但不起作用。

def pred_overhalf(y_true, y_pred):

    return K.count_params( filter( lambda x : x > 0.5 , y_pred ) )
model.compile(optimizer = "adam" , loss = "mse", metrics = [ pred_overhalf])

有什么办法可以解决这个问题吗?我搜索 keras 后端文档,但找不到任何解决方案

【问题讨论】:

标签: python tensorflow deep-learning keras


【解决方案1】:
def pred_overhalf(y_true,y_pred):
    out = K.greater(y_pred,0.5)
    out = K.cast(out,K.floatx())

    #option 1
    return K.mean(out) #fraction of items greater than 0.5

    #option 2
    return K.sum(out) #total count (beware: this will consider all samples)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-31
    • 1970-01-01
    • 2018-01-16
    相关资源
    最近更新 更多