pytorch

news2025/3/13 18:23:25

PyTorch基础

import torch
torch.__version__ #return '1.13.1+cu116'

基本使用方法

矩阵

x = torch.empty(5, 3)
		tensor([[1.4586e-19, 1.1578e+27, 2.0780e-07],
		        [6.0542e+22, 7.8675e+34, 4.6894e+27],
		        [1.6217e-19, 1.4333e-19, 2.7530e+12],
		        [7.5338e+28, 8.1173e-10, 4.3861e-43],
		        [2.8912e-03, 4.3861e-43, 2.8912e-03]])
		        

随机值

x = torch.rand(5, 3)#5行三列的随机值
		tensor([[0.1511, 0.6433, 0.1245],
		        [0.8949, 0.8577, 0.3564],
		        [0.7810, 0.5037, 0.7101],
		        [0.1997, 0.4917, 0.1746],
		        [0.4288, 0.9921, 0.4862]])		

初始化一个全零的矩阵

x = torch.zeros(5, 3, dtype=torch.long)
		tensor([[0, 0, 0],
		        [0, 0, 0],
		        [0, 0, 0],
		        [0, 0, 0],
		        [0, 0, 0]])

直接传入数据

x = torch.tensor([5.5, 3])
tensor([5.5000, 3.0000])
x = x.new_ones(5, 3, dtype=torch.double)    
		tensor([[1., 1., 1.],
		        [1., 1., 1.],
		        [1., 1., 1.],
		        [1., 1., 1.],
		        [1., 1., 1.]], dtype=torch.float64)		
x = torch.randn_like(x, dtype=torch.float) #返回一个x大小相同的张量,其由均值为0、方差为1的标准正态分布填充
		tensor([[ 0.6811, -1.2104, -1.2676],
		        [-0.3295,  0.1155, -0.5736],
		        [-1.3656, -0.4973, -0.7043],
		        [-1.3670, -0.3296,  3.1743],
		        [ 1.3443,  0.3373,  0.6182]])   
		        

展示矩阵大小

x.size()
		torch.Size([5, 3])

基本计算方法

y = torch.rand(5, 3)#随机5行三列矩阵
		tensor([[0.0542, 0.9674, 0.5902],
		        [0.7749, 0.1682, 0.2871],
		        [0.1747, 0.3728, 0.2077],
		        [0.9092, 0.3087, 0.3981],
		        [0.4231, 0.8725, 0.6005]])
x		        
		tensor([[ 0.6811, -1.2104, -1.2676],
		        [-0.3295,  0.1155, -0.5736],
		        [-1.3656, -0.4973, -0.7043],
		        [-1.3670, -0.3296,  3.1743],
		        [ 1.3443,  0.3373,  0.6182]])	
x + y
		tensor([[ 0.7353, -0.2430, -0.6774],
		        [ 0.4454,  0.2837, -0.2865],
		        [-1.1908, -0.1245, -0.4967],
		        [-0.4578, -0.0209,  3.5723],
		        [ 1.7674,  1.2098,  1.2187]])	
torch.add(x, y)#一样的也是加法
		tensor([[ 0.7353, -0.2430, -0.6774],
		        [ 0.4454,  0.2837, -0.2865],
		        [-1.1908, -0.1245, -0.4967],
		        [-0.4578, -0.0209,  3.5723],
		        [ 1.7674,  1.2098,  1.2187]])			        	        	        

索引

x[:, 1]
		tensor([-1.2104,  0.1155, -0.4973, -0.3296,  0.3373])		

x.view() 类似于reshape(),重塑维度

x = torch.randn(4, 4)
		tensor([[ 0.1811, -1.4025, -1.2865, -1.6370],
		        [-0.2279,  1.0993, -0.4067, -0.2652],
		        [-0.5673,  0.2697,  1.8822, -1.3748],
		        [-0.3731, -0.9595,  1.8725, -0.8774]])
y = x.view(16)
		tensor([-0.3035, -2.5819,  1.2449, -0.3448,  1.0095, -0.1734,  1.5666,  0.5170,
		        -1.0587,  0.1241, -0.5550, -1.6905,  0.8625, -1.3681, -0.1491,  0.2202])	
