我正在使用 fastai 中的城市景观数据集进行语义分割。我想在计算准确性时忽略一些类。这就是我根据 fastai 深度学习课程定义准确性的方式:
name2id = {v:k for k,v in enumerate(classes)}
unlabeled = name2id['unlabeled']
ego_v = name2id['ego vehicle']
rectification = name2id['rectification border']
roi = name2id['out of roi']
static = name2id['static']
dynamic = name2id['dynamic']
ground = name2id['ground']
def acc_cityscapes(input, target):
target = target.squeeze(1)
mask=(target!=unlabeled and target!= ego_v and target!= rectification
and target!=roi and target !=static and target!=dynamic and
target!=ground)
return (input.argmax(dim=1)[mask]==target[mask]).float().mean()
如果我只忽略其中一个类,则此代码有效:
mask=target!=unlabeled
但是当我试图忽略这样的多个类时:
mask=(target!=unlabeled and target!= ego_v and target!= rectification
and target!=roi and target !=static and target!=dynamic and
target!=ground)
我收到此错误:
runtimeError: bool value of tensor with more than one value is ambiguous
任何想法我该如何解决这个问题?