【CUDA pytorch】
ev= win10
3050ti
联想笔记本
nvcc --version
得到
PS C:\Users\25515> nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Tue_May__3_19:00:59_Pacific_Daylight_Time_2022
Cuda compilation tools, release 11.7, V11.7.64
Build cuda_11.7.r11.7/compiler.31294372_0
CUDA版本是 11.7
PS C:\Users\25515> wmic path win32_videocontroller get name
Name
NVIDIA GeForce RTX 3050 Ti Laptop GPU
Intel(R) Iris(R) Xe Graphics
下载torch
https://pytorch.org/get-started/locally/
接着测试
import torch# 创建张量
x = torch.tensor([1, 2, 3])
y = torch.tensor([4, 5, 6])# 张量加法
z = x + y
print(z) # 输出 tensor([5, 7, 9])# 测试 GPU 张量(如果 CUDA 可用)
if torch.cuda.is_available():x_gpu = x.to("cuda")print(x_gpu) # 输出类似 tensor([1, 2, 3], device='cuda:0')
else:print("CUDA 不可用")pass
print(torch.__version__)
得到
有个大兄弟在卖代码,等我搓搓,哈哈
https://gitee.com/mqwdasddqw/project-download-address
换源
项目结构
handwritten_digit_recognition/
│
├── a3_cnn.py # 包含 CNN 模型定义
├── model/
│ └── mnist_model.pkl # 保存的模型文件
└── main.py # 主程序文件(以下为完整代码)
hand_writing_number