z = x.view(-1, 8) #-1是值得注意的,x中总共16个元素,现在定义一行是8列(8个元素),16/8 = 2,所以是2行
		tensor([[-0.3035, -2.5819,  1.2449, -0.3448,  1.0095, -0.1734,  1.5666,  0.5170],
		        [-1.0587,  0.1241, -0.5550, -1.6905,  0.8625, -1.3681, -0.1491,  0.2202]])
print(x.size(), y.size(), z.size())
		torch.Size([4, 4]) torch.Size([16]) torch.Size([2, 8])

与Numpy的协同操作(互转)

a = torch.ones(5)
		tensor([1., 1., 1., 1., 1.])
b = a.numpy()
		array([1., 1., 1., 1., 1.], dtype=float32)

import numpy as np
a = np.ones(5)
		array([1., 1., 1., 1., 1.])
b = torch.from_numpy(a)
		tensor([1., 1., 1., 1., 1.], dtype=torch.float64)

autograb机制

需要求导的,可以手动定义:

x = torch.randn(3,4)#torch.randn:用来生成随机数字的tensor,这些随机数字满足标准正态分布(0~1)
		tensor([[-1.5885,  0.6992, -0.2198,  1.2736],
		        [ 0.6211, -0.3729,  0.1261,  1.4094],
		        [ 0.7418, -0.2801, -0.0672, -0.5614]])
x = torch.randn(3,4,requires_grad=True)
		tensor([[ 0.9318, -1.0761,  0.6794,  1.2261],
		        [-1.7192, -0.6009, -0.3852,  0.2492],
		        [-0.1853,  0.2066,  0.9497, -0.3329]], requires_grad=True)
#方法2
x = torch.randn(3,4)
x.requires_grad=True
		tensor([[-1.9635,  0.5769,  1.2705, -0.8758],
		        [ 1.2847, -1.0498, -0.3650, -0.5059],
		        [ 0.2780,  0.0816,  0.7754,  0.2048]], requires_grad=True)	   
b = torch.randn(3,4,requires_grad=True)
t = x + b
y = t.sum()
		tensor(4.4444, grad_fn=<SumBackward0>)
y.backward()
b.grad
		tensor([[1., 1., 1., 1.],
		        [1., 1., 1., 1.],
		        [1., 1., 1., 1.]])		
虽然没有指定t的requires_grad但是需要用到它,也会默认的
x.requires_grad, b.requires_grad, t.requires_grad#return (True, True, True)		        
     		        

在这里插入图片描述

#计算流程
x = torch.rand(1)
b = torch.rand(1, requires_grad = True)
w = torch.rand(1, requires_grad = True)
y = w * x 
z = y + b 
x.requires_grad, b.requires_grad, w.requires_grad, y.requires_grad#注意y也是需要的
		(False, True, True, True)
x.is_leaf, w.is_leaf, b.is_leaf, y.is_leaf, z.is_leaf
		(True, True, True, False, False)	
返向传播计算
z.backward(retain_graph=True)#如果不清空会累加起来
w.grad 累加后的结果
		tensor([1.6244])
b.grad
		tensor([2.])
	

做一个线性回归

构造一组输入数据X和其对应的标签y
x_values = [i for i in range(11)]
x_train = np.array(x_values, dtype=np.float32)
x_train = x_train.reshape(-1, 1)
x_train.shape #return (11, 1)

y_values = [2*i + 1 for i in x_values]
y_train = np.array(y_values, dtype=np.float32)
y_train = y_train.reshape(-1, 1)
y_train.shape# (11, 1)

import torch
import torch.nn as nn
线性回归模型:其实线性回归就是一个不加激活函数的全连接层
class LinearRegressionModel(nn.Module):
    def __init__(self, input_dim, output_dim):
        super(LinearRegressionModel, self).__init__()
        self.linear = nn.Linear(input_dim, output_dim)  

    def forward(self, x):#前向传播
        out = self.linear(x)
        return out
input_dim = 1
output_dim = 1

