惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
MyScale Blog
MyScale Blog
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
U
Unit 42
Blog — PlanetScale
Blog — PlanetScale
L
LangChain Blog
C
Check Point Blog
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
Vercel News
Vercel News
腾讯CDC
GbyAI
GbyAI
有赞技术团队
有赞技术团队
S
SegmentFault 最新的问题
H
Help Net Security
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
Microsoft Security Blog
Microsoft Security Blog
小众软件
小众软件

博客园 - 玛雅人

五大学习方法 Python AI 与深度学习:每周任务拆分及代码练手 Python AI 与深度学习 - D2.MNIST 手写数字识别 Python基础 - 常用类库汇总 ARDUINO - P2:按钮控制LED ARDUINO - P1:BLink Python调用SQLLite3 IIS8.5 安装证书 Kendo 计算字段 Kendo UI 的 k-template UpdatePanel中用后台CS代码调用JS代码,先执行控件事件,后触发JS SQL常用 Node.js 安装 生成缩略图 有用的JS函数 vs2010 mvc3 运算符 || && 如何阻止ASP.NET的按钮控件提交页面 IIS Form 认证 保护HTML页面
Python AI 与深度学习 - D1.PyTorch 深度学习环境一键配置
玛雅人 · 2026-02-04 · via 博客园 - 玛雅人

1. 原生 Python+pip 配置

1 # 直接安装,建议在虚拟环境中执行
2 pip install torch torchvision torchaudio numpy pandas matplotlib scikit-learn gradio opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple

2.环境验证(必做)

执行以下代码,无报错且输出 PyTorch 版本即配置成功:

 1 import torch
 2 import torchvision
 3 #输出PyTorch版本和是否支持CPU(入门只需要CPU)
 4 print("Pytorch版本:",torch.__version__)
 5 
 6 #是否支持通过 GPU(显卡)进行 CUDA 加速的张量运算、模型训练和推理:
 7 #仅用于检测NVIDIA 显卡的 CUDA 加速是否可用
 8 if torch.cuda.is_available():
 9     print("GPU可用!")
10     print("显卡名称:", torch.cuda.get_device_name(0))  # 查看第1块显卡名称(多显卡可改索引)
11     print("显卡显存:", torch.cuda.get_device_properties(0).total_memory / 1024**3, "GB")  # 显存大小
12     print("当前使用显卡索引:", torch.cuda.current_device())
13 else:
14     print("GPU不可用,使用CPU")
15 
16 # 创建一个测试张量并打印,无报错即正常
17 test_tensor = torch.tensor([1,2,3])
18 print("测试张量:", test_tensor)

额外建议(可选)

如果后续想提升训练速度(比如训练更大的模型 / 更多数据),可考虑配置 GPU 环境,前提是你的电脑有NVIDIA 独立显卡,步骤如下(当前阶段无需操作):

  1. 安装对应显卡的 CUDA Toolkit 和 cuDNN;
  2. 卸载现有 CPU 版 PyTorch:pip uninstall torch torchvision torchaudio
  3. 安装 GPU 版 PyTorch(根据 CUDA 版本选择,参考PyTorch 官网)。