编程
wujpbb7
专注于人脸识别十年以上。
展开
-
慎用 np.vstack 和 np.hstack
连接2个array,如果是1维数组,要用 np.hstack,2维数组,要用 np.vstack。但可以统一用 np.concatenate(, axis=0)。原创 2024-06-21 17:06:13 · 202 阅读 · 1 评论 -
多进程中随机数的初始种子
torch、random 和 np.random 在多进程中随机数的初始种子。原创 2024-04-01 16:30:57 · 251 阅读 · 0 评论 -
远程连接 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 · 1605 阅读 · 0 评论 -
“RuntimeError: Unable to find a valid cuDNN algorithm to run convolution“
调小 batch size。原创 2023-10-26 10:27:01 · 108 阅读 · 0 评论 -
reshape 和 view 的效率比较
如果 tensor 是连续的,reshape 返回的是视图,和 view 一致。原创 2023-08-31 16:33:34 · 258 阅读 · 0 评论 -
np.argwhere 返回的数组
np.argwhere 返回的数组,第一维是满足条件的结果数量,第二维是满足条件的结果索引。原创 2023-06-14 10:29:33 · 219 阅读 · 0 评论 -
pytorch 的 dataset 中使用 onnxruntime
把 DataLoader 中 num_workers 设置成 0 就好了。原创 2022-12-13 19:11:11 · 1361 阅读 · 1 评论 -
解析 cifar10 的压缩包到图片
解析 cifar10 的压缩包到图片原创 2022-12-06 16:09:32 · 310 阅读 · 0 评论 -
使用 vscode 远程调试 docker 中的代码
使用 vscode 远程调试 docker 中的代码原创 2022-12-02 11:42:21 · 905 阅读 · 0 评论 -
torch.autocast 放在 forward 中
使用 DDP时,如果不是 每块 GPU 一个进程,torch.autocast 应该放在 forward 中。原创 2022-10-09 15:55:13 · 576 阅读 · 0 评论 -
shape 和 size() 区别
shape 比 size() 通用性更好原创 2022-07-25 11:29:29 · 2027 阅读 · 0 评论 -
cross entropy loss = log softmax + nll loss
cross entropy loss = log softmax + nll loss原创 2022-06-07 16:58:43 · 371 阅读 · 0 评论 -
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 · 1723 阅读 · 0 评论 -
[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 · 1771 阅读 · 0 评论 -
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 · 3632 阅读 · 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 · 8393 阅读 · 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 · 509 阅读 · 0 评论 -
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 · 1100 阅读 · 0 评论 -
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 · 4726 阅读 · 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 · 867 阅读 · 0 评论 -
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 · 1061 阅读 · 0 评论 -
多机多卡训练时的错误
错误1:“NCCL WARN Connect to failed : Network is unreachable”解决方法:设置环境变量NCCL_SOCKET_IFNAME=enp(有可能是eno,可以先用ifconfig 查看)原创 2021-12-23 19:51:50 · 1893 阅读 · 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 · 2277 阅读 · 0 评论 -
被 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 · 5157 阅读 · 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 · 742 阅读 · 0 评论 -
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 · 3953 阅读 · 15 评论 -
直观理解 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 · 899 阅读 · 0 评论 -
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 · 9044 阅读 · 9 评论 -
git clone 慢
替换 github.com 为github.com.cnpmjs.org如果有子模块,修改 .gitmodule原创 2021-06-07 16:31:50 · 101 阅读 · 0 评论 -
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 · 2636 阅读 · 0 评论 -
安装 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 · 7111 阅读 · 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 · 2684 阅读 · 0 评论 -
vscode 远程连接失败
如果远程环境改变,比如系统重装,用vscode 重连时会有如下的错误:“[10:10:08.174] Install terminal quit with output: 过程试图写入的管道不存在。”解决方法:打开 “c:\Users\bb7\.ssh\known_hosts”,删除连接失败主机那行即可。...原创 2021-03-29 10:49:43 · 2183 阅读 · 3 评论 -
torch.renorm 中的 maxnorm 是乘子
>>> x = torch.ones(3, 3)>>> x[1].fill_(2)tensor([ 2., 2., 2.])>>> x[2].fill_(3)tensor([ 3., 3., 3.])>>> xtensor([[ 1., 1., 1.], [ 2., 2., 2.], [ 3., 3., 3.]])>>> torch.renorm(x,.原创 2021-03-25 09:34:44 · 725 阅读 · 1 评论 -
python 中的中文
无论是字符串中的中文,或者 注释中的中文,需要1、在 py 文件开始处加入#-*-coding:utf-8-*-。2、选择右下角的 "UTF-8",“Save with Encoding”,"UTF-8"。参考:彻底搞懂 Python 编码原创 2021-03-12 18:01:11 · 222 阅读 · 0 评论 -
从 DP 到 DDP 到 apex
1、从DataParallel 到 DistributedDataParallel,最大的改变是启动方式:从 python a.py 到 python -m torch.distributed.launch --nproc_per_node=4--use_env a.py--nproc_per_node 表示单机使用4块GPU, --use_env 表示不给 a.py 增加参数--local_rank。torch.distributed.launch 的作用就是用多进程的方式启动 a.py,..原创 2021-01-14 19:14:02 · 1035 阅读 · 0 评论 -
利用 vs code 远程调试 ubuntu 上的 python 程序
1、在 ubuntu 上安装 ptvsd,并运行 python程序 aaa.py 。sudo pip install ptvsd -i http://pypi.douban.com/simple --trusted-host pypi.douban.compython -m ptvsd --host 0.0.0.0 --port 1234 --wait ./aaa.py2、在 vscode 上安装扩展 python 和Remote - SSH。3、在 "Remote Explorer"...原创 2020-09-10 18:16:48 · 939 阅读 · 0 评论 -
在 Docker 中做镜像
1、安装Docker参考:https://docs.docker.com/engine/install/ubuntu/sudo apt-get updatesudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-commoncurl -fsSL https://download.docker.com/linux/u原创 2020-08-21 10:31:13 · 182 阅读 · 0 评论 -
在 Docker 中编译 nvcaffe
1、安装docker。2、拉镜像,镜像是带cuda10.2和cudnn7的ubuntu6.04。sudo docker pull nvidia/cuda:10.2-cudnn7-devel-ubuntu16.04sudo docker images3、在主机上创建文件夹/data1/dock_share,共享到容器中的 /host_data。sudo docker run -dit -P --name container-nvidia -v /data1/dock_share:/h.原创 2020-08-15 11:30:15 · 223 阅读 · 0 评论 -
眼周识别
参考:Periocular Recognition in theWild: Implementation of RGB-OCLBCP Dual-Stream CNN采用 RGB/OCLBCP 双路 CNN 提取特征,再融合。原创 2020-05-23 16:19:33 · 620 阅读 · 0 评论