Comments (3)
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.
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.
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)
- Trying to show the XY value for detecting objects on real-time
- Request for mAP of different scale HOT 8
- FATAL ERROR! reclaim_blob_allocator get wild allocator in Jetson Nano with NCNN Inference HOT 2
- data lable wrong when train yoloworld HOT 7
- Trained YOLOv8 model converted to CoreML doesn't give any predictions HOT 4
- About glean-t and yolov9-t HOT 4
- When I install torch_image, imgsz doesn't work. HOT 1
- Train subclass in Coco data set HOT 4
- Oriented Bounding box health check HOT 1
- [YoloV8] Torch compile model shows metrics degradation on the coco128 dataset HOT 4
- Address Discord badge error HOT 1
- How to reduce the number of target contour points predicted by YOLOv8-Sseg HOT 3
- val step slow down during training HOT 2
- Batch inference speed same than looping through a bunch of imgs HOT 1
- Using YOLOv8(seg) with SHAP HOT 3
- yolov8 object_counting in and out doesn't differentiate for defined line HOT 3
- how to set `verbose:false` so that model can predict the batches without printing anything in the terminal HOT 1
- Questions about incremental training HOT 1
- How can I use the segmentation models of previous versions? HOT 3
- yolov8-obb plot train labels maybe error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ultralytics.