class_docstr: Implementation of https://arxiv.org/abs/1905.04899
class_docstr_tok: ["Implementation","of","https",":","\/\/arxiv.org\/abs\/1905.04899"]
docstr: Give a bounding box location based on the size of the im and a weight
docstr_tok: ["Give","a","bounding","box","location","based","on","the","size","of","the","im","and","a","weight"]
code: def rand_bbox(
      self,
      W: int,  # Input image width
      H: int,  # Input image height
      lam: Tensor,  # lambda sample from Beta distribution i.e tensor([0.3647])
  ) -> (
      tuple
  ):  # Represents the top-left pixel location and the bottom-right pixel location
      "Give a bounding box location based on the size of the im and a weight"
      cut_rat = torch.sqrt(1.0 - lam).to(self.x.device)
      cut_w = (
          torch.round(W * cut_rat).type(torch.long).to(self.x.device)
      )
      cut_h = (
          torch.round(H * cut_rat).type(torch.long).to(self.x.device)
      )
      # uniform
      cx = torch.randint(0, W, (1,)).to(self.x.device)
      cy = torch.randint(0, H, (1,)).to(self.x.device)
      x1 = torch.clamp(
          cx - torch.div(cut_w, 2, rounding_mode="floor"), 0, W
      )
      y1 = torch.clamp(
          cy - torch.div(cut_h, 2, rounding_mode="floor"), 0, H
      )
      x2 = torch.clamp(
          cx + torch.div(cut_w, 2, rounding_mode="floor"), 0, W
      )
      y2 = torch.clamp(
          cy + torch.div(cut_h, 2, rounding_mode="floor"), 0, H
      )
      return x1, y1, x2, y2
  
imports: from __future__ import annotations
  from ..basics import *
  from torch.distributions.beta import Beta
label_desc: Use image node_id 3 for calling the CutMix obj's underlying member method code with example usage: obj.rand_bbox(W, H, lam) and returns: x1,  y1,  x2,  y2