This file contains hidden or 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
| #1 is end and 0 is start in the map. | |
| def map_blur(img,map,s_start=0.375,s_end=8,steps=8): | |
| img_slices = img * 0 | |
| map_slices = map * 0 | |
| for s in range(steps): | |
| sigma = (s/(steps-1)) * (s_end-s_start) + s_start | |
| slice_start = (s+0)/steps | |
| slice_end = (s+1)/steps | |
| map_slice = torch.logical_and( | |
| torch.greater_equal(map,slice_start), |
This file contains hidden or 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
| # Perform max pool 2d with indicies on a tensor | |
| max_size = 8 | |
| max_output, max_indices = F.max_pool2d_with_indices(input_tensor,max_size) | |
| # Unpool it to get a tensor of the original size with zeros in all non-max areas | |
| max_unpool = F.max_unpool2d(max_output,max_indices,max_size,max_size) | |
| # Unpool it using a tensor of ones with the same indices to get ones where the tensor was sampled | |
| max_mask = F.max_unpool2d(torch.ones_like(max_output),max_indices,max_size,max_size) | |
| # Makes a kernel that's round and the distance from the center |
This file contains hidden or 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 | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | |
| class Sobel(nn.Module): | |
| def __init__(self,structure=False,scharr=True, padding_mode='reflect'): | |
| super().__init__() | |
| self.structure = structure |
This file contains hidden or 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 | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | |
| class KaiserLowpass(nn.Module): | |
| def __init__(self, width=7, beta=11, periodic=False, padding_mode='replicate'): | |
| super().__init__() | |
| self.padding_mode = padding_mode |