Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: (InvalidArgument) x dim number should greater than 0, but received value is: 0 [Hint: Expected x_dim > 0, but received x_dim:0 <= 0:0.] #11261

Open
danghoangnhan opened this issue Nov 15, 2023 · 16 comments
Assignees
Labels
bug Something isn't working

Comments

@danghoangnhan
Copy link

danghoangnhan commented Nov 15, 2023

请提供下述完整信息以便快速定位问题/Please provide the following information to quickly locate the problem

  • 系统环境/System Environment:
    • ubuntu 22.04
    • cuda:11.8
  • 版本号/Version:2.7:Paddle: PaddleOCR:
  • 问题相关组件/Related components:
    aiohttp==3.8.6
    aiosignal==1.3.1
    annotated-types==0.6.0
    anyio==3.7.1
    astor==0.8.1
    async-timeout==4.0.3
    attrdict==2.0.1
    attrs==23.1.0
    Babel==2.13.1
    bce-python-sdk==0.8.96
    blinker==1.7.0
    cachetools==5.3.2
    certifi==2023.7.22
    charset-normalizer==3.3.2
    click==8.1.7
    colorama==0.4.6
    colorlog==6.7.0
    contourpy==1.1.1
    cssselect==1.2.0
    cssutils==2.9.0
    cycler==0.12.1
    Cython==3.0.5
    datasets==2.14.7
    decorator==5.1.1
    dill==0.3.4
    et-xmlfile==1.1.0
    exceptiongroup==1.1.3
    fastapi==0.104.1
    filelock==3.13.1
    flask==3.0.0
    Flask-Babel==2.0.0
    fonttools==4.44.0
    frozenlist==1.4.0
    fsspec==2023.10.0
    future==0.18.3
    h11==0.14.0
    httpcore==1.0.2
    httpx==0.25.1
    huggingface-hub==0.19.3
    idna==3.4
    imageio==2.32.0
    imgaug==0.4.0
    importlib-metadata==6.8.0
    importlib-resources==6.1.1
    itsdangerous==2.1.2
    jieba==0.42.1
    Jinja==23.1.2
    joblib==1.3.2
    kiwisolver==1.4.5
    lazy-loader==0.3
    lmdb==1.4.1
    lxml==4.9.3
    markdown-it-py==3.0.0
    MarkupSafe==2.1.3
    matplotlib==3.7.3
    mdurl==0.1.2
    multidict==6.0.4
    multiprocess==0.70.12.2
    networkx==3.1
    numpy==1.24.4
    onnx==1.15.0
    opencv-contrib-python==4.6.0.66
    opencv-python==4.6.0.66
    openpyxl==3.1.2
    opt-einsum==3.3.0
    packaging==23.2
    paddle2onnx==1.1.0
    paddlefsl==1.1.0
    paddlenlp==2.5.2
    paddlepaddle-gpu==2.5.2
    pandas==2.0.3
    Pillow==10.1.0
    pip==20.0.2
    pkg-resources==0.0.0
    premailer==3.10.0
    protobuf==3.20.2
    psutil==5.9.6
    pyarrow==14.0.1
    pyarrow-hotfix==0.5
    pyclipper==1.3.0.post5
    pycryptodome==3.19.0
    pydantic==2.5.1
    pydantic-core==2.14.3
    Pygments==2.16.1
    PyMuPDF==1.20.2
    pypandoc==1.12
    pyparsing==3.1.1
    python-dateutil==2.8.2
    python-docx==1.1.0
    pytz==2023.3.post1
    PyWavelets==1.4.1
    PyYAML==6.0.1
    rapidfuzz==3.5.2
    rarfile==4.1
    requests==2.31.0
    rich==13.7.0
    safetensors==0.4.0
    scikit-image==0.21.0
    scikit-learn==1.3.2
    scipy==1.10.1
    sentencepiece==0.1.99
    seqeval==1.2.2
    setuptools==44.0.0
    shapely==2.0.2
    six==1.16.0
    sniffio==1.3.0
    starlette==0.27.0
    threadpoolctl==3.2.0
    tifffile==2023.7.10
    tqdm==4.66.1
    typer==0.9.0
    typing-extensions==4.8.0
    tzdata==2023.3
    urllib==32.1.0
    uvicorn==0.24.0.post1
    visualdl==2.5.3
    werkzeug==3.0.1
    wheel==0.34.2
    xxhash==3.4.1
    yacs==0.1.8
    yarl==1.9.2
    zipp==3.17.0
  • 运行指令/Command Code:
  python3 ./tools/infer_kie_token_ser_re.py \
  -c configs/kie/vi_layoutxlm/re_vi_layoutxlm_xfund_zh.yml \
  -o Architecture.Backbone.checkpoints=./output/re_vi_layoutxlm_xfund_zh/best_accuracy/ \
  Global.infer_img=./train_data/XFUND/zh_val/image/ \
  -c_ser configs/kie/vi_layoutxlm/ser_vi_layoutxlm_xfund_zh.yml \
  -o_ser Architecture.Backbone.checkpoints=output/re_vi_layoutxlm_xfund_zh/best_accuracy/
  • 完整报错/Complete Error Message:
