ultralytics/yolov3

Making changes to yolov3.yaml & understanding it

sabitatasnim opened this issue ยท 3 comments

Search before asking

Question

I am experimenting with the yolov3 architecture to customize it for some custom hardware platform. To do this, I have been making some changes to the yaml file by adding layers such as convolutions, bottlenecks and upsampling. However, I am running into tensor mismatch problems. It is very possible that I am misunderstanding the conversion from the original .cfg file from a few revisions ago to the now present yaml files. Can someone explain how these yaml files work ?

The following shows the errors I am currently running into:

                 from  n    params  module                                  arguments                     
  0                -1  1       928  models.common.Conv                      [3, 32, 3, 1]                 
  1                -1  1     18560  models.common.Conv                      [32, 64, 3, 2]                
  2                -1  1     20672  models.common.Bottleneck                [64, 64]                      
  3                -1  1     73984  models.common.Conv                      [64, 128, 3, 2]               
  4                -1  2    164608  models.common.Bottleneck                [128, 128]                    
  5                -1  1    295424  models.common.Conv                      [128, 256, 3, 2]              
  6                -1  8   2627584  models.common.Bottleneck                [256, 256]                    
  7                -1  1   1180672  models.common.Conv                      [256, 512, 3, 2]              
  8                -1  8  10498048  models.common.Bottleneck                [512, 512]                    
  9                -1  1   4720640  models.common.Conv                      [512, 1024, 3, 2]             
 10                -1  4  20983808  models.common.Bottleneck                [1024, 1024]                  
 11                -1  1   5245952  models.common.Bottleneck                [1024, 1024, False]           
 12                -1  1    525312  models.common.Conv                      [1024, 512, 1, 1]             
 13                -1  1   4720640  models.common.Conv                      [512, 1024, 3, 1]             
 14                -1  1    525312  models.common.Conv                      [1024, 512, 1, 1]             
 15                -1  1   4720640  models.common.Conv                      [512, 1024, 3, 1]             
 16                -2  1    131584  models.common.Conv                      [512, 256, 1, 1]              
 17                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 18           [-1, 8]  1         0  models.common.Concat                    [1]                           
 19                -1  1   1377792  models.common.Bottleneck                [768, 512, False]             
 20                -1  1   1312256  models.common.Bottleneck                [512, 512, False]             
 21                -1  1    131584  models.common.Conv                      [512, 256, 1, 1]              
 22                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 23           [-1, 8]  1         0  models.common.Concat                    [1]                           
 24                -1  1   3539968  models.common.Conv                      [768, 512, 3, 1]              
 25                -2  1     98560  models.common.Conv                      [768, 128, 1, 1]              
 26                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 27           [-1, 6]  1         0  models.common.Concat                    [1]                           
 28                -1  1    344832  models.common.Bottleneck                [384, 256, False]             
 29                -1  2    656896  models.common.Bottleneck                [256, 256, False]             
 30      [27, 22, 15]  1    425085  models.yolo.Detect                      [80, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [384, 256, 1024]]
Traceback (most recent call last):
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/train.py", line 635, in <module>
    main(opt)
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/train.py", line 528, in main
    train(opt.hyp, opt, device, callbacks)
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/train.py", line 124, in train
    model = Model(cfg or ckpt['model'].yaml, ch=3, nc=nc, anchors=hyp.get('anchors')).to(device)  # create
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/models/yolo.py", line 194, in __init__
    m.stride = torch.tensor([s / x.shape[-2] for x in forward(torch.zeros(1, ch, s, s))])  # forward
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/models/yolo.py", line 193, in <lambda>
    forward = lambda x: self.forward(x)[0] if isinstance(m, Segment) else self.forward(x)
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/models/yolo.py", line 208, in forward
    return self._forward_once(x, profile, visualize)  # single-scale inference, train
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/models/yolo.py", line 120, in _forward_once
    x = m(x)  # run
  File "/home/user/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/models/common.py", line 313, in forward
    return torch.cat(x, self.d)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 32 but got size 16 for tensor number 1 in the list.
Traceback (most recent call last):
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/train.py", line 635, in <module>
    main(opt)
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/train.py", line 528, in main
    train(opt.hyp, opt, device, callbacks)
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/train.py", line 124, in train
    model = Model(cfg or ckpt['model'].yaml, ch=3, nc=nc, anchors=hyp.get('anchors')).to(device)  # create
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/models/yolo.py", line 194, in __init__
    m.stride = torch.tensor([s / x.shape[-2] for x in forward(torch.zeros(1, ch, s, s))])  # forward
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/models/yolo.py", line 193, in <lambda>
    forward = lambda x: self.forward(x)[0] if isinstance(m, Segment) else self.forward(x)
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/models/yolo.py", line 208, in forward
    return self._forward_once(x, profile, visualize)  # single-scale inference, train
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/models/yolo.py", line 120, in _forward_once
    x = m(x)  # run
  File "/home/user/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/user/Documents/dir1/dir2/ultralytics/yolov3/models/common.py", line 313, in forward
    return torch.cat(x, self.d)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 32 but got size 16 for tensor number 1 in the list.

The following screenshot shows the changes I made to yolov3.yaml on lines 42 and 43:
Screenshot from 2023-03-01 01-23-16

Additional

No response

๐Ÿ‘‹ Hello @sabitatasnim, thank you for your interest in YOLOv3 ๐Ÿš€! Please visit our โญ๏ธ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a ๐Ÿ› Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training โ“ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv3 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

YOLOv3 CI

If this badge is green, all YOLOv3 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv3 training, validation, inference, export and benchmarks on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

Introducing YOLOv8 ๐Ÿš€

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 ๐Ÿš€!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics

๐Ÿ‘‹ Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv3 ๐Ÿš€ resources:

Access additional Ultralytics โšก resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv3 ๐Ÿš€ and Vision AI โญ!

@sabitatasnim hi there,

It looks like there may be a mismatch of tensor sizes with the changes you've made to the yolov3.yaml file. Without seeing the specific changes you made to the file, it's a bit difficult to provide a definitive solution.

One potential approach to debugging this issue would be to carefully review the changes made on lines 42 and 43 in the yolov3.yaml file to ensure that the tensor sizes are consistent with the rest of the network architecture.

If you're still encountering issues, I would recommend consulting the YOLO community or the Ultralytics team for further assistance with customizing the YOLOv3 architecture for your hardware platform.

Hope this helps!