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

AttributeError: 'Conv' object has no attribute 'bn' #68

Closed
cvhrnkmp opened this issue Dec 10, 2024 · 2 comments
Closed

AttributeError: 'Conv' object has no attribute 'bn' #68

cvhrnkmp opened this issue Dec 10, 2024 · 2 comments

Comments

@cvhrnkmp
Copy link

Hello,

I got the following error, if I train the model on custom dataset with the following command:

Command:

python train.py --data Dataset --model m-doclayout --epoch 5 --image-size 1600 --project first_shot --device cpu

Error:

OLOv10m-doclayout summary (fused): 465 layers, 19924276 parameters, 0 gradients
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95):   0%|          | 0/1 [00:00<?
Traceback (most recent call last):
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\train.py", line 63, in <module>
    results = model.train(
              ^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\engine\model.py", line 660, in train
    self.trainer.train()
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\engine\trainer.py", line 214, in train
    self._do_train(world_size)
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\engine\trainer.py", line 473, in _do_train
    self.final_eval()
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\engine\trainer.py", line 630, in final_eval
    self.metrics = self.validator(model=f)
                   ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\engine\validator.py", line 192, in __call__
    preds = model(batch["img"], augment=augment)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\AppData\Roaming\Python\Python311\site-packages\torch\nn\modules\module.py", line 1736, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\AppData\Roaming\Python\Python311\site-packages\torch\nn\modules\module.py", line 1747, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\nn\autobackend.py", line 420, in forward
    y = self.model(im, augment=augment, visualize=visualize, embed=embed)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\AppData\Roaming\Python\Python311\site-packages\torch\nn\modules\module.py", line 1736, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\AppData\Roaming\Python\Python311\site-packages\torch\nn\modules\module.py", line 1747, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\nn\tasks.py", line 96, in forward
    return self.predict(x, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\nn\tasks.py", line 114, in predict
    return self._predict_once(x, profile, visualize, embed)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\nn\tasks.py", line 136, in _predict_once
    x = m(x)  # run
        ^^^^
  File "C:\Users\Programming\AppData\Roaming\Python\Python311\site-packages\torch\nn\modules\module.py", line 1736, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\AppData\Roaming\Python\Python311\site-packages\torch\nn\modules\module.py", line 1747, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\nn\modules\g2l_crm.py", line 114, in forward
    y.append(m(y[-1]))
             ^^^^^^^^
  File "C:\Users\Programming\AppData\Roaming\Python\Python311\site-packages\torch\nn\modules\module.py", line 1736, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\AppData\Roaming\Python\Python311\site-packages\torch\nn\modules\module.py", line 1747, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\nn\modules\g2l_crm.py", line 77, in forward
    return x + self.cv2(self.dilated_block(self.cv1(x))) if self.add else self.cv2(self.dilated_block(self.cv1(x)))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\AppData\Roaming\Python\Python311\site-packages\torch\nn\modules\module.py", line 1736, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\AppData\Roaming\Python\Python311\site-packages\torch\nn\modules\module.py", line 1747, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\nn\modules\g2l_crm.py", line 43, in forward
    dx = [self.dilated_conv(x, d) for d in self.dilation]
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\nn\modules\g2l_crm.py", line 43, in <listcomp>
    dx = [self.dilated_conv(x, d) for d in self.dilation]
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\nn\modules\g2l_crm.py", line 36, in dilated_conv
    bn = self.dcv.bn
         ^^^^^^^^^^^
  File "C:\Users\Programming\AppData\Roaming\Python\Python311\site-packages\torch\nn\modules\module.py", line 1931, in __getattr__
    raise AttributeError(
AttributeError: 'Conv' object has no attribute 'bn'

What is the cause of the issue?

Thanks in forward, best regards
Christian

Appendix

The folder structure is:

./DocLayout-YOLO-main
├── layout_data
│   ├── Dataset
│        ├── images
│        ├── labels
│        ├── val.txt
│        ├── text.txt
│        └── train.txt
├── doclayout_yolo
│   └── cfg
│         └── Dataset.yaml
└── train.py

Dataset.yaml:

# Ultralytics YOLO 🚀, AGPL-3.0 license
# COCO 2017 dataset https://cocodataset.org by Microsoft
# Documentation: https://docs.doclayout_yolo.com/datasets/detect/coco/
# Example usage: yolo train data=coco.yaml
# parent
# ├── doclayout_yolo
# └── datasets
#     └── coco  ← downloads here (20.1 GB)

# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ./Dataset  # dataset root dir
train: C:\Users\Programming\Documents\DocLayout-YOLO-main\layout_data\Dataset\train.txt
val: C:\Users\Programming\Documents\DocLayout-YOLO-main\layout_data\Dataset\val.txt
test: C:\Users\Programming\Documents\DocLayout-YOLO-main\layout_data\Dataset\test.txt 

# Classes
names:
    0: 'figure'
    1: 'paragraph'
    2: 'section title'
    3: 'sub section title'
    4: 'subsub section title'
    5: 'table'

train.txt, test.txt, val.txt are with absolute path, like the following example:

C:\Users\Programming\Documents\DocLayout-YOLO-main\layout_data\Dataset\images\37b4ef0c-page_4.png
C:\Users\Programming\Documents\DocLayout-YOLO-main\layout_data\Dataset\images\a73b6a5e-page_3.png
C:\Users\Programming\Documents\DocLayout-YOLO-main\layout_data\Dataset\images\d7531bec-page_5.png

The settings.yaml in Ultraytics is set as follows:

settings_version: 0.0.4
datasets_dir: C:\Users\Programming\Documents\DocLayout-YOLO-main\layout_data
weights_dir: <Path_to_weights>\weights
runs_dir: <Path_to_runs>\runs
uuid: 4ba298c8490b48eee0c6ce4e5fcc68f485c9ae144b377321d03ec0fcd42d63dc
sync: true
api_key: ''
openai_api_key: ''
clearml: true
comet: true
dvc: true
hub: true
mlflow: true
neptune: true
raytune: true
tensorboard: true
wandb: true
@JulioZhao97
Copy link
Collaborator

JulioZhao97 commented Dec 11, 2024

@cvhrnkmp Hello!
This is a known issue in #35:
In the evaluation of final epoch, the evaluation will fail, but the evaluation during middle epochs can perform well, and you can evaluate the metrics of best.pt using val.py using command in https://github.com/opendatalab/DocLayout-YOLO?tab=readme-ov-file#training-and-evaluation, which will give the same results

Meanwhile, the --epoch 5 seems a relative short training period, we follow original yolo setting train for 500 epochs and stop when no better performance on validation set is observed.

@JulioZhao97
Copy link
Collaborator

close due to no further response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants