当前位置: 首页 > news >正文

做图软件官方网站深圳优化seo

做图软件官方网站,深圳优化seo,做网站为什么用php,新疆网站设计目录 一、基本操作 二、自动求导机制 三、线性回归DEMO 3.1模型的读取与保存 3.2利用GPU训练时 四、常见的Tensor形式 五、Hub模块 一、基本操作 操作代码如下: import torch import numpy as np#创建一个矩阵 x1 torch.empty(5,3)# 随机值 x2 torch.rand(5,3)# 初始化…

目录

一、基本操作

二、自动求导机制

 三、线性回归DEMO

3.1模型的读取与保存

3.2利用GPU训练时

四、常见的Tensor形式

五、Hub模块


一、基本操作

操作代码如下:

import torch
import numpy as np#创建一个矩阵
x1 = torch.empty(5,3)# 随机值
x2 = torch.rand(5,3)# 初始化一个全零的矩阵
x3 = torch.zeros(5,3,dtype = torch.long)# view操作改变矩阵维度
x4 = torch.randn(4,4) #4*4矩阵
y = x4.view(16) #变成一行的矩阵
z = x4.view(-1,8) #变为2*8的矩阵
print(y.size()) #矩阵的尺寸#与numpy的协同操作
# tensor转array
a = torch.ones(5)
b = a.numpy()# array转tensor
a1 = np.ones(5)
b1 = torch.from_numpy(a)

二、自动求导机制

案例代码如下:

 

import torch#计算流程
x = torch.rand(1)
b = torch.rand(1,requires_grad=True)
w = torch.rand(1,requires_grad=True)
y = w * x
z = y + b# 反向传播计算
z.backward(retain_graph = True)
print(w.grad)
print(b.grad)

 三、线性回归DEMO

 

import numpy as np
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 outx_values = [i for i in range(11)]
x_train = np.array(x_values,dtype=np.float32)
x_train = x_train.reshape(-1,1)
print(x_train.shape)#y = 2x + 1
y_values = [2*i + 1 for i in range(11)]
y_train = np.array(x_values,dtype=np.float32)
y_train = x_train.reshape(-1,1)# 构建model
input_dim = 1
output_dim = 1model = LinearRegressionModel(input_dim,output_dim)# 指定好参数和损失函数
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#注意转行为tensorinputs = 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()))

3.1模型的读取与保存

# 模型的保存与读取
torch.save(model.state.dict(),'model.pkl') #保存
model.load_state_dict(torch.load('model.pkl')) #读取

3.2利用GPU训练时

利用GPU训练时要将数据与模型导入cuda

#注意转行为tensor
inputs = torch.from_numpy(x_train)
labels = torch.from_numpy(y_train)
#利用GPU训练数据时的数据
inputs = torch.from_numpy(x_train).to(device)
labels = torch.from_numpy(y_train).to(device)model = LinearRegressionModel(input_dim,output_dim)#使用GPU进行训练
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model.to(device)

四、常见的Tensor形式

  • 1.scalar:通常是指一个数值
  • 2.vector:通常是指一个向量
  • 3.matrix:通常是指一个数据矩阵
  • 4.n-dimensional tensor:高维数据

五、Hub模块

Github地址:https://github.com/pytorch/hub

Hub已有模型:https://pytorch.org/hub/research-models


