Skip to content

Commit

Permalink
fix bug when computing available mixture scores
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Miech "WILLOW committed Nov 12, 2019
1 parent 742e7bb commit bb4484f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ def forward(self, text, video, ind, conf=True):
available_m = th.from_numpy(available_m).float()
available_m = Variable(available_m.cuda())

moe_weights = available_m*moe_weights
moe_weights = available_m[None, :, :] * moe_weights[:, None, :]

norm_weights = th.sum(moe_weights, dim=1)
norm_weights = norm_weights.unsqueeze(1)
norm_weights = th.sum(moe_weights, dim=2)
norm_weights = norm_weights.unsqueeze(2)
moe_weights = th.div(moe_weights, norm_weights)

#MOE weights computation + normalization ------ DONE
Expand All @@ -101,15 +101,15 @@ def forward(self, text, video, ind, conf=True):
i = 0
for m in video:
video[m] = video[m].transpose(0,1)
conf_matrix += moe_weights[:,i:i+1]*th.matmul(text_embd[m], video[m])
conf_matrix += moe_weights[:,:,i]*th.matmul(text_embd[m], video[m])
i += 1

return conf_matrix
else:
i = 0
scores = Variable(th.zeros(len(text)).cuda())
for m in video:
text_embd[m] = moe_weights[:,i:i+1]*text_embd[m]*video[m]
text_embd[m] = moe_weights[:,:,i]*text_embd[m]*video[m]
scores += th.sum(text_embd[m], dim=-1)
i += 1

Expand Down

0 comments on commit bb4484f

Please sign in to comment.