crnn icon indicating copy to clipboard operation
crnn copied to clipboard

Training on Different Dataset

Open rayush7 opened this issue 7 years ago • 10 comments

@bgshih I am trying to train crnn on a synthetic dataset that I generated. Along with english alphabets and digits (0-9) it contains special characters like $,@,# etc. I was able to modify the utilities.lua to incorporate their ascii value and hence created the lmdb dataset. But when I am trying to train the model on the synthetic dataset then the predicted value are all the same. I am confused about where I am making the mistake.

The type of images in my dataset are following:

word_11 word_20 word_47 word_50

Here is the training log :

pic3 pic4

Are the weights initialized properly? Also I want to know is it possible to load the weight from the pretrained crnn model (trained on vgg synthetic dataset) before I start training the model on a new dataset? How do I go about doing that?

rayush7 avatar May 25 '17 12:05 rayush7

@bgshih Thanks for this package. I am using this repo for training on my own dataset. As there is code to create dataset in tool/create_dataset.py, but when I run this code I got nothing even after specifying all the parameters. I would like to request you to please help me in this matter. Thanks

azamshoaib avatar Aug 01 '17 11:08 azamshoaib

Hi @rayush7 , I have been trying to retain the network on my custom dataset as well, but the training process after loading a batch errors out at the forward pass (in training.lua in src/) with this message: `

 terminate called after throwing an instance of 'std::invalid_argument'
 
 what():  index out of range
 Aborted (core dumped)

`

Any idea what's going on? Did you ever encounter such a problem? @bgshih , suggestions?

stalagmite7 avatar Aug 10 '17 22:08 stalagmite7

@stalagmite7 I think there is some problem with your lmdb dataset. Are you using this script to generate your lmdb files?

rayush7 avatar Aug 11 '17 11:08 rayush7

Yes, with one small change: instead of checking image validity thru opencv, I use the inbuilt imghdr package from python (since I am using a docker container to work on this, didn't want to have to rebuild the container with opencv):

def checkImageIsValid(imageBin):
    if imageBin is None:
        return False
    ret_val = imghdr.what(None, imageBin)
    if ret_val == 'png':
        return True
    return False

Other than that, I have added all the other ascii printable characters to the set of recognizable characters in the utilities file, those are the only changes I've made.

stalagmite7 avatar Aug 11 '17 15:08 stalagmite7

Could it be that my ascii conversion is incorrect? Since the error it throws is an 'index out of range' error, perhaps I am trying to access indices for ascii characters that are out of the range of ascii? This is the function I am using in src/utilities.lua:

function str2label(strs, maxLength)
         --[[ Convert a list of strings to integer label tensor (zero-padded).

        ARGS:
          - `strs`     : table, list of strings
          - `maxLength`: int, the second dimension of output label tensor

        RETURN:
          - `labels`   : tensor of shape [#(strs) x maxLength]
        ]]
        assert(type(strs) == 'table')

        function ascii2label(ascii)
    	print(ascii)
    	local label
    	if ascii >= 33 and ascii <= 47 then -- symbols '!' to '/' mapped to 1-14
                label = ascii - 32
            
    	elseif ascii >= 48 and ascii <= 57 then -- '0'-'9' are mapped to 15-24
                label = ascii - 47 + 14
    	
    	elseif ascii >= 58 and ascii <= 64 then --symbols ':' to '@' are mapped to 25-31
                label = ascii - 57 + 24

            elseif ascii >= 65 and ascii <= 90 then -- 'A'-'Z' are mapped to 32-57
                label = ascii - 64 + 31
     
            elseif ascii >= 97 and ascii <= 122 then -- 'a'-'z' are mapped to 58-83
                label = ascii - 96 + 57
     
            elseif ascii >= 91 and ascii <= 96 then -- symbols '[' to '`' are mapped to 84-109
                label = ascii - 90 + 83

            elseif ascii >= 123 and ascii <= 126 then --symbols '{' to '~' are mapped to 109-112
                label = ascii - 122 + 109
            end
            return label
        end

        local nStrings = #strs
        local labels = torch.IntTensor(nStrings, maxLength):fill(0)
        for i, str in ipairs(strs) do
            for j = 1, string.len(str) do
                local ascii = string.byte(str, j)
                labels[i][j] = ascii2label(ascii)
            end
        end
        return labels
    end

Does anything seem immediately incorrect?

stalagmite7 avatar Aug 11 '17 16:08 stalagmite7

@stalagmite7 The first "if condition" in ascii2label function seems incorrect. As when ascii value would be 47 then label would be 15 and not 14 (which you have mentioned in the comments). And in the last "elseif condition" you are mapping from 109-112 or 110-113?. Check it. Apart from this not only you have to make changes in ascii2label function but also in label2ascii function, which is just the reverse conversion from labels to the ascii value.

rayush7 avatar Aug 11 '17 17:08 rayush7

Yes, I figured out the ascii2label function error once I looked at it; didn't know of the label2ascii function though, thanks a ton for pointing it out! This should work hopefully. :)

stalagmite7 avatar Aug 11 '17 17:08 stalagmite7

Can this package be used for Chinese characters also. If so what change I have to make. Kindly guide me. Thanks.

azamshoaib avatar Aug 14 '17 04:08 azamshoaib

@shoaibazam hello, have you successfully trained the model for chinese characters?

LiangHao92 avatar Dec 11 '17 02:12 LiangHao92

@shoaibazam the model it self is language independent, it works well on my own chinese dataset

Heisenberg0391 avatar Jan 26 '19 02:01 Heisenberg0391