model = LinearRegressionModel(input_dim, output_dim)
		LinearRegressionModel(
		  (linear): Linear(in_features=1, out_features=1, bias=True)
		)
指定好参数和损失函数
epochs = 1000  #执行次数
learning_rate = 0.01 #准确率
optimizer = torch.optim.SGD(model.parameters(), lr=learning_rate)#优化模型
criterion = nn.MSELoss()#绝对值损失函数是计算预测值与目标值的差的绝对值
训练模型
for epoch in range(epochs):
    epoch += 1
    # 注意转行成tensor
    inputs = torch.from_numpy(x_train)
    labels = torch.from_numpy(y_train)

    # 梯度要清零每一次迭代
    optimizer.zero_grad() 

    # 前向传播
    outputs = model(inputs)

    # 计算损失
    loss = criterion(outputs, labels)

    # 返向传播
    loss.backward()

    # 更新权重参数
    optimizer.step()
    if epoch % 50 == 0:
        print('epoch {}, loss {}'.format(epoch, loss.item()))
				epoch 50, loss 0.4448287785053253
				epoch 100, loss 0.25371354818344116
				epoch 150, loss 0.14470864832401276
				epoch 200, loss 0.08253632485866547
				epoch 250, loss 0.04707561805844307
				epoch 300, loss 0.026850251480937004
				epoch 350, loss 0.015314370393753052
				epoch 400, loss 0.008734731003642082
				epoch 450, loss 0.004981952253729105
				epoch 500, loss 0.002841521752998233
				epoch 550, loss 0.0016206930158659816
				epoch 600, loss 0.0009243797394447029
				epoch 650, loss 0.0005272324196994305
				epoch 700, loss 0.0003007081104442477
				epoch 750, loss 0.00017151293286588043
				epoch 800, loss 9.782632696442306e-05
				epoch 850, loss 5.579544449574314e-05
				epoch 900, loss 3.182474029017612e-05
				epoch 950, loss 1.8151076801586896e-05
				epoch 1000, loss 1.0352457138651516e-05        
测试模型预测结果
predicted = model(torch.from_numpy(x_train).requires_grad_()).data.numpy()
		array([[ 0.99918383],
		       [ 2.9993014 ],
		       [ 4.9994187 ],
		       [ 6.9995365 ],
		       [ 8.999654  ],
		       [10.999771  ],
		       [12.999889  ],
		       [15.000007  ],
		       [17.000124  ],
		       [19.000242  ],
		       [21.000359  ]], dtype=float32)
模型的保存与读取
torch.save(model.state_dict(), 'model.pkl')
model.load_state_dict(torch.load('model.pkl'))
		<All keys matched successfully>

使用GPU进行训练:只需要把数据和模型传入到cuda里面就可以了

import torch
import torch.nn as nn
import numpy as np


class LinearRegressionModel(nn.Module):
    def __init__(self, input_dim, output_dim):
        super(LinearRegressionModel, self).__init__()
        self.linear = nn.Linear(input_dim, output_dim)  

    def forward(self, x):
        out = self.linear(x)
        return out

input_dim = 1
output_dim = 1

model = LinearRegressionModel(input_dim, output_dim)

######使用GPU还是CPU
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model.to(device)


criterion = nn.MSELoss()


learning_rate = 0.01

optimizer = torch.optim.SGD(model.parameters(), lr=learning_rate)

epochs = 1000
for epoch in range(epochs):
    epoch += 1
    ####加上.to(device)
    inputs = torch.from_numpy(x_train).to(device)
    labels = torch.from_numpy(y_train).to(device)

    optimizer.zero_grad() 

    outputs = model(inputs)

    loss = criterion(outputs, labels)

    loss.backward()

    optimizer.step()

    if epoch % 50 == 0:
        print('epoch {}, loss {}'.format(epoch, loss.item()))
				epoch 50, loss 0.011100251227617264
				epoch 100, loss 0.006331132724881172
				epoch 150, loss 0.003611058695241809
				epoch 200, loss 0.0020596047397702932
				epoch 250, loss 0.0011747264070436358
				epoch 300, loss 0.0006700288504362106
				epoch 350, loss 0.00038215285167098045
				epoch 400, loss 0.00021796672081109136
				epoch 450, loss 0.00012431896175257862
				epoch 500, loss 7.090995495673269e-05
				epoch 550, loss 4.044298475491814e-05
				epoch 600, loss 2.3066799258231185e-05
				epoch 650, loss 1.3156819477444515e-05
				epoch 700, loss 7.503344477299834e-06
				epoch 750, loss 4.279831500753062e-06
				epoch 800, loss 2.4414177914877655e-06
				epoch 850, loss 1.3924694712841301e-06
				epoch 900, loss 7.945647553242452e-07
				epoch 950, loss 4.530382398115762e-07
				epoch 1000, loss 2.5830334493548435e-07        

