Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66217682
lstm.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jun 9, 02:06
Size
1 KB
Mime Type
text/x-python
Expires
Tue, Jun 11, 02:06 (2 d)
Engine
blob
Format
Raw Data
Handle
18187405
Attached To
R6590 project14
lstm.py
View Options
import
torch
import
torch.nn
as
nn
from
torch.autograd
import
Variable
class
LSTMmodel
(
nn
.
Module
):
'''
Class representing the LSTM model
'''
def
__init__
(
self
):
super
(
LSTMmodel
,
self
)
.
__init__
()
# Store required sizes
self
.
hidden_size
=
128
#self.grid_size = args.grid_size
self
.
embedding_size
=
64
#self.pooling_size = args.pooling_size #pooling window
self
.
input_size
=
2
self
.
output_size
=
2
#parameters of bivariate distribution
#self.neighborhood_size = args.neighborhood_size
# The LSTM cell. (Social LSTM) embedding size = 64
self
.
lstm
=
nn
.
LSTM
(
self
.
embedding_size
,
self
.
hidden_size
)
# Linear layer to embed the input position into LSTM
self
.
input_embedding_layer
=
nn
.
Linear
(
self
.
input_size
,
self
.
embedding_size
)
# Linear layer to embed the social tensor
#self.tensor_embedding_layer = nn.Linear(self.neighborhood_size*self.neighborhood_size*self.hidden_size, self.embedding_size)
# Linear layer to map the hidden state of LSTM to output
self
.
output_layer
=
nn
.
Linear
(
self
.
hidden_size
,
self
.
output_size
)
# ReLU and dropout unit
self
.
relu
=
nn
.
ReLU
()
#self.dropout = nn.Dropout(0.5)
def
forward
(
self
,
peds
,
hidden_states
,
cell_states
):
'''
Forward pass for the model
params:
peds: coordinates of pedestrians in frame
hidden_states: Hidden states of the pedestrians
cell_states: Cell states of the peds
returns:
weigths: Outputs corresponding to bivariate Gaussian distributions
hidden_states
cell_states
'''
#input = self.dropout(self.relu(self.input_embedding_layer(peds)))
input
=
self
.
relu
(
self
.
input_embedding_layer
(
peds
))
h_peds
,
c_peds
=
self
.
lstm
(
input
,
(
hidden_states
,
cell_states
))
output
=
self
.
output_layer
(
h_peds
)
#weigths = torch.cat((weights,output),0)
return
output
,
h_peds
,
c_peds
Event Timeline
Log In to Comment