Tried to construct a tensor from a int sequence, but found an item of type NoneType at index (0)

When I run the following code that from crnn, I get this error

def encode(self, text):
“”"Support batch or single str.

    Args:
        text (str or list of str): texts to convert.

    Returns:
        torch.IntTensor [length_0 + length_1 + ... length_{n - 1}]: encoded texts.
        torch.IntTensor [n]: length of each text.
    """
    length = []
    result = []
    for item in text:            
        if self.is_chinese(item): 		   
           # item = unicode(item,'utf-8')
           item = item.encode("utf-8")
        length.append(len(item))
        for char in item:				
            index = self.dict.get(char)                
            result.append(index)
        text = result
    return (torch.IntTensor(text), torch.IntTensor(length))

You didn’t post the error message. :wink:

When I train crnn ,it had an error,how should I solve this problem?

Traceback (most recent call last):
File “crnn/crnn_main.py”, line 212, in
cost = trainBatch(crnn, criterion, optimizer)
File “crnn/crnn_main.py”, line 191, in trainBatch
t, l = converter.encode(gpu_texts)
File “/home/yang/Scence_Recognition/crnn/utils.py”, line 66, in encode
return (torch.IntTensor(text), torch.IntTensor(length))
RuntimeError: tried to construct a tensor from a int sequence, but found an item of type NoneType at index (0)

The error message seems to be quite clear.
Could you check, what’s inside text and length?
There seem to be a NoneType at index 0.

:grinning: many thank