CTC loss, for Text-Recognition:Weird Values

Muhammad_Ali: <p>I am trying to use CRNN, model to give me Text-Perceptual-Loss, to be used for Text Super Resolution.<br>
I am using pyotrch’s CTC loss,</p>
<pre><code class="lang-auto">criterion = nn.CTCLoss(blank=0)

def encode_text_batch(text_batch):
    
    text_batch_targets_lens = [len(text) for text in text_batch]
    text_batch_targets_lens = torch.IntTensor(text_batch_targets_lens)
    
    text_batch_concat = "".join(text_batch)
    text_batch_targets = []

    for c in text_batch_concat:
      try:
        if (c=='"' ):
          id = char2id["'"]

        else: 
          id =char2id[c]
          
        text_batch_targets.append(id)
      except:
        text_batch_targets.append(0)
                          

    text_batch_targets = torch.IntTensor(text_batch_targets)
    #print(text_batch_targets)
    return text_batch_targets, text_batch_targets_lens
def compute_loss(text_batch, text_batch_logits):
    """
    text_batch: list of strings of length equal to batch size
    text_batch_logits: Tensor of size([T, batch_size, num_classes])
    """
    print(text_batch_logits.shape)
    text_batch_logps = F.log_softmax(text_batch_logits, 2) # [T, batch_size, num_classes] 
    #print(text_batch_logps.shape) 
    #print(text_batch_logps.size(0))
    text_batch_logps_lens = torch.full(size=(text_batch_logps.size(1),), 
                                       fill_value=text_batch_logps.size(0), 
                                       dtype=torch.int32).to(device) # [batch_size] 
    #print(text_batch_logps_lens) 
    #print(text_batch_logps.shape)
    #print(text_batch_logps_lens) 
    text_batch_targets, text_batch_targets_lens = encode_text_batch(text_batch)
    #print(text_batch_targets,text_batch_targets_lens)
    #print(text_batch_targets_lens)
    loss = criterion(text_batch_logps, text_batch_targets, text_batch_logps_lens, text_batch_targets_lens)

    return loss
</code></pre>
<p>But, like for image-example I am sharing, for “SIT”, if it is predicting SI, loss is less, AS COMPARED TO WHEN IT PREDICTS "SIT<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/2/624e63d4065681d1dbb8d7b868f8ad67cfa1304b.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/624e63d4065681d1dbb8d7b868f8ad67cfa1304b" title="Screenshot 2021-03-05 161633"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/2/624e63d4065681d1dbb8d7b868f8ad67cfa1304b_2_596x500.jpeg" alt="Screenshot 2021-03-05 161633" data-base62-sha1="e1EJZv6APSO2E2WrNLzREdxC1ez" width="596" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/2/624e63d4065681d1dbb8d7b868f8ad67cfa1304b_2_596x500.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/6/2/624e63d4065681d1dbb8d7b868f8ad67cfa1304b_2_894x750.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/6/2/624e63d4065681d1dbb8d7b868f8ad67cfa1304b.jpeg 2x" data-dominant-color="EFEFEF"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot 2021-03-05 161633</span><span class="informations">937×786 113 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div> "</p>
<p>Kindly, help  me with this.<br>
Thanks alot</p>