示例#1
0
    def generate_batch_state(self, batch_tensor: torch.FloatTensor) -> torch.FloatTensor:
        batch_sz, channels, height, width = batch_tensor.size()
        roughness = type(self).roughness(batch_sz, device=batch_tensor.device)
        plasma_sz = (batch_sz, 1, height, width)
        alpha_range = type(self).alpha_range(batch_sz, device=batch_tensor.device).view(-1,1,1,1)
        alpha_mean = type(self).alpha_mean(batch_sz, device=batch_tensor.device).view(-1,1,1,1)
        beta_range = type(self).beta_range(batch_sz, device=batch_tensor.device).view(-1,1,1,1)
        beta_mean = type(self).beta_mean(batch_sz, device=batch_tensor.device).view(-1,1,1,1)


        alpha_plasma = functional_diamond_square(plasma_sz, roughness=roughness, device=batch_tensor.device)
        #print("RndAlpha:",alpha_plasma.min().item(),alpha_plasma.max().item())


        alpha_plasma = (alpha_plasma * alpha_range) + (1-alpha_range)  * alpha_mean
        #print("RndAlpha2:",alpha_plasma.min().item(),alpha_plasma.max().item())

        beta_plasma = functional_diamond_square(plasma_sz, roughness=roughness, device=batch_tensor.device)
        #print("RndBeta:",beta_plasma.min().item(),beta_plasma.max().item())
        beta_plasma = (beta_plasma * beta_range) + (1-beta_range) * beta_mean + beta_range * .5
        #print("RndBeta2:",beta_plasma.min().item(),beta_plasma.max().item())

        #beta_available = (1 - alpha_plasma)

        #beta_alpha = beta_available * beta_alpha
        #beta_beta = (beta_available - beta_alpha) * beta_beta

        #beta_plasma = functional_diamond_square(plasma_sz, roughness=roughness, device=batch_tensor.device)
        #beta_plasma = beta_plasma * beta_alpha + beta_beta
        #print ("Ranges:",(alpha_plasma+beta_plasma).min().item(),(alpha_plasma+beta_plasma).max().item())
        plasma_sum = (alpha_plasma+beta_plasma)
        alpha_plasmam, beta_plasma = (alpha_plasma/plasma_sum,beta_plasma/plasma_sum)
        return alpha_plasma, beta_plasma,
示例#2
0
 def generate_batch_state(self, batch_tensor: torch.FloatTensor) -> torch.FloatTensor:
     batch_sz, channels, height, width = batch_tensor.size()
     roughness = type(self).roughness(batch_sz, device=batch_tensor.device)
     plasma_sz = (batch_sz, 3, height, width)
     intensity = type(self).intensity(batch_sz, device=batch_tensor.device).view(-1, 1, 1, 1)
     brightness_map = 2 * functional_diamond_square(plasma_sz, roughness=roughness, device=batch_tensor.device) - 1
     return brightness_map * intensity,
示例#3
0
 def generate_batch_state(self, image_batch: torch.Tensor) -> AugmentationState:
     batch_sz, _, width, height = image_batch.size()
     roughness = type(self).roughness(batch_sz, device=image_batch.device)
     plasma_sz = (batch_sz, 1, width, height)
     plasma = functional_diamond_square(plasma_sz, roughness=roughness, device=image_batch.device)
     erase_percentile = type(self).erase_percentile(batch_sz, device=image_batch.device)
     return plasma, erase_percentile
示例#4
0
 def generate_batch_state(self, batch_tensor: torch.FloatTensor) -> torch.FloatTensor:
     batch_sz, channels, height, width = batch_tensor.size()
     roughness = type(self).roughness(batch_sz, device=batch_tensor.device)
     tensor_sz = batch_tensor.size()
     noise = type(self).noise(tensor_sz, device=batch_tensor.device)
     plasma_sz = (batch_sz, 1, height, width)
     noise_intencity_coefficient = functional_diamond_square(plasma_sz, roughness=roughness, device=batch_tensor.device)
     return noise * noise_intencity_coefficient,
