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

Initialization of yolov8 #12677

Closed
1 task done
AakiraOtok opened this issue May 14, 2024 · 1 comment
Closed
1 task done

Initialization of yolov8 #12677

AakiraOtok opened this issue May 14, 2024 · 1 comment
Labels
question Further information is requested

Comments

@AakiraOtok
Copy link

AakiraOtok commented May 14, 2024

Search before asking

Question

I found that YOLOv8 does not use initialization weights. It is possible that initialization weights were used in earlier versions, but subsequent experiments showed their inefficiency. Could you provide more information about the reasons behind this decision?

def initialize_weights(model):
    """Initialize model weights to random values."""
    for m in model.modules():
        t = type(m)
        if t is nn.Conv2d:
            pass  # nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
        elif t is nn.BatchNorm2d:
            m.eps = 1e-3
            m.momentum = 0.03
        elif t in {nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6, nn.SiLU}:
            m.inplace = True

Additional

No response

@AakiraOtok AakiraOtok added the question Further information is requested label May 14, 2024
@glenn-jocher
Copy link
Member

Hello! Thanks for reaching out with your question about the initialization of weights in YOLOv8.

In YOLOv8, the decision to move away from specific weight initialization methods like Kaiming Normal was based on extensive testing and research. It was observed that modern deep learning models, especially with advancements in batch normalization and activation functions, are less sensitive to the initial weight values. The default PyTorch initializations (which are used in YOLOv8) have proven to be robust enough for training without the need for custom initialization schemes.

This simplifies the model architecture and can potentially reduce issues related to training stability and convergence. If you have specific needs or find that a different initialization works better for your particular dataset, you can certainly modify the initialize_weights function as needed.

Here's a quick example if you decide to use a custom initialization:

def initialize_weights(model):
    for m in model.modules():
        if isinstance(m, nn.Conv2d):
            nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
        elif isinstance(m, nn.BatchNorm2d):
            nn.init.constant_(m.weight, 1)
            nn.init.constant_(m.bias, 0)

Feel free to experiment and let us know if you have further questions! 😊

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

No branches or pull requests

2 participants