bes-dev / crnn-pytorch

Pytorch implementation of OCR system using CRNN + CTCLoss
BSD 2-Clause "Simplified" License
216 stars 55 forks source link

Error when training with custom dataset: cv2.error error: (-215:Assertion failed) !ssize.empty() in function 'resize' #17

Open lqtrung-95 opened 5 years ago

lqtrung-95 commented 5 years ago

Hi I'm using the crnn-pytorch project to train a new model with my custom dataset, but when I run the command python train.py --data-path datatrain --test-init True --test-epoch 10 --output-dir snapshot --batch-size 8, it returned the error like this

python train.py --data-path datatrain --test-init True --test-epoch 10 --output-dir snapshot --batch-size 8 Test phase 0%| | 0/1 [00:00<?, ?it/s]Traceback (most recent call last): File "train.py", line 108, in main() File "/home/trungle/anaconda3/lib/python3.7/site-packages/click/core.py", line 764, in call return self.main(args, kwargs) File "/home/trungle/anaconda3/lib/python3.7/site-packages/click/core.py", line 717, in main rv = self.invoke(ctx) File "/home/trungle/anaconda3/lib/python3.7/site-packages/click/core.py", line 956, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/trungle/anaconda3/lib/python3.7/site-packages/click/core.py", line 555, in invoke return callback(args, **kwargs) File "train.py", line 67, in main acc, avg_ed = test(net, data, data.get_abc(), cuda, visualize=False) File "/home/trungle/PycharmProjects/crnn-pytorch/test.py", line 28, in test for sample in iterator: File "/home/trungle/anaconda3/lib/python3.7/site-packages/tqdm/_tqdm.py", line 979, in iter for obj in iterable: File "/home/trungle/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 637, in next return self._process_next_batch(batch) File "/home/trungle/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 658, in _process_next_batch raise batch.exc_type(batch.exc_msg) cv2.error: Traceback (most recent call last): File "/home/trungle/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop samples = collate_fn([dataset[i] for i in batch_indices]) File "/home/trungle/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in samples = collate_fn([dataset[i] for i in batch_indices]) File "/home/trungle/PycharmProjects/crnn-pytorch/dataset/text_data.py", line 37, in getitem sample = self.transform(sample) File "/home/trungle/anaconda3/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 49, in call img = t(img) File "/home/trungle/PycharmProjects/crnn-pytorch/dataset/data_transform.py", line 17, in call sample["img"] = cv2.resize(sample["img"], self.size) cv2.error: OpenCV(3.4.2) /tmp/build/80754af9/opencv-suite_1535558553474/work/modules/imgproc/src/resize.cpp:4044: error: (-215:Assertion failed) !ssize.empty() in function 'resize'

I'm pretty sure that the data and desc.json are in the right format. If anyone can help I would be very appreciated, thanks so much.

mjack3 commented 5 years ago

I have the same error right now, did you fixed?

trevorspreadbury commented 5 years ago

I was having the same issue and I seem to have solved it. After investigating my issue, this error was appearing due to the image being None. This was caused by dataset/text_data.py attempting to read path/to/dataset/image_name and not finding an image there. The image is actually located in path/to/dataset/data/image_name as described in the README. The proper path is actually commented out in line 32 in dataset/text_data.py and I'm not sure why. Is this a bug?

So the solution for me was to uncomment line 32 and comment line 33

mjack3 commented 5 years ago

The error is because the json hasnot the correct path to the images. That’s why. I solved this issue in mu computer