Tensor常见的形式

0: scalar:通常就是一个数值
1: vector:例如: [-5., 2., 0.],在深度学习中通常指特征,例如词向量特征,某一维度特征等
2: matrix:一般计算的都是矩阵,通常都是多维的
3: n-dimensional tensor:


Scalar

x = tensor(42.)
		tensor(42.)
x.dim()
		0		

Vector

一维向量
v = tensor([1.5, -0.5, 3.0])
		tensor([ 1.5000, -0.5000,  3.0000])
v.dim()
		1
v.size()
		torch.Size([3])		

Matrix

M = tensor([[1., 2.], [3., 4.]])
	tensor([[1., 2.],
	        [3., 4.]])
M.matmul(M)#矩阵乘法
		tensor([[ 7., 10.],
		        [15., 22.]])	        

几种形状的Tensor

在这里插入图片描述

强大hub模块

GITHUB:https://github.com/pytorch/hub
模型:https://pytorch.org/hub/research-models

import torch
model = torch.hub.load('pytorch/vision:v0.4.2', 'deeplabv3_resnet101', pretrained=True)
model.eval()

torch.hub.list('pytorch/vision:v0.4.2')

# Download an example image from the pytorch website
import urllib
url, filename = ("https://github.com/pytorch/hub/raw/master/dog.jpg", "dog.jpg")
try: urllib.URLopener().retrieve(url, filename)
except: urllib.request.urlretrieve(url, filename)

# sample execution (requires torchvision)
from PIL import Image
from torchvision import transforms
input_image = Image.open(filename)
preprocess = transforms.Compose([
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])

input_tensor = preprocess(input_image)
input_batch = input_tensor.unsqueeze(0) # create a mini-batch as expected by the model

# move the input and model to GPU for speed if available
if torch.cuda.is_available():
    input_batch = input_batch.to('cuda')
    model.to('cuda')

with torch.no_grad():
    output = model(input_batch)['out'][0]
output_predictions = output.argmax(0)

# create a color pallette, selecting a color for each class
palette = torch.tensor([2 ** 25 - 1, 2 ** 15 - 1, 2 ** 21 - 1])
colors = torch.as_tensor([i for i in range(21)])[:, None] * palette
colors = (colors % 255).numpy().astype("uint8")

# plot the semantic segmentation predictions of 21 classes in each color
r = Image.fromarray(output_predictions.byte().cpu().numpy()).resize(input_image.size)
r.putpalette(colors)

import matplotlib.pyplot as plt
plt.imshow(r)
plt.show()

在这里插入图片描述

神经网络实战分类与回归任务

神经网络进行气温预测

import numpy as np
import pandas as pd 
import matplotlib.pyplot as plt
import torch
import torch.optim as optim
import warnings
warnings.filterwarnings("ignore")
%matplotlib inline
#(1)数据获取
features = pd.read_csv('temps.csv')
#看看数据长什么样子
features.head()

在这里插入图片描述

print('数据维度:', features.shape)#数据维度: (348, 9)
# 处理时间数据
import datetime
# 分别得到年,月,日
years = features['year']
months = features['month']
days = features['day']

# datetime格式
dates = [str(int(year)) + '-' + str(int(month)) + '-' + str(int(day)) for year, month, day in zip(years, months, days)]
dates = [datetime.datetime.strptime(date, '%Y-%m-%d') for date in dates]

