class_docstr: A Model defined by inputs and outputs.
  AutoModel combines a HyperModel and a Tuner to tune the HyperModel.
  The user can use it in a similar way to a Keras model since it
  also has `fit()` and  `predict()` methods.
  
  The AutoModel has two use cases. In the first case, the user only specifies
  the input nodes and output heads of the AutoModel. The AutoModel infers the
  rest part of the model. In the second case, user can specify the high-level
  architecture of the AutoModel by connecting the Blocks with the functional
  API, which is the same as the Keras
  [functional API](https://www.tensorflow.org/guide/keras/functional).
  
  # Example
  ```python
      # The user only specifies the input nodes and output heads.
      import autokeras as ak
      ak.AutoModel(
          inputs=[ak.ImageInput(), ak.TextInput()],
          outputs=[ak.ClassificationHead(), ak.RegressionHead()]
      )
  ```
  ```python
      # The user specifies the high-level architecture.
      import autokeras as ak
      image_input = ak.ImageInput()
      image_output = ak.ImageBlock()(image_input)
      text_input = ak.TextInput()
      text_output = ak.TextBlock()(text_input)
      output = ak.Merge()([image_output, text_output])
      classification_output = ak.ClassificationHead()(output)
      regression_output = ak.RegressionHead()(output)
      ak.AutoModel(
          inputs=[image_input, text_input],
          outputs=[classification_output, regression_output]
      )
  ```
  
  # Arguments
      inputs: A list of Node instances.
          The input node(s) of the AutoModel.
      outputs: A list of Node or Head instances.
          The output node(s) or head(s) of the AutoModel.
      project_name: String. The name of the AutoModel. Defaults to
          'auto_model'.
      max_trials: Int. The maximum number of different Keras Models to try.
          The search may finish before reaching the max_trials. Defaults to
          100.
      directory: String. The path to a directory for storing the search
          outputs. Defaults to None, which would create a folder with the
          name of the AutoModel in the current directory.
      objective: String. Name of model metric to minimize
          or maximize, e.g. 'val_accuracy'. Defaults to 'val_loss'.
      tuner: String or subclass of AutoTuner. If string, it should be one of
          'greedy', 'bayesian', 'hyperband' or 'random'. It can also be a
          subclass of AutoTuner. Defaults to 'greedy'.
      overwrite: Boolean. Defaults to `False`. If `False`, reloads an existing
          project of the same name if one is found. Otherwise, overwrites the
          project.
      seed: Int. Random seed.
      max_model_size: Int. Maximum number of scalars in the parameters of a
          model. Models larger than this are rejected.
      **kwargs: Any arguments supported by keras_tuner.Tuner.
class_docstr_tok: ["A","Model","defined","by","inputs","and","outputs",".","AutoModel","combines","a","HyperModel","and","a","Tuner","to","tune","the","HyperModel",".","The","user","can","use","it","in","a","similar","way","to","a","Keras","model","since","it","also","has","`","fit","(",")","`","and","`","predict","(",")","`","methods",".","The","AutoModel","has","two","use","cases",".","In","the","first","case",",","the","user","only","specifies","the","input","nodes","and","output","heads","of","the","AutoModel",".","The","AutoModel","infers","the","rest","part","of","the","model",".","In","the","second","case",",","user","can","specify","the","high-level","architecture","of","the","AutoModel","by","connecting","the","Blocks","with","the","functional","API",",","which","is","the","same","as","the","Keras","[","functional","API","]","(","https",":","\/\/www.tensorflow.org\/guide\/keras\/functional",")",".","#","Example","``","`","python","#","The","user","only","specifies","the","input","nodes","and","output","heads",".","import","autokeras","as","ak","ak.AutoModel","(","inputs=","[","ak.ImageInput","(",")",",","ak.TextInput","(",")","]",",","outputs=","[","ak.ClassificationHead","(",")",",","ak.RegressionHead","(",")","]",")","``","`","``","`","python","#","The","user","specifies","the","high-level","architecture",".","import","autokeras","as","ak","image_input","=","ak.ImageInput","(",")","image_output","=","ak.ImageBlock","(",")","(","image_input",")","text_input","=","ak.TextInput","(",")","text_output","=","ak.TextBlock","(",")","(","text_input",")","output","=","ak.Merge","(",")","(","[","image_output",",","text_output","]",")","classification_output","=","ak.ClassificationHead","(",")","(","output",")","regression_output","=","ak.RegressionHead","(",")","(","output",")","ak.AutoModel","(","inputs=","[","image_input",",","text_input","]",",","outputs=","[","classification_output",",","regression_output","]",")","``","`","#","Arguments","inputs",":","A","list","of","Node","instances",".","The","input","node","(","s",")","of","the","AutoModel",".","outputs",":","A","list","of","Node","or","Head","instances",".","The","output","node","(","s",")","or","head","(","s",")","of","the","AutoModel",".","project_name",":","String",".","The","name","of","the","AutoModel",".","Defaults","to","'auto_model","'",".","max_trials",":","Int",".","The","maximum","number","of","different","Keras","Models","to","try",".","The","search","may","finish","before","reaching","the","max_trials",".","Defaults","to","100.","directory",":","String",".","The","path","to","a","directory","for","storing","the","search","outputs",".","Defaults","to","None",",","which","would","create","a","folder","with","the","name","of","the","AutoModel","in","the","current","directory",".","objective",":","String",".","Name","of","model","metric","to","minimize","or","maximize",",","e.g",".","'val_accuracy","'",".","Defaults","to","'val_loss","'",".","tuner",":","String","or","subclass","of","AutoTuner",".","If","string",",","it","should","be","one","of","'greedy","'",",","'bayesian","'",",","'hyperband","'","or","'random","'",".","It","can","also","be","a","subclass","of","AutoTuner",".","Defaults","to","'greedy","'",".","overwrite",":","Boolean",".","Defaults","to","`","False","`",".","If","`","False","`",",","reloads","an","existing","project","of","the","same","name","if","one","is","found",".","Otherwise",",","overwrites","the","project",".","seed",":","Int",".","Random","seed",".","max_model_size",":","Int",".","Maximum","number","of","scalars","in","the","parameters","of","a","model",".","Models","larger","than","this","are","rejected",".","*","*","kwargs",":","Any","arguments","supported","by","keras_tuner.Tuner","."]
docstr: Search for the best model and hyperparameters for the AutoModel.
  
  It will search for the best model based on the performances on
  validation data.
  
  # Arguments
      x: numpy.ndarray or tensorflow.Dataset. Training data x.
      y: numpy.ndarray or tensorflow.Dataset. Training data y.
      batch_size: Int. Number of samples per gradient update. Defaults to
          32.
      epochs: Int. The number of epochs to train each model during the
          search. If unspecified, by default we train for a maximum of
          1000 epochs, but we stop training if the validation loss stops
          improving for 10 epochs (unless you specified an EarlyStopping
          callback as part of the callbacks argument, in which case the
          EarlyStopping callback you specified will determine early
          stopping).
      callbacks: List of Keras callbacks to apply during training and
          validation.
      validation_split: Float between 0 and 1. Defaults to 0.2.
          Fraction of the training data to be used as validation data.
          The model will set apart this fraction of the training data,
          will not train on it, and will evaluate the loss and any model
          metrics on this data at the end of each epoch.  The validation
          data is selected from the last samples in the `x` and `y` data
          provided, before shuffling. This argument is not supported when
          `x` is a dataset. The best model found would be fit on the
          entire dataset including the validation data.
      validation_data: Data on which to evaluate the loss and any model
          metrics at the end of each epoch. The model will not be trained
          on this data. `validation_data` will override
          `validation_split`. The type of the validation data should be
          the same as the training data. The best model found would be
          fit on the training dataset without the validation data.
      verbose: 0, 1, or 2. Verbosity mode. 0 = silent, 1 = progress bar,
          2 = one line per epoch. Note that the progress bar is not
          particularly useful when logged to a file, so verbose=2 is
          recommended when not running interactively (eg, in a production
          environment). Controls the verbosity of both KerasTuner search
          and
          [keras.Model.fit](https://www.tensorflow.org/api_docs/python/tf/keras/Model#fit)
      **kwargs: Any arguments supported by
          [keras.Model.fit](https://www.tensorflow.org/api_docs/python/tf/keras/Model#fit).
  
  # Returns
      history: A Keras History object corresponding to the best model.
          Its History.history attribute is a record of training
          loss values and metrics values at successive epochs, as well as
          validation loss values and validation metrics values (if
          applicable).
docstr_tok: ["Search","for","the","best","model","and","hyperparameters","for","the","AutoModel",".","It","will","search","for","the","best","model","based","on","the","performances","on","validation","data",".","#","Arguments","x",":","numpy.ndarray","or","tensorflow.Dataset",".","Training","data","x.","y",":","numpy.ndarray","or","tensorflow.Dataset",".","Training","data","y.","batch_size",":","Int",".","Number","of","samples","per","gradient","update",".","Defaults","to","32.","epochs",":","Int",".","The","number","of","epochs","to","train","each","model","during","the","search",".","If","unspecified",",","by","default","we","train","for","a","maximum","of","1000","epochs",",","but","we","stop","training","if","the","validation","loss","stops","improving","for","10","epochs","(","unless","you","specified","an","EarlyStopping","callback","as","part","of","the","callbacks","argument",",","in","which","case","the","EarlyStopping","callback","you","specified","will","determine","early","stopping",")",".","callbacks",":","List","of","Keras","callbacks","to","apply","during","training","and","validation",".","validation_split",":","Float","between","0","and","1",".","Defaults","to","0.2",".","Fraction","of","the","training","data","to","be","used","as","validation","data",".","The","model","will","set","apart","this","fraction","of","the","training","data",",","will","not","train","on","it",",","and","will","evaluate","the","loss","and","any","model","metrics","on","this","data","at","the","end","of","each","epoch",".","The","validation","data","is","selected","from","the","last","samples","in","the","`","x","`","and","`","y","`","data","provided",",","before","shuffling",".","This","argument","is","not","supported","when","`","x","`","is","a","dataset",".","The","best","model","found","would","be","fit","on","the","entire","dataset","including","the","validation","data",".","validation_data",":","Data","on","which","to","evaluate","the","loss","and","any","model","metrics","at","the","end","of","each","epoch",".","The","model","will","not","be","trained","on","this","data",".","`","validation_data","`","will","override","`","validation_split","`",".","The","type","of","the","validation","data","should","be","the","same","as","the","training","data",".","The","best","model","found","would","be","fit","on","the","training","dataset","without","the","validation","data",".","verbose",":","0",",","1",",","or","2",".","Verbosity","mode",".","0","=","silent",",","1","=","progress","bar",",","2","=","one","line","per","epoch",".","Note","that","the","progress","bar","is","not","particularly","useful","when","logged","to","a","file",",","so","verbose=2","is","recommended","when","not","running","interactively","(","eg",",","in","a","production","environment",")",".","Controls","the","verbosity","of","both","KerasTuner","search","and","[","keras.Model.fit","]","(","https",":","\/\/www.tensorflow.org\/api_docs\/python\/tf\/keras\/Model","#","fit",")","*","*","kwargs",":","Any","arguments","supported","by","[","keras.Model.fit","]","(","https",":","\/\/www.tensorflow.org\/api_docs\/python\/tf\/keras\/Model","#","fit",")",".","#","Returns","history",":","A","Keras","History","object","corresponding","to","the","best","model",".","Its","History.history","attribute","is","a","record","of","training","loss","values","and","metrics","values","at","successive","epochs",",","as","well","as","validation","loss","values","and","validation","metrics","values","(","if","applicable",")","."]
code: def fit(
      self,
      x=None,
      y=None,
      batch_size=32,
      epochs=None,
      callbacks=None,
      validation_split=0.2,
      validation_data=None,
      verbose=1,
      **kwargs,
  ):
      """Search for the best model and hyperparameters for the AutoModel.
  
      It will search for the best model based on the performances on
      validation data.
  
      # Arguments
          x: numpy.ndarray or tensorflow.Dataset. Training data x.
          y: numpy.ndarray or tensorflow.Dataset. Training data y.
          batch_size: Int. Number of samples per gradient update. Defaults to
              32.
          epochs: Int. The number of epochs to train each model during the
              search. If unspecified, by default we train for a maximum of
              1000 epochs, but we stop training if the validation loss stops
              improving for 10 epochs (unless you specified an EarlyStopping
              callback as part of the callbacks argument, in which case the
              EarlyStopping callback you specified will determine early
              stopping).
          callbacks: List of Keras callbacks to apply during training and
              validation.
          validation_split: Float between 0 and 1. Defaults to 0.2.
              Fraction of the training data to be used as validation data.
              The model will set apart this fraction of the training data,
              will not train on it, and will evaluate the loss and any model
              metrics on this data at the end of each epoch.  The validation
              data is selected from the last samples in the `x` and `y` data
              provided, before shuffling. This argument is not supported when
              `x` is a dataset. The best model found would be fit on the
              entire dataset including the validation data.
          validation_data: Data on which to evaluate the loss and any model
              metrics at the end of each epoch. The model will not be trained
              on this data. `validation_data` will override
              `validation_split`. The type of the validation data should be
              the same as the training data. The best model found would be
              fit on the training dataset without the validation data.
          verbose: 0, 1, or 2. Verbosity mode. 0 = silent, 1 = progress bar,
              2 = one line per epoch. Note that the progress bar is not
              particularly useful when logged to a file, so verbose=2 is
              recommended when not running interactively (eg, in a production
              environment). Controls the verbosity of both KerasTuner search
              and
              [keras.Model.fit](https://www.tensorflow.org/api_docs/python/tf/keras/Model#fit)
          **kwargs: Any arguments supported by
              [keras.Model.fit](https://www.tensorflow.org/api_docs/python/tf/keras/Model#fit).
  
      # Returns
          history: A Keras History object corresponding to the best model.
              Its History.history attribute is a record of training
              loss values and metrics values at successive epochs, as well as
              validation loss values and validation metrics values (if
              applicable).
      """
      # Check validation information.
      if not validation_data and not validation_split:
          raise ValueError(
              "Either validation_data or a non-zero validation_split "
              "should be provided."
          )
  
      if validation_data:
          validation_split = 0
  
      dataset, validation_data = self._convert_to_dataset(
          x=x,
          y=y,
          validation_data=validation_data,
          batch_size=batch_size,
      )
      self._analyze_data(dataset)
      self._build_hyper_pipeline(dataset)
  
      # Split the data with validation_split.
      if validation_data is None and validation_split:
          dataset, validation_data = data_utils.split_dataset(
              dataset, validation_split
          )
  
      history = self.tuner.search(
          x=dataset,
          epochs=epochs,
          callbacks=callbacks,
          validation_data=validation_data,
          validation_split=validation_split,
          verbose=verbose,
          **kwargs,
      )
  
      return history
  
imports: from pathlib import Path
  from typing import List
  from typing import Optional
  from typing import Type
  from typing import Union
  import numpy
  import tensorflow
  from tensorflow import keras
  from tensorflow import nest
  from autokeras import blocks
  from autokeras import graph
  from autokeras import pipeline
  from autokeras import tuners
  from autokeras.engine import head
  from autokeras.engine import node
  from autokeras.engine import tuner
  from autokeras.nodes import Input
  from autokeras.utils import data_utils
  from autokeras.utils import utils
label_desc: Use image node_id 8 for calling the AutoModel obj's underlying member method code with example usage: obj.fit(x, y, batch_size, epochs, callbacks, validation_split, validation_data, verbose) and returns: history