自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(131)
  • 收藏
  • 关注

原创 多进程中随机数的初始种子

torch、random 和 np.random 在多进程中随机数的初始种子。

2024-04-01 16:30:57 216

原创 远程连接 vscode 出错 “远程主机可能不符合 glibc 和 libstdc++ VS Code 服务器的先决条件”

下载 1.85.2,https://update.code.visualstudio.com/1.85.2/win32-x64-archive/stable。vscode 版本是 1.86,服务器上的 glibc 和 libstdc++ 版本不满足。

2024-02-22 15:52:26 1371

原创 在 docker 中安装 GLEE

docker 中没有 git,可以通过共享主机文件夹,在主机中做 git clone。

2023-12-27 11:42:16 584 1

原创 通过 conda 安装 的 detectron2

发现预编译的版本最高支持 pytorch1.10、cuda11.3。

2023-12-26 17:37:03 770

原创 在 docker 中安装 sam

3、进入 segment-anything 目录,用 pip install . 安装。1、进入 docker,共享一个主机的目录。2、在主机的目录中做 git clone。

2023-12-15 14:51:12 549

原创 “RuntimeError: Unable to find a valid cuDNN algorithm to run convolution“

调小 batch size。

2023-10-26 10:27:01 94

原创 reshape 和 view 的效率比较

如果 tensor 是连续的,reshape 返回的是视图,和 view 一致。

2023-08-31 16:33:34 215

原创 np.argwhere 返回的数组

np.argwhere 返回的数组,第一维是满足条件的结果数量,第二维是满足条件的结果索引。

2023-06-14 10:29:33 168

原创 pytorch 的 dataset 中使用 onnxruntime

把 DataLoader 中 num_workers 设置成 0 就好了。

2022-12-13 19:11:11 1161 1

原创 解析 cifar10 的压缩包到图片

解析 cifar10 的压缩包到图片

2022-12-06 16:09:32 281

原创 使用 vscode 远程调试 docker 中的代码

使用 vscode 远程调试 docker 中的代码

2022-12-02 11:42:21 839

原创 timm 和 torchvision 中的 resnet50

从 timm 和 torchvision 分别加载 resnet50 预训练模型,从 onnx 看,权重是一样的。

2022-11-14 16:50:28 1403 1

原创 torch.autocast 放在 forward 中

使用 DDP时,如果不是 每块 GPU 一个进程,torch.autocast 应该放在 forward 中。

2022-10-09 15:55:13 549

原创 SE 的 ONNX 图

SE 的 ONNX 图

2022-09-13 16:26:14 91

原创 shape 和 size() 区别

shape 比 size() 通用性更好

2022-07-25 11:29:29 1869

原创 cross entropy loss = log softmax + nll loss

cross entropy loss = log softmax + nll loss

2022-06-07 16:58:43 324

原创 IndexError: shape mismatch: indexing tensors could not be broadcast together with shapes [2], [3]

import torcha = torch.randn(3,5)print(a)# 下行会有错误 IndexError: shape mismatch: indexing tensors could not be broadcast together with shapes [2], [3]#b = a[[0,2],[1,3,4]] # 改成 b = a[[0,2],:][:,[1,3,4]] print(b)输出是:tensor([[ 0.3627, -0.7073, -0.39.

2022-05-09 15:05:27 1516

原创 [8] Assertion failed: dims.nbDims == 4 || dims.nbDims == 5

