opendatalab / DocLayout-YOLO

DocLayout-YOLO: Enhancing Document Layout Analysis through Diverse Synthetic Data and Global-to-Local Adaptive Perception
https://huggingface.co/spaces/opendatalab/DocLayout-YOLO
GNU Affero General Public License v3.0
516 stars 36 forks source link

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

Closed Puer-Hyun closed 2 weeks ago

Puer-Hyun commented 2 weeks ago

Hi. Thanks for developing such a good model. Inspired by your model, I'm trying to train a CustomDataset using DocLayout-YOLO, but I'm getting the following error.

ckpt = torch.load(file, map_location="cpu") YOLOv10m-doclayout summary (fused): 465 layers, 19931224 parameters, 0 gradients Traceback (most recent call last): File "/data/DocLayout-YOLO/train.py", line 64, in <module> results = model.train( File "/data/DocLayout-YOLO/doclayout_yolo/engine/model.py", line 660, in train self.trainer.train() File "/data/DocLayout-YOLO/doclayout_yolo/engine/trainer.py", line 214, in train self._do_train(world_size) File "/data/DocLayout-YOLO/doclayout_yolo/engine/trainer.py", line 473, in _do_train self.final_eval() File "/data/DocLayout-YOLO/doclayout_yolo/engine/trainer.py", line 630, in final_eval self.metrics = self.validator(model=f) File "/data/DocLayout-YOLO/doclayout_yolo/engine/validator.py", line 170, in __call__ model.warmup(imgsz=(1 if pt else self.args.batch, 3, imgsz, imgsz)) # warmup File "/data/DocLayout-YOLO/doclayout_yolo/nn/autobackend.py", line 586, in warmup self.forward(im) # warmup File "/data/DocLayout-YOLO/doclayout_yolo/nn/autobackend.py", line 420, in forward y = self.model(im, augment=augment, visualize=visualize, embed=embed) File "/data/DocLayout-YOLO/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/data/DocLayout-YOLO/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl return forward_call(*args, **kwargs) File "/data/DocLayout-YOLO/doclayout_yolo/nn/tasks.py", line 96, in forward return self.predict(x, *args, **kwargs) File "/data/DocLayout-YOLO/doclayout_yolo/nn/tasks.py", line 114, in predict return self._predict_once(x, profile, visualize, embed) File "/data/DocLayout-YOLO/doclayout_yolo/nn/tasks.py", line 136, in _predict_once x = m(x) # run File "/data/DocLayout-YOLO/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/data/DocLayout-YOLO/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl return forward_call(*args, **kwargs) File "/data/DocLayout-YOLO/doclayout_yolo/nn/modules/g2l_crm.py", line 114, in forward y.append(m(y[-1])) File "/data/DocLayout-YOLO/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/data/DocLayout-YOLO/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl return forward_call(*args, **kwargs) File "/data/DocLayout-YOLO/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 "/data/DocLayout-YOLO/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/data/DocLayout-YOLO/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl return forward_call(*args, **kwargs) File "/data/DocLayout-YOLO/doclayout_yolo/nn/modules/g2l_crm.py", line 43, in forward dx = [self.dilated_conv(x, d) for d in self.dilation] File "/data/DocLayout-YOLO/doclayout_yolo/nn/modules/g2l_crm.py", line 43, in <listcomp> dx = [self.dilated_conv(x, d) for d in self.dilation] File "/data/DocLayout-YOLO/doclayout_yolo/nn/modules/g2l_crm.py", line 36, in dilated_conv bn = self.dcv.bn File "/data/DocLayout-YOLO/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1931, in __getattr__ raise AttributeError( AttributeError: 'Conv' object has no attribute 'bn'

Train works fine, but I get an error during Validation or Test Step? The model was saved correctly.

I created the /data/synthetic-test-data.yaml file under the ROOT folder as follows.

`path: /data/DocLayout-YOLO/layout_data/synthetic-test-data train: images val: images test: images

nc: 12 names: ['class 1', 'class 2'...... 'class12'] download: false`

This seems to be an issue with the choice of DilatedBottleneck or CIB, but how do I fix it?

Again, thanks for the great model and inspiration. I would really appreciate it if you would take your time with your answers. Have a nice day

Puer-Hyun commented 2 weeks ago

def dilated_conv(self, x, dilation): act = getattr(self.dcv, 'act', nn.Identity()) bn = getattr(self.dcv, 'bn', nn.Identity()) weight = self.dcv.conv.weight padding = dilation * (self.k//2) return act(bn(F.conv2d(x, weight, stride=1, padding=padding, dilation=dilation)))

Once I made this change, the learning went back to normal, and the validation and testing went smoothly. I don't know how much the change to nn.Identity() will affect the learning, but I thought I should share it.

Puer-Hyun commented 2 weeks ago

I see this was already in someone else's PR request. Thanks.