GraphAutoModel class

autokeras.auto_model.GraphAutoModel(inputs, outputs, name='graph_auto_model', max_trials=100, directory=None, seed=None)

A HyperModel defined by a graph of HyperBlocks.

GraphAutoModel is a subclass of HyperModel. Besides the HyperModel properties, it also has 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 user can specify the high-level neural architecture by connecting the HyperBlocks with the functional API, which is the same as the Keras functional API.


  • inputs: A list of or a HyperNode instances. The input node(s) of the GraphAutoModel.
  • outputs: A list of or a HyperNode instances. The output node(s) of the GraphAutoModel.
  • name: String. The name of the AutoModel. Defaults to 'graph_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.
  • seed: Int. Random seed.

GraphAutoModel methods


fit(x=None, y=None, validation_split=0, validation_data=None)

Search for the best model and hyperparameters for the AutoModel.

It will search for the best model based on the performances on validation data.


  • x: numpy.ndarray or tensorflow.Dataset. Training data x.
  • y: numpy.ndarray or tensorflow.Dataset. Training data y.
  • validation_split: Float between 0 and 1. 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.
  • 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. validation_data could be:

    • tuple (x_val, y_val) of Numpy arrays or tensors
    • tuple (x_val, y_val, val_sample_weights) of Numpy arrays
    • dataset or a dataset iterator

    For the first two cases, batch_size must be provided. For the last case, validation_steps must be provided.

  • **kwargs: Any arguments supported by


predict(x, batch_size=32)

Predict the output for a given testing data.


  • x: or numpy.ndarray. Testing data.
  • batch_size: Int. Defaults to 32.
  • **kwargs: Any arguments supported by keras.Model.predict.