Created
March 5, 2021 09:36
-
-
Save hushell/77b584e94cd8a0722cc52acf189926b0 to your computer and use it in GitHub Desktop.
Superpixel feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
F = torch.rand(5, 10, 10) # C, H, W | |
M = torch.randint(8, (10, 10)) # 8 superpixels | |
M1hot = torch.nn.functional.one_hot(M, 8) # H, W, K | |
counts = M1hot.sum(dim=(0, 1)) # counts of pixels per superpixel | |
Favg = M1hot.view(-1, 8).T.float() @ F0.view(5, -1).T # K, C | |
Favg = Favg.div(counts.unsqueeze(-1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment