Closed abhiML closed 7 years ago
The height of images must be 32 for this assertion.
@meijieru , so we need to rescale our dataset to height=32 before running cnn_main.py ?
@ahmedmazari-dhatim yeah I have started the resizing to 100x32. What about you?
@ahmedmazari-dhatim yes
@ahmedmazari-dhatim how are you resizing it? I modified the create_dataset.py file and inserted these three lines `img=Image.open(imagePath,'r')
img=img.resize((100,32),Image.ANTIALIAS)
img.save(imagePath) `
I am still getting the same error
@meijieru Even after resizing all the images to 100x32 I am getting the same error.
Please check parameters in crnn_main.py
in detail.
@meijieru , after resizing l get this error that l don't understand please see at the end. Your help is warmly appreciated
RuntimeError: inconsistent tensor size at /py/conda-bld/pytorch_1493676237139/work/torch/lib/TH/generic/THTensorCopy.c:51 Exception AttributeError: "'DataLoaderIter' object has no attribute 'shutdown'" in <bound method DataLoaderIter.del of <torch.utils.data.dataloader.DataLoaderIter object at 0x7fbb075c17d0>> ignored
python2 crnn_main.py --trainroot="/home/ahmed/Downloads/training_data/output/train" --valroot="/home/ahmed/Downloads/training_data/output/valid" --cuda
Namespace(Diters=5, adadelta=False, adam=False, alphabet='0123456789abcdefghijklmnopqrstuvwxyz', batchSize=64, beta1=0.5, crnn='', cuda=True, displayInterval=500, experiment=None, imgH=64, keep_ratio=False, lr=1, n_test_disp=10, ngpu=1, nh=100, niter=25, random_sample=False, saveInterval=500, trainroot='/home/ahmed/Downloads/training_data/output/train', valInterval=500, valroot='/home/ahmed/Downloads/training_data/output/valid', workers=2)
Random Seed: 1919
CRNN (
(cnn): Sequential (
(conv0): Conv2d(1, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu0): ReLU (inplace)
(pooling0): MaxPool2d (size=(2, 2), stride=(2, 2), dilation=(1, 1))
(conv1): Conv2d(64, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu1): ReLU (inplace)
(pooling1): MaxPool2d (size=(2, 2), stride=(2, 2), dilation=(1, 1))
(conv2): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(batchnorm2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
(relu2): ReLU (inplace)
(conv3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu3): ReLU (inplace)
(pooling2): MaxPool2d (size=(2, 2), stride=(2, 1), dilation=(1, 1))
(conv4): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(batchnorm4): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
(relu4): ReLU (inplace)
(conv5): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu5): ReLU (inplace)
(pooling3): MaxPool2d (size=(2, 2), stride=(2, 1), dilation=(1, 1))
(conv6): Conv2d(512, 512, kernel_size=(2, 2), stride=(1, 1))
(batchnorm6): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
(relu6): ReLU (inplace)
)
(rnn): Sequential (
(0): BidirectionalLSTM (
(rnn): LSTM(512, 100, bidirectional=True)
(embedding): Linear (200 -> 100)
)
(1): BidirectionalLSTM (
(rnn): LSTM(100, 100, bidirectional=True)
(embedding): Linear (200 -> 37)
)
)
)
Traceback (most recent call last):
File "crnn_main.py", line 194, in <module>
train_iter = iter(train_loader)
File "/home/ahmed/anaconda3/envs/cv/lib/python2.7/site-packages/torch/utils/data/dataloader.py", line 303, in __iter__
return DataLoaderIter(self)
File "/home/ahmed/anaconda3/envs/cv/lib/python2.7/site-packages/torch/utils/data/dataloader.py", line 143, in __init__
self.sample_iter = iter(self.sampler)
File "/home/ahmed/crnn/dataset.py", line 96, in __iter__
index[i * self.batch_size:(i + 1) * self.batch_size] = batch_index
RuntimeError: inconsistent tensor size at /py/conda-bld/pytorch_1493676237139/work/torch/lib/TH/generic/THTensorCopy.c:51
Exception AttributeError: "'DataLoaderIter' object has no attribute 'shutdown'" in <bound method DataLoaderIter.__del__ of <torch.utils.data.dataloader.DataLoaderIter object at 0x7fbb075c17d0>> ignored
It shows that the problem comes from /crnn/dataset.py
line 96 :
index[i * self.batch_size:(i + 1) * self.batch_size] = batch_index
defined in the function :
def __iter__(self):
n_batch = len(self) // self.batch_size
tail = len(self) % self.batch_size
index = torch.LongTensor(len(self)).fill_(0)
for i in range(n_batch):
random_start = random.randint(0, len(self) - self.batch_size)
batch_index = random_start + torch.arange(0, self.batch_size - 1)
index[i * self.batch_size:(i + 1) * self.batch_size] = batch_index
Any suggestion ?
@abhiML , you don't get the same error, change the following lines in dataset.py
line 95 and 100:
torch.range
to torch.arange
and run again your code . please let me know
I think you gotta give imgH=32 in the parameters while running the crnn_main.py
haaa , l was about to share the answer. Yes definitely it works .
Thanks it's done
I keep getting this error on running crnn_main.py.\
Traceback (most recent call last): File "crnn_main.py", line 200, in <module> cost = trainBatch(crnn, criterion, optimizer) File "crnn_main.py", line 183, in trainBatch preds = crnn(image) File "/home/ubuntu/anaconda/lib/python2.7/site-packages/torch/nn/modules/module.py", line 206, in __call__ result = self.forward(*input, **kwargs) File "/home/ubuntu/crnn.pytorch/models/crnn.py", line 80, in forward assert h == 1, "the height of conv must be 1" AssertionError: the height of conv must be 1