AutoModel class

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

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 user can specify the inputs and outputs of the AutoModel. It will infer the rest of the high-level neural architecture.


  • inputs: A list of or a HyperNode instance. The input node(s) of the AutoModel.
  • outputs: A list of or a HyperHead instance. The output head(s) of the AutoModel.
  • 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.
  • seed: Int. Random seed.

AutoModel 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.