dates[:5]
	[datetime.datetime(2016, 1, 1, 0, 0),
	 datetime.datetime(2016, 1, 2, 0, 0),
	 datetime.datetime(2016, 1, 3, 0, 0),
	 datetime.datetime(2016, 1, 4, 0, 0),
	 datetime.datetime(2016, 1, 5, 0, 0)]

# 准备画图
# 指定默认风格
plt.style.use('fivethirtyeight')

# 设置布局
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2, figsize = (10,10))
fig.autofmt_xdate(rotation = 45)

# 标签值
ax1.plot(dates, features['actual'])
ax1.set_xlabel(''); ax1.set_ylabel('Temperature'); ax1.set_title('Max Temp')

# 昨天
ax2.plot(dates, features['temp_1'])
ax2.set_xlabel(''); ax2.set_ylabel('Temperature'); ax2.set_title('Previous Max Temp')

# 前天
ax3.plot(dates, features['temp_2'])
ax3.set_xlabel('Date'); ax3.set_ylabel('Temperature'); ax3.set_title('Two Days Prior Max Temp')

# 我的逗逼朋友
ax4.plot(dates, features['friend'])
ax4.set_xlabel('Date'); ax4.set_ylabel('Temperature'); ax4.set_title('Friend Estimate')

plt.tight_layout(pad=2)

在这里插入图片描述

# 独热编码  将字符串转化为特定的数字,数字编码
features = pd.get_dummies(features)
features.head(5)

在这里插入图片描述

# 标签
labels = np.array(features['actual'])

# 在特征中去掉标签
features= features.drop('actual', axis = 1)

# 名字单独保存一下,以备后患
feature_list = list(features.columns)

# 转换成合适的格式
features = np.array(features)
features.shape#(348, 14)

from sklearn import preprocessing
input_features = preprocessing.StandardScaler().fit_transform(features)
input_features[0]
		array([ 0.        , -1.5678393 , -1.65682171, -1.48452388, -1.49443549,
		       -1.3470703 , -1.98891668,  2.44131112, -0.40482045, -0.40961596,
		       -0.40482045, -0.40482045, -0.41913682, -0.40482045])		      

构建网络模型

x = torch.tensor(input_features, dtype = float)

y = torch.tensor(labels, dtype = float)

# 权重参数初始化
weights = torch.randn((14, 128), dtype = float, requires_grad = True) 
biases = torch.randn(128, dtype = float, requires_grad = True) 
weights2 = torch.randn((128, 1), dtype = float, requires_grad = True) 
biases2 = torch.randn(1, dtype = float, requires_grad = True) 

learning_rate = 0.001 
losses = []

for i in range(1000):
    # 计算隐层
    hidden = x.mm(weights) + biases
    # 加入激活函数
    hidden = torch.relu(hidden)
    # 预测结果
    predictions = hidden.mm(weights2) + biases2
    # 通计算损失
    loss = torch.mean((predictions - y) ** 2) 
    losses.append(loss.data.numpy())
    
    # 打印损失值
    if i % 100 == 0:
        print('loss:', loss)
    #返向传播计算
    loss.backward()
    
    #更新参数
    weights.data.add_(- learning_rate * weights.grad.data)  
    biases.data.add_(- learning_rate * biases.grad.data)
    weights2.data.add_(- learning_rate * weights2.grad.data)
    biases2.data.add_(- learning_rate * biases2.grad.data)
    
    # 每次迭代都得记得清空
    weights.grad.data.zero_()
    biases.grad.data.zero_()
    weights2.grad.data.zero_()
    biases2.grad.data.zero_()
		loss: tensor(8347.9924, dtype=torch.float64, grad_fn=<MeanBackward0>)
		loss: tensor(152.3170, dtype=torch.float64, grad_fn=<MeanBackward0>)
		loss: tensor(145.9625, dtype=torch.float64, grad_fn=<MeanBackward0>)
		loss: tensor(143.9453, dtype=torch.float64, grad_fn=<MeanBackward0>)
		loss: tensor(142.8161, dtype=torch.float64, grad_fn=<MeanBackward0>)
		loss: tensor(142.0664, dtype=torch.float64, grad_fn=<MeanBackward0>)
		loss: tensor(141.5386, dtype=torch.float64, grad_fn=<MeanBackward0>)
		loss: tensor(141.1528, dtype=torch.float64, grad_fn=<MeanBackward0>)
		loss: tensor(140.8618, dtype=torch.float64, grad_fn=<MeanBackward0>)
		loss: tensor(140.6318, dtype=torch.float64, grad_fn=<MeanBackward0>)
