【发布时间】:2019-05-22 18:44:55
【问题描述】:
我想使用 CNN + 分类器进行单词识别,其中输入是图像,输出是 10x37 矩阵。 10 是一个单词中的最大字符数,37 是我的示例中的字母数。
我为此模型编写了一个自定义损失函数,但我不确定它是否正确,因为我无法达到 80% 以上的测试准确度。
我正在使用 Pytorch
class CustomLoss(nn.Module):
def __init__(self):
super().__init__()
self.nllloss = nn.NLLLoss()
def forward(self, output, labels):
loss = 0
for i in range(labels.shape[1]):
loss += self.nllloss(output[:, i, :], labels[:, i])
loss /= labels.shape[1]
return loss
信息:
output.shape = (batch_size, 10, 37)
labels.shape = (batch_size, 10)
损失函数是否正确? 而我的分类问题叫什么(Multiple Multi class classification)?
【问题讨论】:
-
我试图找出模型中的错误。我想,也许错误出在我的损失函数中。问题是我的模型无法达到 80% 的测试准确率(我需要它至少达到 90%)。
标签: python deep-learning classification pytorch loss-function