RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.
时间: 2024-04-26 16:23:15 浏览: 271
yolov5-3.1版本训练时可能会报错及修改方法汇总
引用中的错误相同,都是由于在执行in-place操作时使用了需要梯度的叶节点变量视图。解决方法也是一样的,添加`with torch.no_grad():`来禁用梯度计算,以确保不会出现该错误。中的代码是在解决相同的错误。其中,将原代码使用`torch.nn.Parameter()`将视图重新赋值给`mi.bias`变量,并设置`requires_grad=True`,以确保变量需要梯度计算。这种做法也可以解决该错误。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [yolov5训练报错: a view of a leaf Variable that requires grad is being used in an in-place operation](https://blog.csdn.net/J_oshua/article/details/131822629)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation](https://blog.csdn.net/qq_61666705/article/details/123449024)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文