predictions.shape #torch.Size([348, 1])			

更简单的构建网络模型

input_size = input_features.shape[1]
hidden_size = 128
output_size = 1
batch_size = 16
my_nn = torch.nn.Sequential(
    torch.nn.Linear(input_size, hidden_size),
    torch.nn.Sigmoid(),
    torch.nn.Linear(hidden_size, output_size),
)
cost = torch.nn.MSELoss(reduction='mean')
optimizer = torch.optim.Adam(my_nn.parameters(), lr = 0.001)

# 训练网络
losses = []
for i in range(1000):
    batch_loss = []
    # MINI-Batch方法来进行训练
    for start in range(0, len(input_features), batch_size):
        end = start + batch_size if start + batch_size < len(input_features) else len(input_features)
        xx = torch.tensor(input_features[start:end], dtype = torch.float, requires_grad = True)
        yy = torch.tensor(labels[start:end], dtype = torch.float, requires_grad = True)
        prediction = my_nn(xx)
        loss = cost(prediction, yy)
        optimizer.zero_grad()
        loss.backward(retain_graph=True)
        optimizer.step()
        batch_loss.append(loss.data.numpy())
    
    # 打印损失
    if i % 100==0:
        losses.append(np.mean(batch_loss))
        print(i, np.mean(batch_loss))
				0 3950.7627
				100 37.9201
				200 35.654438
				300 35.278366
				400 35.116814
				500 34.986076
				600 34.868954
				700 34.75414
				800 34.637356
				900 34.516705
预测训练结果
x = torch.tensor(input_features, dtype = torch.float)
predict = my_nn(x).data.numpy()

# 转换日期格式
dates = [str(int(year)) + '-' + str(int(month)) + '-' + str(int(day)) for year, month, day in zip(years, months, days)]
dates = [datetime.datetime.strptime(date, '%Y-%m-%d') for date in dates]

# 创建一个表格来存日期和其对应的标签数值
true_data = pd.DataFrame(data = {'date': dates, 'actual': labels})

# 同理,再创建一个来存日期和其对应的模型预测值
months = features[:, feature_list.index('month')]
days = features[:, feature_list.index('day')]
years = features[:, feature_list.index('year')]

test_dates = [str(int(year)) + '-' + str(int(month)) + '-' + str(int(day)) for year, month, day in zip(years, months, days)]

test_dates = [datetime.datetime.strptime(date, '%Y-%m-%d') for date in test_dates]

predictions_data = pd.DataFrame(data = {'date': test_dates, 'prediction': predict.reshape(-1)}) 

# 真实值
plt.plot(true_data['date'], true_data['actual'], 'b-', label = 'actual')

# 预测值
plt.plot(predictions_data['date'], predictions_data['prediction'], 'ro', label = 'prediction')
plt.xticks(rotation = '60'); 
plt.legend()

# 图名
plt.xlabel('Date'); plt.ylabel('Maximum Temperature (F)'); plt.title('Actual and Predicted Values');

在这里插入图片描述

在这里插入图片描述

神经网络分类任务

Mnist分类任务

在这里插入图片描述

torch.nn.functional

在这里插入图片描述

创建一个model来更简化代码

在这里插入图片描述

使用TensorDataset和DataLoader来简化

在这里插入图片描述

卷积神经网络

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

残差网络 (ResNets)

在这里插入图片描述

卷积神经网络效果(conv) cnn

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/335150.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

数据库中的 ACID 属性