示例#5
0
文件: wrap.py 项目: wsyCUHK/tormentor
 def generate_batch_state(self, sampling_tensors: SamplingField) -> SpatialAugmentationState:
     batch_sz, width, height = sampling_tensors[0].size()
     roughness = type(self).roughness(batch_sz, device=sampling_tensors[0].device)
     plasma_sz = (batch_sz, 1, width, height)
     plasma = functional_diamond_square(plasma_sz, roughness=roughness, device=sampling_tensors[0].device)
     inside = type(self).inside(batch_sz, device=sampling_tensors[0].device).float()
     erase_percentile = type(self).erase_percentile(batch_sz, device=sampling_tensors[0].device)
     return plasma, inside, erase_percentile
示例#6
0
 def generate_batch_state(
         self, batch_tensor: torch.FloatTensor) -> torch.FloatTensor:
     batch_sz, channels, height, width = batch_tensor.size()
     roughness = type(self).roughness(batch_sz, device=batch_tensor.device)
     plasma_sz = (batch_sz, 1, height, width)
     contrast_map = 4 * functional_diamond_square(
         plasma_sz, roughness=roughness, device=batch_tensor.device)
     return contrast_map,
示例#7
0
 def generate_batch_state(self, batch_tensor: torch.FloatTensor) -> torch.FloatTensor:
     batch_sz, channels, height, width = batch_tensor.size()
     roughness = type(self).roughness(batch_sz, device=batch_tensor.device)
     shade_intensity = type(self).shade_intensity(batch_sz, device=batch_tensor.device).view(-1, 1, 1, 1)
     shade_quantity = type(self).shade_quantity(batch_sz, device=batch_tensor.device).view(-1, 1, 1, 1)
     plasma_sz = (batch_sz, 1, height, width)
     shade_map = functional_diamond_square(plasma_sz, roughness=roughness, device=batch_tensor.device)
     shade_map = (shade_map < shade_quantity).float() * shade_intensity
     return shade_map,
示例#8
0
 def forward_batch_img(self, tensor_image):
     batch_size = tensor_image.size(0)
     roughness = type(self).roughness(batch_size)
     pixel_means = type(self).pixel_means(batch_size, device=tensor_image.device).view(-1, 1, 1, 1)
     pixel_ranges = type(self).pixel_ranges(batch_size, device=tensor_image.device).view(-1, 1, 1, 1)
     plasma = functional_diamond_square(tensor_image.size(), roughness=roughness, device=tensor_image.device)
     plasma_reshaped = plasma.reshape([batch_size, -1])
     plasma_min = plasma_reshaped.min(dim=1)[0].view(-1, 1, 1, 1)
     plasma_max = plasma_reshaped.max(dim=1)[0].view(-1, 1, 1, 1)
     return (pixel_ranges * (plasma - plasma_min) / (plasma_max - plasma_min)) + pixel_means - pixel_ranges / 2
示例#9
0
    def generate_batch_state(self, sampling_tensors: SamplingField) -> AugmentationState:
        batch_sz, height, width = sampling_tensors[0].size()
        roughness = type(self).roughness(batch_sz, device=sampling_tensors[0].device)
        intensity = type(self).intensity(batch_sz, device=sampling_tensors[0].device)
        plasma_sz = (batch_sz, 1, height, width)
        plasma_x = functional_diamond_square(plasma_sz, roughness=roughness, device=sampling_tensors[0].device) - .5
        plasma_y = functional_diamond_square(plasma_sz, roughness=roughness, device=sampling_tensors[0].device) - .5
        plasma_x, plasma_y = plasma_x[:,0,:,:], plasma_y[:, 0,:,:]
        plasma_dx = plasma_x[:, :, 1:] - plasma_x[:, :, :-1]
        plasma_dy = plasma_y[:, 1:, :] - plasma_y[:, :-1, :]

        plasma_scale_x = torch.cat([abs(plasma_dx.view(batch_sz, -1).min(dim=1)[0]).view(1, -1), plasma_dx.view(batch_sz, -1).max(dim=1)[0].view(1, -1)], dim=0).max(dim=0)[0]

        plasma_scale_y = torch.cat([abs(plasma_dy.view(batch_sz, -1).min(dim=1)[0]).view(1, -1), plasma_dy.view(batch_sz, -1).max(dim=1)[0].view(1, -1)], dim=0).max(dim=0)[0]

        plasma_x /= ((plasma_scale_x.view(-1, 1, 1) * .25 * width) / intensity.view(-1, 1, 1))
        plasma_y /= ((plasma_scale_y.view(-1, 1, 1) * .25 * height) / intensity.view(-1, 1, 1))

        return plasma_x, plasma_y