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

网站首次备案 多久中国纪检监察报地址

网站首次备案 多久,中国纪检监察报地址,网站设计的原始资料,中国网站建设公司排行简介#xff1a; 主要介绍一下 sin(x)#xff1a; 为 数据 cos(x): 为对应的label 项目包括两个文件 main.py: 模型的训练#xff0c;验证#xff0c;参数保存 lstm.py 模型的构建 目录#xff1a; lstm.py main.py 一 lstm.py # -*- coding: utf-8 -*-主要介绍一下   sin(x)  为 数据 cos(x):   为对应的label 项目包括两个文件 main.py: 模型的训练验证参数保存 lstm.py 模型的构建 目录 lstm.py     main.py 一 lstm.py # -*- coding: utf-8 -*-Created on Tue Aug 8 14:01:15 2023author: chengxf2 import torch import torch.nn as nnclass LSTM(nn.Module):def __init__(self, input_dim, hidden_dim, num_lay, b_first):super(LSTM,self).__init__()self.lstm nn.LSTM(input_size input_dim, hidden_size hidden_dim, num_layers num_lay, batch_firstb_first)self.linear nn.Linear(hidden_dim, 1)def forward(self, X):#X.shape:[batch_size1, seq_num256, input_size1]output, (hidden, cell) self.lstm(X)outs []seq_num output.size(1)#output:[batch_size, seq_num, hidden_dim64]#hidden.shape[num_layer, batch_size, hiden_size]#print(\n output.shape,output.shape)#print(\n hidden.shape,hidden.shape)for time_step in range(seq_num):#h.shape[batch, hidden_dim]h output[:,time_step,:]#print(\n h,h.shape)out self.linear(h)outs.append(out)#沿着一个新维度对输入张量序列进行连接。 #[batch, seq_num, 1]pred torch.stack(outs, dim1)return pred 二  main.py import numpy as np from matplotlib import pyplot as plt import torch from lstm import LSTM import torch.nn as nn from torch.nn import functional as F from torch import optim import timedef showDiff(pred, label, steps):plt.figure()plt.rcParams[font.family] SimHei # 正常显示中文plt.title(预测值 and 真实值, fontsize18)plt.plot(steps, pred.cpu().data.numpy().flatten(),colorr,label预测值)plt.plot(steps, label.cpu().data.numpy().flatten(), colorg,label真实值)plt.legend(locbest)plt.show()def get_data(epoch):TIME_STEP 256start, end epoch*np.pi, epoch*np.pi2*np.pisteps np.linspace(start,end,TIME_STEP,dtypenp.float32)sin_x np.sin(steps)cos_x np.cos(steps)sinx_torch torch.from_numpy(sin_x[np.newaxis, :, np.newaxis])if torch.cuda.is_available():sinx_torch torch.from_numpy(sin_x[np.newaxis,:,np.newaxis]).cuda()# print(sinx_input.shape:,sinx_input.shape)cosx_lable torch.from_numpy(cos_x[np.newaxis, :, np.newaxis]).cuda()else:sinx_torch torch.from_numpy(sin_x[np.newaxis, :, np.newaxis])# print(sinx_input.shape:,sinx_input.shape)cosx_lable torch.from_numpy(cos_x[np.newaxis, :, np.newaxis])# [batch,seq_num,input_size] (1,256,1)return sinx_torch,cosx_lable,stepsdef eval(model):#等同于 self.train(False) 就是评估模式。#在评估模式下batchNorm层dropout层等用于优化训练而添加的网络层会被关闭从而使得评估时不会发生偏移model.eval()test_data,test_label,steps get_data(2)with torch.no_grad():y_pred model(test_data)showDiff(y_pred, test_label, steps)def train(model,maxIter,criterion):训练模型----------model : lstm 模型.maxIter : 迭代次数.criterion : 损失函数------#作用是启用 batch normalization 和 dropoutmodel.train()time_stamp time.time()for epoch in range(maxIter):sinx_torch,cosx_lable,steps get_data(epoch)y_pre model(sinx_torch) loss criterion(y_pre,cosx_lable)optimzer.zero_grad()loss.backward()optimzer.step()if epoch%1000:data_time_interval time.time() - time_stampprint(epoch: %d loss: %7.3f interval: %6.2f%(epoch, loss.detach().numpy(),data_time_interval))#torch.save(model.state_dict(), model_params.pth) showDiff(y_pre, cosx_lable,steps)if __name__ __main__:input_dim 1hidden_dim 64num_layers 2batch_first TruemaxIter 3000model LSTM(input_dim, hidden_dim, num_layers, batch_first)DEVICE torch.device(cuda if torch.cuda.is_available() else cpu)optimzer optim.Adam(model.parameters(),lr0.0001,weight_decay0.00001)criterion nn.MSELoss()model.to(DEVICE)criterion.to(DEVICE)train(model,maxIter,criterion)#model.load_state_dict(torch.load(model_params.pth,map_locationcpu))#eval(model) 参考 pytorch利用rnn通过sin预测cos 利用lstm预测手写数字_pytorch lstm cos_薛定谔的智能的博客-CSDN博客
http://www.dnsts.com.cn/news/163332.html

相关文章:

  • 网站地图是什么样子的网站悬浮窗广告怎么做
  • dede网站后台html个人网站源码
  • 丹阳如何做百度的网站杭州网络公司排名
  • 做景观园林的网站是网页设计学习心得
  • 天蓝色网站电子报 网站开发
  • 山东网站设计公司高端企业网站建设服务商
  • 重庆网站建设案例昆明互联网公司排名前十
  • 网站开发方法是什么动漫制作技术专业入门
  • 网站做全景图预览网页设计代码模板海贼王
  • 一个空间建多个网站的方法wordpress评分点评
  • 潍坊网站建设wancet用英文介绍购物网站
  • 网站开发大全访问国外的网站很慢
  • 东莞没有网站的公司人工智能建筑设计软件
  • 大型外贸网站建设网站连接微信
  • 网站建设的几种形式铆焊加工平台
  • 做网站有哪些公司5g国产天天5g天天
  • 科技网站有哪些包头正大光电 做网站
  • 免费建设com网站上海网站建设包括哪些
  • 家纺 网站模版广告公司服务方案
  • 网站建设佰首选金手指三十穿搭速递html网页制作代码
  • 自助建设网站平台wordpress小程序小白
  • 青岛网站优化排名还有网站吗
  • 搬家公司网站制作天津个人专业做网站
  • 山东省住房城乡和建设厅网站佛山专业英文网站建设
  • 济宁网站运营策略广州天河区酒店
  • 建设网站 报告深圳松岗网站建设
  • 南通网站建设计划书发布网站需要备案吗
  • PC端网站开发以及设计费用中铁三局招聘信息2021
  • 繁体版 企业网站做手机网站的好处
  • 网站建设与维护要用到代码吗网页制作培训哪里好