class_docstr: A image augmentation hypermodel.
  
  The `HyperImageAugment` class searches for the best combination of image
  augmentation operations in Keras preprocessing layers. The input shape of
  the model should be (height, width, channels). The output of the model is
  of the same shape as the input.
  
  Args:
      input_shape: Optional shape tuple, e.g. `(256, 256, 3)`.
      input_tensor: Optional Keras tensor (i.e. output of `layers.Input()`)
          to use as image input for the model.
      rotate: A number between [0, 1], a list of two numbers between [0, 1]
          or None. Configures the search space of the factor of random
          rotation transform in the augmentation. A factor is chosen for each
          trial. It sets maximum of clockwise and counterclockwise rotation
          in terms of fraction of pi, among all samples in the trial.
          Default is 0.5. When `rotate` is a single number, the search range
          is [0, `rotate`].
          The transform is off when set to None.
      translate_x: A number between [0, 1], a list of two numbers between
          [0, 1] or None. Configures the search space of the factor of random
          horizontal translation transform in the augmentation. A factor is
          chosen for each trial. It sets maximum of horizontal translation in
          terms of ratio over the width among all samples in the trial.
          Default is 0.4. When `translate_x` is a single number, the search
          range is [0, `translate_x`].
          The transform is off when set to None.
      translate_y: A number between [0, 1], a list of two numbers between
          [0, 1] or None. Configures the search space of the factor of random
          vertical translation transform in the augmentation. A factor is
          chosen for each trial. It sets maximum of vertical translation in
          terms of ratio over the height among all samples in the trial.
          Default is 0.4. When `translate_y` is a single number ,the search
          range is [0, `translate_y`].  The transform is off when set to None.
      contrast: A number between [0, 1], a list of two numbers between [0, 1]
          or None. Configures the search space of the factor of random
          contrast transform in the augmentation. A factor is chosen for each
          trial. It sets maximum ratio of contrast change among all samples in
          the trial. Default is 0.3. When `contrast` is a single number, the
          search rnage is [0, `contrast`].
          The transform is off when set to None.
      augment_layers: None, int or list of two ints, controlling the number
          of augment applied. Default is 3.
          When `augment_layers` is 0, all transform are applied sequentially.
          When `augment_layers` is nonzero, or a list of two ints, a simple
          version of RandAugment(https://arxiv.org/abs/1909.13719) is used.
          A search space for 'augment_layers' is created to search [0,
          `augment_layers`], or between the two ints if a `augment_layers` is
          a list. For each trial, the hyperparameter 'augment_layers'
          determines number of layers of augment transforms are applied,
          each randomly picked from all available transform types with equal
          probability on each sample.
      **kwargs: Additional keyword arguments that apply to all hypermodels.
          See `keras_tuner.HyperModel`.
  
  Example:
  
  ```python
  hm_aug = HyperImageAugment(input_shape=(32, 32, 3),
                             augment_layers=0,
                             rotate=[0.2, 0.3],
                             translate_x=0.1,
                             translate_y=None,
                             contrast=None)
  ```
  
  Then the hypermodel `hm_aug` will search 'factor_rotate' between [0.2, 0.3]
  and 'factor_translate_x' between [0, 0.1]. These two augments are applied
  on all samples with factor picked per each trial.
  
  ```python
  hm_aug = HyperImageAugment(input_shape=(32, 32, 3),
                             translate_x=0.5,
                             translate_y=[0.2, 0.4]
                             contrast=None)
  ```
  
  Then the hypermodel `hm_aug` will search 'factor_rotate' between [0, 0.2],
  'factor_translate_x' between [0, 0.5], 'factor_translate_y' between
  [0.2, 0.4]. It will use RandAugment, searching 'augment_layers'
  between [0, 3]. Each layer on each sample will be chosen from rotate,
  translate_x and translate_y.
class_docstr_tok: ["A","image","augmentation","hypermodel",".","The","`","HyperImageAugment","`","class","searches","for","the","best","combination","of","image","augmentation","operations","in","Keras","preprocessing","layers",".","The","input","shape","of","the","model","should","be","(","height",",","width",",","channels",")",".","The","output","of","the","model","is","of","the","same","shape","as","the","input",".","Args",":","input_shape",":","Optional","shape","tuple",",","e.g",".","`","(","256",",","256",",","3",")","`",".","input_tensor",":","Optional","Keras","tensor","(","i.e",".","output","of","`","layers.Input","(",")","`",")","to","use","as","image","input","for","the","model",".","rotate",":","A","number","between","[","0",",","1","]",",","a","list","of","two","numbers","between","[","0",",","1","]","or","None",".","Configures","the","search","space","of","the","factor","of","random","rotation","transform","in","the","augmentation",".","A","factor","is","chosen","for","each","trial",".","It","sets","maximum","of","clockwise","and","counterclockwise","rotation","in","terms","of","fraction","of","pi",",","among","all","samples","in","the","trial",".","Default","is","0.5",".","When","`","rotate","`","is","a","single","number",",","the","search","range","is","[","0",",","`","rotate","`","]",".","The","transform","is","off","when","set","to","None",".","translate_x",":","A","number","between","[","0",",","1","]",",","a","list","of","two","numbers","between","[","0",",","1","]","or","None",".","Configures","the","search","space","of","the","factor","of","random","horizontal","translation","transform","in","the","augmentation",".","A","factor","is","chosen","for","each","trial",".","It","sets","maximum","of","horizontal","translation","in","terms","of","ratio","over","the","width","among","all","samples","in","the","trial",".","Default","is","0.4",".","When","`","translate_x","`","is","a","single","number",",","the","search","range","is","[","0",",","`","translate_x","`","]",".","The","transform","is","off","when","set","to","None",".","translate_y",":","A","number","between","[","0",",","1","]",",","a","list","of","two","numbers","between","[","0",",","1","]","or","None",".","Configures","the","search","space","of","the","factor","of","random","vertical","translation","transform","in","the","augmentation",".","A","factor","is","chosen","for","each","trial",".","It","sets","maximum","of","vertical","translation","in","terms","of","ratio","over","the","height","among","all","samples","in","the","trial",".","Default","is","0.4",".","When","`","translate_y","`","is","a","single","number",",","the","search","range","is","[","0",",","`","translate_y","`","]",".","The","transform","is","off","when","set","to","None",".","contrast",":","A","number","between","[","0",",","1","]",",","a","list","of","two","numbers","between","[","0",",","1","]","or","None",".","Configures","the","search","space","of","the","factor","of","random","contrast","transform","in","the","augmentation",".","A","factor","is","chosen","for","each","trial",".","It","sets","maximum","ratio","of","contrast","change","among","all","samples","in","the","trial",".","Default","is","0.3",".","When","`","contrast","`","is","a","single","number",",","the","search","rnage","is","[","0",",","`","contrast","`","]",".","The","transform","is","off","when","set","to","None",".","augment_layers",":","None",",","int","or","list","of","two","ints",",","controlling","the","number","of","augment","applied",".","Default","is","3",".","When","`","augment_layers","`","is","0",",","all","transform","are","applied","sequentially",".","When","`","augment_layers","`","is","nonzero",",","or","a","list","of","two","ints",",","a","simple","version","of","RandAugment","(","https",":","\/\/arxiv.org\/abs\/1909.13719",")","is","used",".","A","search","space","for","'augment_layers","'","is","created","to","search","[","0",",","`","augment_layers","`","]",",","or","between","the","two","ints","if","a","`","augment_layers","`","is","a","list",".","For","each","trial",",","the","hyperparameter","'augment_layers'","determines","number","of","layers","of","augment","transforms","are","applied",",","each","randomly","picked","from","all","available","transform","types","with","equal","probability","on","each","sample",".","*","*","kwargs",":","Additional","keyword","arguments","that","apply","to","all","hypermodels",".","See","`","keras_tuner.HyperModel","`",".","Example",":","``","`","python","hm_aug","=","HyperImageAugment","(","input_shape=","(","32",",","32",",","3",")",",","augment_layers=0",",","rotate=","[","0.2",",","0.3","]",",","translate_x=0.1",",","translate_y=None",",","contrast=None",")","``","`","Then","the","hypermodel","`","hm_aug","`","will","search","'factor_rotate","'","between","[","0.2",",","0.3","]","and","'factor_translate_x","'","between","[","0",",","0.1","]",".","These","two","augments","are","applied","on","all","samples","with","factor","picked","per","each","trial",".","``","`","python","hm_aug","=","HyperImageAugment","(","input_shape=","(","32",",","32",",","3",")",",","translate_x=0.5",",","translate_y=","[","0.2",",","0.4","]","contrast=None",")","``","`","Then","the","hypermodel","`","hm_aug","`","will","search","'factor_rotate","'","between","[","0",",","0.2","]",",","'factor_translate_x","'","between","[","0",",","0.5","]",",","'factor_translate_y","'","between","[","0.2",",","0.4","]",".","It","will","use","RandAugment",",","searching","'augment_layers'","between","[","0",",","3","]",".","Each","layer","on","each","sample","will","be","chosen","from","rotate",",","translate_x","and","translate_y","."]
code: def __init__(
      self,
      input_shape=None,
      input_tensor=None,
      rotate=0.5,
      translate_x=0.4,
      translate_y=0.4,
      contrast=0.3,
      augment_layers=3,
      **kwargs,
  ):
      if input_shape is None and input_tensor is None:
          raise ValueError(
              "You must specify either `input_shape` or `input_tensor`."
          )
  
      self.transforms = []
      self._register_transform("rotate", rotate)
      self._register_transform("translate_x", translate_x)
      self._register_transform("translate_y", translate_y)
      self._register_transform("contrast", contrast)
  
      self.input_shape = input_shape
      self.input_tensor = input_tensor
  
      if augment_layers:
          self.model_name = "image_rand_augment"
          try:
              augment_layers_min = augment_layers[0]
              augment_layers_max = augment_layers[1]
          except TypeError:
              augment_layers_min = 0
              augment_layers_max = augment_layers
          if not (
              isinstance(augment_layers_min, int)
              and isinstance(augment_layers_max, int)
          ):
              raise ValueError(
                  "Keyword argument `augment_layers` must be int, "
                  f"but received {augment_layers}."
              )
  
          self.augment_layers_min = augment_layers_min
          self.augment_layers_max = augment_layers_max
      else:
          # Separatedly tune and apply all augment transforms if
          # `randaug_count` is set to 0.
          self.model_name = "image_augment"
  
      super().__init__(**kwargs)
  
file_path: keras-tuner/keras_tuner/applications/augment.py
imports: from keras_tuner.api_export import keras_tuner_export
  from keras_tuner.backend import keras
  from keras_tuner.backend import ops
  from keras_tuner.backend import random
  from keras_tuner.backend.keras import layers
  from keras_tuner.engine import hypermodel
label_desc: Use image node_id 1 to create a new HyperImageAugment object from inherited base classes: hypermodel with example: obj = HyperImageAugment(input_shape, input_tensor, rotate, translate_x, translate_y, contrast, augment_layers)