onnx 转 trt 的时候出现错误:[04/22/2022-15:45:13] [W] [TRT] onnx2trt_utils.cpp:220: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.[04/22/2022-15:45:13] [E] [TRT] (Unnamed

2022-04-22 16:18:55 1717

原创 enforce fail at inline_container.cc:222

执行 torch.load 时出现错误:“RuntimeError: [enforce fail at inline_container.cc:222] . file not found: archive/data/94479765723472”或者“RuntimeError: [enforce fail at inline_container.cc:145] . PytorchStreamReader failed reading file data/94100453134480: inval

2022-04-14 15:54:40 3443 3

原创 使用 trt 的int8 量化和推断 onnx 模型

目录生成 trt 模型1、使用代码2、onnx模型和图片3、修改代码4、结果推断 trt 模型生成 trt 模型1、使用代码https://github.com/rmccorm4/tensorrt-utils.git2、onnx模型和图片模型:动态batch输入(假设为mob_w160_h160.onnx,输入是 [batchsize, 3, 160, 160])。图片:一堆图片(假设有1024张),不需要其他描述文件。在tensorrt-u...

2022-03-27 22:55:41 8036 2

原创 画 ArcFace 中的 margin 曲线

效果如下:代码如下:from math import cos, sin, piimport numpy as npimport matplotlib.pyplot as plt'''# https://github.com/deepinsight/insightface/blob/master/recognition/arcface_torch/losses.pyclass ArcFace(torch.nn.Module): """ ArcFace (https:/..

2022-03-17 20:12:22 493

原创 Unable to determine the device handle for GPU 0000:02:00.0: GPU is lost.

TITAN X (Pascal) 的显卡,当 batch size 过大爆显存时,就会出现 GPU丢失 的错误。

2022-02-17 18:49:51 1010

原创 unhandled system error, NCCL version 2.7.8

在 宿主机上运行基于 DDP 的 pytorch 训练程序没问题,进入 docker 后运行,出现 "unhandled system error, NCCL version 2.7.8" 的错误。解决方法:在 python -m torch.distributed.launch --nproc_per_node=4 ...前加上 NCCL_DEBUG=INFO可以看到:s215:623:649 [3] include/shm.h:48 NCCL WARN Error while cr

2022-02-16 17:58:14 4255 1

原创 在两台 ubuntu 上安装 K8S

参考:1、ubuntu 安装 k8s2、报错:The connection to the server localhost:8080 was refused - did you specify the right host or port?3、Connecting to raw.githubusercontent.com failed: Connection refused. 解决办法安装 flannel 时使用:(python38) ai200@ubuntu16:/$ kubectl

2022-02-15 16:27:35 836

原创 在两台 ubuntu 之间传输大文件

方法1:scp -c [email protected] usrname@ip:dir加上 -c [email protected],可以加速。方法2:rsync -avP a.tar.gz usrname@ip:dir参考:1、linux中scp传文件速度慢原因2、为什么scp这么慢,如何使它更快?...

2022-01-25 10:38:36 1460

原创 ubuntu14.04 升级到 ubuntu16.04

参考:将Ubuntu 16.04 LTS 升级到 18.04 LTS | 以及问题汇总# 升级前(base) root@s215:~# cat /proc/versionLinux version 3.13.0-147-generic (buildd@lcy01-amd64-024) (gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.4) ) #196-Ubuntu SMP Wed May 2 15:51:34 UTC 2018# 升级后(bas

2022-01-24 16:21:20 967

原创 多机多卡训练时的错误

错误1:“NCCL WARN Connect to failed : Network is unreachable”解决方法:设置环境变量NCCL_SOCKET_IFNAME=enp(有可能是eno,可以先用ifconfig 查看)

2021-12-23 19:51:50 1682 1

原创 onnxruntime-gpu 1.7 出现的警告“Force fallback to CPU execution for node: Gather_191”等

使用 onnxruntime-gpu(简称ORT)1.7 推断 onnx模型时出现如下警告,2021-12-01 15:50:30.792327215 [W:onnxruntime:Default, fallback_cpu_capability.cc:135 GetCpuPreferredNodes] Force fallback to CPU execution for node: Gather_1912021-12-01 15:50:30.792374122 [W:onnxruntime:De

2021-12-01 17:16:00 2092

原创 被 onnx.checker.check_model 检查出的常见错误

错误1:“Field 'name' of graph is required to be non-empty.”解决:对 model.graph.name 赋值。错误2:“Nodes in a graph must be topologically sorted, however input ...”解决:调整节点顺序,保证每个节点的输入都先于它存在。参考代码如下:def check_update_model(model): if (model.graph.name == ''

2021-11-10 17:51:08 4513 2

原创 rearrange 和 einsum 真的优雅吗

结论是,还好吧。从代码量看,差不多:# -*- coding:utf-8 -*-import torchfrom torch import nnfrom torch import einsumfrom einops import rearrangeclass SimpleQKV(nn.Module): def __init__(self, dim, use_ein): super().__init__() self.proj = nn.Linea

2021-11-09 10:59:19 672

原创 swin transformer 转 onnx

swin transformer 代码非官方实现,但是好理解。转 onnx 代码:import torchfrom swin_transformer_pytorch import swin_tpth_filename = './demo.pth' # 训练好的权重onnx_filename = './demo.onnx'net = swin_t()weights = torch.load(pth_filename)#net.load_state_dict(weights)n..

2021-10-29 15:15:52 3712 15

原创 F.pad 的妙用

F.pad 的使用参考Pytorch之torch.nn.functional.pad函数详解F.pad 可用在通道扩充上。import torchimport torch.nn.functional as Fx = torch.randn(1,3,5,4)added_chan_num = 2use_pad = Trueif (not use_pad): z = torch.zeros(1,added_chan_num,5,4) x_a = torch.cat((x,z.

2021-10-28 15:00:55 753

原创 直观理解 torch.nn.Unfold

torch.nn.Unfold 是把batch中的数据按 C、Kernel_W、Kernel_H 打包,详细解释参考:PyTorch中torch.nn.functional.unfold函数使用详解本文主要是把 Unfold 返回的tensor的中间部分还原成 patches。# -*- coding:utf-8 -*-import cv2import torchimport numpy as npimg1 = cv2.imread('../128128/1.png')img2 =

2021-10-15 16:34:17 850

原创 pth 转 onnx 时出现的 gather、unsqueeze 等算子

带动态输入的view或者reshape转成onnx会有shape/gather/unsqueeze/concat算子。替换成 flatten 即可。def forward(self, inputs): x1 = self.conv1(inputs) x2 = self.conv2(x1) # 带动态输入的 view 或者 reshape 转成 onnx 会有shape/gather/unsqueeze/concat算子。 ...

2021-09-14 17:35:01 8231 9

原创 git clone 慢

替换 github.com 为github.com.cnpmjs.org如果有子模块,修改 .gitmodule

2021-06-07 16:31:50 94

原创 ubuntu16.04 安装 CUDA11.3

1、下载cuda_11.3.1_465.19.01_linux.run2、sudo ./cuda_11.3.1_465.19.01_linux.run

2021-06-07 15:44:47 2560

原创 安装 pycuda 出现 PEP517 的错误

执行:pip install pycuda出现:Building wheel for pycuda (PEP 517) ... error使用:pip install pycuda --no-binary :all:不解决问题。从源码编译,解决问题。1、下载pycuda-2021.1.tar.gz2、tar xfz pycuda-2021.1.tar.gz3、cd pycuda-2021.14、python3configure.py --cuda-root=/usr/lo..

2021-05-31 16:30:29 6728 3

转载 PEP是什么

转载 :https://www.cnblogs.com/abella/p/10056875.htmlPEP是什么?PEP的全称是Python Enhancement Proposals,其中Enhancement是增强改进的意思,Proposals则可译为提案或建议书,所以合起来,比较常见的翻译是Python增强提案或Python改进建议书。我个人倾向于前一个翻译,因为它更贴切。Python核心开发者主要通过邮件列表讨论问题、提议、计划等,PEP通常是汇总了多方信息,经过了部分核心开发者revi

2021-05-18 14:42:17 2481

原创 合并多个 onnx

一个训练好的 onnx 中有效信息包含 graph 中的 node(位置关系),initializer(权重),input、output(它们不是node,是value info)。假设有 3个 onnx,是具有相同结构、不同权重的模型(例如使用不同数据训练)。原模型 输入名:‘img’,输出名:‘fea’。新模型的输入和原模型一样,输出需要把原输出相加。# -*- coding:utf-8 -*-import onnximport copylist_modelname = ['./m

2021-05-14 16:57:29 2968 4

原创 编译带 tensorrt 的 onnxruntime

在一个几乎啥都没有的docker环境(ubuntu16.04)中编译带 tensorrt 的 onnxruntime:1、安装 gitroot@a42b2c92c7f3:/# git clone --recursive https://github.com/microsoft/onnxruntime.gitbash: git: command not foundroot@a42b2c92c7f3:/# apt-get install git2、git clone中的错误,参考跳坑 g.

2021-04-26 17:47:14 3058 1

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除