Comments (6)
Hi,
I agree with @SampsonKwan that initialising Wci
, Wcf
and Wco
to zero at the beginning of each batch doesn't make sense as this way C_{t-1}
won't be used when calculating i_t
, f_t
and o_t
in Equation 3 from the paper (as we'd just multiply it with zeros).
I'd say that this is a bug, and that Wci
, Wcf
and Wco
should be initialised in the __init__
of ConvLSTMCell
.
from convolutional_lstm_pytorch.
@automan000
Thanks for your work, here is my simple implementation for ConvLSTM:
class ConvLSTM(nn.Module):
def __init__(self, input_channel, num_filter, b_h_w, kernel_size, stride=1, padding=1):
super().__init__()
self._conv = nn.Conv2d(in_channels=input_channel + num_filter,
out_channels=num_filter*4,
kernel_size=kernel_size,
stride=stride,
padding=padding)
self._batch_size, self._state_height, self._state_width = b_h_w
# if using requires_grad flag, torch.save will not save parameters in deed although it may be updated every epoch.
# Howerver, if you declare an optimizer like Adam(model.parameters()),
# parameters will not be updated forever.
self.Wci = nn.Parameter(torch.zeros(1, num_filter, self._state_height, self._state_width)).to(cfg.GLOBAL.DEVICE)
self.Wcf = nn.Parameter(torch.zeros(1, num_filter, self._state_height, self._state_width)).to(cfg.GLOBAL.DEVICE)
self.Wco = nn.Parameter(torch.zeros(1, num_filter, self._state_height, self._state_width)).to(cfg.GLOBAL.DEVICE)
self._input_channel = input_channel
self._num_filter = num_filter
# inputs and states should not be all none
# inputs: S*B*C*H*W
def forward(self, inputs=None, states=None, seq_len=cfg.HKO.BENCHMARK.IN_LEN):
if states is None:
c = torch.zeros((inputs.size(1), self._num_filter, self._state_height,
self._state_width), dtype=torch.float).to(cfg.GLOBAL.DEVICE)
h = torch.zeros((inputs.size(1), self._num_filter, self._state_height,
self._state_width), dtype=torch.float).to(cfg.GLOBAL.DEVICE)
else:
h, c = states
outputs = []
for index in range(seq_len):
# initial inputs
if inputs is None:
x = torch.zeros((h.size(0), self._input_channel, self._state_height,
self._state_width), dtype=torch.float).to(cfg.GLOBAL.DEVICE)
else:
x = inputs[index, ...]
cat_x = torch.cat([x, h], dim=1)
conv_x = self._conv(cat_x)
i, f, tmp_c, o = torch.chunk(conv_x, 4, dim=1)
i = torch.sigmoid(i+self.Wci*c)
f = torch.sigmoid(f+self.Wcf*c)
c = f*c + i*torch.tanh(tmp_c)
o = torch.sigmoid(o+self.Wco*c)
h = o*torch.tanh(c)
outputs.append(h)
return torch.stack(outputs), (h, c)
I think bias will not have any influence on the model, since Wh_, Wx_ are convolution operations.
from convolutional_lstm_pytorch.
Yes, I agree with all above. According to formula in the paper, if Wci, Wcf and Whc are all initialized as zero in every batch, cell output will not be used or make sense anymore. The implementation of this repo can not work because I have tried to train my own data. At the same time, the weights which should be initialized every time are cell output and hidden state, if they are initially None.
from convolutional_lstm_pytorch.
@Hzzone @ppalasek @SampsonKwan Thanks, guys. I will upload a new version. I forget why I did this in the first version. That's a mistake.
from convolutional_lstm_pytorch.
Issue solved
from convolutional_lstm_pytorch.
Is the explicitly said to initialize with zero or just a choice? I could not find in the paper
from convolutional_lstm_pytorch.
Related Issues (20)
- using for custom dataset HOT 1
- Is there any experiments results provided?
- Found the code is much slower than Keras counterpart (takes 2-3 times longer time). Do you know why?
- What's the shape of input? HOT 1
- I think forward code is wrong
- Input shape issue and lack of bias. HOT 9
- The shape of the output
- Why Wci, Wcf, Wco are Variables rather than nn.Parameters HOT 3
- Where is the squence length HOT 1
- why hidden_channels % 2 == 0 ?
- Error in backward HOT 1
- Peephole connections (Wci, Wcf, Wco) gradient update HOT 1
- Why self.num_features=4 in line 15?
- How can I use this module for predicting the moving mnist like the paper? HOT 1
- about concat HOT 5
- about forward HOT 1
- RuntimeError: Jacobian mismatch for output 0 with respect to input 0 HOT 3
- 关于input 和 step 的问题 HOT 2
- How to do the entire sequence all at once?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from convolutional_lstm_pytorch.