[2023/11/16 02:39:50] ppocr INFO: resume from ./output/re_vi_layoutxlm_xfund_zh/best_accuracy/
Traceback (most recent call last):
  File "./tools/infer_kie_token_ser_re.py", line 217, in <module>
    result = ser_re_engine(data)
  File "./tools/infer_kie_token_ser_re.py", line 151, in __call__
    preds = self.model(re_input)
  File "/home/daniel/PaddleOCR/venv/lib/python3.8/site-packages/paddle/nn/layer/layers.py", line 1254, in __call__
    return self.forward(*inputs, **kwargs)
  File "/home/daniel/PaddleOCR/ppocr/modeling/architectures/base_model.py", line 86, in forward
    x = self.backbone(x)
  File "/home/daniel/PaddleOCR/venv/lib/python3.8/site-packages/paddle/nn/layer/layers.py", line 1254, in __call__
    return self.forward(*inputs, **kwargs)
  File "/home/daniel/PaddleOCR/ppocr/modeling/backbones/vqa_layoutlm.py", line 227, in forward
    x = self.model(
  File "/home/daniel/PaddleOCR/venv/lib/python3.8/site-packages/paddle/nn/layer/layers.py", line 1254, in __call__
    return self.forward(*inputs, **kwargs)
  File "/home/daniel/PaddleOCR/venv/lib/python3.8/site-packages/paddlenlp/transformers/layoutxlm/modeling.py", line 1412, in forward
    loss, pred_relations = self.extractor(sequence_output, entities, relations)
  File "/home/daniel/PaddleOCR/venv/lib/python3.8/site-packages/paddle/nn/layer/layers.py", line 1254, in __call__
    return self.forward(*inputs, **kwargs)
  File "/home/daniel/PaddleOCR/venv/lib/python3.8/site-packages/paddlenlp/transformers/layoutxlm/modeling.py", line 1304, in forward
    relations, entities = self.build_relation(relations, entities)
  File "/home/daniel/PaddleOCR/venv/lib/python3.8/site-packages/paddlenlp/transformers/layoutxlm/modeling.py", line 1248, in build_relation
    all_possible_relations = paddle.stack(
  File "/home/daniel/PaddleOCR/venv/lib/python3.8/site-packages/paddle/tensor/manipulation.py", line 1842, in stack
    return _C_ops.stack(x, axis)
ValueError: (InvalidArgument) x dim number should greater than 0, but received value is: 0
  [Hint: Expected x_dim > 0, but received x_dim:0 <= 0:0.] (at ../paddle/phi/backends/gpu/gpu_launch_config.h:180)
@danghoangnhan
Copy link
Author

danghoangnhan commented Nov 17, 2023

i followed the RE instruction in kie document and got this problem

@gr8nishan
Copy link

I am also facing the same issue in some documents...

@heguyu
Copy link

heguyu commented Nov 27, 2023

also

@c-avan
Copy link

c-avan commented Dec 12, 2023

@danghoangnhan 问题解决了吗,我也遇到这样的类似错了
ValueError: (InvalidArgument) x dim number should greater than 0, but received value is: 0
[Hint: Expected x_dim > 0, but received x_dim:0 <= 0:0.] (at ../paddle/phi/backends/gpu/gpu_launch_config.h:175)

@Joheun-Kang
Copy link

Got the same error, do we have any update on this issue?

@XiYuan68
Copy link

XiYuan68 commented Feb 2, 2024

same error when training RE models

@XiYuan68
Copy link

XiYuan68 commented Feb 21, 2024

same error when training RE models

kv_relations = []
for rel in relations:
pair = [id2label[rel[0]], id2label[rel[1]]]
if pair == ["question", "answer"]:
kv_relations.append({
"head": entity_id_to_index_map[rel[0]],
"tail": entity_id_to_index_map[rel[1]]
})
elif pair == ["answer", "question"]:
kv_relations.append({
"head": entity_id_to_index_map[rel[1]],
"tail": entity_id_to_index_map[rel[0]]
})
else:
continue

Bug found, when building relations in dataloader, labels of entity are limited to "question" and "answer", custom dataset with other labels will be ignored and no relations built.

I modified it into:

        kv_relations = []
        for rel in relations:
            # assume labeled relations are always in the format of head-tail
            try:
                kv_relations.append({
                    "head": entity_id_to_index_map[rel[0]],
                    "tail": entity_id_to_index_map[rel[1]]
                })
            except Exception:
                pass

            # pair = [id2label[rel[0]], id2label[rel[1]]]
            # if pair == ["question", "answer"]:
            #     kv_relations.append({
            #         "head": entity_id_to_index_map[rel[0]],
            #         "tail": entity_id_to_index_map[rel[1]]
            #     })
            # elif pair == ["answer", "question"]:
            #     kv_relations.append({
            #         "head": entity_id_to_index_map[rel[1]],
            #         "tail": entity_id_to_index_map[rel[0]]
            #     })
            # else:
            #     continue
        # print('kv_relations:', kv_relations)

there is a try-except because sometimes entity_id_to_index_map[rel[1]] raises a keyerror

And still there will be (very) few invalid batches, I add a try-except in this for loop, the model starts training:

for idx, batch in enumerate(train_dataloader):

@BB86818BB
Copy link

同样的问题,训练的时候修改vqa_token_relation.py后可以了,但是预测的时候依然报错,完整的错误信息如下:

Traceback (most recent call last):
File "/home/ocr/PaddleOCR-release-2.7.1/./tools/infer_kie_token_ser_re.py", line 218, in
result = ser_re_engine(data)
File "/home/ocr/PaddleOCR-release-2.7.1/./tools/infer_kie_token_ser_re.py", line 152, in call
preds = self.model(re_input)
File "/usr/local/lib/python3.10/site-packages/paddle/nn/layer/layers.py", line 1429, in call
return self.forward(*inputs, **kwargs)
File "/home/ocr/PaddleOCR-release-2.7.1/ppocr/modeling/architectures/base_model.py", line 86, in forward
x = self.backbone(x)
File "/usr/local/lib/python3.10/site-packages/paddle/nn/layer/layers.py", line 1429, in call
return self.forward(*inputs, **kwargs)
File "/home/ocr/PaddleOCR-release-2.7.1/ppocr/modeling/backbones/vqa_layoutlm.py", line 220, in forward
x = self.model(
File "/usr/local/lib/python3.10/site-packages/paddle/nn/layer/layers.py", line 1429, in call
return self.forward(*inputs, **kwargs)
File "/usr/local/lib/python3.10/site-packages/paddlenlp/transformers/layoutxlm/modeling.py", line 1329, in forward
loss, pred_relations = self.extractor(sequence_output, entities, relations)
File "/usr/local/lib/python3.10/site-packages/paddle/nn/layer/layers.py", line 1429, in call
return self.forward(*inputs, **kwargs)
File "/usr/local/lib/python3.10/site-packages/paddlenlp/transformers/layoutxlm/modeling.py", line 1223, in forward
relations, entities = self.build_relation(relations, entities)
File "/usr/local/lib/python3.10/site-packages/paddlenlp/transformers/layoutxlm/modeling.py", line 1167, in build_relation
all_possible_relations = paddle.stack(
File "/usr/local/lib/python3.10/site-packages/paddle/tensor/manipulation.py", line 2001, in stack
return _C_ops.stack(x, axis)
ValueError: (InvalidArgument) x dim number should greater than 0, but received value is: 0
[Hint: Expected x_dim > 0, but received x_dim:0 <= 0:0.] (at ../paddle/phi/backends/gpu/gpu_launch_config.h:166)

@mxhyxym
Copy link

mxhyxym commented Mar 9, 2024

训练re模型的时候我也遇到这个问题,最后解决是通过修改数据集的label的顺序解决的。我是将question排在answer前面,就是对label排个序。我猜测是要保证linking=[[a,b]]的a需要放在b的前面。最后数据集长这样:[{id:1, linking:[[1, 2]]},{id:2, linking:[[1, 2]]}],而不能[{id:2, linking:[[1, 2]]}, {id:1, linking:[[1, 2]]}]

@Mehdi-Ben-Souda
Copy link

Is there any news , i am still struggling with this issue in the prediction .

@Royhuiy
Copy link

Royhuiy commented Jun 20, 2024

训练re模型的时候我也遇到这个问题,最后解决是通过修改数据集的label的顺序解决的。我是将question排在answer前面,就是对label排个序。我猜测是要保证linking=[[a,b]]的a需要放在b的前面。最后数据集长这样:[{id:1, linking:[[1, 2]]},{id:2, linking:[[1, 2]]}],而不能[{id:2, linking:[[1, 2]]}, {id:1, linking:[[1, 2]]}]

你好,请问方便提供带linking的1-2条数据集,我想参考一下

@GreatV GreatV added the bug Something isn't working label Jun 20, 2024
@Royhuiy
Copy link

Royhuiy commented Jun 20, 2024

@danghoangnhan 问题解决了吗,我也遇到这样的类似错了 ValueError: (InvalidArgument) x dim number should greater than 0, but received value is: 0 [Hint: Expected x_dim > 0, but received x_dim:0 <= 0:0.] (at ../paddle/phi/backends/gpu/gpu_launch_config.h:175)

你好,请问你解决这个问题了吗?

@Royhuiy
Copy link

Royhuiy commented Jun 20, 2024

i followed the RE instruction in kie document and got this problem

same error, how did you fix this?

@freezehe
Copy link

freezehe commented Aug 5, 2024

我也遇到了这个问题,请问怎么解决的?

@danghoangnhan
Copy link
Author

Hi everyone, for this problem, I used several tricks to fix the IDs:

  • The IDs must start from 1.
  • The answer ID must be greater than the question ID.
  • In the linking part, the question must be on the left side, for example, linking: [[question_id, answer_id]].

Hope it helps!

@turgutguvercin
Copy link

If you're using a custom recognition model and have updated the dictionary, the model may still use the default dictionary. To apply your changes, you need to update the dictionary directory manually.

python3 predict_kie_token_ser_re.py --kie_algorithm=LayoutXLM
--re_model_dir=../../inference/re_vi_layoutxlm_xfund_infer --ser_model_dir=../../inference/ser_vi_layoutxlm_xfund_infer
--use_visual_backbone=False --image_dir=../../iski_125.jpg
--ser_dict_path=../../train_data/XFUND/class_list_xfun.txt --vis_font_path=../../fonts/Arial.ttf
--det_model_dir=../../inference_model_det_ppocr_v4_custom--rec_char_dict_path=../../dict/custom_dict.txt
--rec_model_dir=../../inference_model_rec_ppocr_v3_custom`
--ocr_order_method="tb-yx"

--rec_char_dict_path=../../dict/custom_dict.txt this line will not work that's why the error happens change dict path manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests