核心内容摘要
【FPGA自学笔记】告别LED盲调!从零手撕 UART 串口回环并跑通 Vivado 波形仿真
ZYNQ开发板上实施 基于卷积神经网络CNN或BP神经网络MLP的本地图像minis和cifa10识别 工程完整代码包括Python网络训练权值文件和测试文件导出vivadoSDKVitis工程。
开发板适配两类:正点原子7020领航者v2或者赛灵思官方7020 zedboard。
先整模型训练以LeNet为例import torch.nn as nn class LeNet(nn.Module): def __init__(self): super().__init__() self.conv1 nn.Conv2d(3, 6,
# CIFAR10是三通道 self.pool nn.AvgPool2d(2,
self.conv2 nn.Conv2d(6, 16,
self.fc1 nn.Linear(16*5*5,
self.fc2 nn.Linear(120,
self.fc3 nn.Linear(84,
def forward(self, x): x self.pool(torch.relu(self.conv1(x))) x self.pool(torch.relu(self.conv2(x))) x x.view(-1, 16*5*
x torch.relu(self.fc1(x)) x torch.relu(self.fc2(x)) return self.fc3(x)这里有个坑要注意ZYNQ的FPGA部分处理浮点太奢侈训练完记得做权重量化。
用这个脚本把权重转成int8def quantize_weights(model): for param in model.parameters(): param.data torch.clamp(param.data, -1,
# 限制范围 param.data (param.data *
.round().byte() # 转8位定点导出模型权重到C头文件是必须操作def save_weights_to_h(model, filename): with open(filename, w) as f: f.write(#ifndef WEIGHTS_H\n#define WEIGHTS_H\n\n) for name, param in model.named_parameters(): data param.data.numpy().astype(np.int
.flatten() f.write(fconst int8_t {name.replace(., _)}[] dssds article-item">
Wwwwwxxxx:点亮你的数字生活,解锁无限可能
岁月流金,温情满溢:妈妈姨妈三姐妹的生日惊喜
肌肌对肤肤肤:解锁肌肤与肌肉的和谐共舞,绽放紧致年轻之美
岁月流金,温情满溢:妈妈姨妈三姐妹的生日惊喜
肌肌对肤肤肤:解锁肌肤与肌肉的和谐共舞,绽放紧致年轻之美