CV和NLP中常见的shape在常见网络层下的变化
在深度学习的CV(计算机视觉)和NLP(自然语言处理)任务中,理解张量形状在不同网络层中的变化至关重要。以下是常见网络层及其输入/输出形状变化的细致总结(使用PyTorch/Numpy的维度约定:(Batch Size, Channels/Features/Embedding Dim, Height, Width) 或 (Batch Size, Sequence Length, Hidden Size/Embedding Dim)):
核心维度概念1.N / batch_size: 批次大小(样本数)2.C / channels / features / embedding_dim / d_model / hidden_size: 特征维度(通道、词嵌入大小、隐藏层大小)3.H: 特征图高度 (CV)4.W: 特征图宽度 (CV)5.L / seq_len: 序列长度 (NLP / 1D CV)6.K: 卷积核大小 (单个维度)7.S / stride: 步长8.P ...
kd树
递归地将空间划分为k维的超矩形区域
优点:适用于低维数据(通常d<20),平均查询复杂度O(log n)2.精确最近邻搜索
123from sklearn.neighbors import KDTreetree = KDTree(points)dist, ind = tree.query(query_point, k=k)
KD树构建过程
选择当前维度(通常循环选择或选择方差最大的维度)
找到当前维度上的中位数作为分割点
将数据集分为小于中位数和大于中位数的两部分
对两个子集递归构建左右子树
KD树搜索过程(1)向下搜索
从根节点开始,比较 查询点 和 当前节点 在 当前分割维度 上的值:
如果 query[axis] < node.point[axis],进入 左子树。
否则,进入 右子树。
递归执行,直到到达叶子节点。
(2)回溯检查
在找到最近候选点后,检查 另一侧子树是否可能存在更近的点:
计算 查询点到当前分割平面的距离 dist = abs(query[axis] - node.point[axis])。
如果 dist < 当前最近 ...
NLP
[[Perplexity]]
Transformer 模型中,主要使用Layer Normalization!!!
在 Transformer 模型中,主要使用 Layer Normalization(层归一化) 作为正则化层,而不是 Batch Normalization(批归一化)。以下是详细说明:
1. Layer Normalization(层归一化)Transformer 中所有核心子层(自注意力层和前馈神经网络)的输出都接 LayerNorm,其作用:
归一化方式:对单个样本的所有特征通道进行归一化(沿特征维度 $C$),而非批处理维度。$$\mu = \frac{1}{C} \sum_{i=1}^C x_i, \quad \sigma = \sqrt{\frac{1}{C} \sum_{i=1}^C (x_i - \mu)^2}$$
结构位置:应用于 残差连接(Residual Connection)之后,形成 Add & Norm 模块:$$\text{Output} = \text{LayerNorm}(x + \text{Sublayer}(x))$$其中 $\text{Sublayer}$ 是自注意力或前馈网络。
...
基石智算
AI 计算平台 西北三区 XB3 基石智算控制台
传输
123456 scp -P 30256 "C:\Users\A\Documents\ComfyUI\models\diffusion_models\flux1-dev-Q4_1.gguf" root@124.88.174.116:/root/epfs/ln -s export http_proxy="http://127.0.0.1:7890"export https_proxy="http://127.0.0.1:7890"
ln -s /root/epfs/flux1-dev-Q4_1.gguf /CompyUI/models/diffusion_models/
gitclone github镜像方达极客社区history12345678910111213141516171819202122232425262728290:00:00 /package/admin/s6/command/s6-s ...
sinkai
Sink In: Stable Diffusion models API for developers
SinkIn API
Workflow Template | TAMS
抽象类
抽象类是一种不能被直接实例化的类,它的主要作用是定义接口规范,要求子类必须实现某些方法。抽象类可以包含普通方法(已实现的方法)和抽象方法(未实现的方法);如果子类没有实现所有抽象方法,Python 会抛出 TypeError。抽象方法是一种只有声明没有实现的方法,必须由子类实现,且抽象类的子类必须实现所有抽象方法,否则无法实例化。在python中通过下列代码导入,然后使用ABC继承和@abstractmethod装饰器
1from abc import ABC, abstractmethod
实现接口和模板方法模式
字符串的排列
输入一个长度为 n 字符串,打印出该字符串中字符的所有排列,你可以以任意顺序返回这个字符串数组。
例如输入字符串ABC,则输出由字符A,B,C所能排列出来的所有字符串ABC,ACB,BAC,BCA,CBA和CAB。
12345678910111213141516171819202122232425262728## 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可## # @param str string字符串 # @return string字符串一维数组#class Solution1: def Permutation(self , str: str) -> List[str]: is_chose = [False]*len(str) self.choices = sorted([ch for ch in str]) res = [] self._back_trace('',is_chose=is_chose,res=res) return res ...
tnr thunder compute
12345678910111213141516uv pip install tnr不在实例上用在实例上都不加tnr,tnr login%% 不用connect,很慢有墙 %%# Upload to instancetnr scp ./local_file.txt 0:/remote/path/# Download from instancetnr scp 0:/remote/file.txt ./local_path/tnr connect <instance id>logout
torch 安不了
123456789101112131415>uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126⠹ Resolving dependencies... error: Failed to fetch: `https://download.pytorch.org/whl/cu126/torch/` Caused by: Request failed after 3 retries Caused by: error sending request for url (https://download.pytorch.org/whl/cu126/torch/) Caused by: client error (Connect) Caused by: tcp conne ...