【发布时间】:2019-02-12 13:08:27
【问题描述】:
我正在尝试在 Keras 中运行自定义指标。我成功了,但我不相信它的结果,所以我想检查一些值。麻烦的是一切都在张量中,我想将它们转换为 ndarrays 以检查它们。要转换它们,我必须有一个会话来评估它们。当我尝试使用 Keras 后端进行会话时,出现错误:
InvalidArgumentError(参见上面的回溯):您必须为占位符张量“Dense_1_target_1”提供一个值,其 dtype 为 float 和 shape [?,?] [[节点:Dense_1_target_1 = Placeholderdtype=DT_FLOAT, shape=[?,?], _device="/job:localhost/replica:0/task:0/device:GPU:0"]]
我唯一想要的是能够打印一些关于张量的信息:值、形状等。
from keras import backend as K
def t_zeros(Y_true, y_pred):
""" Just count # zero's in Y_true and try to print some info """
threshold = 0.5
true_zeros = K.less(Y_true, threshold) # element-wise True where Y_true < theshold
true_zeros = K.cast(true_zeros, K.floatx()) # cast to 0.0 / 1.0
n_zeros = K.sum(true_zeros)
sess = K.get_session()
y_t = Y_true.eval(session=sess) # <== error happens here
print(y_t.shape)
return n_zeros
【问题讨论】:
标签: python tensorflow keras metrics