安装12pip install onnx onnxruntime -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com# pip install onnxruntime-openvino -i http://mirrors.cloud.aliyuncs.com/pypi/simple/ --trusted-host=mirrors.cloud.aliyuncs.com
PyTorch导出onnx模型12345678910111213141516171819202122232425262728293031323334353637383940414243444546# 参考:https://pytorch.ac.cn/tutorials/advanced/super_resolution_with_onnxruntime.htmlimport osimport numpy as npimport torchimport onnximport onnxruntime# 一、定义模型输入数据和计 ...
一、基础版SelfAttention123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import torchimport torch.nn as nnimport torch.nn.functional as Fclass SelfAttention(nn.Module): def __init__(self, embed_size): super(SelfAttention, self).__init__() self.embed_size = embed_size # 定义三个线性层分别生成Q, K, V self.query = nn.Linear(embed_size, embed_size) self.key = nn.Linear(embed_size, embed_size) self.value = nn. ...
一、常用 Norm 介绍LayerNormLayerNorm 是一种神经网络中的归一化技术,用于稳定训练过程(缓解梯度消失/爆炸),加速收敛。它的核心思想是 对单个样本的某一层所有神经元的输出进行归一化
① 计算方式在 Transformer 或 GPT 这类模型中,输入张量的形状通常是 [batch_size, seq_len, hidden_dim],而 LayerNorm 会沿着 hidden_dim 维度进行归一化。
对于形状为 [batch_size, seq_len, hidden_dim] 的输入,LayerNorm 的归一化是 对最后一个维度(hidden_dim)独立进行的,即:
每个 token 的特征向量(长度为 hidden_dim)单独归一化。
均值和方差的计算:对每个样本的每个时间步(即 [hidden_dim] 维度)计算均值和方差。
具体计算步骤如下:
给定输入张量 x(形状 [batch_size, seq_len, hidden_dim]):
计算均值和方差:
对每个样本的每个时间步(即 hidden_dim 维度)计算: [ \m ...
如何暂停 Windows 更新:记录我的方法在日常使用 Windows 系统的过程中,自动更新有时会带来一些不便,尤其是在关键时刻打断工作或占用系统资源。为了避免这种情况,我决定暂停 Windows 更新。以下是我记录的方法,供大家参考。
方法步骤1. 打开注册表编辑器首先,我们需要打开 Windows 的注册表编辑器。按下 Win + R 组合键,输入 regedit,然后按下回车键。
2. 导航到指定路径在注册表编辑器中,导航到以下路径:
1计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings
3. 新建 DWORD (32 位) 值在 Settings 文件夹中,右键点击空白处,选择 新建 -> DWORD (32 位) 值。将新建的值命名为:
1FlightSettingsMaxPauseDays
4. 修改取值双击刚刚创建的 FlightSettingsMaxPauseDays,将其值修改为 35000(十进制)。这个值表示 35000 天(5000周),即大约 100 年。
5. 保 ...
PIL (pillow)123import iofrom PIL import Imageimport matplotlib.pyplot as plt
基础读写123456789101112131415# 读取图片image = Image.open('/path/to/image.png').convert('RGB')image2 = Image.open(io.BytesIO(buffer)) # buffer is bytesimage3 = Image.open(requests.get(image_url, stream=True).raw)# 查看图像实例的属性print("""Format: {image.format}Size: {image.size} = (width, height)Mode: {image.mode} ∈ (L, RGB, RGBA, CMYK, YCbCr, HSV)""")# ...
安装1docker run -d --cpus="8.0" --memory="16g" -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama # 加速docker.1ms.run
拉取模型1docker exec -it ollama ollama pull qwen2.5:3b
对话交互1docker exec -it ollama ollama run qwen2.5:3b
API1234567891011121314151617181920212223242526272829303132333435363738394041424344454647# 查看ollama版本curl http://localhost:11434/api/version# 查看本地模型curl http://localhost:11434/api/tags# 查看当前加载进内存的模型curl http://localhost:11434/api/ps# 查看模型信 ...
开发环境设置
安装 Node.js LTS版
在安卓/iOS手机上安装Expo Go应用
开发第一个app1234npx create-expo-app@latest StickerSmash && cd StickerSmash # 初始化新的Expo应用程序# wget https://docs.expo.dev/static/images/tutorial/sticker-smash-assets.zip && unzip sticker-smash-assets.zip && mv sticker-smash-assets/* ./assets/imagesnpm run reset-project # 重置项目(删除里面的示例模板代码)npx expo start # 开发服务器启动后,用手机上的ExpoGo扫描屏幕上的二维码
简单修改app让我们修改app/index.tsx:
从react-native导入StyleSheet并创建一个styles对象来定义我们的自定义样式
向添加值为#25292e的 ...
ResNet-18的torch实现源码解读
Input: 3x224x224
Layer-0: conv1 + bn1 + relu + maxpool
conv1: 3->64通道。上下左右补3像素,卷积核7x7,步长2像素(尺寸减半112x112)。没有偏置项
bn1+relu: 先批归一化,再激活
maxpool: 上下左右补1像素,池化核3x3,步长为2(尺寸再减半56x56)
Layer-1: self._make_layer(block, 64, layers[0])
BasicBlock-1
conv1: 64->64通道。上下左右补1像素,卷积核3x3,步长1像素。没有偏置项
bn1+relu: 先批归一化,再激活
conv2: 64->64通道。上下左右补1像素,卷积核3x3,步长1像素。没有偏置项
bn2: 批归一化
残差连接: 由于特征图尺寸没变,因此直接相加即可(=本Block的输入+bn2的输出)
relu: 最后relu激活(先残差后激活)
BasicBlock-2
conv1: 64->64通道。 ...
12345678910111213def get_tran(text,source_lang="",target_lang=""): """ 调用 https://findmyip.net/api/translate.php 接口 翻译文本 :param text:需要翻译的源文本 :param source_lang:源文本语言种类(此参数若不填写,将会进行自动检测) :param target_lang:翻译后的语言种类(此参数若不填写,将会自动翻译成中文) :return: 翻译后的内容 """ import requests url=f"https://findmyip.net/api/translate.php?text={text}&source_lang={source_lang}&target_lang={target_lang}&q ...
