一、概念
人工神经网络
1950年 图灵测试,象棋
深度学习 与 机器学习的区别
不需要特征工程,网络神经元。擅长处理高维数据
特点:
多层 ,每一层神经网络,每层都有激活函数(非线性变化)
1.多层非线性变换
2.自动特征提取
3.大数据和计算能力
4.可解释性差
常见的深度学习模型
全连接神经网络(MLP/DNN)
卷积神经网络 (CNN)
循环神经网络(RNN)
Transformer(当前主流架构)
Diffusion(扩散模型)
深度强化学习(DRL)
图神经网络(GNN)
应用场景
2.NLP
3.多模态
4.推荐系统
数据知识
线性代数:掌握标量、向量、矩阵、张量、范数
导数和微分:理解导数定义,掌握常用求导公式
https://blog.csdn.net/i_k_o_x_s/article/details/159999903?spm=1001.2014.3001.5502
二、Pytorch 安装
官网: https://pytorch.org/get-started/locally/

conda -> 环境变量 -> pip install ... (官网根据设备安装命令)
安装GPU 版本。工业级
GPU显卡内存 >= 4G

=========================================================================
三、Pytorch 初始化张量

float32 和 int64 比较常用。也是默认的。
参数:
维度: ndim
形状: shape
类型: dtype
设备:device 指的是现在是 cpu还是cuda -> Mac M系列 用mps
梯度计算: requires_grad 是否开启梯队计算
python
t1 = torch.tensor(1,device=torch.device('mps'))
print(f'0D张量:{t1},维度:{t1.ndim},shape:{t1.shape},type:{t1.dtype},device:{t1.device},requires_grad:{t1.requires_grad}')
torch.tensor 小写创建
大写 -> 指定类型张量 比小写多带一个形状
python
t1_1_1 = torch.IntTensor(2,4,6)
print(f'3D张量:{t1_1_1},维度:{t1_1_1.ndim},shape:{t1_1_1.shape},type:{t1_1_1.dtype}')
Tensor
torch.IntTensor float->int的时候,只保留整数部分
torch.DoubleTensor
torch.FloatTensor
torch.LongTensor
创建 线性和随机 张量 以及类型转换
1. arange
python
# 从0-9个线性张量
# arange(start,end,step):区间是[start,end)
t1 = torch.arange(0,10)
2. linspace
python
# 0-10之间 生成steps = 10 10个数,默认是等差 生成
# 区间[start, end],注意steps表示的是元素个数
t2 = torch.linspace(0,10,steps=10)
3. manual_seed
python
# 随机种子
# [0,1) 间 浮点数创建
torch.manual_seed(1003)
t3 = torch.rand(2,3)
4. randn
python
# 均值0,方差数。正态分布 (-无穷 到 + 无穷) 默认浮点
t4 = torch.randn(2,3)
5. randint
python
# randint(low,high,size):区间是[low,high)
t5 = torch.randint(0,10,(2,3))
6. 指定值创建 ones. zeros. full
python
# 默认 浮点
t6 = torch.ones(2,3,4)
t6 = torch.zeros(2,3,4)
t6 = torch.full(
size=[2,3,4],
fill_value=999)
7. 模仿创建 ones_like. zeros_like. full_like
python
# like 模型形状
# fill_value 指定值
# ones 全1
# zeros 全0
t7 = torch.ones_like(t6)
t7 = torch.zeros_like(t6)
t7 = torch.full_like(t6,fill_value=666)
8. 类型转换 to. type. (tourch.int64) ......
python
t2 = torch.tensor([2.,3.,4.])
t2_2 = t2.to(torch.int64)
t2_3 = t2.long()
t2_4 = t2.type(dtype=torch.int16)
9. cpi. cuda(cpu). msp(mac M系列)
python
device = torch.device(
'cuda' if torch.cuda.is_available()
else 'mps' if torch.backends.mps.is_available()
else 'cpu')
device_mps = torch.device('mps')
t1 = torch.tensor(1)
t2 = torch.tensor(1)
t1 = t1.to(device)
print(f'device:{t1.device}')
t2 = t2.to(device_mps)
print(f'device:{t2.device}')