当前位置: 首页 > news >正文

pytorch和deep learning技巧和bug解决方法短篇收集

有一些几句话就可以说明白的观点或者解决的的问题,小虎单独收集到这里。

torch.hub.load how does it work

下载预训练模型再载入,用程序下载链接可能失效。

model = torch.hub.load('ultralytics/yolov5', 'yolov5s')model = torch.hub.load('ultralytics/yolov3', 'yolov3')

I found yolov3.pt in Release.
参考:
https://discuss.pytorch.org/t/using-torch-load-on-a-torch-hub-model/89365
https://docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading/#before-you-start

No module named ‘models’

In yolov3 ~ yolov7 repo directory,

import torch
# _model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # _model is the model itself
model = torch.load("yolov3.pt", map_location='cpu')['model']
torch.save(model.state_dict(), "yolov3.pth")

But the pretrained weight seems not matched to yolov7_d2. Funny design of yolo pretrained model.

The following submodules of the model were never called during the trace of the graph.

定义的submodules没有用到,可能出现在ddp的时候。移除即可。

 The following submodules of the model were never called during the trace of the graph. They may be unused, or they were accessed by direct calls to .forward() or via other python methods. In the latter case they will have zeros for statistics, though their statistics will still contribute to their parent calling module.

Inplace update to inference tensor outside inferencemode

Use @torch.no_grad() instead of torch.inferece_mode().
在这里插入图片描述
Inference mode vs no_grad()
Inplace update to inference tensor outside InferenceMode is not allowed.You can make a clone to get a normal tensor before doing inplace update.See https://github.com/pytorch/rfcs/pull/17 for more details.

One difference would be that you are not allowed to set the requires_grad attribute on tensors from an inference_mode context:

with torch.no_grad():x = torch.randn(1)y = x + 1y.requires_grad = True
z = y + 1
print(z.grad_fn)
> <AddBackward0 object at 0x7fe9c6eafdf0>with torch.inference_mode():x = torch.randn(1)y = x + 1y.requires_grad = True
> RuntimeError: Setting requires_grad=True on inference tensor outside InferenceMode is not allowed.

In a word, outside inference mode, inference tensor is still restricted.

http://www.lryc.cn/news/416909.html

相关文章:

  • 【socket编程】UDP网络通信 {简单的服务器echo程序;简单的远程控制程序;简单的网络聊天室程序}
  • 大数据存储解决方案:HDFS与NoSQL数据库详解
  • 如何用 ChatGPT 提升学术写作:15 个高效提示
  • 【算法】贪心算法
  • 常见中间件漏洞复现之【Jboss】!
  • Java常用中间件(后续更新)
  • 网站或者网页Cookie 启用说明
  • Java 抽象知识笔记总结(油管)
  • 鲜花销售小程序的设计
  • Golang | Leetcode Golang题解之第324题摆动排序II
  • 32、Python之面向对象:对象的表示,再论Python是dict包括语法糖
  • 高级java每日一道面试题-2024年8月07日-网络篇-你对TCP的三次握手了解多少?
  • vite.config.ts中proxy的rewrite理解
  • 大数据环境下用户数据隐私安全防护系统的设计与实现(论文+源码)_kaic
  • 基于springboot+vue+uniapp的“口腔助手”小程序
  • 算法刷题之链表
  • C# 设计模式之适配器模式
  • BFS实现迷宫最短路径
  • Linux IPC解析:匿名命名管道与共享内存
  • Codeforces Round 964 (Div. 4) A~G
  • 单体应用提高性能和处理高并发-使用缓存
  • ollama教程——使用LangChain调用Ollama接口实现ReAct
  • 【Bug分析】Keil报错:error: #18:expected a “)“问题解决
  • MAC上设置快捷打开终端以及如何运用剪切快捷键
  • linux docker安装 gitlab后忘记root密码如何找回
  • C语言典型例题27
  • clion开发stm32f4系列(一)————移植rt-thread os系统
  • 计算机网络(网络层)
  • Python3 第六十六课 -- CGI编程
  • 【Unity23种设计模式】之状态模式