【发布时间】:2020-09-07 08:01:15
【问题描述】:
我有一个模型可以预测 5 个类别。我想更改准确度指标,如下例所示:
def accuracy(y_pred,y_true):
#our pred tensor
y_pred = [ [0,0,0,0,1], [0,1,0,0,0], [0,0,0,1,0], [1,0,0,0,0], [0,0,1,0,0]]
# make some manipulations with tensor y_pred
# actons description :
for array in y_pred :
if array[3] == 1 :
array[3] = 0
array[0] = 1
if array[4] == 1 :
array[4] = 0
array[1] = 1
else :
continue
#this nice work with arrays but howe can i implement it with tensors ?
#after manipulations result->
y_pred = [ [0,1,0,0,0], [0,1,0,0,0], [1,0,0,0,0], [1,0,0,0,0],[0,0,1,0,0] ]
#the same ations i want to do with y_true
# and after it i want to run this preprocess tensors the same way as simple tf.keras.metrics.Accuracy metric
我认为 tf.where 可以帮助过滤张量,但不幸的是不能正确地做到这一点。
如何使用张量制作这个预处理精度指标?
【问题讨论】:
-
这类似于this。希望对你有帮助
-
你想怎么改?
-
@Zabir Al Nazi 这只是一个动作示例,我想用我的张量来做。这个循环不是张量的正确解决方案。
标签: python python-3.x tensorflow machine-learning tensorflow2.x