注:家里有一台带英伟达3070 8G电脑和一台intel ultra9 cpu的笔记本电脑。
最近关注到npu,发现新买的笔记本带npu,于是尝试调用npu(听网上说这东西是0%利用)
用pytorch建立模型,用cuda训练后保存(英伟达GPU电脑)
import torch
import torch.nn as nn
import torch.optim as optim
# 定义一个包含卷积层的更复杂的神经网络
class ComplexConvModel(nn.Module):
def __init__(self):
super(ComplexConvModel, self).__init__()
self.conv1 = nn.Conv2d(1, 32, kernel_size=3, stride=1, padding=1)
self.conv2 = nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1)
self.fc1 = nn.Linear(64 * 7 * 7, 512)
self.fc2 = nn.Linear(512, 256)
self.fc3 = nn.Linear(256, 128)
self.fc4 = nn.Linear(128, 10)
def forward(self, x):
x = x.view(-1, 1, 28, 28) # 假设输入数据是28x28的灰度图像
x = torch.relu(self.conv1(x))
x = torch.max_pool2d(x, 2)
x = torch.relu(self.conv2(x))