Skip to content

rnn runtime error question #9

@ericbillwang

Description

@ericbillwang

Dear TA,

I got below run time error.
RuntimeError: Expected hidden size (1, 1L, 512), got (1L, 50L, 512L)

Below is my source code which I confirmed final rnn_input is 1 x batch x input_size
Can you give me some idea of debugging direction ?

    # V = resized image features(att_feats)
            # (batch * att_size) * att_feat_size
    V = att_feats.view(-1,self.att_feat_size) # batch x 49 x 2048
    # att = W*V
            # (batch * att_size) * att_hid_size
            # batch * att_size * att_hid_size
    att = self.ctx2att(V) # (batch x 49) x 512
    att = att.view(-1,att_size,self.att_hid_size)
    # att_h = W*hidden
            # batch * att_hid_size
            # batch * att_size * att_hid_size
    att_h = self.h2att(state[0]) # batch x 512
    att_h = att_h.squeeze()
    att_h = att_h.unsqueeze(1)
    att_h = att_h.expand_as(torch.Tensor(50,att_size,self.att_hid_size))
    # e = W*tanh(att+att_h)
            # batch * att_size * att_hid_size
            # batch * att_size * att_hid_size
            # (batch * att_size) * att_hid_size
            # (batch * att_size) * 1
            # batch * att_size
    tmp_e = att + att_h
    tmp_e = tmp_e.tanh()
    tmp_e = tmp_e.view(-1,self.att_hid_size)
    e = self.alpha_net(tmp_e)
    e = e.squeeze()
    e = e.view(-1,att_size)
    # alpha = softmax(e)
            # batch * att_size
    alpha = F.softmax(e)
    alpha = alpha.unsqueeze(1)
    # V = resized image features(att_feats)
            # batch * att_size * att_feat_size
    V = V.view(-1,att_size, self.att_feat_size)
    # C = alpha*V
            # batch * att_feat_size
    C = torch.bmm(alpha,V)
    C = C.squeeze()
    #print(C.size())

    # Use rnn to generate output
    rnn_input = torch.cat((xt,C),1)
    rnn_input = rnn_input.unsqueeze(0)
    print(rnn_input.size())
    output, state = self.rnn(rnn_input, state)
    #       input: Concatenates(xt, C) in size=(1 * batch_size * input_size)

Thanks, Ericbill

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions