JaidedAI / EasyOCR

Ready-to-use OCR with 80+ supported languages and all popular writing scripts including Latin, Chinese, Arabic, Devanagari, Cyrillic and etc.
https://www.jaided.ai
Apache License 2.0
23.61k stars 3.1k forks source link

ImportError: cannot import name 'validation' from 'test' (/usr/lib/python3.7/test/__init__.py) #858

Open SardarArslan opened 1 year ago

SardarArslan commented 1 year ago

import os import torch.backends.cudnn as cudnn import yaml from train import train from utils import AttrDict import pandas as pd

4th line gives this error, kindly help me to remove this error.

SardarArslan commented 1 year ago

ImportError Traceback (most recent call last) in 3 import yaml 4 #from test import validation ----> 5 from train import train 6 from utils import AttrDict 7 import pandas as pd

/content/EasyOCR/trainer/train.py in 15 from dataset import hierarchical_dataset, AlignCollate, Batch_Balanced_Dataset 16 from model import Model ---> 17 from test import validation 18 device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') 19

ImportError: cannot import name 'validation' from 'test' (/usr/lib/python3.7/test/init.py)

This is the full error

ftmasadi commented 1 year ago

ImportError Traceback (most recent call last) in 3 import yaml 4 #from test import validation ----> 5 from train import train 6 from utils import AttrDict 7 import pandas as pd

/content/EasyOCR/trainer/train.py in 15 from dataset import hierarchical_dataset, AlignCollate, Batch_Balanced_Dataset 16 from model import Model ---> 17 from test import validation 18 device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') 19

ImportError: cannot import name 'validation' from 'test' (/usr/lib/python3.7/test/init.py)

This is the full error can you find answer for this error?

huynhkhoa44 commented 1 year ago

Does anyone have solution for this error ?

SardarArslan commented 1 year ago

Yes. Copy the train and test function in your code and comment this line. It'll work.

On Sat, Oct 22, 2022, 10:23 huynhkhoa44 @.***> wrote:

Does anyone have solution for this error ?

— Reply to this email directly, view it on GitHub https://github.com/JaidedAI/EasyOCR/issues/858#issuecomment-1287635348, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATYE26CG4SWUC5VUAUUX2E3WEN26VANCNFSM6AAAAAAQQFERX4 . You are receiving this because you authored the thread.Message ID: @.***>

huynhkhoa44 commented 1 year ago

Can you describe more clearly, I don't really understand :(((

SardarArslan commented 1 year ago

In the trainer directory, you'll find test.py and train.py. Just copy paste the entire code above the train(opt, amp=False) line. Comment out the import validation from test line with #, run the above two functions and then call train as mentioned, in the order i wrote. It'll work. I use colab I ran the test and train in separate cells and then called the train function.

On Mon, Oct 24, 2022, 11:54 huynhkhoa44 @.***> wrote:

Can you describe more clearly, I don't really understand :(((

— Reply to this email directly, view it on GitHub https://github.com/JaidedAI/EasyOCR/issues/858#issuecomment-1288504381, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATYE26HY5YKF7CP3ACRYIBDWEYXBHANCNFSM6AAAAAAQQFERX4 . You are receiving this because you authored the thread.Message ID: @.***>

Abhilash1902 commented 1 year ago

Can you show me a pic or snap how you are suggesting to do so

SardarArslan commented 1 year ago

Can you show me a pic or snap how you are suggesting to do so

Kindly check it out.

SardarArslan commented 1 year ago

Here's the colab link, it has another error, which I don't remeber how I resolved but check it out, it also has the inference code : https://drive.google.com/file/d/1Culfo69gTH0m10C5tvn2rPTow_FH1Jd6/view?usp=sharing

amir2628 commented 1 year ago

ImportError Traceback (most recent call last) in 3 import yaml 4 #from test import validation ----> 5 from train import train 6 from utils import AttrDict 7 import pandas as pd

/content/EasyOCR/trainer/train.py in 15 from dataset import hierarchical_dataset, AlignCollate, Batch_Balanced_Dataset 16 from model import Model ---> 17 from test import validation 18 device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') 19

ImportError: cannot import name 'validation' from 'test' (/usr/lib/python3.7/test/**init**.py)

This is the full error

The reason is that test is being called from another module (/usr/lib/python3.7/test/init.py) You can just rename the test.py in the trainer folder to mytest.py (or something else), and in the train.py replace the: from test import validation to from mytest import validation

Melanee-Melanee commented 1 month ago

Copy "validation" functoin from test.py ( /content/EasyOCR/trainer/test.py) to train.py ( /content/EasyOCR/trainer/train.py) and then comment out from test import validation from train.py. Please do not forget to import necessarily modulus from test.py. Finally restart your session if you are working on Google Colab.