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

Parameter fusion #13039

Open
1 task done
znmzdx-zrh opened this issue May 23, 2024 · 5 comments
Open
1 task done

Parameter fusion #13039

znmzdx-zrh opened this issue May 23, 2024 · 5 comments
Labels
question Further information is requested Stale

Comments

@znmzdx-zrh
Copy link

Search before asking

Question

How to integrate some parameters from imported external modules into the entire YOLOv8 model for joint training?I want to introduce some filters as a module into the YOLOv8 model to enhance images. How can I merge the parameters inside the filters into the trainable parameter list of YOLOv8 for joint training and updating?Thank you for help

Additional

No response

@znmzdx-zrh znmzdx-zrh added the question Further information is requested label May 23, 2024
Copy link

👋 Hello @znmzdx-zrh, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

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.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

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

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

To integrate external module parameters into YOLOv8 for joint training, you can modify the model's architecture to include your custom module. Here’s a brief example using PyTorch:

import torch
import torch.nn as nn
from ultralytics import YOLO

class CustomFilterModule(nn.Module):
    def __init__(self):
        super(CustomFilterModule, self).__init__()
        # Define your filters here, e.g., a convolutional layer
        self.conv = nn.Conv2d(in_channels=3, out_channels=3, kernel_size=3, padding=1)

    def forward(self, x):
        # Apply your filters
        return self.conv(x)

# Load your YOLOv8 model
model = YOLO('yolov8n.pt')

# Add your custom filter module before the YOLOv8 model
class CustomYOLO(nn.Module):
    def __init__(self, yolo_model, filter_module):
        super(CustomYOLO, self).__init__()
        self.filter = filter_module
        self.yolo = yolo_model

    def forward(self, x):
        x = self.filter(x)
        return self.yolo(x)

# Combine them
custom_model = CustomYOLO(model, CustomFilterModule())

# Now custom_model can be trained with both the filter and YOLOv8 parameters being updated

This setup allows the parameters of both the custom filter and the YOLOv8 model to be updated during training. Adjust the CustomFilterModule to include your specific filters and integrate it accordingly.

@znmzdx-zrh
Copy link
Author

@glenn-jocher I really appreciate your response, and I am currently trying out the solution you proposed. Thank you very much

@glenn-jocher
Copy link
Member

You're welcome! If you have any more questions or need further assistance as you implement the solution, feel free to reach out. Happy coding! 😊

Copy link

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

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 YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

2 participants