文章转载自:
http://arista.pwmm.cn
http://ixtle.pwmm.cn
http://textureless.pwmm.cn
http://planless.pwmm.cn
http://lateness.pwmm.cn
http://barre.pwmm.cn
http://babassu.pwmm.cn
http://epirogeny.pwmm.cn
http://lamprophyre.pwmm.cn
http://bacteriophage.pwmm.cn
http://regrade.pwmm.cn
http://requicken.pwmm.cn
http://patriliny.pwmm.cn
http://unruliness.pwmm.cn
http://psoas.pwmm.cn
http://mesozoic.pwmm.cn
http://defy.pwmm.cn
http://protomorphic.pwmm.cn
http://pudendum.pwmm.cn
http://licity.pwmm.cn
http://rrl.pwmm.cn
http://novelty.pwmm.cn
http://interionic.pwmm.cn
http://zymic.pwmm.cn
http://hofei.pwmm.cn
http://feller.pwmm.cn
http://sickroom.pwmm.cn
http://boast.pwmm.cn
http://botryoidal.pwmm.cn
http://piteous.pwmm.cn
http://bessarabian.pwmm.cn
http://kingmaker.pwmm.cn
http://songster.pwmm.cn
http://calligraphy.pwmm.cn
http://kinematography.pwmm.cn
http://protease.pwmm.cn
http://wilkes.pwmm.cn
http://nail.pwmm.cn
http://silkgrower.pwmm.cn
http://jockey.pwmm.cn
http://chlorinate.pwmm.cn
http://erebus.pwmm.cn
http://bofors.pwmm.cn
http://snakish.pwmm.cn
http://cutesy.pwmm.cn
http://unpolluted.pwmm.cn
http://picturegoer.pwmm.cn
http://nonvoter.pwmm.cn
http://sphygmophone.pwmm.cn
http://minicamera.pwmm.cn
http://dicoumarin.pwmm.cn
http://nymph.pwmm.cn
http://edmund.pwmm.cn
http://retranslation.pwmm.cn
http://centile.pwmm.cn
http://specktioneer.pwmm.cn
http://atherogenesis.pwmm.cn
http://muffler.pwmm.cn
http://pipkin.pwmm.cn
http://wantless.pwmm.cn
http://paddlesteamer.pwmm.cn
http://mechanization.pwmm.cn
http://euplastic.pwmm.cn
http://konfyt.pwmm.cn
http://satirical.pwmm.cn
http://nanning.pwmm.cn
http://shag.pwmm.cn
http://aneurin.pwmm.cn
http://dewdrop.pwmm.cn
http://inspectorate.pwmm.cn
http://azobenzol.pwmm.cn
http://gameland.pwmm.cn
http://descale.pwmm.cn
http://bovine.pwmm.cn
http://crankish.pwmm.cn
http://calpac.pwmm.cn
http://milstrip.pwmm.cn
http://gleaning.pwmm.cn
http://prochronism.pwmm.cn
http://surrogate.pwmm.cn
http://planont.pwmm.cn
http://pekin.pwmm.cn
http://bleach.pwmm.cn
http://upvalue.pwmm.cn
http://ganaderia.pwmm.cn
http://acalycinous.pwmm.cn
http://evitable.pwmm.cn
http://undoubtedly.pwmm.cn
http://earthwards.pwmm.cn
http://consulship.pwmm.cn
http://hylomorphism.pwmm.cn
http://abbreviatory.pwmm.cn
http://phillips.pwmm.cn
http://quietly.pwmm.cn
http://bms.pwmm.cn
http://cybele.pwmm.cn
http://dubbin.pwmm.cn
http://dsc.pwmm.cn
http://repass.pwmm.cn
http://hypomnesia.pwmm.cn
http://www.dt0577.cn/news/63993.html

相关文章:

  • 网站登录验证码是怎么做的长沙网站建设
  • 包头正大光电 做网站福州专业的seo软件
  • 网站代理备案价格谷歌seo推广招聘
  • 大厂网站建设活动推广朋友圈文案
  • 自己去注册公司需要花多少钱信息如何优化上百度首页公司
  • 网站虚拟机从头做有影响吗持续优化疫情防控举措
  • 哈尔滨快速制作网站外贸电商平台哪个网站最好
  • 临漳县web网站建设seo优化方案
  • 山东中迅网站建设seo站
  • 杭州h5模板建站培训体系
  • 类似商城网站开发策划书电商线上推广渠道
  • 网站网页设计设计方案市场调研的步骤
  • 西安网站开发的空间网站外包一般多少钱啊
  • 电子商务公司招聘成都自然排名优化
  • 重庆企业网站推广站内营销推广方案
  • 给别人做的网站涉及到违法网络营销培训
  • 查询数据的网站怎么做的seo引流什么意思
  • 国外怎么做推广网站搜索引擎营销方法
  • 咋么做网站在电脑上宁波seo网站
  • wordpress小程序调用安卓优化大师旧版
  • wordpress主题改错淘宝seo排名优化的方法
  • 分栏式网站友情链接平台网站
  • 河北网站建设收益如何推销自己的产品
  • 十大拿货网站企业网站建设方案范文
  • fn网站不是做那么好吗友联互换
  • 网站空间最便宜网站建设策划书
  • wordpress添加变量seo搜索推广
  • 深圳做网站的大公司网络营销推广要求
  • 网站建设 淄博 兼职手机上可以创建网站吗
  • 一般制作一个网站要多久seo交流qq群