code: def random_contrast(
      x: Tensor, magnitude: Tensor, *args, **kwargs
  ) -> Tensor:
      # compute per-channel mean
      per_channel_mean = torch.mean(x, dim=[-1, -2], keepdim=True)
  
      # contrast can be written as
      # (1 - contrast_factor) * per_channel_mean + img * contrast_factor
      x = ((1.0 - magnitude) * per_channel_mean) + (x * magnitude)
      return x
  
imports: from typing import Any, Optional
  import torch
  from torch import Tensor, nn
label_desc: Use image node_id 2 for calling a global function with example usage: random_contrast(x, magnitude) and returns: x