doctr icon indicating copy to clipboard operation
doctr copied to clipboard

Error on np.ndarray transpose method

Open dvivarelli opened this issue 2 years ago • 4 comments

Bug description

when i put assume_straight_pages = False i receive an error. The error seems to be in dotr/models/_utils.py extract_rcrops cv2.warpAffine( img if channels_last else img.transpose(1, 2, 0), <-- on this line # Transformation matrix cv2.getAffineTransform(src_pts[idx], dst_pts[idx]), (int(d1[idx]), int(d2[idx])), )

Code snippet to reproduce the bug

model = ocr_predictor(det_arch='db_resnet50_rotation', reco_arch='crnn_vgg16_bn', assume_straight_pages=False, preserve_aspect_ratio=True, pretrained=True)

Error traceback

Exception calling application: transpose() received an invalid combination of arguments - got (int, int, int), but expected one of:

  • (int dim0, int dim1)
  • (name dim0, name dim1) Traceback (most recent call last): File "C:\Users\david\AppData\Local\Programs\Python\Python38\lib\site-packages\grpc_server.py", line 443, in _call_behavior response_or_iterator = behavior(argument, context) File ".\src\grpc_server.py", line 24, in extractText text, confidence = service.extractText(img) File "D:\Detection\application\ocr-api\src\service.py", line 18, in extractText result = model([img]) File "C:\Users\david\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl return forward_call(*input, **kwargs) File "C:\Users\david\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context return func(*args, **kwargs) File "C:\Users\david\AppData\Local\Programs\Python\Python38\lib\site-packages\doctr\models\predictor\pytorch.py", line 82, in forward crops, loc_preds = self._prepare_crops( File "C:\Users\david\AppData\Local\Programs\Python\Python38\lib\site-packages\doctr\models\predictor\base.py", line 74, in _prepare_crops crops = _OCRPredictor._generate_crops(pages, loc_preds, channels_last, assume_straight_pages) File "C:\Users\david\AppData\Local\Programs\Python\Python38\lib\site-packages\doctr\models\predictor\base.py", line 60, in _generate_crops crops = [ File "C:\Users\david\AppData\Local\Programs\Python\Python38\lib\site-packages\doctr\models\predictor\base.py", line 61, in extraction_fn(page, _boxes[:, :4], channels_last=channels_last) # type: ignore[operator] File "C:\Users\david\AppData\Local\Programs\Python\Python38\lib\site-packages\doctr\models_utils.py", line 86, in extract_rcrops crops = [ File "C:\Users\david\AppData\Local\Programs\Python\Python38\lib\site-packages\doctr\models_utils.py", line 88, in img if channels_last else img.transpose(1, 2, 0), TypeError: transpose() received an invalid combination of arguments - got (int, int, int), but expected one of:
  • (int dim0, int dim1)
  • (name dim0, name dim1)

Environment

DocTR version: 1.9.0 TensorFlow version: N/A PyTorch version: 1.11.0+cpu (torchvision 0.10.1+cpu) OpenCV version: 4.5.3 OS: Microsoft Windows 10 Home Python version: 3.8.10 Is CUDA available (TensorFlow): N/A Is CUDA available (PyTorch): No CUDA runtime version: 11.2.67 GPU models and configuration: Could not collect Nvidia driver version: Could not collect cuDNN version: Could not collect

Deep Learning backend

Python 3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

from doctr.file_utils import is_tf_available, is_torch_available

print(f"is_tf_available: {is_tf_available()}") is_tf_available: False print(f"is_torch_available: {is_torch_available()}") is_torch_available: True

dvivarelli avatar Apr 04 '22 08:04 dvivarelli

it works if chage the line in this way: img if channels_last else img.transpose(0, 2).transpose(0, 1).numpy()

dvivarelli avatar Apr 08 '22 11:04 dvivarelli

Hi @dvivarelli, I can't reproduce the bug locally when running

model = ocr_predictor(
      det_arch='db_resnet50_rotation',
      reco_arch='crnn_vgg16_bn',
      assume_straight_pages=False,
      preserve_aspect_ratio=True,
      pretrained=True
)

on different images. Can you attach the image on which it doesn't work to this issue ? Otherwise, if it doesn't come from an edge-case image it may come from the environment (openCV version, etc...)

charlesmindee avatar Apr 13 '22 12:04 charlesmindee

Hi @dvivarelli, any updates ?

charlesmindee avatar Apr 28 '22 08:04 charlesmindee

Hello @dvivarelli :wave: Would you mind providing a bit more information so that we can figure this out please? :pray:

frgfm avatar Jun 28 '22 15:06 frgfm

Hi @dvivarelli can we close this ? Or does the problem still exists ? :)

felixdittrich92 avatar Sep 03 '22 17:09 felixdittrich92

no response and cannot be reproduced - close

felixdittrich92 avatar Sep 07 '22 11:09 felixdittrich92