我正在开发一个机器学习模型来从骨骼图像中检测骨骼。我使用的是火把,我使用的模型是沙漏模型。
当我使用binary_cross_entropy_with_logits时,我可以看到损失的减少,但是当我尝试测试模型时,我注意到:
我就是这样称呼binary_cross_entropy_with_logits的
loss = F.binary_cross_entropy_with_logits(ouputs[i], Y, weight=Mask, reduction='sum') / Mask.sum()我就是这样做测试的
ouput = model(X)
ouput_sig = torch.sigmoid(ouput)
plot_voxel2d(ouput_soft1)如果我使用这样的mse损失,同样的模型、输入、目标也能工作:
loss = torch.sum(((ouputs[i] - Y) ** 2) * Mask) / torch.sum(Mask)我确保目标在0到1之间。感谢你的帮助。
发布于 2021-08-02 18:31:58
以下代码块是G. Hinton在他的课程中提出的:lec6.pdf
optimizer = optim.RMSprop(net.parameters(), lr=0.005, weight_decay=1e-8)
if net.n_classes > 1:
criterion = nn.CrossEntropyLoss()
else:
criterion = nn.BCEWithLogitsLoss()然后,您需要以与下面的代码示例类似的方式使用sigmoid (火炬函数式:F.sigmoid):
for isample, sample in enumerate(ds):
mask_torch = net2(sample['image'][None, :, :, :].type(torch.cuda.FloatTensor))
mask = (F.sigmoid(mask_torch.type(torch.cuda.FloatTensor)) > 0.4925099).type(torch.FloatTensor)
print(mask)
for ichan in range(3):
ax[isample, ichan].imshow(sample['image'][ichan].cpu())
ax[isample, 3].imshow(sample['mask'][0].cpu())
ax[isample, 4].imshow(mask[0, 0].cpu().detach().numpy())将乙状体放在层叠后的末端。看起来会是这样的:
对于乙状结肠,它看起来如下所示:
def forward(self, x):
#print(x.shape)
x = self.layer_1(x)
x = self.layer_2(x)
x = self.layer_3(x)
logits = F.sigmoid(self.outc(x))
return logits发布于 2021-11-30 03:44:32
我多次遇到这种情况,每次原因都是标签不在0到1之间
https://stackoverflow.com/questions/68607705
复制相似问题