GabrielDornelles / pytorch-ocr

Simple Pytorch framework to train OCRs. Supports CRNNs, Attention, CTC and Cross Entropy Loss.
MIT License
70 stars 16 forks source link

`TypeError: 'numpy._DTypeMeta' object is not subscriptable` during training #5

Closed goodwin64 closed 10 months ago

goodwin64 commented 10 months ago

Heyyy there! Thanks for this repo, I'm studying the Pytorch atm and found your repo from the search. I faced some issue during training process, would love the feedback on what might be the cause of it.

I'm using the:

I installed dependencies using pip install -r requirements.txt

The error I get looks like to be from cv2:

maxdonchenko@maxdonchenko pytorch-ocr % python train.py                
Traceback (most recent call last):
  File "/Users/maxdonchenko/pytorch-ocr/train.py", line 16, in <module>
    from utils.data_loading import build_dataloaders
  File "/Users/maxdonchenko/pytorch-ocr/utils/data_loading.py", line 1, in <module>
    import albumentations
  File "/Users/maxdonchenko/.pyenv/versions/3.10.12/lib/python3.10/site-packages/albumentations/__init__.py", line 5, in <module>
    from .augmentations import *
  File "/Users/maxdonchenko/.pyenv/versions/3.10.12/lib/python3.10/site-packages/albumentations/augmentations/__init__.py", line 2, in <module>
    from .crops.functional import *
  File "/Users/maxdonchenko/.pyenv/versions/3.10.12/lib/python3.10/site-packages/albumentations/augmentations/crops/__init__.py", line 1, in <module>
    from .functional import *
  File "/Users/maxdonchenko/.pyenv/versions/3.10.12/lib/python3.10/site-packages/albumentations/augmentations/crops/functional.py", line 4, in <module>
    import cv2
  File "/Users/maxdonchenko/.pyenv/versions/3.10.12/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/Users/maxdonchenko/.pyenv/versions/3.10.12/lib/python3.10/site-packages/cv2/__init__.py", line 175, in bootstrap
    if __load_extra_py_code_for_module("cv2", submodule, DEBUG):
  File "/Users/maxdonchenko/.pyenv/versions/3.10.12/lib/python3.10/site-packages/cv2/__init__.py", line 28, in __load_extra_py_code_for_module
    py_module = importlib.import_module(module_name)
  File "/Users/maxdonchenko/.pyenv/versions/3.10.12/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/Users/maxdonchenko/.pyenv/versions/3.10.12/lib/python3.10/site-packages/cv2/typing/__init__.py", line 69, in <module>
    NumPyArrayGeneric = numpy.ndarray[typing.Any, numpy.dtype[numpy.generic]]
TypeError: 'numpy._DTypeMeta' object is not subscriptable

any ideas on it?

goodwin64 commented 10 months ago

Ah, according to this suggestion, I installed numpy 1.23.0, and it worked! I'm creating a PR with a fix in a moment.

GabrielDornelles commented 10 months ago

Im on the beach right now so I cant test the versions, hopefully updating numpy to this version wont create compatility problems with torch or something, if it does ill take a look in a few days. I'm glad you found the repo useful! Ill approve the pr.

goodwin64 commented 10 months ago

I just checked - I have some other issues:

Dataset number of classes: 27
Classes are: ['0' '1' '2' '3' '4' '5' '6' '7' '8' '9' 'a' 'c' 'd' 'e' 'g' 'h' 'k' 'n'
 'o' 'p' 'q' 's' 'u' 'v' 'x' 'y' 'z']
Error executing job with overrides: []
Traceback (most recent call last):
  File "/Users/maxdonchenko/pytorch-ocr/train.py", line 48, in run_training
    ).to(device)
  File "/Users/maxdonchenko/.pyenv/versions/3.10.12/lib/python3.10/site-packages/torch/nn/modules/module.py", line 927, in to
    return self._apply(convert)
  File "/Users/maxdonchenko/.pyenv/versions/3.10.12/lib/python3.10/site-packages/torch/nn/modules/module.py", line 579, in _apply
    module._apply(fn)
  File "/Users/maxdonchenko/.pyenv/versions/3.10.12/lib/python3.10/site-packages/torch/nn/modules/module.py", line 579, in _apply
    module._apply(fn)
  File "/Users/maxdonchenko/.pyenv/versions/3.10.12/lib/python3.10/site-packages/torch/nn/modules/module.py", line 602, in _apply
    param_applied = fn(param)
  File "/Users/maxdonchenko/.pyenv/versions/3.10.12/lib/python3.10/site-packages/torch/nn/modules/module.py", line 925, in convert
    return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)
  File "/Users/maxdonchenko/.pyenv/versions/3.10.12/lib/python3.10/site-packages/torch/cuda/__init__.py", line 211, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.

also, I checked that CUDA is some NVIDIA thing for pytorch. Just to double-check - can I run the model in this repo on MacOS or it's compatible only with Windows?

GabrielDornelles commented 10 months ago

the repo should run just fine in any OS. Cuda is the gpu driver for nvidia gpus, pytorch needs to be installed with cuda (Automatic if you already have an nvidia cuda driver), otherwise it installs cpu only version. To check whether you have the driver, run the command nvidia-smi

it displays info about the gpu, on the top It - shows the cuda driver version. You need to install those drivers for your gpu in any OS, then it should work just fine.

GabrielDornelles commented 10 months ago

if using cpu (not recommended, training will take forever), then you can change on config file the device to cpu

goodwin64 commented 10 months ago

Got it! Brilliant, thanks for the explanation!

I've tried setting cpu in the config file but indeed it takes ages. Closing this issue as solved, thank you!