code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def invert(img: Tensor) -> Tensor: """Invert the colors of an RGB/grayscale image. Args: img (PIL Image or Tensor): Image to have its colors inverted. If img is torch Tensor, it is expected to be in [..., 1 or 3, H, W] format, where ... means it can have an arbitrary number of l...
Invert the colors of an RGB/grayscale image. Args: img (PIL Image or Tensor): Image to have its colors inverted. If img is torch Tensor, it is expected to be in [..., 1 or 3, H, W] format, where ... means it can have an arbitrary number of leading dimensions. If img is P...
invert
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/functional.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/functional.py
Apache-2.0
def posterize(img: Tensor, bits: int) -> Tensor: """Posterize an image by reducing the number of bits for each color channel. Args: img (PIL Image or Tensor): Image to have its colors posterized. If img is torch Tensor, it should be of type torch.uint8 and it is expected to be i...
Posterize an image by reducing the number of bits for each color channel. Args: img (PIL Image or Tensor): Image to have its colors posterized. If img is torch Tensor, it should be of type torch.uint8 and it is expected to be in [..., 1 or 3, H, W] format, where ... means ...
posterize
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/functional.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/functional.py
Apache-2.0
def solarize(img: Tensor, threshold: float) -> Tensor: """Solarize an RGB/grayscale image by inverting all pixel values above a threshold. Args: img (PIL Image or Tensor): Image to have its colors inverted. If img is torch Tensor, it is expected to be in [..., 1 or 3, H, W] format, ...
Solarize an RGB/grayscale image by inverting all pixel values above a threshold. Args: img (PIL Image or Tensor): Image to have its colors inverted. If img is torch Tensor, it is expected to be in [..., 1 or 3, H, W] format, where ... means it can have an arbitrary number of leading...
solarize
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/functional.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/functional.py
Apache-2.0
def adjust_sharpness(img: Tensor, sharpness_factor: float) -> Tensor: """Adjust the sharpness of an image. Args: img (PIL Image or Tensor): Image to be adjusted. If img is torch Tensor, it is expected to be in [..., 1 or 3, H, W] format, where ... means it can have an arbitrary ...
Adjust the sharpness of an image. Args: img (PIL Image or Tensor): Image to be adjusted. If img is torch Tensor, it is expected to be in [..., 1 or 3, H, W] format, where ... means it can have an arbitrary number of leading dimensions. sharpness_factor (float): How much to ...
adjust_sharpness
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/functional.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/functional.py
Apache-2.0
def autocontrast(img: Tensor) -> Tensor: """Maximize contrast of an image by remapping its pixels per channel so that the lowest becomes black and the lightest becomes white. Args: img (PIL Image or Tensor): Image on which autocontrast is applied. If img is torch Tensor, it is expec...
Maximize contrast of an image by remapping its pixels per channel so that the lowest becomes black and the lightest becomes white. Args: img (PIL Image or Tensor): Image on which autocontrast is applied. If img is torch Tensor, it is expected to be in [..., 1 or 3, H, W] format, ...
autocontrast
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/functional.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/functional.py
Apache-2.0
def equalize(img: Tensor) -> Tensor: """Equalize the histogram of an image by applying a non-linear mapping to the input in order to create a uniform distribution of grayscale values in the output. Args: img (PIL Image or Tensor): Image on which equalize is applied. If img is torch ...
Equalize the histogram of an image by applying a non-linear mapping to the input in order to create a uniform distribution of grayscale values in the output. Args: img (PIL Image or Tensor): Image on which equalize is applied. If img is torch Tensor, it is expected to be in [..., 1 or 3...
equalize
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/functional.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/functional.py
Apache-2.0
def get_params(img: Tensor, output_size: Tuple[int, int]) -> Tuple[int, int, int, int]: """Get parameters for ``crop`` for a random crop. Args: img (PIL Image or Tensor): Image to be cropped. output_size (tuple): Expected output size of the crop. Retu...
Get parameters for ``crop`` for a random crop. Args: img (PIL Image or Tensor): Image to be cropped. output_size (tuple): Expected output size of the crop. Returns: tuple: params (i, j, h, w) to be passed to ``crop`` for random crop.
get_params
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, img): """ Args: img (PIL Image or Tensor): Image to be cropped. Returns: PIL Image or Tensor: Cropped image. """ if self.padding is not None: img = F.pad(img, self.padding, self.fill, self.padding_mode) width, height...
Args: img (PIL Image or Tensor): Image to be cropped. Returns: PIL Image or Tensor: Cropped image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, img): """ Args: img (PIL Image or Tensor): Image to be flipped. Returns: PIL Image or Tensor: Randomly flipped image. """ if torch.rand(1) < self.p: return F.hflip(img) return img
Args: img (PIL Image or Tensor): Image to be flipped. Returns: PIL Image or Tensor: Randomly flipped image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, img): """ Args: img (PIL Image or Tensor): Image to be Perspectively transformed. Returns: PIL Image or Tensor: Randomly transformed image. """ fill = self.fill if isinstance(img, Tensor): if isinstance(fill, (int, f...
Args: img (PIL Image or Tensor): Image to be Perspectively transformed. Returns: PIL Image or Tensor: Randomly transformed image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def get_params(width: int, height: int, distortion_scale: float) -> Tuple[ List[List[int]], List[List[int]]]: """Get parameters for ``perspective`` for a random perspective transform. Args: width (int): width of the image. height (int): height of the image. ...
Get parameters for ``perspective`` for a random perspective transform. Args: width (int): width of the image. height (int): height of the image. distortion_scale (float): argument to control the degree of distortion and ranges from 0 to 1. Returns: List ...
get_params
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, tensor: Tensor) -> Tensor: """ Args: tensor (Tensor): Tensor image to be whitened. Returns: Tensor: Transformed image. """ shape = tensor.shape n = shape[-3] * shape[-2] * shape[-1] if n != self.transformation_matrix.shap...
Args: tensor (Tensor): Tensor image to be whitened. Returns: Tensor: Transformed image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def get_params( brightness: Optional[List[float]], contrast: Optional[List[float]], saturation: Optional[List[float]], hue: Optional[List[float]]) -> Tuple[Tensor, Optional[ float], Optional[float], Optional[float], Optional[float]]: """Get the par...
Get the parameters for the randomized transform to be applied on image. Args: brightness (tuple of float (min, max), optional): The range from which the brightness_factor is chosen uniformly. Pass None to turn off the transformation. contrast (tuple of float (min, max), ...
get_params
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, img): """ Args: img (PIL Image or Tensor): Input image. Returns: PIL Image or Tensor: Color jittered image. """ fn_idx, brightness_factor, contrast_factor, saturation_factor, hue_factor = \ self.get_params(self.brightness, se...
Args: img (PIL Image or Tensor): Input image. Returns: PIL Image or Tensor: Color jittered image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def get_params(degrees: List[float]) -> float: """Get parameters for ``rotate`` for a random rotation. Returns: float: angle parameter to be passed to ``rotate`` for random rotation. """ angle = float( torch.empty(1).uniform_(float(degrees[0]), float(degrees[1]))...
Get parameters for ``rotate`` for a random rotation. Returns: float: angle parameter to be passed to ``rotate`` for random rotation.
get_params
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, img): """ Args: img (PIL Image or Tensor): Image to be rotated. Returns: PIL Image or Tensor: Rotated image. """ fill = self.fill if isinstance(img, Tensor): if isinstance(fill, (int, float)): fill = [...
Args: img (PIL Image or Tensor): Image to be rotated. Returns: PIL Image or Tensor: Rotated image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def get_params(degrees: List[float], translate: Optional[List[float]], scale_ranges: Optional[List[float]], shears: Optional[List[float]], img_size: List[int]) -> Tuple[float, Tuple[int, int], float, ...
Get parameters for affine transformation Returns: params to be passed to the affine transformation
get_params
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, img): """ img (PIL Image or Tensor): Image to be transformed. Returns: PIL Image or Tensor: Affine transformed image. """ fill = self.fill if isinstance(img, Tensor): if isinstance(fill, (int, float)): fill = ...
img (PIL Image or Tensor): Image to be transformed. Returns: PIL Image or Tensor: Affine transformed image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, img): """ Args: img (PIL Image or Tensor): Image to be converted to grayscale. Returns: PIL Image or Tensor: Randomly grayscaled image. """ num_output_channels = F._get_image_num_channels(img) if torch.rand(1) < self.p: ...
Args: img (PIL Image or Tensor): Image to be converted to grayscale. Returns: PIL Image or Tensor: Randomly grayscaled image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def get_params(img: Tensor, scale: Tuple[float, float], ratio: Tuple[float, float], value: Optional[List[float]]=None) -> Tuple[int, int, int, int, Tensor]: """Get parameters for ``erase`` for...
Get parameters for ``erase`` for a random erasing. Args: img (Tensor): Tensor image to be erased. scale (sequence): range of proportion of erased area against input image. ratio (sequence): range of aspect ratio of erased area. value (list, optional): erasing val...
get_params
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, img): """ Args: img (Tensor): Tensor image to be erased. Returns: img (Tensor): Erased Tensor image. """ if torch.rand(1) < self.p: # cast self.value to script acceptable type if isinstance(self.value, (int, floa...
Args: img (Tensor): Tensor image to be erased. Returns: img (Tensor): Erased Tensor image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, img: Tensor) -> Tensor: """ Args: img (PIL Image or Tensor): image to be blurred. Returns: PIL Image or Tensor: Gaussian blurred image """ sigma = self.get_params(self.sigma[0], self.sigma[1]) return F.gaussian_blur(img, self.ker...
Args: img (PIL Image or Tensor): image to be blurred. Returns: PIL Image or Tensor: Gaussian blurred image
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, img): """ Args: img (PIL Image or Tensor): Image to be inverted. Returns: PIL Image or Tensor: Randomly color inverted image. """ if torch.rand(1).item() < self.p: return F.invert(img) return img
Args: img (PIL Image or Tensor): Image to be inverted. Returns: PIL Image or Tensor: Randomly color inverted image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, img): """ Args: img (PIL Image or Tensor): Image to be posterized. Returns: PIL Image or Tensor: Randomly posterized image. """ if torch.rand(1).item() < self.p: return F.posterize(img, self.bits) return img
Args: img (PIL Image or Tensor): Image to be posterized. Returns: PIL Image or Tensor: Randomly posterized image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, img): """ Args: img (PIL Image or Tensor): Image to be solarized. Returns: PIL Image or Tensor: Randomly solarized image. """ if torch.rand(1).item() < self.p: return F.solarize(img, self.threshold) return img
Args: img (PIL Image or Tensor): Image to be solarized. Returns: PIL Image or Tensor: Randomly solarized image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, img): """ Args: img (PIL Image or Tensor): Image to be sharpened. Returns: PIL Image or Tensor: Randomly sharpened image. """ if torch.rand(1).item() < self.p: return F.adjust_sharpness(img, self.sharpness_factor) ret...
Args: img (PIL Image or Tensor): Image to be sharpened. Returns: PIL Image or Tensor: Randomly sharpened image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, img): """ Args: img (PIL Image or Tensor): Image to be autocontrasted. Returns: PIL Image or Tensor: Randomly autocontrasted image. """ if torch.rand(1).item() < self.p: return F.autocontrast(img) return img
Args: img (PIL Image or Tensor): Image to be autocontrasted. Returns: PIL Image or Tensor: Randomly autocontrasted image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def forward(self, img): """ Args: img (PIL Image or Tensor): Image to be equalized. Returns: PIL Image or Tensor: Randomly equalized image. """ if torch.rand(1).item() < self.p: return F.equalize(img) return img
Args: img (PIL Image or Tensor): Image to be equalized. Returns: PIL Image or Tensor: Randomly equalized image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_ref/torchvision/transforms/transforms.py
Apache-2.0
def __init__(self, args): """ Args: args: Parameters generated using argparser. Returns: None """ super().__init__() self.args = args # init inference engine self.predictor, self.config, self.input_tensor, self.output_tensor = self.load_predi...
Args: args: Parameters generated using argparser. Returns: None
__init__
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step6/deploy/inference_python/infer.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step6/deploy/inference_python/infer.py
Apache-2.0
def load_predictor(self, model_file_path, params_file_path): """load_predictor initialize the inference engine Args: model_file_path: inference model path (*.pdmodel) model_file_path: inference parmaeter path (*.pdiparams) Return: predictor: Predicto...
load_predictor initialize the inference engine Args: model_file_path: inference model path (*.pdmodel) model_file_path: inference parmaeter path (*.pdiparams) Return: predictor: Predictor created using Paddle Inference. config: Configuration of t...
load_predictor
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step6/deploy/inference_python/infer.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step6/deploy/inference_python/infer.py
Apache-2.0
def preprocess(self, img_path): """preprocess Preprocess to the input. Args: img_path: Image path. Returns: Input data after preprocess. """ with open(img_path, "rb") as f: img = Image.open(f) img = img.convert("RGB") img = s...
preprocess Preprocess to the input. Args: img_path: Image path. Returns: Input data after preprocess.
preprocess
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step6/deploy/inference_python/infer.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step6/deploy/inference_python/infer.py
Apache-2.0
def postprocess(self, x): """postprocess Postprocess to the inference engine output. Args: x: Inference engine output. Returns: Output data after argmax. """ x = x.flatten() class_id = x.argmax() prob = x[class_id] return class_id, p...
postprocess Postprocess to the inference engine output. Args: x: Inference engine output. Returns: Output data after argmax.
postprocess
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step6/deploy/inference_python/infer.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step6/deploy/inference_python/infer.py
Apache-2.0
def run(self, x): """run Inference process using inference engine. Args: x: Input data after preprocess. Returns: Inference engine output """ self.input_tensor.copy_from_cpu(x) self.predictor.run() output = self.output_tensor.copy_to_cpu() ...
run Inference process using inference engine. Args: x: Input data after preprocess. Returns: Inference engine output
run
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step6/deploy/inference_python/infer.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step6/deploy/inference_python/infer.py
Apache-2.0
def alexnet(pretrained: bool=False, **kwargs: Any) -> AlexNet: r"""AlexNet model architecture from the `"One weird trick..." <https://arxiv.org/abs/1404.5997>`_ paper. The required minimum input size of the model is 63x63. Args: pretrained (str): Pre-trained parameters of the model on ImageNet ...
AlexNet model architecture from the `"One weird trick..." <https://arxiv.org/abs/1404.5997>`_ paper. The required minimum input size of the model is 63x63. Args: pretrained (str): Pre-trained parameters of the model on ImageNet
alexnet
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step6/paddlevision/models/alexnet.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step6/paddlevision/models/alexnet.py
Apache-2.0
def hflip(img): """Horizontally flip the given image. Args: img (PIL Image or Tensor): Image to be flipped. If img is a Tensor, it is expected to be in [..., H, W] format, where ... means it can have an arbitrary number of leading dimensions. Returns: PIL ...
Horizontally flip the given image. Args: img (PIL Image or Tensor): Image to be flipped. If img is a Tensor, it is expected to be in [..., H, W] format, where ... means it can have an arbitrary number of leading dimensions. Returns: PIL Image or Tensor: Horiz...
hflip
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step6/paddlevision/transforms/functional.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step6/paddlevision/transforms/functional.py
Apache-2.0
def forward(self, img): """ Args: img (PIL Image or Tensor): Image to be flipped. Returns: PIL Image or Tensor: Randomly flipped image. """ if random.random() < self.p: return F.hflip(img) return img
Args: img (PIL Image or Tensor): Image to be flipped. Returns: PIL Image or Tensor: Randomly flipped image.
forward
python
PaddlePaddle/models
tutorials/mobilenetv3_prod/Step6/paddlevision/transforms/transforms.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step6/paddlevision/transforms/transforms.py
Apache-2.0
def predict(self, image_list, threshold=0.5, repeats=1, add_timer=True): ''' Args: image_list (list): list of image threshold (float): threshold of predicted box' score repeats (int): repeat number for prediction add_timer (bool): whether add timer during ...
Args: image_list (list): list of image threshold (float): threshold of predicted box' score repeats (int): repeat number for prediction add_timer (bool): whether add timer during prediction Returns: results (dict): include 'boxes': np.ndarray:...
predict
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/deploy/infer.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/deploy/infer.py
Apache-2.0
def setup_logger(name="ppdet", output=None): """ Initialize logger and set its verbosity level to INFO. Args: output (str): a file name or a directory to save log. If None, will not save log file. If ends with ".txt" or ".log", assumed to be a file name. Otherwise, logs will ...
Initialize logger and set its verbosity level to INFO. Args: output (str): a file name or a directory to save log. If None, will not save log file. If ends with ".txt" or ".log", assumed to be a file name. Otherwise, logs will be saved to `output/log.txt`. name (str): th...
setup_logger
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/deploy/logger.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/deploy/logger.py
Apache-2.0
def _get_save_image_name(self, output_dir, image_path): """ Get save image name from source image path. """ if not os.path.exists(output_dir): os.makedirs(output_dir) image_name = os.path.split(image_path)[-1] name, ext = os.path.splitext(image_name) r...
Get save image name from source image path.
_get_save_image_name
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/core/trainer.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/core/trainer.py
Apache-2.0
def get_categories(metric_type, anno_file=None, arch=None): """ Get class id to category id map and category id to category name map from annotation file. Args: metric_type (str): metric type, currently support 'coco'. anno_file (str): annotation file path """ if arch == 'keypoi...
Get class id to category id map and category id to category name map from annotation file. Args: metric_type (str): metric type, currently support 'coco'. anno_file (str): annotation file path
get_categories
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/category.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/category.py
Apache-2.0
def _mot_category(category='pedestrian'): """ Get class id to category id map and category id to category name map of mot dataset """ label_map = {category: 0} label_map = sorted(label_map.items(), key=lambda x: x[1]) cats = [l[0] for l in label_map] clsid2catid = {i: i for i in range(l...
Get class id to category id map and category id to category name map of mot dataset
_mot_category
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/category.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/category.py
Apache-2.0
def _coco17_category(): """ Get class id to category id map and category id to category name map of COCO2017 dataset """ clsid2catid = { 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10, 11: 11, ...
Get class id to category id map and category id to category name map of COCO2017 dataset
_coco17_category
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/category.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/category.py
Apache-2.0
def _dota_category(): """ Get class id to category id map and category id to category name map of dota dataset """ catid2name = { 0: 'background', 1: 'plane', 2: 'baseball-diamond', 3: 'bridge', 4: 'ground-track-field', 5: 'small-vehicle', 6: '...
Get class id to category id map and category id to category name map of dota dataset
_dota_category
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/category.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/category.py
Apache-2.0
def __getitem__(self, idx): """Prepare sample for training given the index.""" records = copy.deepcopy(self.db[idx]) records['image'] = cv2.imread(records['image_file'], cv2.IMREAD_COLOR | cv2.IMREAD_IGNORE_ORIENTATION) records['image'] = cv2.cvtColo...
Prepare sample for training given the index.
__getitem__
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/keypoint_coco.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/keypoint_coco.py
Apache-2.0
def policy_v0(): """Autoaugment policy that was used in AutoAugment Detection Paper.""" # Each tuple is an augmentation operation of the form # (operation, probability, magnitude). Each element in policy is a # sub-policy that will be applied sequentially on the image. policy = [ [('Translat...
Autoaugment policy that was used in AutoAugment Detection Paper.
policy_v0
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def policy_v2(): """Additional policy that performs well on object detection.""" # Each tuple is an augmentation operation of the form # (operation, probability, magnitude). Each element in policy is a # sub-policy that will be applied sequentially on the image. policy = [ [('Color', 0.0, 6)...
Additional policy that performs well on object detection.
policy_v2
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def policy_v3(): """"Additional policy that performs well on object detection.""" # Each tuple is an augmentation operation of the form # (operation, probability, magnitude). Each element in policy is a # sub-policy that will be applied sequentially on the image. policy = [ [('Posterize', 0....
"Additional policy that performs well on object detection.
policy_v3
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def blend(image1, image2, factor): """Blend image1 and image2 using 'factor'. Factor can be above 0.0. A value of 0.0 means only image1 is used. A value of 1.0 means only image2 is used. A value between 0.0 and 1.0 means we linearly interpolate the pixel values between the two images. A va...
Blend image1 and image2 using 'factor'. Factor can be above 0.0. A value of 0.0 means only image1 is used. A value of 1.0 means only image2 is used. A value between 0.0 and 1.0 means we linearly interpolate the pixel values between the two images. A value greater than 1.0 "extrapolates" the di...
blend
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def cutout(image, pad_size, replace=0): """Apply cutout (https://arxiv.org/abs/1708.04552) to image. This operation applies a (2*pad_size x 2*pad_size) mask of zeros to a random location within `img`. The pixel values filled in will be of the value `replace`. The located where the mask will be applied ...
Apply cutout (https://arxiv.org/abs/1708.04552) to image. This operation applies a (2*pad_size x 2*pad_size) mask of zeros to a random location within `img`. The pixel values filled in will be of the value `replace`. The located where the mask will be applied is randomly chosen uniformly over the whole...
cutout
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def rotate(image, degrees, replace): """Rotates the image by degrees either clockwise or counterclockwise. Args: image: An image Tensor of type uint8. degrees: Float, a scalar angle in degrees to rotate all images by. If degrees is positive the image will be rotated clockwise otherw...
Rotates the image by degrees either clockwise or counterclockwise. Args: image: An image Tensor of type uint8. degrees: Float, a scalar angle in degrees to rotate all images by. If degrees is positive the image will be rotated clockwise otherwise it will be rotated countercl...
rotate
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def random_shift_bbox(image, bbox, pixel_scaling, replace, new_min_bbox_coords=None): """Move the bbox and the image content to a slightly new random location. Args: image: 3D uint8 Tensor. bbox: 1D Tensor t...
Move the bbox and the image content to a slightly new random location. Args: image: 3D uint8 Tensor. bbox: 1D Tensor that has 4 elements (min_y, min_x, max_y, max_x) of type float that represents the normalized coordinates between 0 and 1. The potential values for the new mi...
random_shift_bbox
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def mask_and_add_image(min_y_, min_x_, max_y_, max_x_, mask, content_tensor, image_): """Applies mask to bbox region in image then adds content_tensor to it.""" mask = np.pad(mask, [[min_y_, (image_height - 1) - max_y_], [min_x_, (image_width - 1) ...
Applies mask to bbox region in image then adds content_tensor to it.
mask_and_add_image
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def _clip_bbox(min_y, min_x, max_y, max_x): """Clip bounding box coordinates between 0 and 1. Args: min_y: Normalized bbox coordinate of type float between 0 and 1. min_x: Normalized bbox coordinate of type float between 0 and 1. max_y: Normalized bbox coordinate of type float between 0...
Clip bounding box coordinates between 0 and 1. Args: min_y: Normalized bbox coordinate of type float between 0 and 1. min_x: Normalized bbox coordinate of type float between 0 and 1. max_y: Normalized bbox coordinate of type float between 0 and 1. max_x: Normalized bbox coordinate o...
_clip_bbox
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def _check_bbox_area(min_y, min_x, max_y, max_x, delta=0.05): """Adjusts bbox coordinates to make sure the area is > 0. Args: min_y: Normalized bbox coordinate of type float between 0 and 1. min_x: Normalized bbox coordinate of type float between 0 and 1. max_y: Normalized bbox coordina...
Adjusts bbox coordinates to make sure the area is > 0. Args: min_y: Normalized bbox coordinate of type float between 0 and 1. min_x: Normalized bbox coordinate of type float between 0 and 1. max_y: Normalized bbox coordinate of type float between 0 and 1. max_x: Normalized bbox coor...
_check_bbox_area
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def _apply_bbox_augmentation(image, bbox, augmentation_func, *args): """Applies augmentation_func to the subsection of image indicated by bbox. Args: image: 3D uint8 Tensor. bbox: 1D Tensor that has 4 elements (min_y, min_x, max_y, max_x) of type float that represents the normalized...
Applies augmentation_func to the subsection of image indicated by bbox. Args: image: 3D uint8 Tensor. bbox: 1D Tensor that has 4 elements (min_y, min_x, max_y, max_x) of type float that represents the normalized coordinates between 0 and 1. augmentation_func: Augmentation functi...
_apply_bbox_augmentation
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def _concat_bbox(bbox, bboxes): """Helper function that concates bbox to bboxes along the first dimension.""" # Note if all elements in bboxes are -1 (_INVALID_BOX), then this means # we discard bboxes and start the bboxes Tensor with the current bbox. bboxes_sum_check = np.sum(bboxes) bbox = np.ex...
Helper function that concates bbox to bboxes along the first dimension.
_concat_bbox
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def _apply_bbox_augmentation_wrapper(image, bbox, new_bboxes, prob, augmentation_func, func_changes_bbox, *args): """Applies _apply_bbox_augmentation with probability prob. Args: image: 3D uint8 Tensor. bbox: 1D Tensor th...
Applies _apply_bbox_augmentation with probability prob. Args: image: 3D uint8 Tensor. bbox: 1D Tensor that has 4 elements (min_y, min_x, max_y, max_x) of type float that represents the normalized coordinates between 0 and 1. new_bboxes: 2D Tensor that is a list of the bboxes in ...
_apply_bbox_augmentation_wrapper
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def _apply_multi_bbox_augmentation(image, bboxes, prob, aug_func, func_changes_bbox, *args): """Applies aug_func to the image for each bbox in bboxes. Args: image: 3D uint8 Tensor. bboxes: 2D Tensor that is a list of the bboxes in the image. Each bbox ...
Applies aug_func to the image for each bbox in bboxes. Args: image: 3D uint8 Tensor. bboxes: 2D Tensor that is a list of the bboxes in the image. Each bbox has 4 elements (min_y, min_x, max_y, max_x) of type float. prob: Float that is the probability of applying aug_func to a sp...
_apply_multi_bbox_augmentation
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def _apply_multi_bbox_augmentation_wrapper(image, bboxes, prob, aug_func, func_changes_bbox, *args): """Checks to be sure num bboxes > 0 before calling inner function.""" num_bboxes = len(bboxes) new_image = deepcopy(image) new_bboxes = deepcopy(bboxes) if ...
Checks to be sure num bboxes > 0 before calling inner function.
_apply_multi_bbox_augmentation_wrapper
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def rotate_only_bboxes(image, bboxes, prob, degrees, replace): """Apply rotate to each bbox in the image with probability prob.""" func_changes_bbox = False prob = _scale_bbox_only_op_probability(prob) return _apply_multi_bbox_augmentation_wrapper( image, bboxes, prob, rotate, func_changes_bbox,...
Apply rotate to each bbox in the image with probability prob.
rotate_only_bboxes
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def shear_x_only_bboxes(image, bboxes, prob, level, replace): """Apply shear_x to each bbox in the image with probability prob.""" func_changes_bbox = False prob = _scale_bbox_only_op_probability(prob) return _apply_multi_bbox_augmentation_wrapper( image, bboxes, prob, shear_x, func_changes_bbox...
Apply shear_x to each bbox in the image with probability prob.
shear_x_only_bboxes
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def shear_y_only_bboxes(image, bboxes, prob, level, replace): """Apply shear_y to each bbox in the image with probability prob.""" func_changes_bbox = False prob = _scale_bbox_only_op_probability(prob) return _apply_multi_bbox_augmentation_wrapper( image, bboxes, prob, shear_y, func_changes_bbox...
Apply shear_y to each bbox in the image with probability prob.
shear_y_only_bboxes
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def translate_x_only_bboxes(image, bboxes, prob, pixels, replace): """Apply translate_x to each bbox in the image with probability prob.""" func_changes_bbox = False prob = _scale_bbox_only_op_probability(prob) return _apply_multi_bbox_augmentation_wrapper( image, bboxes, prob, translate_x, func...
Apply translate_x to each bbox in the image with probability prob.
translate_x_only_bboxes
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def translate_y_only_bboxes(image, bboxes, prob, pixels, replace): """Apply translate_y to each bbox in the image with probability prob.""" func_changes_bbox = False prob = _scale_bbox_only_op_probability(prob) return _apply_multi_bbox_augmentation_wrapper( image, bboxes, prob, translate_y, func...
Apply translate_y to each bbox in the image with probability prob.
translate_y_only_bboxes
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def flip_only_bboxes(image, bboxes, prob): """Apply flip_lr to each bbox in the image with probability prob.""" func_changes_bbox = False prob = _scale_bbox_only_op_probability(prob) return _apply_multi_bbox_augmentation_wrapper(image, bboxes, prob, np.f...
Apply flip_lr to each bbox in the image with probability prob.
flip_only_bboxes
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def solarize_only_bboxes(image, bboxes, prob, threshold): """Apply solarize to each bbox in the image with probability prob.""" func_changes_bbox = False prob = _scale_bbox_only_op_probability(prob) return _apply_multi_bbox_augmentation_wrapper( image, bboxes, prob, solarize, func_changes_bbox, ...
Apply solarize to each bbox in the image with probability prob.
solarize_only_bboxes
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def equalize_only_bboxes(image, bboxes, prob): """Apply equalize to each bbox in the image with probability prob.""" func_changes_bbox = False prob = _scale_bbox_only_op_probability(prob) return _apply_multi_bbox_augmentation_wrapper(image, bboxes, prob, ...
Apply equalize to each bbox in the image with probability prob.
equalize_only_bboxes
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def cutout_only_bboxes(image, bboxes, prob, pad_size, replace): """Apply cutout to each bbox in the image with probability prob.""" func_changes_bbox = False prob = _scale_bbox_only_op_probability(prob) return _apply_multi_bbox_augmentation_wrapper( image, bboxes, prob, cutout, func_changes_bbox...
Apply cutout to each bbox in the image with probability prob.
cutout_only_bboxes
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def _rotate_bbox(bbox, image_height, image_width, degrees): """Rotates the bbox coordinated by degrees. Args: bbox: 1D Tensor that has 4 elements (min_y, min_x, max_y, max_x) of type float that represents the normalized coordinates between 0 and 1. image_height: Int, height of the i...
Rotates the bbox coordinated by degrees. Args: bbox: 1D Tensor that has 4 elements (min_y, min_x, max_y, max_x) of type float that represents the normalized coordinates between 0 and 1. image_height: Int, height of the image. image_width: Int, height of the image. degree...
_rotate_bbox
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def translate_x(image, pixels, replace): """Equivalent of PIL Translate in X dimension.""" image = Image.fromarray(wrap(image)) image = image.transform(image.size, Image.AFFINE, (1, 0, pixels, 0, 1, 0)) return unwrap(np.array(image), replace)
Equivalent of PIL Translate in X dimension.
translate_x
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def translate_y(image, pixels, replace): """Equivalent of PIL Translate in Y dimension.""" image = Image.fromarray(wrap(image)) image = image.transform(image.size, Image.AFFINE, (1, 0, 0, 0, 1, pixels)) return unwrap(np.array(image), replace)
Equivalent of PIL Translate in Y dimension.
translate_y
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def _shift_bbox(bbox, image_height, image_width, pixels, shift_horizontal): """Shifts the bbox coordinates by pixels. Args: bbox: 1D Tensor that has 4 elements (min_y, min_x, max_y, max_x) of type float that represents the normalized coordinates between 0 and 1. image_height: Int, h...
Shifts the bbox coordinates by pixels. Args: bbox: 1D Tensor that has 4 elements (min_y, min_x, max_y, max_x) of type float that represents the normalized coordinates between 0 and 1. image_height: Int, height of the image. image_width: Int, width of the image. pixels: A...
_shift_bbox
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def translate_bbox(image, bboxes, pixels, replace, shift_horizontal): """Equivalent of PIL Translate in X/Y dimension that shifts image and bbox. Args: image: 3D uint8 Tensor. bboxes: 2D Tensor that is a list of the bboxes in the image. Each bbox has 4 elements (min_y, min_x, max_y,...
Equivalent of PIL Translate in X/Y dimension that shifts image and bbox. Args: image: 3D uint8 Tensor. bboxes: 2D Tensor that is a list of the bboxes in the image. Each bbox has 4 elements (min_y, min_x, max_y, max_x) of type float with values between [0, 1]. pixels:...
translate_bbox
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def shear_x(image, level, replace): """Equivalent of PIL Shearing in X dimension.""" # Shear parallel to x axis is a projective transform # with a matrix form of: # [1 level # 0 1]. image = Image.fromarray(wrap(image)) image = image.transform(image.size, Image.AFFINE, (1, level, 0, ...
Equivalent of PIL Shearing in X dimension.
shear_x
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def shear_y(image, level, replace): """Equivalent of PIL Shearing in Y dimension.""" # Shear parallel to y axis is a projective transform # with a matrix form of: # [1 0 # level 1]. image = Image.fromarray(wrap(image)) image = image.transform(image.size, Image.AFFINE, (1, 0, 0, leve...
Equivalent of PIL Shearing in Y dimension.
shear_y
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def _shear_bbox(bbox, image_height, image_width, level, shear_horizontal): """Shifts the bbox according to how the image was sheared. Args: bbox: 1D Tensor that has 4 elements (min_y, min_x, max_y, max_x) of type float that represents the normalized coordinates between 0 and 1. imag...
Shifts the bbox according to how the image was sheared. Args: bbox: 1D Tensor that has 4 elements (min_y, min_x, max_y, max_x) of type float that represents the normalized coordinates between 0 and 1. image_height: Int, height of the image. image_width: Int, height of the image....
_shear_bbox
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def shear_with_bboxes(image, bboxes, level, replace, shear_horizontal): """Applies Shear Transformation to the image and shifts the bboxes. Args: image: 3D uint8 Tensor. bboxes: 2D Tensor that is a list of the bboxes in the image. Each bbox has 4 elements (min_y, min_x, max_y, max_x...
Applies Shear Transformation to the image and shifts the bboxes. Args: image: 3D uint8 Tensor. bboxes: 2D Tensor that is a list of the bboxes in the image. Each bbox has 4 elements (min_y, min_x, max_y, max_x) of type float with values between [0, 1]. level: Float. H...
shear_with_bboxes
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def autocontrast(image): """Implements Autocontrast function from PIL. Args: image: A 3D uint8 tensor. Returns: The image after it has had autocontrast applied to it and will be of type uint8. """ def scale_channel(image): """Scale the 2D image using the autocontra...
Implements Autocontrast function from PIL. Args: image: A 3D uint8 tensor. Returns: The image after it has had autocontrast applied to it and will be of type uint8.
autocontrast
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def scale_channel(image): """Scale the 2D image using the autocontrast rule.""" # A possibly cheaper version can be done using cumsum/unique_with_counts # over the histogram values, rather than iterating over the entire image. # to compute mins and maxes. lo = float(np.min(image)...
Scale the 2D image using the autocontrast rule.
scale_channel
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def equalize(image): """Implements Equalize function from PIL using.""" def scale_channel(im, c): """Scale the data in the channel to implement equalize.""" im = im[:, :, c].astype(np.int32) # Compute the histogram of the image channel. histo, _ = np.histogram(im, range=[0, 255]...
Implements Equalize function from PIL using.
equalize
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def scale_channel(im, c): """Scale the data in the channel to implement equalize.""" im = im[:, :, c].astype(np.int32) # Compute the histogram of the image channel. histo, _ = np.histogram(im, range=[0, 255], bins=256) # For the purposes of computing the step, filter out the non...
Scale the data in the channel to implement equalize.
scale_channel
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def wrap(image): """Returns 'image' with an extra channel set to all 1s.""" shape = image.shape extended_channel = 255 * np.ones([shape[0], shape[1], 1], image.dtype) extended = np.concatenate([image, extended_channel], 2).astype(image.dtype) return extended
Returns 'image' with an extra channel set to all 1s.
wrap
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def unwrap(image, replace): """Unwraps an image produced by wrap. Where there is a 0 in the last channel for every spatial position, the rest of the three channels in that spatial dimension are grayed (set to 128). Operations like translate and shear on a wrapped Tensor will leave 0s in empty lo...
Unwraps an image produced by wrap. Where there is a 0 in the last channel for every spatial position, the rest of the three channels in that spatial dimension are grayed (set to 128). Operations like translate and shear on a wrapped Tensor will leave 0s in empty locations. Some transformations lo...
unwrap
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def _cutout_inside_bbox(image, bbox, pad_fraction): """Generates cutout mask and the mean pixel value of the bbox. First a location is randomly chosen within the image as the center where the cutout mask will be applied. Note this can be towards the boundaries of the image, so the full cutout mask may ...
Generates cutout mask and the mean pixel value of the bbox. First a location is randomly chosen within the image as the center where the cutout mask will be applied. Note this can be towards the boundaries of the image, so the full cutout mask may not be applied. Args: image: 3D uint8 Tensor. ...
_cutout_inside_bbox
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def bbox_cutout(image, bboxes, pad_fraction, replace_with_mean): """Applies cutout to the image according to bbox information. This is a cutout variant that using bbox information to make more informed decisions on where to place the cutout mask. Args: image: 3D uint8 Tensor. bboxes: 2...
Applies cutout to the image according to bbox information. This is a cutout variant that using bbox information to make more informed decisions on where to place the cutout mask. Args: image: 3D uint8 Tensor. bboxes: 2D Tensor that is a list of the bboxes in the image. Each bbox ...
bbox_cutout
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def apply_bbox_cutout(image, bboxes, pad_fraction): """Applies cutout to a single bounding box within image.""" # Choose a single bounding box to apply cutout to. random_index = np.random.randint(0, bboxes.shape[0], dtype=np.int32) # Select the corresponding bbox and apply cutout. ...
Applies cutout to a single bounding box within image.
apply_bbox_cutout
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def _randomly_negate_tensor(tensor): """With 50% prob turn the tensor negative.""" should_flip = np.floor(np.random.rand() + 0.5) >= 1 final_tensor = tensor if should_flip else -tensor return final_tensor
With 50% prob turn the tensor negative.
_randomly_negate_tensor
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def _shrink_level_to_arg(level): """Converts level to ratio by which we shrink the image content.""" if level == 0: return (1.0, ) # if level is zero, do not shrink the image # Maximum shrinking ratio is 2.9. level = 2. / (_MAX_LEVEL / level) + 0.9 return (level, )
Converts level to ratio by which we shrink the image content.
_shrink_level_to_arg
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def bbox_wrapper(func): """Adds a bboxes function argument to func and returns unchanged bboxes.""" def wrapper(images, bboxes, *args, **kwargs): return (func(images, *args, **kwargs), bboxes) return wrapper
Adds a bboxes function argument to func and returns unchanged bboxes.
bbox_wrapper
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def _parse_policy_info(name, prob, level, replace_value, augmentation_hparams): """Return the function that corresponds to `name` and update `level` param.""" func = NAME_TO_FUNC[name] args = level_to_arg(augmentation_hparams)[name](level) # Check to see if prob is passed into function. This is used fo...
Return the function that corresponds to `name` and update `level` param.
_parse_policy_info
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def _apply_func_with_prob(func, image, args, prob, bboxes): """Apply `func` to image w/ `args` as input with probability `prob`.""" assert isinstance(args, tuple) assert 'bboxes' == inspect.getfullargspec(func)[0][1] # If prob is a function argument, then this randomness is being handled # inside t...
Apply `func` to image w/ `args` as input with probability `prob`.
_apply_func_with_prob
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def select_and_apply_random_policy(policies, image, bboxes): """Select a random policy from `policies` and apply it to `image`.""" policy_to_select = np.random.randint(0, len(policies), dtype=np.int32) # policy_to_select = 6 # for test for (i, policy) in enumerate(policies): if i == policy_to_se...
Select a random policy from `policies` and apply it to `image`.
select_and_apply_random_policy
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def build_and_apply_nas_policy(policies, image, bboxes, augmentation_hparams): """Build a policy from the given policies passed in and apply to image. Args: policies: list of lists of tuples in the form `(func, prob, level)`, `func` is a string name of the augmentation function, `prob` is t...
Build a policy from the given policies passed in and apply to image. Args: policies: list of lists of tuples in the form `(func, prob, level)`, `func` is a string name of the augmentation function, `prob` is the probability of applying the `func` operation, `level` is the input argu...
build_and_apply_nas_policy
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def distort_image_with_autoaugment(image, bboxes, augmentation_name): """Applies the AutoAugment policy to `image` and `bboxes`. Args: image: `Tensor` of shape [height, width, 3] representing an image. bboxes: `Tensor` of shape [N, 4] representing ground truth boxes that are normali...
Applies the AutoAugment policy to `image` and `bboxes`. Args: image: `Tensor` of shape [height, width, 3] representing an image. bboxes: `Tensor` of shape [N, 4] representing ground truth boxes that are normalized between [0, 1]. augmentation_name: The name of the AutoAugment po...
distort_image_with_autoaugment
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/autoaugment_utils.py
Apache-2.0
def __call__(self, sample, context=None): """ Process a sample. Args: sample (dict): a dict of sample, eg: {'image':xx, 'label': xxx} context (dict): info about this sample processing Returns: result (dict): a processed sample """ if isinstance...
Process a sample. Args: sample (dict): a dict of sample, eg: {'image':xx, 'label': xxx} context (dict): info about this sample processing Returns: result (dict): a processed sample
__call__
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/operators.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/operators.py
Apache-2.0
def apply(self, sample, context=None): """ load image if 'im_file' field is not empty but 'image' is""" if 'image' not in sample: with open(sample['im_file'], 'rb') as f: sample['image'] = f.read() sample.pop('im_file') im = sample['image'] data =...
load image if 'im_file' field is not empty but 'image' is
apply
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/operators.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/operators.py
Apache-2.0
def __init__(self, mean=[0.485, 0.456, 0.406], std=[1, 1, 1], is_scale=True): """ Args: mean (list): the pixel mean std (list): the pixel variance """ super(NormalizeImage, self).__init__() self.mean = mea...
Args: mean (list): the pixel mean std (list): the pixel variance
__init__
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/operators.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/operators.py
Apache-2.0
def apply(self, sample, context=None): """Normalize the image. Operators: 1.(optional) Scale the image to [0,1] 2. Each pixel minus mean and is divided by std """ im = sample['image'] im = im.astype(np.float32, copy=False) mean = np.array(self.mean...
Normalize the image. Operators: 1.(optional) Scale the image to [0,1] 2. Each pixel minus mean and is divided by std
apply
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/operators.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/dataset/transform/operators.py
Apache-2.0
def get_infer_results(outs, catid, bias=0): """ Get result at the stage of inference. The output format is dictionary containing bbox or mask result. For example, bbox result is a list and each element contains image_id, category_id, bbox and score. """ if outs is None or len(outs) == 0: ...
Get result at the stage of inference. The output format is dictionary containing bbox or mask result. For example, bbox result is a list and each element contains image_id, category_id, bbox and score.
get_infer_results
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/metrics/coco_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/metrics/coco_utils.py
Apache-2.0
def cocoapi_eval(jsonfile, style, coco_gt=None, anno_file=None, max_dets=(100, 300, 1000), classwise=False, sigmas=None, use_area=True): """ Args: jsonfile (str): Evaluation json file, ...
Args: jsonfile (str): Evaluation json file, eg: bbox.json, mask.json. style (str): COCOeval style, can be `bbox` , `segm` , `proposal`, `keypoints` and `keypoints_crowd`. coco_gt (str): Whether to load COCOAPI through anno_file, eg: coco_gt = COCO(anno_file) anno_fi...
cocoapi_eval
python
PaddlePaddle/models
tutorials/pp-series/HRNet-Keypoint/lib/metrics/coco_utils.py
https://github.com/PaddlePaddle/models/blob/master/tutorials/pp-series/HRNet-Keypoint/lib/metrics/coco_utils.py
Apache-2.0