Open LJXLJXLJX opened 4 years ago
@LJXLJXLJX Have you solved it?
I pretrained a model using ctcloss and it works well. Then I loaded the weights and continued to train with the aceloss. The losses seemed to be coming down, but the test results were terrible, almost all wrong.
Here is my implementation of ACELoss.
device = torch.device("cuda:" + cfg.TRAIN.GPU_ID if torch.cuda.is_available() else "cpu") class ACELoss(nn.Module): def __init__(self): super().__init__() def forward(self, input_, target, target_lens): w, bs, num_class = input_.size() aggragetions = torch.zeros(bs, cfg.ARCH.NUM_CLASS) for i in range(bs): idx = 0 for j in range(target_lens[i]): aggragetions[i][target[idx]] += 1 idx += 1 aggragetions[i][0] = w - target_lens[i] target = aggragetions.to(device) input_ = input_ + 1e-10 input_ = torch.sum(input_, 0) input_ = input_ / w target = target / w loss = (-torch.sum(torch.log(input_) * target)) / bs return loss
your idx
seems wrong
I pretrained a model using ctcloss and it works well. Then I loaded the weights and continued to train with the aceloss. The losses seemed to be coming down, but the test results were terrible, almost all wrong. Here is my implementation of ACELoss.
device = torch.device("cuda:" + cfg.TRAIN.GPU_ID if torch.cuda.is_available() else "cpu") class ACELoss(nn.Module): def __init__(self): super().__init__() def forward(self, input_, target, target_lens): w, bs, num_class = input_.size() aggragetions = torch.zeros(bs, cfg.ARCH.NUM_CLASS) for i in range(bs): idx = 0 for j in range(target_lens[i]): aggragetions[i][target[idx]] += 1 idx += 1 aggragetions[i][0] = w - target_lens[i] target = aggragetions.to(device) input_ = input_ + 1e-10 input_ = torch.sum(input_, 0) input_ = input_ / w target = target / w loss = (-torch.sum(torch.log(input_) * target)) / bs return loss
your
idx
seems wrong
Hello, I checked it, and I think it is not wrong.
+1,all the test results is "blank"---------
I pretrained a model using ctcloss and it works well. Then I loaded the weights and continued to train with the aceloss. The losses seemed to be coming down, but the test results were terrible, almost all wrong.
Here is my implementation of ACELoss.
device = torch.device("cuda:" + cfg.TRAIN.GPU_ID if torch.cuda.is_available() else "cpu") class ACELoss(nn.Module): def __init__(self): super().__init__() def forward(self, input_, target, target_lens): w, bs, num_class = input_.size() aggragetions = torch.zeros(bs, cfg.ARCH.NUM_CLASS) for i in range(bs): idx = 0 for j in range(target_lens[i]): aggragetions[i][target[idx]] += 1 idx += 1 aggragetions[i][0] = w - target_lens[i] target = aggragetions.to(device) input_ = input_ + 1e-10 input_ = torch.sum(input_, 0) input_ = input_ / w target = target / w loss = (-torch.sum(torch.log(input_) * target)) / bs return loss
what is the difference between cfg.ARCH.NUM_CLASS and num_class? whether contain the blank?
I pretrained a model using ctcloss and it works well. Then I loaded the weights and continued to train with the aceloss. The losses seemed to be coming down, but the test results were terrible, almost all wrong.
Here is my implementation of ACELoss.