mindee / doctr

docTR (Document Text Recognition) - a seamless, high-performing & accessible library for OCR-related tasks powered by Deep Learning.
https://mindee.github.io/doctr/
Apache License 2.0
3.92k stars 447 forks source link

ValueError: Layer 'conv2d_9' expected 1 variables, but received 0 variables during loading. Expected: ['conv2d_9/kernel:0'] #1792

Open MuhammadShifa opened 4 days ago

MuhammadShifa commented 4 days ago

Bug description

Hello thanks for the awesome package. I am going to process a pdf document with OCR but I am facing the issue in Window Machine. I have installed the doctr, tf and pt from source via the following line.

git clone https://github.com/mindee/doctr.git
pip install -e doctr/.
# for TensorFlow
pip install -e doctr/.[tf]
# for PyTorch
pip install -e doctr/.[torch]

Code snippet to reproduce the bug

from doctr.io import DocumentFile
from doctr.models import kie_predictor

# Model
model = kie_predictor(det_arch='db_resnet50', reco_arch='crnn_vgg16_bn', pretrained=True)
# PDF
doc = DocumentFile.from_pdf("./testing_doctr_ocr.pdf")
# Analyze
result = model(doc)

predictions = result.pages[0].predictions
for class_name in predictions.keys():
    list_predictions = predictions[class_name]
    for prediction in list_predictions:
        print(f"Prediction for {class_name}: {prediction}")```

### Error traceback

Traceback (most recent call last): File "E:\OCR\ml_mo\doctr_mo\testing_doct.py", line 5, in model = kie_predictor(det_arch='db_resnet50', reco_arch='crnn_vgg16_bn', pretrained=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\OCR\ml_mo\doctr\doctr\models\zoo.py", line 228, in kie_predictor return _kie_predictor( ^^^^^^^^^^^^^^^ File "E:\OCR\ml_mo\doctr\doctr\models\zoo.py", line 146, in _kie_predictor det_predictor = detection_predictor( ^^^^^^^^^^^^^^^^^^^^ File "E:\OCR\ml_mo\doctr\doctr\models\detection\zoo.py", line 110, in detection_predictor return _predictor( ^^^^^^^^^^^ File "E:\OCR\ml_mo\doctr\doctr\models\detection\zoo.py", line 50, in _predictor _model = detection.dict[arch]( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\OCR\ml_mo\doctr\doctr\models\detection\differentiable_binarization\tensorflow.py", line 390, in db_resnet50 return _db_resnet( ^^^^^^^^^^^ File "E:\OCR\ml_mo\doctr\doctr\models\detection\differentiable_binarization\tensorflow.py", line 318, in _db_resnet load_pretrained_params( File "E:\OCR\ml_mo\doctr\doctr\models\utils\tensorflow.py", line 73, in load_pretrained_params model.load_weights(archive_path, skip_mismatch=skip_mismatch) File "C:\Users\admin\anaconda3\envs\doctr_ocr\Lib\site-packages\tf_keras\src\utils\traceback_utils.py", line 70, in error_handler raise e.with_traceback(filtered_tb) from None File "C:\Users\admin\anaconda3\envs\doctr_ocr\Lib\site-packages\tf_keras\src\engine\base_layer.py", line 3518, in load_own_variables raise ValueError( ValueError: Layer 'conv2d_9' expected 1 variables, but received 0 variables during loading. Expected: ['conv2d_9/kernel:0']



### Environment

WARNING:tensorflow:From C:\Users\admin\anaconda3\envs\doctr_ocr\Lib\site-packages\tf_keras\src\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.

WARNING:tensorflow:From C:\Users\admin\anaconda3\envs\doctr_ocr\Lib\site-packages\tf2onnx\tf_loader.py:68: The name tf.reset_default_graph is deprecated. Please use tf.compat.v1.reset_default_graph instead.

WARNING:tensorflow:From C:\Users\admin\anaconda3\envs\doctr_ocr\Lib\site-packages\tf2onnx\tf_loader.py:72: The name tf.train.import_meta_graph is deprecated. Please use tf.compat.v1.train.import_meta_graph instead.

WARNING:tensorflow:From C:\Users\admin\anaconda3\envs\doctr_ocr\Lib\site-packages\tf_keras\src\backend.py:873: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

Collecting environment information...

DocTR version: 0.10.1a0
TensorFlow version: 2.18.0
PyTorch version: 2.5.1+cpu (torchvision 0.20.1+cpu)
OpenCV version: 4.10.0
OS: Microsoft Windows 10 Pro
Python version: 3.11.10
Is CUDA available (TensorFlow): No
Is CUDA available (PyTorch): No
CUDA runtime version: 11.8.89
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
(doctr_ocr) PS E:\OCR\ml_mo\doctr\scripts>

### Deep Learning backend

is_tf_available: True
is_torch_available: True
felixdittrich92 commented 4 days ago

Hi @MuhammadShifa :wave:,

Thanks for reporting this seems to be an issue with TensorFlow on Windows machines -> https://github.com/mindee/doctr/discussions/1776

CC @odulcy-mindee Do we have a windows machine where we can try to reproduce the bug ? :sweat_smile:

With linux everything works as expected -> CI also green

MuhammadShifa commented 4 days ago

Hi @felixdittrich92 , @odulcy-mindee Yes exactly, I am using the Window Machine.

felixdittrich92 commented 4 days ago

Quickly tested also with py3.11 in a docker container without issues. So it's definitely related to Windows