Skip to content

代码bug指出及修正(关于模型输出和实际使用的冲突) #7

@Jangkoole

Description

@Jangkoole

涉及到两个文件:train_multi_fundus.py和genda_net.py
其中train_multi_fundus.py涉及到所有使用了sigmoid函数的位置(ctl + f查找所有sigmoid)
genda_net.py涉及到第51行左右,也就是模型最后输出预测seg_pred的final操作

冲突之处在于,根据train_multi_fundus.py文件,由于使用了很多sigmoid函数,可以推断出训练代码是假设
模型输出的是属于某一概率的logit图,并没有经过softmax2d函数进行通道维度的softmax

但是根据模型代码,final()操作中却有softmax2d函数,也就是说模型输出的实际是某个像素属于某一类别的概率值

这样的冲突会引起很严重的后果
因为如果模型返回的是概率值(一定非负),然后经过sigmoid函数后,输出的值:1. 一定在[0.5,1]之间 2. 值比较小且一定小于
1 / (1+e-1),这个值大概是0.73,而这个值一定小于train_multi_fundus.py中的0.75(在71行左右),所以pred_val一定是0,
那么输出的预测图就一定是全黑的

所以,最方便且一定要做的修改是,将genda_net.py的第51行:
self.final = nn.Sequential(nn.Conv2d(filters[0], self.num_classes, kernel_size=1), nn.Softmax2d())

修改为
self.final = nn.Conv2d(filters[0], self.num_classes, kernel_size=1)

这样才能正确运行

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions