GithubHelp home page GithubHelp logo

v8Detection loss backward about ultralytics HOT 3 OPEN

deepukr007 avatar deepukr007 commented on June 20, 2024
v8Detection loss backward

from ultralytics.

Comments (3)

glenn-jocher avatar glenn-jocher commented on June 20, 2024

Hello! It looks like you're encountering an issue with the backward pass of your loss calculation. In your case, you should only call .backward() on loss1 as it is the tensor that should contain the gradients from the loss computation. lossitem1 is detached from the graph (as indicated by .detach()), which means it doesn't track gradients, hence the error you're seeing.

Make sure that your model's parameters require gradients and that your inputs to the model are also set to require gradients if necessary. You can check if your model's parameters are set to require gradients by printing model_1.parameters() and checking the .requires_grad attribute.

If the problem persists, ensure that all operations in your custom training loop support gradient tracking and that no tensors are inadvertently detached from the computation graph before the loss calculation. If you need further assistance, feel free to share more details about your training loop and model setup!

from ultralytics.

deepukr007 avatar deepukr007 commented on June 20, 2024

Hi ,
Thank you so much for the reply.

It is working now when I freeze all the parameters except the 22nd layer.

but the problem is I don't want to update the parameters of the yolo model

for example:
I have 3 pretrained models on different exposure images and I am having a gate which routes the image to particular model.
In the training loop I can get gate weight ouputs w1,w2,w3 for image and multiply that with losses of three models and if I do backward and optimser.step() I don't want to change the pretrained model instead I just want to update the gate weights.

from ultralytics.

glenn-jocher avatar glenn-jocher commented on June 20, 2024

Hello,

Great to hear that freezing the parameters worked for you!

To update only the gate weights without altering the pretrained model parameters, you can selectively disable gradient computations for the model parameters. This can be done by setting .requires_grad to False for all parameters of the YOLO models. Here’s how you can do it:

for param in model.parameters():
    param.requires_grad = False

Apply this to each of your pretrained models. This way, only the parameters of the gate (assuming they have .requires_grad set to True) will be updated during backward() and optimizer.step().

If you need further assistance or have more questions, feel free to ask. Happy coding! πŸš€

from ultralytics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.