Giter VIP home page Giter VIP logo

Comments (6)

ppalasek avatar ppalasek commented on July 18, 2024 4

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.

Hzzone avatar Hzzone commented on July 18, 2024 2

@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.

Hzzone avatar Hzzone commented on July 18, 2024

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.

automan000 avatar automan000 commented on July 18, 2024

@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.

automan000 avatar automan000 commented on July 18, 2024

Issue solved

from convolutional_lstm_pytorch.

bkoyuncu avatar bkoyuncu commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.