&#x1f482; 个人网站:【海拥】【摸鱼游戏】【神级源码资源网】&#x1f91f; 前端学习课程&#xff1a;&#x1f449;【28个案例趣学前端】【400个JS面试题】&#x1f485; 想寻找共同学习交流、摸鱼划水的小伙伴&#xff0c;请点击【摸鱼学习交流群】 大多数使用数据库的程…

扩散模型用于图像恢复任务详细介绍 (去雨,去雾等皆可),附实现代码

文章目录1. 去噪扩散概率模型2. 前向扩散3. 反向采样3. 图像条件扩散模型4. 可以考虑改进的点5. 实现代码1. 去噪扩散概率模型 扩散模型是一类生成模型, 和生成对抗网络GAN 、变分自动编码器VAE和标准化流模型NFM等生成网络不同的是, 扩散模型在前向扩散过程中对图像逐步施加噪…

C++11--右值引用与移动语义

目录 基本概念 左值与右值 左值引用与右值引用 右值引用的使用场景和意义 左值引用的使用场景 右值引用和移动语义 移动构造和拷贝构造的区别 编译器的优化 移动赋值和赋值运算符重载的区别 右值引用的其他应用场景 完美转发 万能引用 完美转发保持值属性 完美转…

2023互联网相关岗位转行与就业选择的简单分析

文章目录1、城市2、岗位1、城市 能找得到工作的城市&#xff0c;可能主要也就这些base了 2、岗位 主要技术岗位 Python 侧重人工智能&#xff0c;人工智能门槛高大家心知肚明。如果学python 不走人工智能&#xff0c;只走单纯的后端开发&#xff0c;不管从薪资还是岗位数量…

SpringCloud微服务

一、微服务架构 1.1、单体应用架构 将项目所有模块(功能)打成jar或者war&#xff0c;然后部署一个进程 优点: 1:部署简单:由于是完整的结构体&#xff0c;可以直接部署在一个服务器上即可。 2:技术单一:项目不需要复杂的技术栈&#xff0c;往往一套熟悉的技术栈就可以完成开…

游戏服务器如何选择合适的服务器配置

游戏服务器如何选择合适的服务器配置 大家好&#xff0c;今天给大家分享一下游戏服务器配置的选择&#xff0c;为什么特别的说明一下服务器呢&#xff1f;服务器是决定服稳定性和安全性最重要的一个程序&#xff0c;如果是服务器配置不够&#xff0c;可能会导致服掉线、卡顿的…

完美解决同一条好友邀请信息给大量的人发,导致领英账号被封的方法?

做外贸的领英新人经常有一个问题&#xff1a;领英上添加好友时&#xff0c;同一条好友邀请信息给大量的人发&#xff0c;会导致领英账号被封吗&#xff1f;这是一个被一部分人所忽略&#xff0c;也在被一部分人所担心的问题&#xff0c;因为很多领英新手都是在复制粘贴发送相同…

Mybatis 2

Mybatis 动态 SQL MyBatis 的一个强大的特性之一通常是它的动态 SQL 能力。 如果你有使用 JDBC 或其他 相似框架的经验,你就明白条件地串联 SQL 字符串在一起是多么 的痛苦,确保不能忘了空格或在列表的最后省略逗号。动态 SQL 可以彻底处理 这种痛苦。 MyBatis 中用于实现动态…

项目管理_项目整合管理

项目整合管理 一、概述 整合管理是指为确保项目中各项工作&#xff0c;能够有机地协调和配合而展开的&#xff0c;综合性和全局性的项目管理工作和过程。包括项目集成计划的制订、项目集成计划的实施和项目变动总体控制等。 其作用犹如项链中的那根线&#xff1b; 项目整体管…

MySQL —— 表的增删改查(二)

目录 表的增删改查&#xff08;二&#xff09; 一、聚合函数 1. 统计班级有多少学生 2. 统计班级收集的qq号有多少 3. 统计本次考试的数学成绩分数个数&#xff08;去重&#xff09; 4. 统计数学成绩总分 5. 统计平均总分 6. 返回英语最高分 7. 返回 >70 分以上的…

Vue3 更高效的构建工具——Vite

