Hello, I am trying to implement some kind of importance sampling from a pseudo in the following code,
inp = torch.rand([32, 20, 10, 16])
inp_norms = torch.norm(inp, dim=3, keepdim=True, p=2)
print(inp.size())
sums = torch.sum(inp_norms, dim=1, keepdim=True)
probs = inp_norms/sums
t = torch.split(probs, dim=2, split_size_or_sections=1)
sampls = torch.multinomial(inp_norms, num_samples=15, replacement=True)
samples = torch.stack([torch.multinomial(tt, num_samples=15, replacement=True) for tt in t], dim=2)
print(samples.size())
I would like to get 15 samples from dim=1 of inp for each element in dim=2. samples contain the indices of the samples but I can not get the samples from inp. (I do not want to use 2 for loops one for batch dimension and second for dim=2 of inp.) Is there any other way that I can follow, I would be glad if someone can at least give me keywords to search:D
index_select and gather did not do good to me or at least I could not understand them enough to convert to my problem.
Best and thanks in advance!
Barış