当前位置:网站首页>RNN model
RNN model
2022-06-12 06:07:00 【Singing under the hedge】
List of articles
#RNN Model
One 、 Code
import torch
import torch.nn as nn
x_input = torch.randn(2,3,10)
class RNN(nn.Module):
def __init__(self,input_size,hidden_size,batch_first=False):
super(RNN,self).__init__()
self.rnn_cell = nn.RNNCell(input_size,hidden_size)
self.batch_first = batch_first
self.hidden_size = hidden_size
def _initialize_hidden(self,batch_size):
return torch.zeros((batch_size,self.hidden_size))
def forward(self,inputs,initial_hidden=None):
if self.batch_first:
batch_size,seq_size,feat_size = inputs.size()
inputs = inputs.permute(1,0,2)
else:
seq_size,batch_size,feat_size = inputs
hiddens = []
if initial_hidden is None:
initial_hidden = self._initialize_hidden(batch_size)
initial_hidden = initial_hidden.to(inputs.device)
hidden_t = initial_hidden
for t in range(seq_size):
hidden_t = self.rnn_cell(inputs[t],hidden_t)
hiddens.append(hidden_t)
hiddens = torch.stack(hiddens)
if self.batch_first:
hiddens = hiddens.permute(1,0,2)
return hiddens
model = RNN(10,15,batch_first=True)
output = model(x_input)
print(output)
Two 、 Realization effect

边栏推荐
- 468. verifying the IP address
- Sqlite Cross - compile Dynamic Library
- Sensor bringup 中的一些问题总结
- MySQL master-slave, 6 minutes to master
- Recursive implementation of exponential, permutation and combination enumerations
- Mysql笔记
- Json-c common APIs
- Unity can realize the rotation, translation and scaling script of the camera around the target point on the mobile terminal device
- Guns framework multi data source configuration without modifying the configuration file
- 2D human pose estimation for pose estimation - pifpaf:composite fields for human pose estimation
猜你喜欢

MySQL 主从,6 分钟带你掌握

BRDF of directx11 advanced tutorial PBR (2)

肝了一個月的 DDD,一文帶你掌握

Directx11 advanced tutorial tiled based deffered shading

IDEA常用配置

Project and build Publishing

Login authentication filter

Leetcode-1260. 2D mesh migration

Understand Houdini's (heightfield) remap operation

Performance optimization metrics and tools
随机推荐
Getting started with houdininengine HDA and UE4
JS预解析
Project management and overall planning
Leetcode-1705. Maximum number of apples to eat
Recursive implementation of exponential, permutation and combination enumerations
Directx11 advanced tutorial tiled based deffered shading
Unity custom translucent surface material shader
jpg格式与xml格式文件分离到不同的文件夹
JS变量作用域
数据库实验三:数据查询
Leetcode-1260. 2D mesh migration
MySQL 主从,6 分钟带你掌握
Guns framework multi data source configuration without modifying the configuration file
Json-c common APIs
Brief introduction to project development process
Annotation configuration of filter
分段贝塞尔曲线
项目开发流程简单介绍
Solution to the problem of the 80th fortnight competition of leetcode
nRF52832自定義服務與特性