文章目录前言一、Vite简介1. Vite组成2.为什么选 Vite?二、Vite的优缺点vite优点vite缺点三、使用Vite创建Vue3项目1. 创建 vite 的项目2.项目的结构前言 本文讲解了构建工具 Vite&#xff0c;目前只有vue3才可以使用Vite&#xff0c;如果本文对你有所帮助请三连支持博主。 下…

落枕、肩颈酸痛,用磁疗就可缓解!

睡觉之前还是好好的&#xff0c;一觉醒来脖子莫名疼痛&#xff0c;转都转不了&#xff0c;有时候连肩膀和上肢都难受&#xff0c;很可能是“落枕”了。 落枕引起的肩颈疼痛与多种因素有关&#xff0c;如颈肩部肌肉的过度使用、不良的睡眠姿势或颈肩部受寒湿空气的侵袭&#xff…

基于RFID技术的数据中心资产智能管理系统

一、项目背景数据中心日常运维的工作核心是以合适的成本来保障业务系统不间断运行&#xff0c;充分利用资源&#xff0c;因此承载这些业务的IT资产的管理和容量(资源)的有效管理显得尤为重要。另一方面&#xff0c;容量的规划和管理也直接决定了数据中心的管理水平。然而&#…

分布式文件系统介绍与minio介绍与使用(附minio java client 使用)

&#x1f340;&#x1f340;&#x1f340;&#x1f340;分布式文件系统-minio&#xff1a; 第一章&#xff1a;分布式文件系统介绍与minio介绍与使用&#xff08;附minio java client 使用&#xff09; 文章目录1.分布式文件系统基本概念1.1 文件系统1.2 分布式文件系统1.3 分布…

hbuilderx云打包苹果证书的生成和应用上架流程

使用hbuilder或apicloud等开发工具&#xff0c;打包ios应用的时候&#xff0c;需要苹果证书&#xff0c;而这个苹果证书是需要在mac电脑创建的&#xff0c;然后再去苹果开发者中心生成。这里关键是需要mac电脑&#xff0c;但是mac电脑的价格要7000多&#xff0c;为了创建一个证…

空间剪枝:使用自适应滤波器来改进稀疏CNN的训练

论文作者 | Paul Wimmer,Jens Mehnert and Alexandru Paul Condurache论文来源 | CVPR2022文章解读 | William一、摘要非结构化的剪枝非常适合在训练和推理时减少卷积神经网络(CNN)的内存占用。标准的非结构化剪枝(Standard unstructured Pruning&#xff0c;SP)通过将滤波器元…

体验了一下 ChatGPT,连连竖大拇指

近段时间&#xff0c;ChatGPT 真的是太火了&#xff0c;我也忍不住的去体验一把。体验了之后&#xff0c;怪不得 ChatGPT 最近火爆全网了&#xff0c;看得我连连竖起了我的大拇指&#xff0c;惊艳到我了~ ChatGPT 是什么&#xff1f; ChatGPT 是一款由 OpenAl 开发的语言模型…

Linux命令大全,赶紧收藏!

新的一年 新的征程 新的课程开班 等你来学&#xff01; 本文为Linux命令大全&#xff0c;从A到Z都有总结&#xff0c;建议大家收藏以便查用&#xff0c;或者查漏补缺&#xff01; A 命令 描述 access 用于检查调用程序是否可以访问指定的文件&#xff0c;用于检查文件…

Java笔记-内部类

目录1.内部类介绍&#xff08;1&#xff09;为啥需要内部类&#xff08;2&#xff09;内部类有&#xff1a;&#xff08;2.1&#xff09;成员内部类(2.2)静态内部类&#xff08;2.3&#xff09;局部内部类&#xff08;2.4&#xff09;匿名内部类权限符修饰规则1.内部类介绍 A类…

Linux尚硅谷

Linuxlinuxlinux课程介绍Linux进阶之路Linux基础篇交互虚拟机网络连接三种形式配置网络vmtools安装介绍vmtaools安装与使用Linux目录结构总结一下Linux实操篇远程登陆Linux系统xftp的安装和配置解决xftp中文乱码情况vi和vim编译器vi和vim常见三种模式三种模式相互转换vi与vim快…